chore: Add IsSubscribedToResource endpoint#4081
Merged
Merged
Conversation
Signed-off-by: Adriano Lazzaretti <lazzaretti136@gmail.com>
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
IsSubscribedToResourceTest, the "returns 404 for non-existent resource" case appears in both the permissions and functionality describes with very similar setup and assertions; consider consolidating this into a shared helper or a single describe to avoid duplication and keep the intent clearer. - The long
caseinload_resource/2overresource_typeis getting quite large; consider extracting the mapping fromresource_typeto{module, function}(or a small behaviour) to make it easier to extend and to reduce the size and branching of this function.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `IsSubscribedToResourceTest`, the "returns 404 for non-existent resource" case appears in both the permissions and functionality describes with very similar setup and assertions; consider consolidating this into a shared helper or a single describe to avoid duplication and keep the intent clearer.
- The long `case` in `load_resource/2` over `resource_type` is getting quite large; consider extracting the mapping from `resource_type` to `{module, function}` (or a small behaviour) to make it easier to extend and to reduce the size and branching of this function.
## Individual Comments
### Comment 1
<location> `app/lib/operately_web/api/queries/is_resource_subscribed.ex:27-31` </location>
<code_context>
+ |> respond()
+ end
+
+ defp respond(result) do
+ case result do
+ {:ok, ctx} -> {:ok, ctx.serialized}
+ {:error, :resource_id, _} -> {:error, :bad_request}
+ {:error, :resource, %{error: :invalid_resource_type}} -> {:error, :bad_request}
+ {:error, :resource, _} -> {:error, :not_found}
+ {:error, :check_permissions, _} -> {:error, :not_found}
</code_context>
<issue_to_address>
**issue (bug_risk):** The `invalid_resource_type` error shape from `load_resource/2` will not match the `respond/1` clause and will currently resolve as `:not_found` instead of `:bad_request`.
`load_resource/2` returns `{:error, :invalid_resource_type}`, which becomes `{:error, :resource, :invalid_resource_type}` in the `Action` pipeline. `respond/1` is instead matching `{:error, :resource, %{error: :invalid_resource_type}}`, so this clause never fires and the error falls through to `:not_found`. To return `:bad_request` for this case, either update the pattern in `respond/1` to `{:error, :resource, :invalid_resource_type}` or change `load_resource/2` to emit a `%{error: :invalid_resource_type}` map.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.