forked from documize/community
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07c8238
commit c235fb5
Showing
9 changed files
with
819 additions
and
664 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package space | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/documize/community/core/uniqueid" | ||
"github.com/documize/community/domain/test" | ||
"github.com/documize/community/model/space" | ||
) | ||
|
||
//add a new space and get it. if the get returns the same space as the one just added it passes the test | ||
func TestAddSpace(t *testing.T) { | ||
//Setup - get the necessary info to add a space, generate a test space | ||
rt, s, ctx := test.SetupTest() | ||
var err error | ||
|
||
//Run test - Add a space to the DB, read it to make sure it was added correctly | ||
ctx.Transaction, err = rt.Db.Beginx() | ||
if err != nil { | ||
return | ||
} | ||
sp := space.Space{} | ||
sp.RefID = uniqueid.Generate() | ||
sp.OrgID = ctx.OrgID | ||
sp.Type = space.ScopePrivate | ||
sp.UserID = ctx.UserID | ||
sp.Name = "test" | ||
|
||
err = s.Space.Add(ctx, sp) | ||
if err != nil { | ||
ctx.Transaction.Rollback() | ||
return | ||
} | ||
ctx.Transaction.Commit() | ||
|
||
sp2, err := s.Space.Get(ctx, sp.RefID) | ||
if err != nil { | ||
return | ||
} | ||
|
||
if sp != sp2 { | ||
t.Errorf("Test Failed, space one (%v) does not match space 2(%v)", sp, sp2) | ||
} | ||
} | ||
|
||
// Function to create a space with an identifier, remove it and then try get it using that Identifier, if it doesnt get it, it is removed | ||
// func TestRemoveSpace(t *testing.T) { | ||
// //Setup - get the necessary info to add a space, generate a test space | ||
// rt, s, ctx := test.SetupTest() | ||
// var err error | ||
// println("marker 1") | ||
|
||
// //Run test - Add a space | ||
// ctx.Transaction, err = rt.Db.Beginx() | ||
// if err != nil { | ||
// return | ||
// } | ||
|
||
// println("marker 2") | ||
|
||
// sp := space.Space{} | ||
// sp.RefID = uniqueid.Generate() | ||
// sp.OrgID = ctx.OrgID | ||
// sp.Type = space.ScopePrivate | ||
// sp.UserID = ctx.UserID | ||
// sp.Name = "test-toBeDeleted" | ||
|
||
// println("marker 3") | ||
|
||
// err = s.Space.Add(ctx, sp) | ||
// if err != nil { | ||
// ctx.Transaction.Rollback() | ||
// return | ||
// } | ||
// ctx.Transaction.Commit() | ||
|
||
// //Remove the space | ||
// ctx.Transaction, err = rt.Db.Beginx() | ||
|
||
// _, err = s.Space.Delete(ctx, sp.RefID) | ||
|
||
// move := "moveToId" | ||
|
||
// err = s.Document.MoveDocumentSpace(ctx, sp.RefID, move) | ||
|
||
// err = s.Space.MoveSpaceRoles(ctx, sp.RefID, move) | ||
|
||
// _, err = s.Pin.DeletePinnedSpace(ctx, sp.RefID) | ||
|
||
// s.Audit.Record(ctx, audit.EventTypeSpaceDelete) | ||
|
||
// ctx.Transaction.Commit() | ||
|
||
// _, err = s.Space.Get(ctx, sp.RefID) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package test | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/documize/community/core/env" | ||
"github.com/documize/community/domain" | ||
"github.com/documize/community/edition/boot" | ||
"github.com/documize/community/edition/logging" | ||
_ "github.com/go-sql-driver/mysql" // testing | ||
) | ||
|
||
// SetupTest prepares test environment | ||
func SetupTest() (rt *env.Runtime, s *domain.Store, ctx domain.RequestContext) { | ||
rt, s = startRuntime() | ||
ctx = setupContext() | ||
return rt, s, ctx | ||
} | ||
|
||
func startRuntime() (rt *env.Runtime, s *domain.Store) { | ||
rt = new(env.Runtime) | ||
s = new(domain.Store) | ||
rt.Log = logging.NewLogger() | ||
|
||
rt.Product = env.ProdInfo{} | ||
rt.Product.Major = "0" | ||
rt.Product.Minor = "0" | ||
rt.Product.Patch = "0" | ||
rt.Product.Version = fmt.Sprintf("%s.%s.%s", rt.Product.Major, rt.Product.Minor, rt.Product.Patch) | ||
rt.Product.Edition = "Test" | ||
rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition) | ||
rt.Product.License = env.License{} | ||
rt.Product.License.Seats = 1 | ||
rt.Product.License.Valid = true | ||
rt.Product.License.Trial = false | ||
rt.Product.License.Edition = "Community" | ||
|
||
// parse settings from command line and environment | ||
rt.Flags = env.ParseFlags() | ||
boot.InitRuntime(rt, s) | ||
|
||
// section.Register(rt, s) | ||
|
||
return rt, s | ||
} | ||
|
||
// setup testing context | ||
func setupContext() domain.RequestContext { | ||
ctx := domain.RequestContext{} | ||
ctx.AllowAnonymousAccess = true | ||
ctx.Authenticated = true | ||
ctx.Administrator = true | ||
ctx.Guest = false | ||
ctx.Editor = true | ||
ctx.Global = true | ||
ctx.UserID = "1" | ||
ctx.OrgID = "1" | ||
return ctx | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
{ | ||
"community": | ||
{ | ||
"version": "1.52.2", | ||
"version": "1.53.0", | ||
"major": 1, | ||
"minor": 52, | ||
"patch": 2 | ||
"minor": 53, | ||
"patch": 0 | ||
}, | ||
"enterprise": | ||
{ | ||
"version": "1.54.2", | ||
"version": "1.55.0", | ||
"major": 1, | ||
"minor": 54, | ||
"patch": 2 | ||
"minor": 55, | ||
"patch": 0 | ||
} | ||
} |