From 0afea82aaeef1187a63fd8bfa78a1707a539ccfc Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Tue, 2 Apr 2024 23:31:42 +0200 Subject: [PATCH] Add spec for CountriesAndCities service --- spec/services/countries_and_cities_spec.rb | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 spec/services/countries_and_cities_spec.rb diff --git a/spec/services/countries_and_cities_spec.rb b/spec/services/countries_and_cities_spec.rb new file mode 100644 index 00000000..24d8ab3d --- /dev/null +++ b/spec/services/countries_and_cities_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' + +RSpec.describe CountriesAndCities do + describe '#call' do + subject(:countries_and_cities) { described_class.new(points).call } + + let(:points) do + [ + create(:point, latitude: 0, longitude: 0, city: 'City', country: 'Country'), + create(:point, latitude: 1, longitude: 1, city: 'City', country: 'Country'), + create(:point, latitude: 2, longitude: 2, city: 'City', country: 'Country'), + create(:point, latitude: 2, longitude: 2, city: 'Another city', country: 'Some Country'), + create(:point, latitude: 2, longitude: 6, city: 'Another city', country: 'Some Country') + ] + end + + before do + stub_const('CountriesAndCities::MINIMUM_POINTS_IN_CITY', 1) + end + + it 'returns countries and cities' do + expect(countries_and_cities).to eq( + [ + { cities: [{city: "City", points: 3, timestamp: 1}], country: "Country" }, + { cities: [{city: "Another city", points: 2, timestamp: 1}], country: "Some Country" } + ] + ) + end + end +end