Skip to content

Commit

Permalink
adds more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Dec 12, 2023
1 parent 8ef58ce commit 9187118
Showing 1 changed file with 262 additions and 0 deletions.
262 changes: 262 additions & 0 deletions recipe/emailpassword/accountlinkingRecipeImplementation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 9187118

Please sign in to comment.