Skip to content

Commit

Permalink
Fix sending submissions as signed-out listener, add automated test ag…
Browse files Browse the repository at this point in the history
…ainst regressions
  • Loading branch information
skanderm committed Jan 17, 2024
1 parent 46e5b33 commit b1227f2
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 5 deletions.
4 changes: 2 additions & 2 deletions server/lib/orcasite/radio/candidate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ defmodule Orcasite.Radio.Candidate do
authorize_if always()
end

policy action_type(:read) do
bypass action_type(:read) do
authorize_if always()
end

policy action_type(:create) do
bypass action_type(:create) do
authorize_if always()
end

Expand Down
4 changes: 2 additions & 2 deletions server/lib/orcasite/radio/detection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ defmodule Orcasite.Radio.Detection do
authorize_if always()
end

policy action_type(:read) do
bypass action_type(:read) do
authorize_if always()
end

policy action_type(:create) do
bypass action_type(:create) do
authorize_if always()
end

Expand Down
2 changes: 1 addition & 1 deletion server/lib/orcasite/radio/feed.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule Orcasite.Radio.Feed do
authorize_if always()
end

policy action_type(:read) do
bypass action_type(:read) do
authorize_if always()
end
end
Expand Down
72 changes: 72 additions & 0 deletions server/test/orcasite_web/graphql/radio_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
defmodule OrcasiteWeb.RadioTest do
use OrcasiteWeb.ConnCase

setup do
feed =
Orcasite.Radio.Feed
|> Ash.Changeset.for_create(
:create,
%{
lat_lng_string: "48.5583362, -123.1735774",
name: "Orcasound Lab (Haro Strait)",
node_name: "rpi_orcasound_lab",
slug: "orcasound-lab"
}
)
|> Orcasite.Radio.create!()

[feed: feed]
end

test "unauthenticated listeners can submit a detection", %{conn: conn, feed: feed} do
conn =
conn
|> post("/graphql", %{
"query" => """
mutation submitDetection(
$feedId: String!
$playlistTimestamp: Int!
$playerOffset: Decimal!
$description: String!
$listenerCount: Int
$category: DetectionCategory!
) {
submitDetection(
input: {
feedId: $feedId
playlistTimestamp: $playlistTimestamp
playerOffset: $playerOffset
listenerCount: $listenerCount
description: $description
category: $category
sendNotifications: false
}
) {
result {
id
}
errors {
message
code
fields
shortMessage
vars
}
}
}
""",
"variables" => %{
"feedId" => feed.id,
"playlistTimestamp" => DateTime.to_unix(DateTime.utc_now()),
"playerOffset" => 5.54,
"description" => "Test detection",
"listenerCount" => 1,
"category" => "OTHER"
}
})

assert %{"data" => %{"submitDetection" => %{"errors" => [], "result" => %{"id" => id}}}} =
json_response(conn, 200)
assert "det_" <> _ = id
end
end
15 changes: 15 additions & 0 deletions ui/src/graphql/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,14 @@ export type SubmitDetectionMutation = {
submitDetection?: {
__typename?: "SubmitDetectionResult";
result?: { __typename?: "Detection"; id: string } | null;
errors?: Array<{
__typename?: "MutationError";
message?: string | null;
code?: string | null;
fields?: Array<string | null> | null;
shortMessage?: string | null;
vars?: { [key: string]: any } | null;
} | null> | null;
} | null;
};

Expand Down Expand Up @@ -1694,6 +1702,13 @@ export const SubmitDetectionDocument = `
result {
id
}
errors {
message
code
fields
shortMessage
vars
}
}
}
`;
Expand Down
7 changes: 7 additions & 0 deletions ui/src/graphql/mutations/submitDetection.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ mutation submitDetection(
result {
id
}
errors {
message
code
fields
shortMessage
vars
}
}
}

0 comments on commit b1227f2

Please sign in to comment.