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 14, 2023
1 parent d9018de commit 061d0bb
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion recipe/emailpassword/accountlinkingRecipeImplementation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ func TestLinkAccountFailureAccountInfoAlreadyAssociatedWithAnotherPrimaryUser(t

}

func TestUnLinkAccountsSuccess(t *testing.T) {
func TestUnlinkAccountsSuccess(t *testing.T) {
BeforeEach()
unittesting.StartUpST("localhost", "8080")
defer AfterEach()
Expand Down Expand Up @@ -1222,6 +1222,63 @@ func TestUnLinkAccountsSuccess(t *testing.T) {
assert.Len(t, sessions, 0)
}

func TestUnlinkAccountsWithDeleteUserSuccess(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{
session.Init(nil),
Init(nil),
supertokens.InitAccountLinking(nil),
},
})

epuser, err := SignUp("public", "test@gmail.com", "pass123")
if err != nil {
t.Error(err)
return
}

user1 := convertEpUserToSuperTokensUser(epuser.OK.User)
assert.False(t, user1.IsPrimaryUser)
supertokens.CreatePrimaryUser(user1.LoginMethods[0].RecipeUserID)

epuser2, err := SignUp("public", "test2@gmail.com", "pass123")
if err != nil {
t.Error(err)
return
}

user2 := convertEpUserToSuperTokensUser(epuser2.OK.User)
assert.False(t, user2.IsPrimaryUser)

linkAccountResponse, err := supertokens.LinkAccounts(user2.LoginMethods[0].RecipeUserID, user1.ID)
if err != nil {
t.Error(err)
return
}
assert.False(t, linkAccountResponse.OK.AccountsAlreadyLinked)

unlinkResponse, err := supertokens.UnlinkAccounts(user1.LoginMethods[0].RecipeUserID)
if err != nil {
t.Error(err)
return
}
assert.True(t, unlinkResponse.WasRecipeUserDeleted)
assert.True(t, unlinkResponse.WasLinked)
}

// TODO: remove this function
func convertEpUserToSuperTokensUser(epuser epmodels.User) supertokens.User {
rUId, err := supertokens.NewRecipeUserID(epuser.ID)
Expand Down

0 comments on commit 061d0bb

Please sign in to comment.