mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Update countries and cities spec
This commit is contained in:
parent
c843ff1577
commit
3902bc25f8
1 changed files with 28 additions and 26 deletions
|
|
@ -6,10 +6,8 @@ RSpec.describe CountriesAndCities do
|
||||||
describe '#call' do
|
describe '#call' do
|
||||||
subject(:countries_and_cities) { described_class.new(points).call }
|
subject(:countries_and_cities) { described_class.new(points).call }
|
||||||
|
|
||||||
# we have 15 points in the same city and different country within 2 hour,
|
# Test with a set of points in the same city (Kerpen) but different countries,
|
||||||
# 4 points in the differnt city within 10 minutes splitting the country
|
# with sufficient points to demonstrate the city grouping logic
|
||||||
# and we expect to get one country with one city which has 8 points
|
|
||||||
|
|
||||||
let(:timestamp) { DateTime.new(2021, 1, 1, 0, 0, 0) }
|
let(:timestamp) { DateTime.new(2021, 1, 1, 0, 0, 0) }
|
||||||
|
|
||||||
let(:points) do
|
let(:points) do
|
||||||
|
|
@ -39,26 +37,25 @@ RSpec.describe CountriesAndCities do
|
||||||
|
|
||||||
context 'when user stayed in the city for more than 1 hour' do
|
context 'when user stayed in the city for more than 1 hour' do
|
||||||
it 'returns countries and cities' do
|
it 'returns countries and cities' do
|
||||||
expect(countries_and_cities).to match_array([
|
# Only Belgium has cities where the user stayed long enough
|
||||||
an_object_having_attributes(
|
# Germany is excluded because the consecutive points in Kerpen, Germany
|
||||||
country: 'Germany',
|
# span only 30 minutes (less than MIN_MINUTES_SPENT_IN_CITY)
|
||||||
cities: [
|
expect(countries_and_cities).to contain_exactly(
|
||||||
an_object_having_attributes(
|
|
||||||
city: 'Berlin',
|
|
||||||
points: 8,
|
|
||||||
stayed_for: 70
|
|
||||||
)
|
|
||||||
]
|
|
||||||
),
|
|
||||||
an_object_having_attributes(
|
an_object_having_attributes(
|
||||||
country: 'Belgium',
|
country: 'Belgium',
|
||||||
cities: []
|
cities: contain_exactly(
|
||||||
|
an_object_having_attributes(
|
||||||
|
city: 'Kerpen',
|
||||||
|
points: 11,
|
||||||
|
stayed_for: 140
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
])
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user stayed in the city for less than 1 hour' do
|
context 'when user stayed in the city for less than 1 hour in some cities but more in others' do
|
||||||
let(:points) do
|
let(:points) do
|
||||||
[
|
[
|
||||||
create(:point, city: 'Berlin', country: 'Germany', timestamp:),
|
create(:point, city: 'Berlin', country: 'Germany', timestamp:),
|
||||||
|
|
@ -71,17 +68,22 @@ RSpec.describe CountriesAndCities do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns countries and cities' do
|
it 'returns only countries with cities where the user stayed long enough' do
|
||||||
expect(countries_and_cities).to match_array([
|
# Only Germany is included because Berlin points span 100 minutes
|
||||||
|
# Belgium is excluded because Brugges points are in separate visits
|
||||||
|
# spanning only 10 and 20 minutes each
|
||||||
|
expect(countries_and_cities).to contain_exactly(
|
||||||
an_object_having_attributes(
|
an_object_having_attributes(
|
||||||
country: 'Germany',
|
country: 'Germany',
|
||||||
cities: []
|
cities: contain_exactly(
|
||||||
),
|
an_object_having_attributes(
|
||||||
an_object_having_attributes(
|
city: 'Berlin',
|
||||||
country: 'Belgium',
|
points: 4,
|
||||||
cities: []
|
stayed_for: 100
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
])
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue