feat: uniq tenant_users
This commit is contained in:
67
backend/modules/users/service_test.go
Normal file
67
backend/modules/users/service_test.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"backend/fixtures"
|
||||
dbUtil "backend/pkg/db"
|
||||
"backend/pkg/pg"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestService_GetOrNew(t *testing.T) {
|
||||
FocusConvey("Test GetOrNew", t, func() {
|
||||
// So(dbUtil.TruncateAllTables(context.TODO(), db, "users", "users_tenants"), ShouldBeNil)
|
||||
db, err := fixtures.GetDB()
|
||||
So(err, ShouldBeNil)
|
||||
defer db.Close()
|
||||
|
||||
Convey("Test GetOrNew", func() {
|
||||
svc := &Service{db: db}
|
||||
So(svc.Prepare(), ShouldBeNil)
|
||||
|
||||
user, err := svc.GetByOpenID(context.Background(), "hello")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(user, ShouldNotBeNil)
|
||||
So(user.OpenID, ShouldEqual, "hello")
|
||||
})
|
||||
|
||||
FocusConvey("Test GetOrNew", func() {
|
||||
svc := &Service{db: db}
|
||||
So(svc.Prepare(), ShouldBeNil)
|
||||
|
||||
openid := "test_openid"
|
||||
authInfo := pg.UserOAuth{
|
||||
AccessToken: "test_access_token",
|
||||
}
|
||||
|
||||
user, err := svc.GetOrNew(context.Background(), 1, openid, authInfo)
|
||||
So(err, ShouldBeNil)
|
||||
So(user.OpenID, ShouldEqual, openid)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestService_CreateTenantUser(t *testing.T) {
|
||||
FocusConvey("Test CreateTenantUser", t, func() {
|
||||
db, err := fixtures.GetDB()
|
||||
So(err, ShouldBeNil)
|
||||
defer db.Close()
|
||||
|
||||
So(dbUtil.TruncateAllTables(context.TODO(), db, "users", "users_tenants"), ShouldBeNil)
|
||||
|
||||
FocusConvey("Test Create", func() {
|
||||
svc := &Service{db: db}
|
||||
So(svc.Prepare(), ShouldBeNil)
|
||||
|
||||
err := svc.CreateTenantUser(context.Background(), 1, 1)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = svc.CreateTenantUser(context.Background(), 1, 1)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user