-
Notifications
You must be signed in to change notification settings - Fork 899
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #966 from teamhanko/feat-add-user-admin-endpoint
Feat add create user admin endpoint
- Loading branch information
Showing
7 changed files
with
293 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"github.com/teamhanko/hanko/backend/test" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
|
@@ -153,3 +154,96 @@ func (s *userAdminSuite) TestUserHandlerAdmin_List_InvalidPaginationParam() { | |
|
||
s.Equal(http.StatusBadRequest, rec.Code) | ||
} | ||
|
||
func (s *userAdminSuite) TestUserHandlerAdmin_Create() { | ||
if testing.Short() { | ||
s.T().Skip("skipping test in short mode.") | ||
} | ||
|
||
e := NewAdminRouter(&test.DefaultConfig, s.Storage, nil) | ||
|
||
tests := []struct { | ||
name string | ||
body string | ||
expectedStatusCode int | ||
}{ | ||
{ | ||
name: "success", | ||
body: `{"emails": [{"address": "[email protected]", "is_primary": true}]}`, | ||
expectedStatusCode: http.StatusOK, | ||
}, | ||
{ | ||
name: "success with user id", | ||
body: `{"id": "98a46ea2-51f6-4e30-bd29-8272de77c8c8", "emails": [{"address": "[email protected]", "is_primary": true}]}`, | ||
expectedStatusCode: http.StatusOK, | ||
}, | ||
{ | ||
name: "success with multiple emails", | ||
body: `{"emails": [{"address": "[email protected]", "is_primary": true}, {"address": "[email protected]"}]}`, | ||
expectedStatusCode: http.StatusOK, | ||
}, | ||
{ | ||
name: "success with created_at", | ||
body: `{"emails": [{"address": "[email protected]", "is_primary": true}], "created_at": "2023-06-07T13:42:49.369489Z"}`, | ||
expectedStatusCode: http.StatusOK, | ||
}, | ||
{ | ||
name: "with already existing user id", | ||
body: `{"id": "b5dd5267-b462-48be-b70d-bcd6f1bbe7a5", "emails": [{"address": "[email protected]", "is_primary": true}]}`, | ||
expectedStatusCode: http.StatusConflict, | ||
}, | ||
{ | ||
name: "with non uuid v4 id", | ||
body: `{"id": "customId", "emails": [{"address": "[email protected]", "is_primary": true}]}`, | ||
expectedStatusCode: http.StatusBadRequest, | ||
}, | ||
{ | ||
name: "with no emails", | ||
body: `{"id": "98a46ea2-51f6-4e30-bd29-8272de77c8c8", "emails": []}`, | ||
expectedStatusCode: http.StatusBadRequest, | ||
}, | ||
{ | ||
name: "with missing emails", | ||
body: `{"id": "98a46ea2-51f6-4e30-bd29-8272de77c8c8"}`, | ||
expectedStatusCode: http.StatusBadRequest, | ||
}, | ||
{ | ||
name: "with no primary email", | ||
body: `{"emails": [{"address": "[email protected]"}]}`, | ||
expectedStatusCode: http.StatusBadRequest, | ||
}, | ||
{ | ||
name: "with multiple primary emails", | ||
body: `{"emails": [{"address": "[email protected]", "is_primary": true"}, {"address": "[email protected]", "is_primary": true"}]}`, | ||
expectedStatusCode: http.StatusBadRequest, | ||
}, | ||
{ | ||
name: "with non unique emails", | ||
body: `{"emails": [{"address": "[email protected]", "is_primary": true"}, {"address": "[email protected]"}]}`, | ||
expectedStatusCode: http.StatusBadRequest, | ||
}, | ||
{ | ||
name: "with already existing email", | ||
body: `{"emails": [{"address": "[email protected]", "is_primary": true}]}`, | ||
expectedStatusCode: http.StatusConflict, | ||
}, | ||
} | ||
|
||
for _, currentTest := range tests { | ||
s.Run(currentTest.name, func() { | ||
s.Require().NoError(s.Storage.MigrateUp()) | ||
|
||
err := s.LoadFixtures("../test/fixtures/user_admin") | ||
s.Require().NoError(err) | ||
|
||
req := httptest.NewRequest(http.MethodPost, "/users", strings.NewReader(currentTest.body)) | ||
req.Header.Set("Content-Type", "application/json") | ||
rec := httptest.NewRecorder() | ||
|
||
e.ServeHTTP(rec, req) | ||
|
||
s.Equal(currentTest.expectedStatusCode, rec.Code) | ||
s.Require().NoError(s.Storage.MigrateDown(-1)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters