Skip to content

Commit

Permalink
fix wrong response data
Browse files Browse the repository at this point in the history
  • Loading branch information
mfdeveloper508 committed Sep 20, 2023
1 parent eb64f55 commit 09fd306
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions cmd/server/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ func deleteFile(logger log.Logger, repo WireFileRepository) http.HandlerFunc {

w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(`{"error": null}`)

type response struct {
Error error `json:"error"`
}

json.NewEncoder(w).Encode(&response{Error: nil})
}
}

Expand Down Expand Up @@ -287,7 +292,12 @@ func validateFile(logger log.Logger, repo WireFileRepository) http.HandlerFunc {
logger.Log("validated file")
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(`{"error": null}`)

type response struct {
Error error `json:"error"`
}

json.NewEncoder(w).Encode(&response{Error: nil})
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/server/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func TestFiles_deleteFile(t *testing.T) {
w.Flush()

assert.Equal(t, http.StatusOK, w.Code, w.Body)
assert.Contains(t, w.Body.String(), `{"error":null}`)
})

t.Run("repo error", func(t *testing.T) {
Expand Down Expand Up @@ -411,8 +412,7 @@ func TestFiles_validateFile(t *testing.T) {
router.ServeHTTP(w, req)
w.Flush()

assert.Equal(t, http.StatusOK, w.Code, w.Body)
assert.Contains(t, w.Body.String(), `"{\"error\": null}"`)
assert.Contains(t, w.Body.String(), `{"error":null}`)
})

t.Run("repo error", func(t *testing.T) {
Expand Down

0 comments on commit 09fd306

Please sign in to comment.