-
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
9187118
commit 02d158e
Showing
2 changed files
with
0 additions
and
566 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 |
---|---|---|
|
@@ -28,219 +28,6 @@ import ( | |
"github.com/supertokens/supertokens-golang/test/unittesting" | ||
) | ||
|
||
func TestGetUsersOldestFirst(t *testing.T) { | ||
configValue := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
ConnectionURI: "http://localhost:8080", | ||
}, | ||
AppInfo: supertokens.AppInfo{ | ||
APIDomain: "api.supertokens.io", | ||
AppName: "SuperTokens", | ||
WebsiteDomain: "supertokens.io", | ||
}, | ||
RecipeList: []supertokens.Recipe{ | ||
Init(nil), | ||
session.Init(&sessmodels.TypeInput{ | ||
GetTokenTransferMethod: func(req *http.Request, forCreateNewSession bool, userContext supertokens.UserContext) sessmodels.TokenTransferMethod { | ||
return sessmodels.CookieTransferMethod | ||
}, | ||
}), | ||
}, | ||
} | ||
|
||
BeforeEach() | ||
unittesting.StartUpST("localhost", "8080") | ||
defer AfterEach() | ||
err := supertokens.Init(configValue) | ||
if err != nil { | ||
|
||
t.Error(err.Error()) | ||
} | ||
mux := http.NewServeMux() | ||
testServer := httptest.NewServer(supertokens.Middleware(mux)) | ||
defer testServer.Close() | ||
|
||
_, err = unittesting.SignupRequest("[email protected]", "testPass123", testServer.URL) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
_, err = unittesting.SignupRequest("[email protected]", "testPass123", testServer.URL) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
_, err = unittesting.SignupRequest("[email protected]", "testPass123", testServer.URL) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
_, err = unittesting.SignupRequest("[email protected]", "testPass123", testServer.URL) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
_, err = unittesting.SignupRequest("[email protected]", "testPass123", testServer.URL) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
users, err := supertokens.GetUsersOldestFirst("public", nil, nil, nil, nil) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
assert.Equal(t, len(users.Users), 5) | ||
assert.Nil(t, users.NextPaginationToken) | ||
|
||
limit := 1 | ||
users, err = supertokens.GetUsersOldestFirst("public", nil, &limit, nil, nil) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
assert.Equal(t, len(users.Users), 1) | ||
assert.NotNil(t, users.NextPaginationToken) | ||
assert.Equal(t, "[email protected]", users.Users[0].Emails[0]) | ||
|
||
users, err = supertokens.GetUsersOldestFirst("public", users.NextPaginationToken, &limit, nil, nil) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
assert.Equal(t, len(users.Users), 1) | ||
assert.NotNil(t, users.NextPaginationToken) | ||
assert.Equal(t, "[email protected]", users.Users[0].Emails[0]) | ||
|
||
limit = 5 | ||
users, err = supertokens.GetUsersOldestFirst("public", users.NextPaginationToken, &limit, nil, nil) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
assert.Equal(t, len(users.Users), 3) | ||
assert.Nil(t, users.NextPaginationToken) | ||
|
||
customPaginationToken := "invalid-pagination-token" | ||
limit = 10 | ||
users, err = supertokens.GetUsersOldestFirst("public", &customPaginationToken, &limit, nil, nil) | ||
if err != nil { | ||
assert.Equal(t, "SuperTokens core threw an error for a request to path: '/public/users' with status code: 400 and message: invalid pagination token\n", err.Error()) | ||
} else { | ||
t.Fail() | ||
} | ||
|
||
limit = -1 | ||
users, err = supertokens.GetUsersOldestFirst("public", nil, &limit, nil, nil) | ||
if err != nil { | ||
assert.Equal(t, "SuperTokens core threw an error for a request to path: '/public/users' with status code: 400 and message: limit must a positive integer with min value 1\n", err.Error()) | ||
} else { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestGetUsersNewestFirst(t *testing.T) { | ||
configValue := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
ConnectionURI: "http://localhost:8080", | ||
}, | ||
AppInfo: supertokens.AppInfo{ | ||
APIDomain: "api.supertokens.io", | ||
AppName: "SuperTokens", | ||
WebsiteDomain: "supertokens.io", | ||
}, | ||
RecipeList: []supertokens.Recipe{ | ||
Init(nil), | ||
session.Init(&sessmodels.TypeInput{ | ||
GetTokenTransferMethod: func(req *http.Request, forCreateNewSession bool, userContext supertokens.UserContext) sessmodels.TokenTransferMethod { | ||
return sessmodels.CookieTransferMethod | ||
}, | ||
}), | ||
}, | ||
} | ||
|
||
BeforeEach() | ||
unittesting.StartUpST("localhost", "8080") | ||
defer AfterEach() | ||
err := supertokens.Init(configValue) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
mux := http.NewServeMux() | ||
testServer := httptest.NewServer(supertokens.Middleware(mux)) | ||
defer testServer.Close() | ||
|
||
_, err = unittesting.SignupRequest("[email protected]", "testPass123", testServer.URL) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
_, err = unittesting.SignupRequest("[email protected]", "testPass123", testServer.URL) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
_, err = unittesting.SignupRequest("[email protected]", "testPass123", testServer.URL) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
_, err = unittesting.SignupRequest("[email protected]", "testPass123", testServer.URL) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
_, err = unittesting.SignupRequest("[email protected]", "testPass123", testServer.URL) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
users, err := supertokens.GetUsersNewestFirst("public", nil, nil, nil, nil) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
assert.Equal(t, len(users.Users), 5) | ||
assert.Nil(t, users.NextPaginationToken) | ||
|
||
limit := 1 | ||
users, err = supertokens.GetUsersNewestFirst("public", nil, &limit, nil, nil) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
assert.Equal(t, len(users.Users), 1) | ||
assert.NotNil(t, users.NextPaginationToken) | ||
assert.Equal(t, "[email protected]", users.Users[0].Emails[0]) | ||
|
||
users, err = supertokens.GetUsersNewestFirst("public", users.NextPaginationToken, &limit, nil, nil) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
assert.Equal(t, len(users.Users), 1) | ||
assert.NotNil(t, users.NextPaginationToken) | ||
assert.Equal(t, "[email protected]", users.Users[0].Emails[0]) | ||
|
||
limit = 5 | ||
users, err = supertokens.GetUsersNewestFirst("public", users.NextPaginationToken, &limit, nil, nil) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
assert.Equal(t, len(users.Users), 3) | ||
assert.Nil(t, users.NextPaginationToken) | ||
|
||
customPaginationToken := "invalid-pagination-token" | ||
limit = 10 | ||
users, err = supertokens.GetUsersNewestFirst("public", &customPaginationToken, &limit, nil, nil) | ||
if err != nil { | ||
assert.Equal(t, "SuperTokens core threw an error for a request to path: '/public/users' with status code: 400 and message: invalid pagination token\n", err.Error()) | ||
} else { | ||
t.Fail() | ||
} | ||
|
||
limit = -1 | ||
users, err = supertokens.GetUsersNewestFirst("public", nil, &limit, nil, nil) | ||
if err != nil { | ||
assert.Equal(t, "SuperTokens core threw an error for a request to path: '/public/users' with status code: 400 and message: limit must a positive integer with min value 1\n", err.Error()) | ||
} else { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestGetUserCount(t *testing.T) { | ||
configValue := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
|
Oops, something went wrong.