Skip to content

Commit

Permalink
Refactored TestGetBountyById UT v1
Browse files Browse the repository at this point in the history
  • Loading branch information
MirzaHanan committed Jun 24, 2024
1 parent 938e0bc commit ca56860
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
13 changes: 4 additions & 9 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,16 @@ func (h *bountyHandler) GetBountyById(w http.ResponseWriter, r *http.Request) {
bountyId := chi.URLParam(r, "bountyId")
if bountyId == "" {
w.WriteHeader(http.StatusNotFound)
return
}
bounties, err := h.db.GetBountyById(bountyId)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("[bounty] Error", err)
return
}
if len(bounties) == 0 {
w.WriteHeader(http.StatusBadRequest)
return
} else {
var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}
var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}

func (h *bountyHandler) GetNextBountyByCreated(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 2 additions & 2 deletions handlers/bounty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,8 +1038,8 @@ func TestGetBountyById(t *testing.T) {
handler := http.HandlerFunc(bHandler.GetBountyById)

rctx := chi.NewRouteContext()
rctx.URLParams.Add("bountyId", "999")
req, err := http.NewRequestWithContext(context.WithValue(context.Background(), chi.RouteCtxKey, rctx), http.MethodGet, "/bounty/999", nil)
rctx.URLParams.Add("bountyId", "Invalid-id")
req, err := http.NewRequestWithContext(context.WithValue(context.Background(), chi.RouteCtxKey, rctx), http.MethodGet, "/bounty/Invalid-id", nil)
assert.NoError(t, err)

handler.ServeHTTP(rr, req)
Expand Down

0 comments on commit ca56860

Please sign in to comment.