Skip to content

Commit

Permalink
moves tests around and removes tpep folder
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Apr 9, 2024
1 parent 8f65e8e commit edcc793
Show file tree
Hide file tree
Showing 34 changed files with 610 additions and 4,000 deletions.
3 changes: 2 additions & 1 deletion frontendDriverInterfaceSupported.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"_comment": "contains a list of frontend-driver interfaces branch names that this core supports",
"versions": [
"1.17"
"1.17",
"2.0"
]
}
59 changes: 3 additions & 56 deletions recipe/dashboard/api/userdetails/userPasswordPut.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword"
"github.com/supertokens/supertokens-golang/supertokens"
)

Expand Down Expand Up @@ -69,66 +68,14 @@ func UserPasswordPut(apiInterface dashboardmodels.APIInterface, tenantId string,
recipeToUse = "emailpassword"
}

if recipeToUse == "none" {
tpepInstance := thirdpartyemailpassword.GetRecipeInstance()

if tpepInstance != nil {
recipeToUse = "thirdpartyemailpassword"
}
}

if recipeToUse == "none" {
// This means that neither emailpassword or thirdpartyemailpassword is initialised
return userPasswordPutResponse{}, errors.New("Should never come here")
}

if recipeToUse == "emailpassword" {
var passwordField epmodels.NormalisedFormField

for _, value := range emailPasswordInstance.Config.SignUpFeature.FormFields {
if value.ID == "password" {
passwordField = value
}
}

validationError := passwordField.Validate(*readBody.NewPassword, tenantId)

if validationError != nil {
return userPasswordPutResponse{
Status: "INVALID_PASSWORD_ERROR",
Error: *validationError,
}, nil
}

passwordResetToken, resetTokenErr := emailpassword.CreateResetPasswordToken(tenantId, *readBody.UserId, userContext)

if resetTokenErr != nil {
return userPasswordPutResponse{}, resetTokenErr
}

if passwordResetToken.UnknownUserIdError != nil {
// Techincally it can but its an edge case so we assume that it wont
return userPasswordPutResponse{}, errors.New("Should never come here")
}

passwordResetResponse, passwordResetErr := emailpassword.ResetPasswordUsingToken(tenantId, passwordResetToken.OK.Token, *readBody.NewPassword, userContext)

if passwordResetErr != nil {
return userPasswordPutResponse{}, passwordResetErr
}

if passwordResetResponse.ResetPasswordInvalidTokenError != nil {
return userPasswordPutResponse{}, errors.New("Should never come here")
}

return userPasswordPutResponse{
Status: "OK",
}, nil
}

var passwordField epmodels.NormalisedFormField

for _, value := range thirdpartyemailpassword.GetRecipeInstance().GetEmailPasswordRecipe().Config.SignUpFeature.FormFields {
for _, value := range emailPasswordInstance.Config.SignUpFeature.FormFields {
if value.ID == "password" {
passwordField = value
}
Expand All @@ -143,7 +90,7 @@ func UserPasswordPut(apiInterface dashboardmodels.APIInterface, tenantId string,
}, nil
}

passwordResetToken, resetTokenErr := thirdpartyemailpassword.CreateResetPasswordToken(tenantId, *readBody.UserId, userContext)
passwordResetToken, resetTokenErr := emailpassword.CreateResetPasswordToken(tenantId, *readBody.UserId, userContext)

if resetTokenErr != nil {
return userPasswordPutResponse{}, resetTokenErr
Expand All @@ -154,7 +101,7 @@ func UserPasswordPut(apiInterface dashboardmodels.APIInterface, tenantId string,
return userPasswordPutResponse{}, errors.New("Should never come here")
}

passwordResetResponse, passwordResetErr := thirdpartyemailpassword.ResetPasswordUsingToken(tenantId, passwordResetToken.OK.Token, *readBody.NewPassword, userContext)
passwordResetResponse, passwordResetErr := emailpassword.ResetPasswordUsingToken(tenantId, passwordResetToken.OK.Token, *readBody.NewPassword, userContext)

if passwordResetErr != nil {
return userPasswordPutResponse{}, passwordResetErr
Expand Down
41 changes: 0 additions & 41 deletions recipe/dashboard/api/userdetails/userPut.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
"github.com/supertokens/supertokens-golang/recipe/passwordless"
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless"
"github.com/supertokens/supertokens-golang/recipe/usermetadata"
"github.com/supertokens/supertokens-golang/supertokens"
Expand Down Expand Up @@ -95,46 +94,6 @@ func updateEmailForRecipeId(recipeId string, userId string, email string, tenant
}, nil
}

if recipeId == "thirdpartyemailpassword" {
var emailField epmodels.NormalisedFormField

for _, value := range thirdpartyemailpassword.GetRecipeInstance().GetEmailPasswordRecipe().Config.SignUpFeature.FormFields {
if value.ID == "email" {
emailField = value
}
}

validationError := emailField.Validate(email, tenantId)

if validationError != nil {
return updateEmailResponse{
Status: "INVALID_EMAIL_ERROR",
Error: *validationError,
}, nil
}

tenantId := "public"
updateResponse, err := thirdpartyemailpassword.UpdateEmailOrPassword(userId, &email, nil, nil, &tenantId, userContext)

if err != nil {
return updateEmailResponse{}, err
}

if updateResponse.EmailAlreadyExistsError != nil {
return updateEmailResponse{
Status: "EMAIL_ALREADY_EXISTS_ERROR",
}, nil
}

if updateResponse.UnknownUserIdError != nil {
return updateEmailResponse{}, errors.New("Should never come here")
}

return updateEmailResponse{
Status: "OK",
}, nil
}

if recipeId == "passwordless" {
isValidEmail := true
validationError := ""
Expand Down
49 changes: 0 additions & 49 deletions recipe/dashboard/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
"github.com/supertokens/supertokens-golang/recipe/passwordless"
"github.com/supertokens/supertokens-golang/recipe/thirdparty"
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless"
"github.com/supertokens/supertokens-golang/supertokens"
)
Expand Down Expand Up @@ -45,21 +44,6 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.

recipeToReturn = emailpassword.RECIPE_ID
}

if reflect.DeepEqual(userToReturn, dashboardmodels.UserType{}) {
tpepResponse, tpepError := thirdpartyemailpassword.GetUserById(userId, userContext)

if tpepError == nil && tpepResponse != nil {
userToReturn.Id = tpepResponse.ID
userToReturn.TimeJoined = tpepResponse.TimeJoined
userToReturn.FirstName = ""
userToReturn.LastName = ""
userToReturn.Email = tpepResponse.Email
userToReturn.TenantIds = tpepResponse.TenantIds

recipeToReturn = thirdpartyemailpassword.RECIPE_ID
}
}
} else if recipeId == thirdparty.RECIPE_ID {
response, error := thirdparty.GetUserByID(userId, userContext)

Expand All @@ -76,23 +60,6 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.
userToReturn.TenantIds = response.TenantIds
}

if reflect.DeepEqual(userToReturn, dashboardmodels.UserType{}) {
tpepResponse, tpepError := thirdpartyemailpassword.GetUserById(userId, userContext)

if tpepError == nil && tpepResponse != nil {
userToReturn.Id = tpepResponse.ID
userToReturn.TimeJoined = tpepResponse.TimeJoined
userToReturn.FirstName = ""
userToReturn.LastName = ""
userToReturn.Email = tpepResponse.Email
userToReturn.ThirdParty = &dashboardmodels.ThirdParty{
Id: tpepResponse.ThirdParty.ID,
UserId: tpepResponse.ThirdParty.UserID,
}
userToReturn.TenantIds = tpepResponse.TenantIds
}
}

if reflect.DeepEqual(userToReturn, dashboardmodels.UserType{}) {
tpplessResponse, tpplessError := thirdpartypasswordless.GetUserById(userId, userContext)

Expand Down Expand Up @@ -171,14 +138,6 @@ func IsRecipeInitialised(recipeId string) bool {
if err == nil {
isRecipeInitialised = true
}

if !isRecipeInitialised {
_, err := thirdpartyemailpassword.GetRecipeInstanceOrThrowError()

if err == nil {
isRecipeInitialised = true
}
}
} else if recipeId == passwordless.RECIPE_ID {
_, err := passwordless.GetRecipeInstanceOrThrowError()

Expand All @@ -200,14 +159,6 @@ func IsRecipeInitialised(recipeId string) bool {
isRecipeInitialised = true
}

if !isRecipeInitialised {
_, err := thirdpartyemailpassword.GetRecipeInstanceOrThrowError()

if err == nil {
isRecipeInitialised = true
}
}

if !isRecipeInitialised {
_, err := thirdpartypasswordless.GetRecipeInstanceOrThrowError()

Expand Down
2 changes: 0 additions & 2 deletions recipe/dashboard/testingUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"github.com/supertokens/supertokens-golang/recipe/multitenancy"
"github.com/supertokens/supertokens-golang/recipe/session"
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword"

"github.com/supertokens/supertokens-golang/supertokens"
"github.com/supertokens/supertokens-golang/test/unittesting"
Expand All @@ -30,7 +29,6 @@ func resetAll() {
supertokens.ResetForTest()
ResetForTest()
session.ResetForTest()
thirdpartyemailpassword.ResetForTest()
multitenancy.ResetForTest()
}

Expand Down
19 changes: 9 additions & 10 deletions recipe/dashboard/userGet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@ package dashboard

import (
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/supertokens/supertokens-golang/recipe/dashboard/api"
"github.com/supertokens/supertokens-golang/recipe/dashboard/api/userdetails"
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
"github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels"
"github.com/supertokens/supertokens-golang/recipe/session"
"github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword"
"github.com/supertokens/supertokens-golang/supertokens"
"github.com/supertokens/supertokens-golang/test/unittesting"
)

/*
- Initialise with thirdpartyemailpassword and provide no custom form fields
- Create an emailpassword user using the thirdpartyemailpassword recipe
- Get user from the user get API
- Check that user has public tenant
*/
Expand All @@ -42,7 +41,7 @@ func TestThatUserGetReturnsTenantIDsCorrectly(t *testing.T) {
WebsiteDomain: "supertokens.io",
},
RecipeList: []supertokens.Recipe{
thirdpartyemailpassword.Init(nil),
emailpassword.Init(nil),
Init(&dashboardmodels.TypeInput{
ApiKey: "testapikey",
}),
Expand All @@ -61,7 +60,7 @@ func TestThatUserGetReturnsTenantIDsCorrectly(t *testing.T) {
testServer := httptest.NewServer(supertokens.Middleware(mux))
defer testServer.Close()

signupResponse, err := thirdpartyemailpassword.EmailPasswordSignUp("public", "[email protected]", "abcd1234")
signupResponse, err := emailpassword.SignUp("public", "[email protected]", "abcd1234")
if err != nil {
t.Error(err.Error())
}
Expand Down
10 changes: 4 additions & 6 deletions recipe/dashboard/userPasswordPut_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import (

"github.com/stretchr/testify/assert"
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword"
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
"github.com/supertokens/supertokens-golang/supertokens"
"github.com/supertokens/supertokens-golang/test/unittesting"
)

/*
- Initialise with thirdpartyemailpassword and provide no custom form fields
- Create an emailpassword user using the thirdpartyemailpassword recipe
- Try to change the password of the user
- Should result in no errors
- Sign in with new password
Expand All @@ -35,7 +33,7 @@ func TestThatUpdatingPasswordWithNoSignUpFeatureInTPEPWorks(t *testing.T) {
WebsiteDomain: "supertokens.io",
},
RecipeList: []supertokens.Recipe{
thirdpartyemailpassword.Init(nil),
emailpassword.Init(nil),
Init(&dashboardmodels.TypeInput{
ApiKey: "testapikey",
}),
Expand All @@ -54,7 +52,7 @@ func TestThatUpdatingPasswordWithNoSignUpFeatureInTPEPWorks(t *testing.T) {
testServer := httptest.NewServer(supertokens.Middleware(mux))
defer testServer.Close()

signupResponse, err := thirdpartyemailpassword.EmailPasswordSignUp("public", "[email protected]", "abcd1234")
signupResponse, err := emailpassword.SignUp("public", "[email protected]", "abcd1234")
if err != nil {
t.Error(err.Error())
}
Expand All @@ -78,7 +76,7 @@ func TestThatUpdatingPasswordWithNoSignUpFeatureInTPEPWorks(t *testing.T) {

assert.Equal(t, http.StatusOK, res.StatusCode)

signInResponse, err := thirdpartyemailpassword.EmailPasswordSignIn("public", "[email protected]", "newabcd1234")
signInResponse, err := emailpassword.SignIn("public", "[email protected]", "newabcd1234")
if err != nil {
t.Error(err.Error())
}
Expand Down
10 changes: 4 additions & 6 deletions recipe/dashboard/userPut_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import (

"github.com/stretchr/testify/assert"
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword"
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
"github.com/supertokens/supertokens-golang/supertokens"
"github.com/supertokens/supertokens-golang/test/unittesting"
)

/*
- Initialise with thirdpartyemailpassword and provide no custom form fields
- Create an emailpassword user using the thirdpartyemailpassword recipe
- Try to change the password of the user
- Should result in no errors
- Sign in with new password
Expand All @@ -35,7 +33,7 @@ func TestThatUpdatingEmailWithNoSignUpFeatureInTPEPWorks(t *testing.T) {
WebsiteDomain: "supertokens.io",
},
RecipeList: []supertokens.Recipe{
thirdpartyemailpassword.Init(nil),
emailpassword.Init(nil),
Init(&dashboardmodels.TypeInput{
ApiKey: "testapikey",
}),
Expand All @@ -54,7 +52,7 @@ func TestThatUpdatingEmailWithNoSignUpFeatureInTPEPWorks(t *testing.T) {
testServer := httptest.NewServer(supertokens.Middleware(mux))
defer testServer.Close()

signupResponse, err := thirdpartyemailpassword.EmailPasswordSignUp("public", "[email protected]", "abcd1234")
signupResponse, err := emailpassword.SignUp("public", "[email protected]", "abcd1234")
if err != nil {
t.Error(err.Error())
}
Expand All @@ -78,7 +76,7 @@ func TestThatUpdatingEmailWithNoSignUpFeatureInTPEPWorks(t *testing.T) {

assert.Equal(t, http.StatusOK, res.StatusCode)

signInResponse, err := thirdpartyemailpassword.EmailPasswordSignIn("public", "[email protected]", "abcd1234")
signInResponse, err := emailpassword.SignIn("public", "[email protected]", "abcd1234")

if err != nil {
t.Error(err.Error())
Expand Down
Loading

0 comments on commit edcc793

Please sign in to comment.