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

refactor(RoutePatterns.Repo): use factories and mock for tests #2027

Merged
merged 12 commits into from
May 6, 2024

Conversation

thecristen
Copy link
Collaborator

@thecristen thecristen commented May 2, 2024

No ticket, just a refactor that should help me test the timetable changes that's incoming.

This also removes what was left of our code relying on shape priority. As far as I can tell, we had already stopped parsing it. This field was removed in V3 API shapes in version 2020-05-01.

@thecristen thecristen marked this pull request as ready for review May 2, 2024 14:04
@thecristen thecristen requested a review from a team as a code owner May 2, 2024 14:04
@thecristen thecristen requested a review from anthonyshull May 2, 2024 14:04
Copy link
Contributor

@anthonyshull anthonyshull left a comment

Choose a reason for hiding this comment

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

Comment on lines 11 to 13
id: attrs[:id] || sequence(:id, &"item-#{&1}"),
attributes: attrs[:attributes] || %{},
relationships: attrs[:relationships] || %{}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you have to do this with the attrs. It should just override ones you pass in.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah okay, I wasn't sure how it handled nested levels

def route_pattern_item_factory(attrs) do
item = %Item{
id: attrs[:id] || sequence(:id, &"item-#{&1}"),
attributes:
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to break these out so they can be reused: attributes, relationships.

end

test "returns nil for an unknown route pattern" do
refute Repo.get("unknown_route_pattern")
expect(MBTA.Api.Mock, :get_json, fn "/route_patterns/unknown_route_pattern", _ ->
Copy link
Contributor

Choose a reason for hiding this comment

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

You could turn this into a clearer expectation and remove the hard coded checking.

test "..." do
  pattern = Faker.Internet.slug()
  
  expect(..., ..., fn path, _ ->
    assert path == "/route_patterns/" <> pattern
  end)
  
  refute RoutePatterns.Repo.get(pattern)
end

test/leaflet/map_data/polyline_test.exs Outdated Show resolved Hide resolved
@@ -148,10 +148,6 @@ const ScheduleDirection = ({
if (result.length === 0 || current.typicality < result[0].typicality)
return [current];
if (current.typicality === result[0].typicality) {
if (result[0].shape_priority < 0 && current.shape_priority > 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why this is being removed in the context of this PR. A note in the PR would help.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, totally forgot to mention it. Priority was an attribute of V3 API shapes that's been removed in more recent versions, and as far as I could tell we had already stopped reading/parsing it in our own codebase. Added a note to the main PR text too.

response =
get(conn, stop_path(conn, :grouped_route_patterns, "place-here")) |> json_response(200)

assert %{
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this hard-coded somewhere? This test is a little hard to figure out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I totally forgot about this and because the whole module's excluded it didn't fail the tests! I'll fix this.

@thecristen thecristen force-pushed the cbj/routepatternsrepo branch from cf38c51 to 3a1f56a Compare May 6, 2024 19:00
test/route_patterns/repo_test.exs Outdated Show resolved Hide resolved
@thecristen thecristen merged commit d062512 into main May 6, 2024
17 checks passed
@thecristen thecristen deleted the cbj/routepatternsrepo branch May 6, 2024 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants