diff --git a/recipe/emailpassword/accountlinkingRecipeImplementation_test.go b/recipe/emailpassword/accountlinkingRecipeImplementation_test.go index 0b5c3d13..c90d683d 100644 --- a/recipe/emailpassword/accountlinkingRecipeImplementation_test.go +++ b/recipe/emailpassword/accountlinkingRecipeImplementation_test.go @@ -1279,6 +1279,50 @@ func TestUnlinkAccountsWithDeleteUserSuccess(t *testing.T) { assert.True(t, unlinkResponse.WasLinked) } +func TestDeleteUser(t *testing.T) { + telemetry := false + configValue := supertokens.TypeInput{ + Telemetry: &telemetry, + Supertokens: &supertokens.ConnectionInfo{ + ConnectionURI: "http://localhost:8080", + }, + AppInfo: supertokens.AppInfo{ + APIDomain: "api.supertokens.io", + AppName: "SuperTokens", + WebsiteDomain: "supertokens.io", + }, + RecipeList: []supertokens.Recipe{ + Init(nil), + }, + } + BeforeEach() + unittesting.StartUpST("localhost", "8080") + defer AfterEach() + err := supertokens.Init(configValue) + if err != nil { + t.Error(err.Error()) + } + + res, err := SignUp("public", "test@example.com", "1234abcd") + if err != nil { + t.Error(err.Error()) + } + reponseBeforeDeletingUser, err := supertokens.GetUsersOldestFirst("public", nil, nil, nil, nil) + if err != nil { + t.Error(err.Error()) + } + assert.Equal(t, 1, len(reponseBeforeDeletingUser.Users)) + err = supertokens.DeleteUser(res.OK.User.ID, true) + if err != nil { + t.Error(err.Error()) + } + responseAfterDeletingUser, err := supertokens.GetUsersOldestFirst("public", nil, nil, nil, nil) + if err != nil { + t.Error(err.Error()) + } + assert.Equal(t, 0, len(responseAfterDeletingUser.Users)) +} + // TODO: remove this function func convertEpUserToSuperTokensUser(epuser epmodels.User) supertokens.User { rUId, err := supertokens.NewRecipeUserID(epuser.ID) diff --git a/recipe/emailpassword/deleteUser_test.go b/recipe/emailpassword/deleteUser_test.go deleted file mode 100644 index 32a7e172..00000000 --- a/recipe/emailpassword/deleteUser_test.go +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package emailpassword - -import ( - "net/http" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/supertokens/supertokens-golang/recipe/session" - "github.com/supertokens/supertokens-golang/recipe/session/sessmodels" - "github.com/supertokens/supertokens-golang/supertokens" - "github.com/supertokens/supertokens-golang/test/unittesting" -) - -func TestDeleteUser(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()) - } - querier, err := supertokens.GetNewQuerierInstanceOrThrowError("") - if err != nil { - t.Error(err.Error()) - } - cdiVersion, err := querier.GetQuerierAPIVersion() - if err != nil { - t.Error(err.Error()) - } - if unittesting.MaxVersion("2.10", cdiVersion) == cdiVersion { - res, err := SignUp("public", "test@example.com", "1234abcd") - if err != nil { - t.Error(err.Error()) - } - reponseBeforeDeletingUser, err := supertokens.GetUsersOldestFirst("public", nil, nil, nil, nil) - if err != nil { - t.Error(err.Error()) - } - assert.Equal(t, 1, len(reponseBeforeDeletingUser.Users)) - err = supertokens.DeleteUser(res.OK.User.ID) - if err != nil { - t.Error(err.Error()) - } - responseAfterDeletingUser, err := supertokens.GetUsersOldestFirst("public", nil, nil, nil, nil) - if err != nil { - t.Error(err.Error()) - } - assert.Equal(t, 0, len(responseAfterDeletingUser.Users)) - } -} diff --git a/recipe/emailpassword/emailExistsAndVerificationCheck_test.go b/recipe/emailpassword/emailExistsAndVerificationCheck_test.go index aa206463..b3f19205 100644 --- a/recipe/emailpassword/emailExistsAndVerificationCheck_test.go +++ b/recipe/emailpassword/emailExistsAndVerificationCheck_test.go @@ -1854,7 +1854,7 @@ func TestEmailVerifyWithDeletedUser(t *testing.T) { userId := response["user"].(map[string]interface{})["id"] cookieData := unittesting.ExtractInfoFromResponse(resp) - supertokens.DeleteUser(userId.(string)) + supertokens.DeleteUser(userId.(string), true) resp1, err := unittesting.EmailVerifyTokenRequest(testServer.URL, userId.(string), cookieData["sAccessToken"], cookieData["antiCsrf"]) diff --git a/recipe/emailpassword/userIdMapping_users_test.go b/recipe/emailpassword/userIdMapping_users_test.go index 2448acdd..166b14c3 100644 --- a/recipe/emailpassword/userIdMapping_users_test.go +++ b/recipe/emailpassword/userIdMapping_users_test.go @@ -37,7 +37,7 @@ func TestCreateUserIdMappingAndDeleteUser(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, createResp.OK) - err = supertokens.DeleteUser(externalUserId) + err = supertokens.DeleteUser(externalUserId, true) assert.NoError(t, err) }