feat: add helper for updating all users
This commit is contained in:
@@ -14,9 +14,9 @@ import (
|
||||
|
||||
func resendOTPTest(t *testing.T, s TestSetup) {
|
||||
t.Helper()
|
||||
t.Run(`should verify otp`, func(t *testing.T) {
|
||||
t.Run(`should resend otp`, func(t *testing.T) {
|
||||
req, ctx := createContext(s)
|
||||
email := "verify_otp." + s.TestInfo.Email
|
||||
email := "resend_otp." + s.TestInfo.Email
|
||||
res, err := resolvers.SignupResolver(ctx, model.SignUpInput{
|
||||
Email: email,
|
||||
Password: s.TestInfo.Password,
|
||||
|
@@ -33,7 +33,7 @@ func TestResolvers(t *testing.T) {
|
||||
if utils.StringSliceContains(testDBs, constants.DbTypeSqlite) && len(testDBs) == 1 {
|
||||
// do nothing
|
||||
} else {
|
||||
t.Log("waiting for docker containers to spun up")
|
||||
t.Log("waiting for docker containers to start...")
|
||||
// wait for docker containers to spun up
|
||||
time.Sleep(30 * time.Second)
|
||||
}
|
||||
@@ -116,6 +116,8 @@ func TestResolvers(t *testing.T) {
|
||||
validateJwtTokenTest(t, s)
|
||||
verifyOTPTest(t, s)
|
||||
resendOTPTest(t, s)
|
||||
|
||||
updateAllUsersTest(t, s)
|
||||
webhookLogsTest(t, s) // get logs after above resolver tests are done
|
||||
deleteWebhookTest(t, s) // delete webhooks (admin resolver)
|
||||
})
|
||||
|
67
server/test/update_all_users_tests.go
Normal file
67
server/test/update_all_users_tests.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
"github.com/authorizerdev/authorizer/server/db"
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||
"github.com/authorizerdev/authorizer/server/refs"
|
||||
"github.com/authorizerdev/authorizer/server/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func updateAllUsersTest(t *testing.T, s TestSetup) {
|
||||
t.Helper()
|
||||
t.Run("Should update all users", func(t *testing.T) {
|
||||
_, ctx := createContext(s)
|
||||
|
||||
users := []models.User{}
|
||||
for i := 0; i < 10; i++ {
|
||||
user := models.User{
|
||||
Email: fmt.Sprintf("update_all_user_%d_%s", i, s.TestInfo.Email),
|
||||
SignupMethods: constants.AuthRecipeMethodBasicAuth,
|
||||
Roles: "user",
|
||||
}
|
||||
users = append(users, user)
|
||||
u, err := db.Provider.AddUser(ctx, user)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, u)
|
||||
}
|
||||
|
||||
err := db.Provider.UpdateUsers(ctx, map[string]interface{}{
|
||||
"is_multi_factor_auth_enabled": true,
|
||||
}, nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
listUsers, err := db.Provider.ListUsers(ctx, model.Pagination{
|
||||
Limit: 20,
|
||||
Offset: 0,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
for _, u := range listUsers.Users {
|
||||
assert.True(t, refs.BoolValue(u.IsMultiFactorAuthEnabled))
|
||||
}
|
||||
|
||||
// // update few users
|
||||
updateIds := []string{listUsers.Users[0].ID, listUsers.Users[1].ID}
|
||||
err = db.Provider.UpdateUsers(ctx, map[string]interface{}{
|
||||
"is_multi_factor_auth_enabled": false,
|
||||
}, updateIds)
|
||||
assert.NoError(t, err)
|
||||
|
||||
listUsers, err = db.Provider.ListUsers(ctx, model.Pagination{
|
||||
Limit: 20,
|
||||
Offset: 0,
|
||||
})
|
||||
for _, u := range listUsers.Users {
|
||||
if utils.StringSliceContains(updateIds, u.ID) {
|
||||
assert.False(t, refs.BoolValue(u.IsMultiFactorAuthEnabled))
|
||||
} else {
|
||||
assert.True(t, refs.BoolValue(u.IsMultiFactorAuthEnabled))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
@@ -44,9 +44,11 @@ func verifyOTPTest(t *testing.T, s TestSetup) {
|
||||
// Using access token update profile
|
||||
s.GinContext.Request.Header.Set("Authorization", "Bearer "+refs.StringValue(verifyRes.AccessToken))
|
||||
ctx = context.WithValue(req.Context(), "GinContextKey", s.GinContext)
|
||||
_, err = resolvers.UpdateProfileResolver(ctx, model.UpdateProfileInput{
|
||||
updateProfileRes, err := resolvers.UpdateProfileResolver(ctx, model.UpdateProfileInput{
|
||||
IsMultiFactorAuthEnabled: refs.NewBoolRef(true),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, updateProfileRes.Message)
|
||||
|
||||
// Login should not return error but access token should be empty as otp should have been sent
|
||||
loginRes, err = resolvers.LoginResolver(ctx, model.LoginInput{
|
||||
|
Reference in New Issue
Block a user