|
| 1 | +package dashboard |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/stretchr/testify/assert" |
| 5 | + "github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels" |
| 6 | + "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" |
| 7 | + "github.com/supertokens/supertokens-golang/supertokens" |
| 8 | + "github.com/supertokens/supertokens-golang/test/unittesting" |
| 9 | + "net/http" |
| 10 | + "net/http/httptest" |
| 11 | + "strings" |
| 12 | + "testing" |
| 13 | +) |
| 14 | + |
| 15 | +/** |
| 16 | +- Initialise with thirdpartyemailpassword and provide no custom form fields |
| 17 | +- Create an emailpassword user using the thirdpartyemailpassword recipe |
| 18 | +- Try to change the password of the user |
| 19 | +- Should result in no errors |
| 20 | +- Sign in with new password |
| 21 | +- Should result in no errors and same user should be returned |
| 22 | +*/ |
| 23 | +func TestThatUpdatingEmailWithNoSignUpFeatureInTPEPWorks(t *testing.T) { |
| 24 | + config := supertokens.TypeInput{ |
| 25 | + OnSuperTokensAPIError: func(err error, req *http.Request, res http.ResponseWriter) { |
| 26 | + print(err) |
| 27 | + }, |
| 28 | + Supertokens: &supertokens.ConnectionInfo{ |
| 29 | + ConnectionURI: "http://localhost:8080", |
| 30 | + }, |
| 31 | + AppInfo: supertokens.AppInfo{ |
| 32 | + APIDomain: "api.supertokens.io", |
| 33 | + AppName: "SuperTokens", |
| 34 | + WebsiteDomain: "supertokens.io", |
| 35 | + }, |
| 36 | + RecipeList: []supertokens.Recipe{ |
| 37 | + thirdpartyemailpassword.Init(nil), |
| 38 | + Init(&dashboardmodels.TypeInput{ |
| 39 | + ApiKey: "testapikey", |
| 40 | + }), |
| 41 | + }, |
| 42 | + } |
| 43 | + |
| 44 | + BeforeEach() |
| 45 | + unittesting.StartUpST("localhost", "8080") |
| 46 | + defer AfterEach() |
| 47 | + err := supertokens.Init(config) |
| 48 | + if err != nil { |
| 49 | + t.Error(err.Error()) |
| 50 | + } |
| 51 | + |
| 52 | + mux := http.NewServeMux() |
| 53 | + testServer := httptest.NewServer(supertokens.Middleware(mux)) |
| 54 | + defer testServer.Close() |
| 55 | + |
| 56 | + signupResponse, err := thirdpartyemailpassword.EmailPasswordSignUp("testing@supertokens.com", "abcd1234") |
| 57 | + if err != nil { |
| 58 | + t.Error(err.Error()) |
| 59 | + } |
| 60 | + |
| 61 | + assert.NotNil(t, signupResponse.OK) |
| 62 | + |
| 63 | + userId := signupResponse.OK.User.ID |
| 64 | + |
| 65 | + req, err := http.NewRequest(http.MethodPut, testServer.URL+"/auth/dashboard/api/user", strings.NewReader(`{"userId": "`+userId+`", "firstName": "", "lastName": "", "phone": "", "email": "testing2@supertokens.com", "recipeId": "emailpassword"}`)) |
| 66 | + |
| 67 | + if err != nil { |
| 68 | + t.Error(err.Error()) |
| 69 | + } |
| 70 | + |
| 71 | + req.Header.Set("Authorization", "Bearer testapikey") |
| 72 | + res, err := http.DefaultClient.Do(req) |
| 73 | + |
| 74 | + if err != nil { |
| 75 | + t.Error(err.Error()) |
| 76 | + } |
| 77 | + |
| 78 | + assert.Equal(t, http.StatusOK, res.StatusCode) |
| 79 | + |
| 80 | + signInResponse, err := thirdpartyemailpassword.EmailPasswordSignIn("testing2@supertokens.com", "abcd1234") |
| 81 | + |
| 82 | + if err != nil { |
| 83 | + t.Error(err.Error()) |
| 84 | + } |
| 85 | + |
| 86 | + assert.NotNil(t, signInResponse.OK) |
| 87 | + assert.Equal(t, signInResponse.OK.User.ID, userId) |
| 88 | +} |
0 commit comments