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: attempt at some further api tests - WIP #242

Open
wants to merge 1 commit into
base: feat/6/api-for-habitat-stats
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 12 additions & 3 deletions spec/controllers/api/v1/countries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@

RSpec.describe Api::V1::CountriesController, type: :controller do
describe 'GET #show' do
let!(:country) { create_list(:country, 2) }
include_context 'geo_entity_stat_setup'

before do
habitats.each do |habitat|
countries.each do |country|
FactoryBot.create(:geo_entity_stat, habitat: habitat, geo_entity: country)
FactoryBot.create(:coastal_stat, geo_entity: country)
end
end
end

it 'returns summary data for a country' do
get :show, params: { iso3: country.first.iso3 }, format: :json
get :show, params: { iso3: countries.last.iso3 }, format: :json
expect(response).to be_successful

response_body = JSON.parse(response.body)
expect(response_body['iso3']).to match(country.first.iso3)
expect(response_body['iso3']).to match(countries.last.iso3)
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/models/geo_entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
habitats.each do |habitat|
countries.each do |country|
FactoryBot.create(:geo_entity_stat, habitat: habitat, geo_entity: country)
FactoryBot.create(:coastal_stat, geo_entity: country)
end
end
end
Expand Down Expand Up @@ -90,4 +91,13 @@
expect(pa_stats[0][:total_area].to_s).to eq('100.0')
end
end

describe '#coastline_coverage' do
it 'outputs an array of coastline coverage statistics' do
coastline_stats = geo_entity.coastline_coverage

expect(coastline_stats.count).to equal(7)
expect(coastline_stats).to all( include(:name, :coverage) )
end
end
end