Skip to content

Commit f713bd9

Browse files
committed
fix: the countries statistics on a collection page doesn't count the series with the non-specified countries.
As countries are unknown, let's follow the pessimistic scenario and assume that all the series belong to the same country. Fix #371
1 parent 3b665cd commit f713bd9

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/main/resources/sql/country_dao_queries.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ SELECT COUNT(*) \
3939
WHERE LOWER(name_ru) = :name
4040

4141
country.count_countries_of_collection = \
42-
SELECT COUNT(DISTINCT s.country_id) AS counter \
43-
FROM collections_series cs \
44-
JOIN series s \
45-
ON s.id = cs.series_id \
46-
WHERE cs.collection_id = :collection_id
42+
SELECT COUNT(DISTINCT COALESCE(s.country_id, -1)) AS counter \
43+
FROM collections_series cs \
44+
LEFT JOIN series s \
45+
ON s.id = cs.series_id \
46+
WHERE cs.collection_id = :collection_id
4747

4848
country.count_countries_added_since = \
4949
SELECT COUNT(*) \

src/test/java/ru/mystamps/web/feature/country/JdbcCountryDaoTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,32 @@ public void countCountriesOfCollectionWithMultipleSeriesFromEachCountry() {
8888
assertThat(numberOfCountries).isEqualTo(2);
8989
}
9090

91+
@Test
92+
@Sql(
93+
scripts = {
94+
"/db/users-coder.sql",
95+
"/db/collections-coder.sql",
96+
"/db/categories-sport.sql",
97+
"/db/series-2-sport-qty3.sql",
98+
"/db/series-3-sport-qty7.sql"
99+
},
100+
statements = {
101+
"INSERT INTO collections_series(collection_id, series_id, number_of_stamps) "
102+
+ "VALUES (1, 2, 3), (1, 3, 7)"
103+
}
104+
)
105+
public void countCountriesOfCollectionWithSeriesFromUnknownCountries() {
106+
// as countries are unknown, we assume the pessimistic scenario
107+
// where all the series belong to the same country
108+
109+
// given
110+
long expectedNumberOfCountries = 1;
111+
// when
112+
long numberOfCountries = countryDao.countCountriesOfCollection(1);
113+
// then
114+
assertThat(numberOfCountries).isEqualTo(expectedNumberOfCountries);
115+
}
116+
91117
//
92118
// Tests for getStatisticsOf()
93119
//

0 commit comments

Comments
 (0)