Skip to content

Commit

Permalink
removes unnecessary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Dec 12, 2023
1 parent 9187118 commit 02d158e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 566 deletions.
213 changes: 0 additions & 213 deletions recipe/emailpassword/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Loading

0 comments on commit 02d158e

Please sign in to comment.