1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-20 05:39:42 +02:00
documize/domain/space/space_test.go

55 lines
1.1 KiB
Go
Raw Normal View History

2017-08-22 17:23:30 +01:00
package space
import (
"testing"
"github.com/documize/community/core/uniqueid"
"github.com/documize/community/domain/test"
"github.com/documize/community/model/space"
)
2017-09-01 15:28:05 +01:00
// TestSpace tests all space database operations.
func TestSpace(t *testing.T) {
2017-08-22 17:23:30 +01:00
rt, s, ctx := test.SetupTest()
2017-09-01 15:28:05 +01:00
spaceID := uniqueid.Generate()
2017-08-22 17:23:30 +01:00
var err error
2017-09-01 15:28:05 +01:00
t.Run("Add Space", func(t *testing.T) {
ctx.Transaction, err = rt.Db.Beginx()
if err != nil {
return
}
sp := space.Space{}
sp.RefID = spaceID
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()
t.Error("failed to delete space")
}
ctx.Transaction.Commit()
sp2, err := s.Space.Get(ctx, sp.RefID)
if err != nil || sp.Name != sp2.Name {
t.Error("failed to create space")
}
})
t.Run("Delete Space", func(t *testing.T) {
ctx.Transaction, err = rt.Db.Beginx()
_, err = s.Space.Delete(ctx, spaceID)
if err != nil {
ctx.Transaction.Rollback()
t.Error("failed to delete space")
return
}
ctx.Transaction.Commit()
})
2017-08-22 17:23:30 +01:00
}