Bug 1550649 - Should not roll trailhead branch if has addons attribution data (#5036)

This commit is contained in:
Kate Hudson 2019-05-16 18:21:22 -04:00 коммит произвёл Ed Lee
Родитель b3ec7ea080
Коммит 29f9c678ce
2 изменённых файлов: 27 добавлений и 1 удалений

Просмотреть файл

@ -669,6 +669,15 @@ class _ASRouter {
}
}
async _hasAddonAttributionData() {
try {
const data = await AttributionCode.getAttrDataAsync() || {};
return data.source === "addons.mozilla.org";
} catch (e) {
return false;
}
}
/**
* _generateTrailheadBranches - Generates and returns Trailhead configuration and chooses an experiment
* based on clientID and locale.
@ -688,7 +697,7 @@ class _ASRouter {
const locale = Services.locale.appLocaleAsLangTag;
if (TRAILHEAD_CONFIG.LOCALES.includes(locale)) {
if (TRAILHEAD_CONFIG.LOCALES.includes(locale) && !(await this._hasAddonAttributionData())) {
const {userId} = ClientEnvironment;
experiment = await chooseBranch(`${userId}-trailhead-experiments`, TRAILHEAD_CONFIG.EXPERIMENT_RATIOS);

Просмотреть файл

@ -1624,6 +1624,10 @@ describe("ASRouter", () => {
sandbox.stub(global.Services.locale, "appLocaleAsLangTag").get(() => "zh-CN");
checkReturnValue({experiment: "", interrupt: "control", triplet: ""});
});
it("should return control experience with no experiment if attribution data contains an addon source", async () => {
sandbox.stub(fakeAttributionCode, "getAttrDataAsync").resolves({source: "addons.mozilla.org"});
checkReturnValue({experiment: "", interrupt: "control", triplet: ""});
});
it("should use values in override pref if it is set with no experiment", async () => {
getStringPrefStub.withArgs(TRAILHEAD_CONFIG.OVERRIDE_PREF).returns("join-privacy");
checkReturnValue({experiment: "", interrupt: "join", triplet: "privacy"});
@ -1644,6 +1648,19 @@ describe("ASRouter", () => {
sandbox.stub(global.Services.locale, "appLocaleAsLangTag").get(() => "en-US");
checkReturnValue({experiment: "interrupts", interrupt: "join", triplet: "supercharge"});
});
it("should roll for experiment if attribution data is empty", async () => {
sandbox.stub(global.Sampling, "ratioSample").resolves(1); // 1 = interrupts experiment
sandbox.stub(global.Services.locale, "appLocaleAsLangTag").get(() => "en-US");
sandbox.stub(fakeAttributionCode, "getAttrDataAsync").resolves(null);
checkReturnValue({experiment: "interrupts", interrupt: "join", triplet: "supercharge"});
});
it("should roll for experiment if attribution data rejects with an error", async () => {
sandbox.stub(global.Sampling, "ratioSample").resolves(1); // 1 = interrupts experiment
sandbox.stub(global.Services.locale, "appLocaleAsLangTag").get(() => "en-US");
sandbox.stub(fakeAttributionCode, "getAttrDataAsync").rejects(new Error("whoops"));
checkReturnValue({experiment: "interrupts", interrupt: "join", triplet: "supercharge"});
});
it("should roll a triplet experiment", async () => {
sandbox.stub(global.Sampling, "ratioSample").resolves(2); // 2 = triplets experiment
sandbox.stub(global.Services.locale, "appLocaleAsLangTag").get(() => "en-US");