Skip to content

Commit

Permalink
Return 404 from PUT /library/casts when the cast doesnt exist
Browse files Browse the repository at this point in the history
  • Loading branch information
khlieng committed Jul 9, 2015
1 parent 54d7745 commit da5012e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 8 additions & 6 deletions api/casts.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ func renameCast(c *echo.Context) error {
}

cast := store.GetCast(id)
if cast != nil {
prev := cast.Name
cast.Name = form(c, "name")
if cast.Name != prev {
return store.SaveCast(cast)
}
if cast == nil {
return c.String(404, "Cast not found")
}

prev := cast.Name
cast.Name = form(c, "name")
if cast.Name != prev {
return store.SaveCast(cast)
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions api/casts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,16 @@ func TestRenameCast(t *testing.T) {
res := req.send()
assert.Equal(t, 200, res.Code)
assert.Equal(t, "new", store.GetCast(1).Name)
res = req.send()
assert.Equal(t, 200, res.Code)

// It should return 400 if the ID is invalid
req.URL.Path = "/library/casts/nope"
assert.Equal(t, 400, req.send().Code)

// It returns 200 if the cast is not found
// It returns 404 if the cast is not found
req.URL.Path = "/library/casts/1337"
assert.Equal(t, 200, req.send().Code)
assert.Equal(t, 404, req.send().Code)
}

func TestRemoveCast(t *testing.T) {
Expand Down

0 comments on commit da5012e

Please sign in to comment.