Skip to content

Commit

Permalink
adds one test for user pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Dec 12, 2023
1 parent 1cbd2aa commit 8ef58ce
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
133 changes: 133 additions & 0 deletions recipe/emailpassword/accountlinkingRecipeImplementation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* Copyright (c) 2023, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package emailpassword

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/supertokens/supertokens-golang/supertokens"
"github.com/supertokens/supertokens-golang/test/unittesting"
)

// we have this file here case we cannot put it in supertokens or unittesting
// package due to cyclic imports.

func TestGetOldestUsersFirst(t *testing.T) {
BeforeEach()
unittesting.StartUpST("localhost", "8080")
defer AfterEach()
telemetry := false
supertokens.Init(supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "http://localhost:8080",
},
AppInfo: supertokens.AppInfo{
AppName: "Testing",
Origin: "http://localhost:3000",
APIDomain: "http://localhost:3001",
},
Telemetry: &telemetry,
RecipeList: []supertokens.Recipe{
Init(nil),
},
})

user1, err := SignUp("public", "[email protected]", "testPass123")
if err != nil {
t.Error(err)
return
}
_, err = SignUp("public", "[email protected]", "testPass123")
if err != nil {
t.Error(err)
return
}
_, err = SignUp("public", "[email protected]", "testPass123")
if err != nil {
t.Error(err)
return
}
_, err = SignUp("public", "[email protected]", "testPass123")
if err != nil {
t.Error(err)
return
}
_, err = SignUp("public", "[email protected]", "testPass123")
if err != nil {
t.Error(err)
return
}

{
paginationResult, err := supertokens.GetUsersOldestFirst("public", nil, nil, nil, nil)
if err != nil {
t.Error(err)
return
}

email := "[email protected]"
assert.Nil(t, paginationResult.NextPaginationToken)
assert.Len(t, paginationResult.Users, 5)
assert.True(t, paginationResult.Users[0].LoginMethods[0].HasSameEmailAs(&email))
assert.Equal(t, paginationResult.Users[0].ID, user1.OK.User.ID)
assert.Equal(t, paginationResult.Users[0].ID, paginationResult.Users[0].LoginMethods[0].RecipeUserID.GetAsString())
}

{
limit := 1
paginationResult, err := supertokens.GetUsersOldestFirst("public", nil, &limit, nil, nil)
if err != nil {
t.Error(err)
return
}

assert.NotNil(t, paginationResult.NextPaginationToken)
assert.Len(t, paginationResult.Users, 1)
assert.Equal(t, paginationResult.Users[0].Emails[0], "[email protected]")

paginationResult, err = supertokens.GetUsersOldestFirst("public", paginationResult.NextPaginationToken, &limit, nil, nil)
if err != nil {
t.Error(err)
return
}

assert.NotNil(t, paginationResult.NextPaginationToken)
assert.Len(t, paginationResult.Users, 1)
assert.Equal(t, paginationResult.Users[0].Emails[0], "[email protected]")

limit = 5
paginationResult, err = supertokens.GetUsersOldestFirst("public", paginationResult.NextPaginationToken, &limit, nil, nil)
if err != nil {
t.Error(err)
return
}

assert.Nil(t, paginationResult.NextPaginationToken)
assert.Len(t, paginationResult.Users, 3)
assert.Equal(t, paginationResult.Users[0].Emails[0], "[email protected]")
}

{
paginationToken := "invalid"
_, err := supertokens.GetUsersOldestFirst("public", &paginationToken, nil, nil, nil)
if err != nil {
assert.Contains(t, err.Error(), "invalid pagination token")
} else {
assert.Fail(t, "pagination token invalid should fail")
}
}
}
4 changes: 4 additions & 0 deletions supertokens/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func Init(config TypeInput) error {
return nil
}

func InitAccountLinking(config *AccountLinkingTypeInput) Recipe {
return accountLinkingRecipeInit(config)
}

func Middleware(theirHandler http.Handler) http.Handler {
instance, err := GetInstanceOrThrowError()
if err != nil {
Expand Down

0 comments on commit 8ef58ce

Please sign in to comment.