From 5aeac601c2a6098433012a9301cbea391b1ba4ed Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Fri, 3 Apr 2020 15:01:36 +0300 Subject: [PATCH] [ads] territories for download on map banners are fixed --- map/download_on_map_ads_delegate.cpp | 6 +-- map/download_on_map_ads_delegate.hpp | 2 +- partners_api/ads/ads_base.cpp | 13 +++-- partners_api/ads/ads_base.hpp | 2 +- partners_api/ads/tinkoff_insurance_ads.cpp | 1 - .../partners_api_tests/ads_engine_tests.cpp | 2 +- .../download_on_map_container_delegate.hpp | 10 ++-- partners_api/partners_api_tests/mts_tests.cpp | 10 ++-- .../tinkoff_airlines_tests.cpp | 49 ++++++++++++------- .../tinkoff_insurance_tests.cpp | 34 ++++++++----- 10 files changed, 76 insertions(+), 53 deletions(-) diff --git a/map/download_on_map_ads_delegate.cpp b/map/download_on_map_ads_delegate.cpp index 5754abef6b..ef6632a272 100644 --- a/map/download_on_map_ads_delegate.cpp +++ b/map/download_on_map_ads_delegate.cpp @@ -17,11 +17,9 @@ storage::CountryId DownloadOnMapDelegate::GetCountryId(m2::PointD const & pos) return m_countryInfoGetter.GetRegionCountryId(pos); } -storage::CountriesVec DownloadOnMapDelegate::GetTopmostNodesFor(storage::CountryId const & countryId) const +storage::CountryId DownloadOnMapDelegate::GetTopmostParentFor(storage::CountryId const & countryId) const { - storage::CountriesVec countries; - m_storage.GetTopmostNodesFor(countryId, countries); - return countries; + return m_storage.GetTopmostParentFor(countryId); } std::string DownloadOnMapDelegate::GetLinkForCountryId(storage::CountryId const & countryId) const diff --git a/map/download_on_map_ads_delegate.hpp b/map/download_on_map_ads_delegate.hpp index 42952a5c8b..ceb7acd188 100644 --- a/map/download_on_map_ads_delegate.hpp +++ b/map/download_on_map_ads_delegate.hpp @@ -27,7 +27,7 @@ public: // DownloadOnMapContainer::Delegate overrides: storage::CountryId GetCountryId(m2::PointD const & pos) override; - storage::CountriesVec GetTopmostNodesFor(storage::CountryId const & countryId) const override; + storage::CountryId GetTopmostParentFor(storage::CountryId const & countryId) const override; std::string GetLinkForCountryId(storage::CountryId const & countryId) const override; private: diff --git a/partners_api/ads/ads_base.cpp b/partners_api/ads/ads_base.cpp index 4360704936..a5ee54e860 100644 --- a/partners_api/ads/ads_base.cpp +++ b/partners_api/ads/ads_base.cpp @@ -99,11 +99,14 @@ bool DownloadOnMapContainer::HasBanner(storage::CountryId const & countryId, m2::PointD const & userPos, std::string const & userLanguage) const { - auto const userPosMwm = m_delegate.GetCountryId(userPos); - auto userPosCountries = m_delegate.GetTopmostNodesFor(userPosMwm); - userPosCountries.push_back(userPosMwm); - auto downloadMwmCountries = m_delegate.GetTopmostNodesFor(countryId); - downloadMwmCountries.push_back(countryId); + storage::CountriesVec userPosCountries; + auto const userPosCountryId = m_delegate.GetCountryId(userPos); + userPosCountries.emplace_back(userPosCountryId); + userPosCountries.emplace_back(m_delegate.GetTopmostParentFor(userPosCountryId)); + + storage::CountriesVec downloadMwmCountries; + downloadMwmCountries.emplace_back(countryId); + downloadMwmCountries.emplace_back(m_delegate.GetTopmostParentFor(countryId)); return !std::any_of(userPosCountries.begin(), userPosCountries.end(), [this](auto const & id) { return IsUserPosCountryExcluded(id); }) && diff --git a/partners_api/ads/ads_base.hpp b/partners_api/ads/ads_base.hpp index 1639e8d271..fb72d8a982 100644 --- a/partners_api/ads/ads_base.hpp +++ b/partners_api/ads/ads_base.hpp @@ -92,7 +92,7 @@ public: virtual ~Delegate() = default; virtual storage::CountryId GetCountryId(m2::PointD const & pos) = 0; - virtual storage::CountriesVec GetTopmostNodesFor(storage::CountryId const & countryId) const = 0; + virtual storage::CountryId GetTopmostParentFor(storage::CountryId const & countryId) const = 0; virtual std::string GetLinkForCountryId(storage::CountryId const & countryId) const = 0; }; diff --git a/partners_api/ads/tinkoff_insurance_ads.cpp b/partners_api/ads/tinkoff_insurance_ads.cpp index d9a92bc2d5..baa2e1640b 100644 --- a/partners_api/ads/tinkoff_insurance_ads.cpp +++ b/partners_api/ads/tinkoff_insurance_ads.cpp @@ -29,7 +29,6 @@ std::initializer_list const kSupportedCountries = { "Hungary", "Indonesia", "Iran", - "Ireland", "Israel", "Jerusalem", "Jordan", diff --git a/partners_api/partners_api_tests/ads_engine_tests.cpp b/partners_api/partners_api_tests/ads_engine_tests.cpp index 3eaeed9010..958cad3af7 100644 --- a/partners_api/partners_api_tests/ads_engine_tests.cpp +++ b/partners_api/partners_api_tests/ads_engine_tests.cpp @@ -22,7 +22,7 @@ public: // ads::DownloadOnMapContainer::Delegate storage::CountryId GetCountryId(m2::PointD const & pos) override { return {}; } - storage::CountriesVec GetTopmostNodesFor(storage::CountryId const & mwmId) const override { return {}; }; + storage::CountryId GetTopmostParentFor(storage::CountryId const & mwmId) const override { return {}; }; std::string GetLinkForCountryId(storage::CountryId const & countryId) const override { return {}; }; }; diff --git a/partners_api/partners_api_tests/download_on_map_container_delegate.hpp b/partners_api/partners_api_tests/download_on_map_container_delegate.hpp index c94a97b58e..26a856eb2a 100644 --- a/partners_api/partners_api_tests/download_on_map_container_delegate.hpp +++ b/partners_api/partners_api_tests/download_on_map_container_delegate.hpp @@ -12,9 +12,9 @@ class DownloadOnMapContainerDelegateForTesting : public ads::DownloadOnMapContai { public: void SetCountryId(storage::CountryId const & countryId) { m_countryId = countryId; } - void SetTopmostNodes(storage::CountriesVec const & topmostNodes) + void SetTopmostParent(storage::CountryId const & topmostParent) { - m_topmostNodes = topmostNodes; + m_topmostParent = topmostParent; } void SetLinkForCountryId(std::string const & linkForCountryId) { @@ -23,9 +23,9 @@ public: // ads::DownloadOnMapContainer::Delegate storage::CountryId GetCountryId(m2::PointD const & pos) override { return m_countryId; } - storage::CountriesVec GetTopmostNodesFor(storage::CountryId const & mwmId) const override + storage::CountryId GetTopmostParentFor(storage::CountryId const & mwmId) const override { - return m_topmostNodes; + return m_topmostParent; } std::string GetLinkForCountryId(storage::CountryId const & countryId) const override { @@ -34,6 +34,6 @@ public: private: storage::CountryId m_countryId; - storage::CountriesVec m_topmostNodes; + storage::CountryId m_topmostParent; std::string m_linkForCountryId; }; diff --git a/partners_api/partners_api_tests/mts_tests.cpp b/partners_api/partners_api_tests/mts_tests.cpp index bc44c434ce..9282316b73 100644 --- a/partners_api/partners_api_tests/mts_tests.cpp +++ b/partners_api/partners_api_tests/mts_tests.cpp @@ -10,29 +10,29 @@ UNIT_TEST(Mts_GetBanner) ads::Mts mts(delegate); { - delegate.SetTopmostNodes({"France"}); + delegate.SetTopmostParent("France"); auto const banner = mts.GetBanner("", {}, "ru"); TEST(!banner.empty(), ()); } { - delegate.SetTopmostNodes({"France"}); + delegate.SetTopmostParent("France"); auto const banner = mts.GetBanner("", {}, "en"); TEST(banner.empty(), ()); } { - delegate.SetTopmostNodes({"France"}); + delegate.SetTopmostParent("France"); delegate.SetCountryId("Russian Federation"); auto const banner = mts.GetBanner("", {}, "ru"); TEST(banner.empty(), ()); } { - delegate.SetTopmostNodes({"France", "Thailand"}); + delegate.SetTopmostParent("Thailand"); delegate.SetCountryId("Russian Federation"); auto const banner = mts.GetBanner("", {}, "ru"); TEST(banner.empty(), ()); } { - delegate.SetTopmostNodes({"France", "Thailand"}); + delegate.SetTopmostParent("Thailand"); delegate.SetCountryId("Cote dIvoire"); auto const banner = mts.GetBanner("", {}, "ru"); TEST(!banner.empty(), ()); diff --git a/partners_api/partners_api_tests/tinkoff_airlines_tests.cpp b/partners_api/partners_api_tests/tinkoff_airlines_tests.cpp index bb12b28bc2..7bd641a769 100644 --- a/partners_api/partners_api_tests/tinkoff_airlines_tests.cpp +++ b/partners_api/partners_api_tests/tinkoff_airlines_tests.cpp @@ -10,28 +10,43 @@ UNIT_TEST(TinkoffAirlines_GetBanner) ads::TinkoffAllAirlines tinkoffAirlines(delegate); { - delegate.SetTopmostNodes({"Germany", "Russian Federation"}); - auto const banner = tinkoffAirlines.GetBanner("", {}, "ru"); - TEST(!banner.empty(), ()); - } - { - delegate.SetTopmostNodes({"Germany", "Russian Federation"}); - auto const banner = tinkoffAirlines.GetBanner("", {}, "en"); - TEST(banner.empty(), ()); - } - { - delegate.SetTopmostNodes({"Germany", "Cote dIvoire"}); - auto const banner = tinkoffAirlines.GetBanner("", {}, "ru"); - TEST(banner.empty(), ()); - } - { - delegate.SetTopmostNodes({"Norway"}); + delegate.SetTopmostParent("Germany"); delegate.SetCountryId("Russian Federation"); auto const banner = tinkoffAirlines.GetBanner("", {}, "ru"); TEST(!banner.empty(), ()); } { - delegate.SetTopmostNodes({"Norway"}); + delegate.SetTopmostParent("Russian Federation"); + delegate.SetCountryId("Russian Federation"); + auto const banner = tinkoffAirlines.GetBanner("", {}, "ru"); + TEST(banner.empty(), ()); + } + { + delegate.SetTopmostParent("Germany"); + delegate.SetCountryId("Russian Federation"); + auto const banner = tinkoffAirlines.GetBanner("", {}, "en"); + TEST(banner.empty(), ()); + } + { + delegate.SetTopmostParent("Russian Federation"); + delegate.SetCountryId("Russian Federation"); + auto const banner = tinkoffAirlines.GetBanner("", {}, "en"); + TEST(banner.empty(), ()); + } + { + delegate.SetTopmostParent("Germany"); + delegate.SetCountryId("Cote dIvoire"); + auto const banner = tinkoffAirlines.GetBanner("", {}, "ru"); + TEST(banner.empty(), ()); + } + { + delegate.SetTopmostParent({"Norway"}); + delegate.SetCountryId("Russian Federation"); + auto const banner = tinkoffAirlines.GetBanner("", {}, "ru"); + TEST(!banner.empty(), ()); + } + { + delegate.SetTopmostParent({"Norway"}); delegate.SetCountryId("Ukraine"); auto const banner = tinkoffAirlines.GetBanner("", {}, "ru"); TEST(banner.empty(), ()); diff --git a/partners_api/partners_api_tests/tinkoff_insurance_tests.cpp b/partners_api/partners_api_tests/tinkoff_insurance_tests.cpp index 67b2a720d3..9c6e0b7c8b 100644 --- a/partners_api/partners_api_tests/tinkoff_insurance_tests.cpp +++ b/partners_api/partners_api_tests/tinkoff_insurance_tests.cpp @@ -10,28 +10,36 @@ UNIT_TEST(TinkoffInsurance_GetBanner) ads::TinkoffInsurance tinkoffInsurance(delegate); { - delegate.SetTopmostNodes({"France", "Russian Federation"}); - auto const banner = tinkoffInsurance.GetBanner("", {}, "ru"); - TEST(!banner.empty(), ()); - } - { - delegate.SetTopmostNodes({"France", "Russian Federation"}); - auto const banner = tinkoffInsurance.GetBanner("", {}, "en"); - TEST(banner.empty(), ()); - } - { - delegate.SetTopmostNodes({"France", "Cote dIvoire"}); + delegate.SetTopmostParent("France"); auto const banner = tinkoffInsurance.GetBanner("", {}, "ru"); TEST(banner.empty(), ()); } { - delegate.SetTopmostNodes({"Nepal"}); + delegate.SetTopmostParent("France"); delegate.SetCountryId("Russian Federation"); auto const banner = tinkoffInsurance.GetBanner("", {}, "ru"); TEST(!banner.empty(), ()); } { - delegate.SetTopmostNodes({"Nepal"}); + delegate.SetTopmostParent("France"); + delegate.SetCountryId("Russian Federation"); + auto const banner = tinkoffInsurance.GetBanner("", {}, "en"); + TEST(banner.empty(), ()); + } + { + delegate.SetTopmostParent("Russian Federation"); + delegate.SetCountryId("Russian Federation"); + auto const banner = tinkoffInsurance.GetBanner("", {}, "en"); + TEST(banner.empty(), ()); + } + { + delegate.SetTopmostParent("Nepal"); + delegate.SetCountryId("Russian Federation"); + auto const banner = tinkoffInsurance.GetBanner("", {}, "ru"); + TEST(!banner.empty(), ()); + } + { + delegate.SetTopmostParent("Nepal"); delegate.SetCountryId("Norway"); auto const banner = tinkoffInsurance.GetBanner("", {}, "ru"); TEST(banner.empty(), ());