FEATURE: use groups to control who sees ads

This commit is contained in:
Neil Lalonde
2019-05-03 11:39:34 -04:00
parent 369d5dfc9e
commit 5272995e74
12 changed files with 249 additions and 129 deletions
@@ -1,8 +1,10 @@
import { acceptance, replaceCurrentUser } from "helpers/qunit-helpers";
import groupFixtures from "fixtures/group-fixtures";
acceptance("AdSense", {
loggedIn: true,
settings: {
no_ads_for_groups: "discourse",
adsense_publisher_code: "MYADSENSEID",
adsense_through_trust_level: 2,
adsense_topic_list_top_code: "list_top_ad_unit",
@@ -17,8 +19,7 @@ acceptance("AdSense", {
}
});
// TODO: tests work on my machine, but breaks build
QUnit.skip("correct number of ads should show", async assert => {
test("correct number of ads should show", async assert => {
replaceCurrentUser({ staff: false, trust_level: 1 });
await visit("/t/280"); // 20 posts
const ads = find(".google-adsense.adsense-post-bottom");
@@ -46,7 +47,7 @@ QUnit.skip("correct number of ads should show", async assert => {
);
});
QUnit.skip("no ads for trust level 3", async assert => {
test("no ads for trust level 3", async assert => {
replaceCurrentUser({ staff: false, trust_level: 3 });
await visit("/t/280");
assert.equal(
@@ -56,7 +57,7 @@ QUnit.skip("no ads for trust level 3", async assert => {
);
});
QUnit.skip("can omit ads based on groups", async assert => {
test("can omit ads based on groups", async assert => {
replaceCurrentUser({
staff: false,
trust_level: 1,
@@ -0,0 +1,72 @@
import { acceptance, replaceCurrentUser } from "helpers/qunit-helpers";
import groupFixtures from "fixtures/group-fixtures";
acceptance("DFP Ads", {
loggedIn: true,
settings: {
no_ads_for_groups: "discourse",
dfp_publisher_id: "MYdfpID",
dfp_through_trust_level: 2,
dfp_topic_list_top_code: "list_top_ad_unit",
dfp_topic_list_top_ad_sizes: "728*90 - leaderboard",
dfp_mobile_topic_list_top_code: "mobile_list_top_ad_unit",
dfp_mobile_topic_list_top_ad_size: "300*250 - medium rectangle",
dfp_post_bottom_code: "post_bottom_ad_unit",
dfp_post_bottom_ad_sizes: "728*90 - leaderboard",
dfp_mobile_post_bottom_code: "mobile_post_bottom_ad_unit",
dfp_mobile_post_bottom_ad_size: "300*250 - medium rectangle",
dfp_nth_post_code: 6
}
});
test("correct number of ads should show", async assert => {
replaceCurrentUser({ staff: false, trust_level: 1 });
await visit("/t/280"); // 20 posts
const ads = find(".google-dfp-ad.dfp-ad-post-bottom");
assert.equal(ads.length, 3, "it should render 3 ads");
assert.equal(
find("#post_6 + .widget-connector").find(
".google-dfp-ad.dfp-ad-post-bottom"
).length,
1,
"ad after 6th post"
);
assert.equal(
find("#post_12 + .widget-connector").find(
".google-dfp-ad.dfp-ad-post-bottom"
).length,
1,
"ad after 12th post"
);
assert.equal(
find("#post_18 + .widget-connector").find(
".google-dfp-ad.dfp-ad-post-bottom"
).length,
1,
"ad after 18th post"
);
});
test("no ads for trust level 3", async assert => {
replaceCurrentUser({ staff: false, trust_level: 3 });
await visit("/t/280");
assert.equal(
find(".google-dfp-ad.dfp-ad-post-bottom").length,
0,
"it should render 0 ads"
);
});
test("can omit ads based on groups", async assert => {
replaceCurrentUser({
staff: false,
trust_level: 1,
groups: [groupFixtures["/groups/discourse.json"].group]
});
await visit("/t/280");
assert.equal(
find(".google-dfp-ad.dfp-ad-post-bottom").length,
0,
"it should render 0 ads"
);
});