|
| 1 | +package thirdpartyemailpassword |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "io/ioutil" |
| 6 | + "net/http" |
| 7 | + "net/http/httptest" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | + "github.com/supertokens/supertokens-golang/supertokens" |
| 12 | + "github.com/supertokens/supertokens-golang/test/unittesting" |
| 13 | +) |
| 14 | + |
| 15 | +func TestLoginMethodsReturnEmptyProviderArray(t *testing.T) { |
| 16 | + configValue := supertokens.TypeInput{ |
| 17 | + Supertokens: &supertokens.ConnectionInfo{ |
| 18 | + ConnectionURI: "http://localhost:8080", |
| 19 | + }, |
| 20 | + AppInfo: supertokens.AppInfo{ |
| 21 | + APIDomain: "api.supertokens.io", |
| 22 | + AppName: "SuperTokens", |
| 23 | + WebsiteDomain: "supertokens.io", |
| 24 | + }, |
| 25 | + RecipeList: []supertokens.Recipe{ |
| 26 | + Init(nil), |
| 27 | + }, |
| 28 | + } |
| 29 | + |
| 30 | + BeforeEach() |
| 31 | + unittesting.StartUpST("localhost", "8080") |
| 32 | + defer AfterEach() |
| 33 | + err := supertokens.Init(configValue) |
| 34 | + if err != nil { |
| 35 | + t.Error(err.Error()) |
| 36 | + } |
| 37 | + mux := http.NewServeMux() |
| 38 | + testServer := httptest.NewServer(supertokens.Middleware(mux)) |
| 39 | + defer testServer.Close() |
| 40 | + |
| 41 | + resp, err := http.Get(testServer.URL + "/auth/loginmethods") |
| 42 | + if err != nil { |
| 43 | + t.Error(err.Error()) |
| 44 | + } |
| 45 | + assert.Equal(t, http.StatusOK, resp.StatusCode) |
| 46 | + |
| 47 | + respObj := map[string]interface{}{} |
| 48 | + respBytes, err := ioutil.ReadAll(resp.Body) |
| 49 | + assert.Nil(t, err) |
| 50 | + err = json.Unmarshal(respBytes, &respObj) |
| 51 | + assert.Nil(t, err) |
| 52 | + providersArr, ok := respObj["thirdParty"].(map[string]interface{})["providers"] |
| 53 | + assert.True(t, ok) |
| 54 | + assert.NotNil(t, providersArr) |
| 55 | +} |
0 commit comments