Skip to content

Commit

Permalink
Fixes state level ads being shown on version without state level targ…
Browse files Browse the repository at this point in the history
…eting
  • Loading branch information
tmancey committed Jul 7, 2020
1 parent eaf05bb commit a5aa4fb
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 30 deletions.
53 changes: 37 additions & 16 deletions vendor/bat-native-ads/data/resources/catalog-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@
"totalMax",
"segments",
"creatives",
"oses"
"oses",
"channels"
],
"properties": {
"creativeSetId": {
Expand Down Expand Up @@ -163,6 +164,7 @@
},
"segments": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -202,6 +204,12 @@
}
}
},
"channels": {
"type": "array",
"items": {
"type": "string"
}
},
"creatives": {
"type": "array",
"items": {
Expand Down Expand Up @@ -242,23 +250,36 @@
},
"payload": {
"type": "object",
"additionalProperties": false,
"required": [
"targetUrl",
"body",
"title"
],
"properties": {
"targetUrl": {
"type": "string"
},
"body": {
"type": "string"
"oneOf": [
{
"properties": {
"targetUrl": {
"type": "string"
},
"body": {
"type": "string"
},
"title": {
"type": "string"
}
},
"additionalProperties": false
},
"title": {
"type": "string"
{
"properties": {
"creativeUrl": {
"type": "string"
},
"size": {
"type": "string"
},
"targetUrl": {
"type": "string"
}
},
"additionalProperties": false
}
}
]
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions vendor/bat-native-ads/data/test/catalog.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 1,
"version": 3,
"issuers": [
{
"name": "confirmation",
Expand Down Expand Up @@ -60,12 +60,15 @@
"type": "postview"
}
],
"channels": [
],
"creativeSetId": "340c927f-696e-4060-9933-3eafc56c3f31",
"perDay": 5,
"totalMax": 100
}
],
"dayParts": [],
"dayParts": [
],
"geoTargets": [
{
"code": "US",
Expand Down Expand Up @@ -113,12 +116,15 @@
"type": "postclick"
}
],
"channels": [
],
"creativeSetId": "3e2e503a-dd38-42d1-9e26-1e5dbb66aada",
"perDay": 5,
"totalMax": 100
}
],
"dayParts": [],
"dayParts": [
],
"geoTargets": [
{
"code": "US",
Expand Down
2 changes: 1 addition & 1 deletion vendor/bat-native-ads/src/bat/ads/internal/ads_serve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void AdsServe::DownloadCatalog() {
}

BLOG(1, "Download catalog");
BLOG(2, "GET /v2/catalog");
BLOG(2, "GET " << CATALOG_PATH);

auto callback = std::bind(&AdsServe::OnCatalogDownloaded,
this, url_, _1, _2, _3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Result CatalogState::FromJson(
new_catalog_id = catalog["catalogId"].GetString();

new_version = catalog["version"].GetUint64();
if (new_version != 1) {
if (new_version != 3) {
return SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ TEST_F(BatAdsAdConversionsDatabaseTableTest,

const URLEndpoints endpoints = {
{
"/v2/catalog", {
"/v3/catalog", {
{
net::HTTP_OK, "/catalog.json"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest,

const URLEndpoints endpoints = {
{
"/v2/catalog", {
"/v3/catalog", {
{
net::HTTP_OK, "/catalog.json"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ bool SubdivisionTargetingFrequencyCap::DoesRespectCap(

if (!ads_->get_subdivision_targeting()->ShouldAllowAdsSubdivisionTargeting(
locale)) {
return true;
return !DoesAdTargetSubdivision(ad);
}

if (ads_->get_subdivision_targeting()->IsDisabled()) {
return true;
return !DoesAdTargetSubdivision(ad);
}

const std::string subdivision_targeting_code =
Expand All @@ -80,6 +80,23 @@ bool SubdivisionTargetingFrequencyCap::DoesAdSupportSubdivisionTargetingCode(
return true;
}

bool SubdivisionTargetingFrequencyCap::DoesAdTargetSubdivision(
const CreativeAdInfo& ad) const {
const auto iter = std::find_if(ad.geo_targets.begin(), ad.geo_targets.end(),
[&](const std::string& geo_target) {
const std::vector<std::string> components = base::SplitString(
geo_target, "-", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);

return components.size() == 2;
});

if (iter == ad.geo_targets.end()) {
return false;
}

return true;
}

std::string SubdivisionTargetingFrequencyCap::GetCountryCode(
const std::string& subdivision_targeting_code) const {
const std::vector<std::string> components = base::SplitString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class SubdivisionTargetingFrequencyCap : public ExclusionRule {
const CreativeAdInfo& ad,
const std::string& subdivision_targeting_code) const;

bool DoesAdTargetSubdivision(
const CreativeAdInfo& ad) const;

std::string GetCountryCode(
const std::string& subdivision_targeting_code) const;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ TEST_F(BatAdsSubdivisionTargetingFrequencyCapTest,
}

TEST_F(BatAdsSubdivisionTargetingFrequencyCapTest,
AllowAdIfSubdivisionTargetingIsNotSupportedForSubdivisionGeoTarget) {
DoNotAllowAdIfSubdivisionTargetingIsNotSupportedForSubdivisionGeoTarget) {
// Arrange
ON_CALL(*locale_helper_mock_, GetLocale())
.WillByDefault(Return("en-GB"));
Expand All @@ -207,7 +207,7 @@ TEST_F(BatAdsSubdivisionTargetingFrequencyCapTest,
const bool should_exclude = frequency_cap_->ShouldExclude(ad);

// Assert
EXPECT_FALSE(should_exclude);
EXPECT_TRUE(should_exclude);
}

TEST_F(BatAdsSubdivisionTargetingFrequencyCapTest,
Expand All @@ -228,7 +228,7 @@ TEST_F(BatAdsSubdivisionTargetingFrequencyCapTest,
}

TEST_F(BatAdsSubdivisionTargetingFrequencyCapTest,
AllowAdIfSubdivisionTargetingIsDisabledForSubdivisionGeoTarget) {
DoNotAllowAdIfSubdivisionTargetingIsDisabledForSubdivisionGeoTarget) {
// Arrange
ON_CALL(*ads_client_mock_, GetAdsSubdivisionTargetingCode())
.WillByDefault(Return("DISABLED"));
Expand All @@ -241,7 +241,7 @@ TEST_F(BatAdsSubdivisionTargetingFrequencyCapTest,
const bool should_exclude = frequency_cap_->ShouldExclude(ad);

// Assert
EXPECT_FALSE(should_exclude);
EXPECT_TRUE(should_exclude);
}

TEST_F(BatAdsSubdivisionTargetingFrequencyCapTest,
Expand Down
2 changes: 1 addition & 1 deletion vendor/bat-native-ads/src/bat/ads/internal/static_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace ads {
#define STAGING_SERVER "https://ads-serve.bravesoftware.com"
#define DEVELOPMENT_SERVER "https://ads-serve.brave.software"

#define CATALOG_PATH "/v2/catalog"
#define CATALOG_PATH "/v3/catalog"
#define GETSTATE_PATH "/v5/getstate"

const int kIdleThresholdInSeconds = 15;
Expand Down

0 comments on commit a5aa4fb

Please sign in to comment.