-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write integration test for the POST
/users
endpoint
- Loading branch information
1 parent
4d24658
commit 720987a
Showing
2 changed files
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,24 @@ func TestServerWithSqliteStore(t *testing.T) { | |
fmt.Println("tasks", tasks) | ||
assert.DoesNotContain(t, tasks, *unwantedTask) | ||
}) | ||
|
||
t.Run("users", func(t *testing.T) { | ||
createUserDTO := models.NewCreateUserDTO( | ||
"Sherlock", | ||
"[email protected]", | ||
"sherlocked", | ||
) | ||
postUserResponse, err := sendPostUser(server, createUserDTO) | ||
assert.HasNoError(t, err) | ||
createdUser := testutils.GetUserFromResponse(t, postUserResponse.Body) | ||
wantedUser := models.NewUser( | ||
createdUser.Id, | ||
createUserDTO.Name, | ||
createdUser.Email, | ||
createUserDTO.Password, | ||
) | ||
assert.Equals(t, createdUser, *wantedUser) | ||
}) | ||
} | ||
|
||
func TestServerWithFileSystemStore(t *testing.T) { | ||
|
@@ -233,6 +251,24 @@ func sendPostTask(server *api.Server, dto *models.CreateTaskDTO) ( | |
return response, nil | ||
} | ||
|
||
func sendPostUser(server *api.Server, dto *models.CreateUserDTO) ( | ||
*httptest.ResponseRecorder, | ||
error, | ||
) { | ||
jsonBody, err := json.Marshal(dto) | ||
if err != nil { | ||
return nil, err | ||
} | ||
request := httptest.NewRequest( | ||
http.MethodPost, | ||
"/users", | ||
bytes.NewBuffer(jsonBody), | ||
) | ||
response := httptest.NewRecorder() | ||
server.ServeHTTP(response, request) | ||
return response, nil | ||
} | ||
|
||
func cleanSqliteDatabase(path string) { | ||
os.Remove(path) | ||
} |
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