def create2(_conn, _data), do: {:error, :bad_request}
@doc "PUT /api/v1/media/:id"
- def update(%{assigns: %{user: user}, body_params: %{description: description}} = conn, %{
- id: id
- })
- when is_binary(description) do
+ def update(%{assigns: %{user: user}, body_params: %{description: description}} = conn, %{id: id}) do
with %Object{} = object <- Object.get_by_id(id),
true <- Object.authorize_mutation(object, user),
{:ok, %Object{data: data}} <- Object.update_data(object, %{"name" => description}) do
end
end
- def update(_conn, _data), do: {:error, :bad_request}
+ def update(conn, data), do: show(conn, data)
@doc "GET /api/v1/media/:id"
def show(conn, %{id: id}) do
assert media["description"] == "test-media"
assert refresh_record(object).data["name"] == "test-media"
end
-
- test "/api/v1/media/:id bad request", %{conn: conn, object: object} do
- media =
- conn
- |> put_req_header("content-type", "multipart/form-data")
- |> put("/api/v1/media/#{object.id}", %{})
- |> json_response_and_validate_schema(400)
-
- assert media == %{"error" => "bad_request"}
- end
end
describe "Get media by id" do