Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set up GraphQL API #18

Merged
merged 16 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion envrc.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export API_KEY=
#export API_KEY=
export API_URL=https://api-dev.mbtace.com/
47 changes: 47 additions & 0 deletions test/mobile_app_backend_web/schema_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
defmodule MobileAppBackendWeb.SchemaTest do
use MobileAppBackendWeb.ConnCase

@stop_query """
query {
stop(id: "place-boyls") {
id
name
routes {
id
name
routePatterns {
id
name
}
}
}
}
"""

test "query: stop", %{conn: conn} do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (non-blocking): Can the data be mocked for this test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, but there's a lot of data in the real response, and I'm not sure which parts would and would not be reasonable to elide from the real response.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a lot of parts can be elided without breaking the test, though.

conn =
post(conn, "/graphql", %{
"query" => @stop_query
})

assert %{"data" => %{"stop" => stop_data}} = json_response(conn, 200)
assert %{"id" => "place-boyls", "name" => "Boylston", "routes" => routes} = stop_data

routes = Enum.sort_by(routes, & &1["id"])

assert routes |> Enum.map(& &1["id"]) == [
"Green-B",
"Green-C",
"Green-D",
"Green-E"
]

assert %{
"id" => "Green-B",
"name" => "Green Line B",
"routePatterns" => route_patterns
} = hd(routes)

assert length(route_patterns) > 0
end
end