fix: create common resolver test suite
This commit is contained in:
parent
beae4502d4
commit
6e9370458b
|
@ -60,7 +60,7 @@ func (r *queryResolver) Meta(ctx context.Context) (*model.Meta, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *queryResolver) Session(ctx context.Context, roles []string) (*model.AuthResponse, error) {
|
func (r *queryResolver) Session(ctx context.Context, roles []string) (*model.AuthResponse, error) {
|
||||||
return resolvers.Token(ctx, roles)
|
return resolvers.Session(ctx, roles)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *queryResolver) Profile(ctx context.Context) (*model.User, error) {
|
func (r *queryResolver) Profile(ctx context.Context) (*model.User, error) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/authorizerdev/authorizer/server/utils"
|
"github.com/authorizerdev/authorizer/server/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Token(ctx context.Context, roles []string) (*model.AuthResponse, error) {
|
func Session(ctx context.Context, roles []string) (*model.AuthResponse, error) {
|
||||||
var res *model.AuthResponse
|
var res *model.AuthResponse
|
||||||
|
|
||||||
gc, err := utils.GinContextFromContext(ctx)
|
gc, err := utils.GinContextFromContext(ctx)
|
|
@ -3,7 +3,6 @@ package test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
"github.com/authorizerdev/authorizer/server/enum"
|
"github.com/authorizerdev/authorizer/server/enum"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
@ -11,7 +10,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func commonForgotPasswordTest(s TestSetup, t *testing.T) {
|
func forgotPasswordTest(s TestSetup, t *testing.T) {
|
||||||
email := "forgot_password." + s.TestInfo.Email
|
email := "forgot_password." + s.TestInfo.Email
|
||||||
_, err := resolvers.Signup(s.Ctx, model.SignUpInput{
|
_, err := resolvers.Signup(s.Ctx, model.SignUpInput{
|
||||||
Email: email,
|
Email: email,
|
||||||
|
@ -31,35 +30,3 @@ func commonForgotPasswordTest(s TestSetup, t *testing.T) {
|
||||||
|
|
||||||
cleanData(email)
|
cleanData(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestForgotPassword(t *testing.T) {
|
|
||||||
s := testSetup()
|
|
||||||
defer s.Server.Close()
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForSQL {
|
|
||||||
t.Run("forgot password for sql dbs should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.SQL
|
|
||||||
constants.DATABASE_TYPE = enum.Sqlite.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonForgotPasswordTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForArango {
|
|
||||||
t.Run("forgot password for arangodb should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.ArangoDB
|
|
||||||
constants.DATABASE_TYPE = enum.Arangodb.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonForgotPasswordTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForMongo {
|
|
||||||
t.Run("forgot password for mongodb should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.MongoDB
|
|
||||||
constants.DATABASE_TYPE = enum.Mongodb.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonForgotPasswordTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
"github.com/authorizerdev/authorizer/server/enum"
|
"github.com/authorizerdev/authorizer/server/enum"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
@ -12,7 +10,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func commonLoginTest(s TestSetup, t *testing.T) {
|
func loginTests(s TestSetup, t *testing.T) {
|
||||||
email := "login." + s.TestInfo.Email
|
email := "login." + s.TestInfo.Email
|
||||||
_, err := resolvers.Signup(s.Ctx, model.SignUpInput{
|
_, err := resolvers.Signup(s.Ctx, model.SignUpInput{
|
||||||
Email: email,
|
Email: email,
|
||||||
|
@ -50,41 +48,8 @@ func commonLoginTest(s TestSetup, t *testing.T) {
|
||||||
Password: s.TestInfo.Password,
|
Password: s.TestInfo.Password,
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Println("=> access token:", loginRes.AccessToken)
|
|
||||||
assert.Nil(t, err, "login successful")
|
assert.Nil(t, err, "login successful")
|
||||||
assert.NotNil(t, loginRes.AccessToken, "access token should not be empty")
|
assert.Nil(t, loginRes.AccessToken, "access token should not be empty")
|
||||||
|
|
||||||
cleanData(email)
|
cleanData(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLogin(t *testing.T) {
|
|
||||||
s := testSetup()
|
|
||||||
defer s.Server.Close()
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForSQL {
|
|
||||||
t.Run("login for sql dbs should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.SQL
|
|
||||||
constants.DATABASE_TYPE = enum.Sqlite.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonLoginTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForArango {
|
|
||||||
t.Run("login for arangodb should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.ArangoDB
|
|
||||||
constants.DATABASE_TYPE = enum.Arangodb.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonLoginTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForMongo {
|
|
||||||
t.Run("login for mongodb should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.MongoDB
|
|
||||||
constants.DATABASE_TYPE = enum.Mongodb.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonLoginTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,15 +3,13 @@ package test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
|
||||||
"github.com/authorizerdev/authorizer/server/enum"
|
"github.com/authorizerdev/authorizer/server/enum"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
"github.com/authorizerdev/authorizer/server/resolvers"
|
"github.com/authorizerdev/authorizer/server/resolvers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func commonResendVerifyEmailTest(s TestSetup, t *testing.T) {
|
func resendVerifyEmailTests(s TestSetup, t *testing.T) {
|
||||||
email := "resend_verify_email." + s.TestInfo.Email
|
email := "resend_verify_email." + s.TestInfo.Email
|
||||||
_, err := resolvers.Signup(s.Ctx, model.SignUpInput{
|
_, err := resolvers.Signup(s.Ctx, model.SignUpInput{
|
||||||
Email: email,
|
Email: email,
|
||||||
|
@ -28,35 +26,3 @@ func commonResendVerifyEmailTest(s TestSetup, t *testing.T) {
|
||||||
|
|
||||||
cleanData(email)
|
cleanData(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResendVerifyEmail(t *testing.T) {
|
|
||||||
s := testSetup()
|
|
||||||
defer s.Server.Close()
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForSQL {
|
|
||||||
t.Run("resend verify email for sql dbs should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.SQL
|
|
||||||
constants.DATABASE_TYPE = enum.Sqlite.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonResendVerifyEmailTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForArango {
|
|
||||||
t.Run("resend verify email for arangodb should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.ArangoDB
|
|
||||||
constants.DATABASE_TYPE = enum.Arangodb.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonResendVerifyEmailTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForMongo {
|
|
||||||
t.Run("resend verify email for mongodb should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.MongoDB
|
|
||||||
constants.DATABASE_TYPE = enum.Mongodb.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonResendVerifyEmailTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
"github.com/authorizerdev/authorizer/server/enum"
|
"github.com/authorizerdev/authorizer/server/enum"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
@ -11,7 +10,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func commonResetPasswordTest(s TestSetup, t *testing.T) {
|
func resetPasswordTest(s TestSetup, t *testing.T) {
|
||||||
email := "reset_password." + s.TestInfo.Email
|
email := "reset_password." + s.TestInfo.Email
|
||||||
_, err := resolvers.Signup(s.Ctx, model.SignUpInput{
|
_, err := resolvers.Signup(s.Ctx, model.SignUpInput{
|
||||||
Email: email,
|
Email: email,
|
||||||
|
@ -45,35 +44,3 @@ func commonResetPasswordTest(s TestSetup, t *testing.T) {
|
||||||
|
|
||||||
cleanData(email)
|
cleanData(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPassword(t *testing.T) {
|
|
||||||
s := testSetup()
|
|
||||||
defer s.Server.Close()
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForSQL {
|
|
||||||
t.Run("reset password for sql dbs should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.SQL
|
|
||||||
constants.DATABASE_TYPE = enum.Sqlite.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonResetPasswordTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForArango {
|
|
||||||
t.Run("reset password for arangodb should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.ArangoDB
|
|
||||||
constants.DATABASE_TYPE = enum.Arangodb.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonResetPasswordTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForMongo {
|
|
||||||
t.Run("reset password for mongodb should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.MongoDB
|
|
||||||
constants.DATABASE_TYPE = enum.Mongodb.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonResetPasswordTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
36
server/test/resolvers_test.go
Normal file
36
server/test/resolvers_test.go
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
|
"github.com/authorizerdev/authorizer/server/enum"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestResolvers(t *testing.T) {
|
||||||
|
databases := map[string]string{
|
||||||
|
enum.Sqlite.String(): "../../data.db",
|
||||||
|
enum.Arangodb.String(): "http://root:root@localhost:8529",
|
||||||
|
enum.Mongodb.String(): "mongodb://localhost:27017",
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("==== Testing resolvers =====")
|
||||||
|
|
||||||
|
for dbType, dbURL := range databases {
|
||||||
|
constants.DATABASE_URL = dbURL
|
||||||
|
constants.DATABASE_TYPE = dbType
|
||||||
|
db.InitDB()
|
||||||
|
s := testSetup()
|
||||||
|
defer s.Server.Close()
|
||||||
|
t.Run("running test cases for "+dbType, func(t *testing.T) {
|
||||||
|
loginTests(s, t)
|
||||||
|
signupTests(s, t)
|
||||||
|
forgotPasswordTest(s, t)
|
||||||
|
resendVerifyEmailTests(s, t)
|
||||||
|
resetPasswordTest(s, t)
|
||||||
|
verifyEmailTest(s, t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,6 @@ package test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
"github.com/authorizerdev/authorizer/server/enum"
|
"github.com/authorizerdev/authorizer/server/enum"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
@ -11,7 +10,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func commonSignupTest(s TestSetup, t *testing.T) {
|
func signupTests(s TestSetup, t *testing.T) {
|
||||||
email := "signup." + s.TestInfo.Email
|
email := "signup." + s.TestInfo.Email
|
||||||
res, err := resolvers.Signup(s.Ctx, model.SignUpInput{
|
res, err := resolvers.Signup(s.Ctx, model.SignUpInput{
|
||||||
Email: email,
|
Email: email,
|
||||||
|
@ -43,35 +42,3 @@ func commonSignupTest(s TestSetup, t *testing.T) {
|
||||||
assert.Equal(t, email, verificationRequest.Email)
|
assert.Equal(t, email, verificationRequest.Email)
|
||||||
cleanData(email)
|
cleanData(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSignUp(t *testing.T) {
|
|
||||||
s := testSetup()
|
|
||||||
defer s.Server.Close()
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForSQL {
|
|
||||||
t.Run("signup for sql dbs should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.SQL
|
|
||||||
constants.DATABASE_TYPE = enum.Sqlite.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonSignupTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForArango {
|
|
||||||
t.Run("signup for arangodb should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.ArangoDB
|
|
||||||
constants.DATABASE_TYPE = enum.Arangodb.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonSignupTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForMongo {
|
|
||||||
t.Run("signup for mongodb should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.MongoDB
|
|
||||||
constants.DATABASE_TYPE = enum.Mongodb.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonSignupTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -19,14 +19,8 @@ import (
|
||||||
|
|
||||||
// common user data to share across tests
|
// common user data to share across tests
|
||||||
type TestData struct {
|
type TestData struct {
|
||||||
Email string
|
Email string
|
||||||
Password string
|
Password string
|
||||||
SQL string
|
|
||||||
MongoDB string
|
|
||||||
ArangoDB string
|
|
||||||
ShouldExecuteForSQL bool
|
|
||||||
ShouldExecuteForArango bool
|
|
||||||
ShouldExecuteForMongo bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestSetup struct {
|
type TestSetup struct {
|
||||||
|
@ -38,52 +32,6 @@ type TestSetup struct {
|
||||||
TestInfo TestData
|
TestInfo TestData
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSetup() TestSetup {
|
|
||||||
testData := TestData{
|
|
||||||
Email: "authorizer_tester@yopmail.com",
|
|
||||||
Password: "test",
|
|
||||||
SQL: "../../data.db",
|
|
||||||
ArangoDB: "http://root:root@localhost:8529",
|
|
||||||
MongoDB: "mongodb://localhost:27017",
|
|
||||||
ShouldExecuteForSQL: true,
|
|
||||||
ShouldExecuteForArango: true,
|
|
||||||
ShouldExecuteForMongo: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
constants.ENV_PATH = "../../.env.sample"
|
|
||||||
constants.DATABASE_URL = testData.SQL
|
|
||||||
env.InitEnv()
|
|
||||||
session.InitSession()
|
|
||||||
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
c, r := gin.CreateTestContext(w)
|
|
||||||
r.Use(location.Default())
|
|
||||||
r.Use(middlewares.GinContextToContextMiddleware())
|
|
||||||
r.Use(middlewares.CORSMiddleware())
|
|
||||||
|
|
||||||
r.POST("/graphql", handlers.GraphqlHandler())
|
|
||||||
|
|
||||||
server := httptest.NewServer(r)
|
|
||||||
|
|
||||||
req, _ := http.NewRequest(
|
|
||||||
"POST",
|
|
||||||
"http://"+server.Listener.Addr().String()+"/graphql",
|
|
||||||
nil,
|
|
||||||
)
|
|
||||||
req.Header.Add("x-authorizer-admin-secret", constants.ADMIN_SECRET)
|
|
||||||
c.Request = req
|
|
||||||
ctx := context.WithValue(req.Context(), "GinContextKey", c)
|
|
||||||
|
|
||||||
return TestSetup{
|
|
||||||
GinEngine: r,
|
|
||||||
GinContext: c,
|
|
||||||
Ctx: ctx,
|
|
||||||
Server: server,
|
|
||||||
Req: req,
|
|
||||||
TestInfo: testData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func cleanData(email string) {
|
func cleanData(email string) {
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, enum.BasicAuthSignup.String())
|
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, enum.BasicAuthSignup.String())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -115,3 +63,42 @@ func cleanData(email string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testSetup() TestSetup {
|
||||||
|
testData := TestData{
|
||||||
|
Email: "authorizer_tester@yopmail.com",
|
||||||
|
Password: "test",
|
||||||
|
}
|
||||||
|
|
||||||
|
constants.ENV_PATH = "../../.env.sample"
|
||||||
|
env.InitEnv()
|
||||||
|
session.InitSession()
|
||||||
|
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
c, r := gin.CreateTestContext(w)
|
||||||
|
r.Use(location.Default())
|
||||||
|
r.Use(middlewares.GinContextToContextMiddleware())
|
||||||
|
r.Use(middlewares.CORSMiddleware())
|
||||||
|
|
||||||
|
r.POST("/graphql", handlers.GraphqlHandler())
|
||||||
|
|
||||||
|
server := httptest.NewServer(r)
|
||||||
|
|
||||||
|
req, _ := http.NewRequest(
|
||||||
|
"POST",
|
||||||
|
"http://"+server.Listener.Addr().String()+"/graphql",
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
req.Header.Add("x-authorizer-admin-secret", constants.ADMIN_SECRET)
|
||||||
|
c.Request = req
|
||||||
|
ctx := context.WithValue(req.Context(), "GinContextKey", c)
|
||||||
|
|
||||||
|
return TestSetup{
|
||||||
|
GinEngine: r,
|
||||||
|
GinContext: c,
|
||||||
|
Ctx: ctx,
|
||||||
|
Server: server,
|
||||||
|
Req: req,
|
||||||
|
TestInfo: testData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
"github.com/authorizerdev/authorizer/server/enum"
|
"github.com/authorizerdev/authorizer/server/enum"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
@ -11,7 +10,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func commonVerifyEmailTest(s TestSetup, t *testing.T) {
|
func verifyEmailTest(s TestSetup, t *testing.T) {
|
||||||
email := "verify_email." + s.TestInfo.Email
|
email := "verify_email." + s.TestInfo.Email
|
||||||
res, err := resolvers.Signup(s.Ctx, model.SignUpInput{
|
res, err := resolvers.Signup(s.Ctx, model.SignUpInput{
|
||||||
Email: email,
|
Email: email,
|
||||||
|
@ -34,35 +33,3 @@ func commonVerifyEmailTest(s TestSetup, t *testing.T) {
|
||||||
|
|
||||||
cleanData(email)
|
cleanData(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVerifyEmail(t *testing.T) {
|
|
||||||
s := testSetup()
|
|
||||||
defer s.Server.Close()
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForSQL {
|
|
||||||
t.Run("verify email for sql dbs should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.SQL
|
|
||||||
constants.DATABASE_TYPE = enum.Sqlite.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonVerifyEmailTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForArango {
|
|
||||||
t.Run("verify email for arangodb should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.ArangoDB
|
|
||||||
constants.DATABASE_TYPE = enum.Arangodb.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonVerifyEmailTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.TestInfo.ShouldExecuteForMongo {
|
|
||||||
t.Run("verify email for mongodb should pass", func(t *testing.T) {
|
|
||||||
constants.DATABASE_URL = s.TestInfo.MongoDB
|
|
||||||
constants.DATABASE_TYPE = enum.Mongodb.String()
|
|
||||||
db.InitDB()
|
|
||||||
commonVerifyEmailTest(s, t)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user