55 lines
1.5 KiB
Ruby
55 lines
1.5 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe "Api::V1::Parks", type: :request do
|
|
describe "GET /parks" do
|
|
it "returns parks" do
|
|
get api_v1_parks_url
|
|
expect(response).to have_http_status(:success)
|
|
expect(response.parsed_body).to include(
|
|
hash_including(
|
|
code: "crla", name: "Crater Lake National Park", states: "OR"
|
|
)
|
|
)
|
|
expect(response.parsed_body).to include(
|
|
hash_including(
|
|
code: "olym", name: "Olympic National Park", states: "WA"
|
|
)
|
|
)
|
|
end
|
|
|
|
it "filters by state" do
|
|
get api_v1_parks_url, params: { state: "OR" }
|
|
expect(response.parsed_body.pluck("code")).to eq(["crla"])
|
|
end
|
|
|
|
context "with pagination" do
|
|
it "respects page size param" do
|
|
get api_v1_parks_url, params: { per_page: 1 }
|
|
expect(response.parsed_body.size).to eq(1)
|
|
end
|
|
|
|
it "respects page param" do
|
|
get api_v1_parks_url, params: { per_page: 1, page: 2 }
|
|
expect(response.parsed_body.first["code"]).to eq("crla")
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "GET /parks/:code" do
|
|
it "returns :not_found for unknown codes" do
|
|
get api_v1_park_url("foo")
|
|
expect(response).to have_http_status(:not_found)
|
|
end
|
|
|
|
it "returns the park" do
|
|
get api_v1_park_url("crla")
|
|
expect(response).to have_http_status(:success)
|
|
expect(response.parsed_body).to match(
|
|
hash_including(
|
|
code: "crla", name: "Crater Lake National Park", states: "OR"
|
|
)
|
|
)
|
|
end
|
|
end
|
|
end
|