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