From 061d0bbbfad4470a67f964854748dcf7c4564b37 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Thu, 14 Dec 2023 14:56:40 +0530 Subject: [PATCH] adds more tests --- ...accountlinkingRecipeImplementation_test.go | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/recipe/emailpassword/accountlinkingRecipeImplementation_test.go b/recipe/emailpassword/accountlinkingRecipeImplementation_test.go index d5bd10dd..0b5c3d13 100644 --- a/recipe/emailpassword/accountlinkingRecipeImplementation_test.go +++ b/recipe/emailpassword/accountlinkingRecipeImplementation_test.go @@ -1134,7 +1134,7 @@ func TestLinkAccountFailureAccountInfoAlreadyAssociatedWithAnotherPrimaryUser(t } -func TestUnLinkAccountsSuccess(t *testing.T) { +func TestUnlinkAccountsSuccess(t *testing.T) { BeforeEach() unittesting.StartUpST("localhost", "8080") defer AfterEach() @@ -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)