-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ef58ce
commit 9187118
Showing
1 changed file
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,3 +131,265 @@ func TestGetOldestUsersFirst(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestGetNewestUsersFirst(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), | ||
}, | ||
}) | ||
|
||
_, 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 | ||
} | ||
user5, err := SignUp("public", "[email protected]", "testPass123") | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
{ | ||
paginationResult, err := supertokens.GetUsersNewestFirst("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, user5.OK.User.ID) | ||
assert.Equal(t, paginationResult.Users[0].ID, paginationResult.Users[0].LoginMethods[0].RecipeUserID.GetAsString()) | ||
} | ||
|
||
{ | ||
limit := 1 | ||
paginationResult, err := supertokens.GetUsersNewestFirst("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.GetUsersNewestFirst("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.GetUsersNewestFirst("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.GetUsersNewestFirst("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") | ||
} | ||
} | ||
} | ||
|
||
func TestGetOldestUsersFirstWithSearchParams(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), | ||
}, | ||
}) | ||
|
||
_, 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, map[string]string{ | ||
"email": "doe", | ||
}) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
assert.Nil(t, paginationResult.NextPaginationToken) | ||
assert.Len(t, paginationResult.Users, 0) | ||
} | ||
|
||
{ | ||
paginationResult, err := supertokens.GetUsersOldestFirst("public", nil, nil, nil, map[string]string{ | ||
"email": "john", | ||
}) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
assert.Nil(t, paginationResult.NextPaginationToken) | ||
assert.Len(t, paginationResult.Users, 1) | ||
assert.Equal(t, paginationResult.Users[0].Emails[0], "[email protected]") | ||
assert.Len(t, paginationResult.Users[0].LoginMethods, 1) | ||
assert.Len(t, paginationResult.Users[0].Emails, 1) | ||
assert.Len(t, paginationResult.Users[0].PhoneNumbers, 0) | ||
assert.Len(t, paginationResult.Users[0].ThirdParty, 0) | ||
} | ||
} | ||
|
||
func TestGetNewestUsersFirstWithSearchParams(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), | ||
}, | ||
}) | ||
|
||
_, 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.GetUsersNewestFirst("public", nil, nil, nil, map[string]string{ | ||
"email": "doe", | ||
}) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
assert.Nil(t, paginationResult.NextPaginationToken) | ||
assert.Len(t, paginationResult.Users, 0) | ||
} | ||
|
||
{ | ||
paginationResult, err := supertokens.GetUsersNewestFirst("public", nil, nil, nil, map[string]string{ | ||
"email": "john", | ||
}) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
assert.Nil(t, paginationResult.NextPaginationToken) | ||
assert.Len(t, paginationResult.Users, 1) | ||
assert.Equal(t, paginationResult.Users[0].Emails[0], "[email protected]") | ||
assert.Len(t, paginationResult.Users[0].LoginMethods, 1) | ||
assert.Len(t, paginationResult.Users[0].Emails, 1) | ||
assert.Len(t, paginationResult.Users[0].PhoneNumbers, 0) | ||
assert.Len(t, paginationResult.Users[0].ThirdParty, 0) | ||
} | ||
} |