Skip to content

Commit

Permalink
Fix collections controller 204 (#2740)
Browse files Browse the repository at this point in the history
The RFC spec for 204s specifies that you can't send through a response
body. The tests didn't pick this up because we're not using a real
webserver during tests.

Fixes #2733
  • Loading branch information
stuartc authored Dec 3, 2024
1 parent 67a4710 commit 09e3b6c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ and this project adheres to

### Fixed

- Collections controller sending an invalid response body when a item doesn't
exist [#2733](https://github.com/OpenFn/lightning/issues/2733)

## [v2.10.4] - 2024-11-22

### Added
Expand Down
4 changes: 1 addition & 3 deletions lib/lightning_web/controllers/collections_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ defmodule LightningWeb.CollectionsController do
:ok <- authorize(conn, collection) do
case Collections.get(collection, key) do
nil ->
conn
|> put_status(:no_content)
|> json(nil)
resp(conn, :no_content, "")

item ->
json(conn, item)
Expand Down
2 changes: 1 addition & 1 deletion test/lightning_web/collections_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule LightningWeb.API.CollectionsControllerTest do
|> assign_bearer(token)
|> get(~p"/collections/#{collection.name}/some-unexisting-key")

assert json_response(conn, 204) == nil
assert response(conn, 204) == ""
end
end

Expand Down

0 comments on commit 09e3b6c

Please sign in to comment.