58 lines
1.7 KiB
Ruby
58 lines
1.7 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["parks"]).to include(
|
|
hash_including(
|
|
code: "crla", name: "Crater Lake National Park"
|
|
)
|
|
)
|
|
expect(response.parsed_body["parks"]).to include(
|
|
hash_including(
|
|
code: "olym", name: "Olympic National Park"
|
|
)
|
|
)
|
|
end
|
|
|
|
it "filters by state" do
|
|
get api_v1_parks_url, params: { state: "OR" }
|
|
expect(response.parsed_body["parks"].pluck("code")).to eq(["crla"])
|
|
end
|
|
|
|
context "with pagination" do
|
|
it "respects limit param" do
|
|
get api_v1_parks_url, params: { limit: 1 }
|
|
expect(response.parsed_body["total"]).to eq(2)
|
|
expect(response.parsed_body["limit"]).to eq(1)
|
|
expect(response.parsed_body["offset"]).to eq(0)
|
|
expect(response.parsed_body["parks"].size).to eq(1)
|
|
end
|
|
|
|
it "respects offset param" do
|
|
get api_v1_parks_url, params: { offset: 1 }
|
|
expect(response.parsed_body["parks"].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(parks(:one).code)
|
|
expect(response).to have_http_status(:success)
|
|
expect(response.parsed_body).to match(
|
|
hash_including(
|
|
code: "crla", name: "Crater Lake National Park"
|
|
)
|
|
)
|
|
end
|
|
end
|
|
end
|