forked from mirrors/gecko-dev
Bug 1855974 - Use Shopping Status API status as data or errors. r=shopping-reviewers,Gijs
- Pass analysis status as data to display not enough reviews and page not supported messages. - Throws errors when we get an response that there was an issue from the Shopping Status and Analyze APIs. - Add integration tests for setting sidebar status based on analysis status. Differential Revision: https://phabricator.services.mozilla.com/D190366
This commit is contained in:
parent
1f55944f31
commit
93d6d73068
7 changed files with 203 additions and 64 deletions
|
|
@ -260,14 +260,35 @@ export class ShoppingSidebarChild extends RemotePageChild {
|
||||||
isAnalysisInProgress,
|
isAnalysisInProgress,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
await this.#product.pollForAnalysisCompleted({
|
analysisStatusResponse = await this.#product.pollForAnalysisCompleted(
|
||||||
pollInitialWait: analysisStatus == "in_progress" ? 0 : undefined,
|
{
|
||||||
});
|
pollInitialWait: analysisStatus == "in_progress" ? 0 : undefined,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
analysisStatus = analysisStatusResponse?.status;
|
||||||
isAnalysisInProgress = false;
|
isAnalysisInProgress = false;
|
||||||
}
|
}
|
||||||
data = await this.#product.requestAnalysis();
|
|
||||||
|
// Use the analysis status instead of re-requesting unnecessarily,
|
||||||
|
// or throw if the status from the last analysis was an error.
|
||||||
|
switch (analysisStatus) {
|
||||||
|
case "not_analyzable":
|
||||||
|
case "page_not_supported":
|
||||||
|
data = { page_not_supported: true };
|
||||||
|
break;
|
||||||
|
case "unprocessable":
|
||||||
|
case "stale":
|
||||||
|
throw new Error(analysisStatus, { cause: analysisStatus });
|
||||||
|
default:
|
||||||
|
// Status is "completed" or "not_found" (no analysis status),
|
||||||
|
// so we should request the analysis data.
|
||||||
|
}
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
throw new Error("request failed");
|
data = await this.#product.requestAnalysis();
|
||||||
|
if (!data) {
|
||||||
|
throw new Error("request failed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to fetch product analysis data", err);
|
console.error("Failed to fetch product analysis data", err);
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,10 @@
|
||||||
"in_progress",
|
"in_progress",
|
||||||
"completed",
|
"completed",
|
||||||
"not_analyzable",
|
"not_analyzable",
|
||||||
"unprocessable"
|
"unprocessable",
|
||||||
|
"page_not_supported",
|
||||||
|
"not_enough_reviews",
|
||||||
|
"stale"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"progress": {
|
"progress": {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,9 @@
|
||||||
"in_progress",
|
"in_progress",
|
||||||
"completed",
|
"completed",
|
||||||
"not_analyzable",
|
"not_analyzable",
|
||||||
"unprocessable"
|
"unprocessable",
|
||||||
|
"page_not_supported",
|
||||||
|
"not_enough_reviews"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,24 @@ function loadHelperScript(path) {
|
||||||
/* import-globals-from ./server_helper.js */
|
/* import-globals-from ./server_helper.js */
|
||||||
loadHelperScript("server_helper.js");
|
loadHelperScript("server_helper.js");
|
||||||
|
|
||||||
function handleRequest(_request, response) {
|
let gResponses = new Map(
|
||||||
// We always want the status to be completed for the current tests.
|
Object.entries({
|
||||||
let status = {
|
N0T3NOUGHR: { status: "not_enough_reviews", progress: 100.0 },
|
||||||
status: "completed",
|
PAG3N0TSUP: { status: "page_not_supported", progress: 100.0 },
|
||||||
progress: 100.0,
|
UNPR0C3SSA: { status: "unprocessable", progress: 100.0 },
|
||||||
};
|
})
|
||||||
response.write(JSON.stringify(status));
|
);
|
||||||
|
|
||||||
|
function handleRequest(request, response) {
|
||||||
|
let body = getPostBody(request.bodyInputStream);
|
||||||
|
let requestData = JSON.parse(body);
|
||||||
|
let responseData = gResponses.get(requestData.product_id);
|
||||||
|
if (!responseData) {
|
||||||
|
// We want the status to be completed for most tests.
|
||||||
|
responseData = {
|
||||||
|
status: "completed",
|
||||||
|
progress: 100.0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
response.write(JSON.stringify(responseData));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,6 @@ prefs = [
|
||||||
support-files = [
|
support-files = [
|
||||||
"head.js",
|
"head.js",
|
||||||
"server_helper.js",
|
"server_helper.js",
|
||||||
]
|
|
||||||
|
|
||||||
["browser_shopping_ads_test.js"]
|
|
||||||
["browser_shopping_ad_not_available.js"]
|
|
||||||
["browser_shopping_integration.js"]
|
|
||||||
support-files = [
|
|
||||||
"analysis.sjs",
|
"analysis.sjs",
|
||||||
"recommendations.sjs",
|
"recommendations.sjs",
|
||||||
"attribution.sjs",
|
"attribution.sjs",
|
||||||
|
|
@ -23,3 +17,8 @@ support-files = [
|
||||||
"analyze.sjs",
|
"analyze.sjs",
|
||||||
"analysis_status.sjs",
|
"analysis_status.sjs",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
["browser_shopping_ads_test.js"]
|
||||||
|
["browser_shopping_ad_not_available.js"]
|
||||||
|
["browser_shopping_integration.js"]
|
||||||
|
["browser_shopping_sidebar_messages.js"]
|
||||||
|
|
|
||||||
|
|
@ -240,50 +240,6 @@ add_task(async function test_sidebar_button_open_close() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(async function test_sidebar_error() {
|
|
||||||
// Disable OHTTP for now to get this landed; we'll re-enable with proper
|
|
||||||
// mocking in the near future.
|
|
||||||
await SpecialPowers.pushPrefEnv({
|
|
||||||
set: [
|
|
||||||
["toolkit.shopping.ohttpRelayURL", ""],
|
|
||||||
["toolkit.shopping.ohttpConfigURL", ""],
|
|
||||||
],
|
|
||||||
});
|
|
||||||
await BrowserTestUtils.withNewTab(BAD_PRODUCT_TEST_URL, async browser => {
|
|
||||||
let sidebar = gBrowser.getPanel(browser).querySelector("shopping-sidebar");
|
|
||||||
|
|
||||||
Assert.ok(sidebar, "Sidebar should exist");
|
|
||||||
|
|
||||||
Assert.ok(
|
|
||||||
BrowserTestUtils.is_visible(sidebar),
|
|
||||||
"Sidebar should be visible."
|
|
||||||
);
|
|
||||||
info("Waiting for sidebar to update.");
|
|
||||||
await promiseSidebarUpdated(sidebar, BAD_PRODUCT_TEST_URL);
|
|
||||||
|
|
||||||
info("Verifying a generic error is shown.");
|
|
||||||
await SpecialPowers.spawn(
|
|
||||||
sidebar.querySelector("browser"),
|
|
||||||
[],
|
|
||||||
async prodInfo => {
|
|
||||||
let doc = content.document;
|
|
||||||
let shoppingContainer =
|
|
||||||
doc.querySelector("shopping-container").wrappedJSObject;
|
|
||||||
|
|
||||||
ok(
|
|
||||||
shoppingContainer.shoppingMessageBarEl,
|
|
||||||
"Got shopping-message-bar element"
|
|
||||||
);
|
|
||||||
is(
|
|
||||||
shoppingContainer.shoppingMessageBarEl.getAttribute("type"),
|
|
||||||
"generic-error",
|
|
||||||
"generic-error type should be correct"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_task(async function test_ads_requested_after_enabled() {
|
add_task(async function test_ads_requested_after_enabled() {
|
||||||
await SpecialPowers.pushPrefEnv({
|
await SpecialPowers.pushPrefEnv({
|
||||||
set: [
|
set: [
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,145 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const NOT_ENOUGH_REVIEWS_TEST_URL =
|
||||||
|
"https://example.com/Bad-Product/dp/N0T3NOUGHR";
|
||||||
|
const NOT_SUPPORTED_TEST_URL = "https://example.com/Bad-Product/dp/PAG3N0TSUP";
|
||||||
|
const UNPROCESSABLE_TEST_URL = "https://example.com/Bad-Product/dp/UNPR0C3SSA";
|
||||||
|
|
||||||
|
add_task(async function test_sidebar_error() {
|
||||||
|
// Disable OHTTP for now to get this landed; we'll re-enable with proper
|
||||||
|
// mocking in the near future.
|
||||||
|
await SpecialPowers.pushPrefEnv({
|
||||||
|
set: [
|
||||||
|
["toolkit.shopping.ohttpRelayURL", ""],
|
||||||
|
["toolkit.shopping.ohttpConfigURL", ""],
|
||||||
|
],
|
||||||
|
});
|
||||||
|
await BrowserTestUtils.withNewTab(BAD_PRODUCT_TEST_URL, async browser => {
|
||||||
|
let sidebar = gBrowser.getPanel(browser).querySelector("shopping-sidebar");
|
||||||
|
|
||||||
|
Assert.ok(sidebar, "Sidebar should exist");
|
||||||
|
|
||||||
|
Assert.ok(
|
||||||
|
BrowserTestUtils.is_visible(sidebar),
|
||||||
|
"Sidebar should be visible."
|
||||||
|
);
|
||||||
|
info("Waiting for sidebar to update.");
|
||||||
|
await promiseSidebarUpdated(sidebar, BAD_PRODUCT_TEST_URL);
|
||||||
|
|
||||||
|
info("Verifying a generic error is shown.");
|
||||||
|
await SpecialPowers.spawn(
|
||||||
|
sidebar.querySelector("browser"),
|
||||||
|
[],
|
||||||
|
async prodInfo => {
|
||||||
|
let doc = content.document;
|
||||||
|
let shoppingContainer =
|
||||||
|
doc.querySelector("shopping-container").wrappedJSObject;
|
||||||
|
|
||||||
|
ok(
|
||||||
|
shoppingContainer.shoppingMessageBarEl,
|
||||||
|
"Got shopping-message-bar element"
|
||||||
|
);
|
||||||
|
is(
|
||||||
|
shoppingContainer.shoppingMessageBarEl.getAttribute("type"),
|
||||||
|
"generic-error",
|
||||||
|
"generic-error type should be correct"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(async function test_sidebar_analysis_status_page_not_supported() {
|
||||||
|
// Disable OHTTP for now to get this landed; we'll re-enable with proper
|
||||||
|
// mocking in the near future.
|
||||||
|
await SpecialPowers.pushPrefEnv({
|
||||||
|
set: [
|
||||||
|
["toolkit.shopping.ohttpRelayURL", ""],
|
||||||
|
["toolkit.shopping.ohttpConfigURL", ""],
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Product not supported status
|
||||||
|
await BrowserTestUtils.withNewTab(NOT_SUPPORTED_TEST_URL, async browser => {
|
||||||
|
let sidebar = gBrowser.getPanel(browser).querySelector("shopping-sidebar");
|
||||||
|
|
||||||
|
Assert.ok(sidebar, "Sidebar should exist");
|
||||||
|
|
||||||
|
Assert.ok(
|
||||||
|
BrowserTestUtils.is_visible(sidebar),
|
||||||
|
"Sidebar should be visible."
|
||||||
|
);
|
||||||
|
info("Waiting for sidebar to update.");
|
||||||
|
await promiseSidebarUpdated(sidebar, NOT_SUPPORTED_TEST_URL);
|
||||||
|
|
||||||
|
info("Verifying a generic error is shown.");
|
||||||
|
await SpecialPowers.spawn(
|
||||||
|
sidebar.querySelector("browser"),
|
||||||
|
[],
|
||||||
|
async prodInfo => {
|
||||||
|
let doc = content.document;
|
||||||
|
let shoppingContainer =
|
||||||
|
doc.querySelector("shopping-container").wrappedJSObject;
|
||||||
|
|
||||||
|
ok(
|
||||||
|
shoppingContainer.shoppingMessageBarEl,
|
||||||
|
"Got shopping-message-bar element"
|
||||||
|
);
|
||||||
|
is(
|
||||||
|
shoppingContainer.shoppingMessageBarEl.getAttribute("type"),
|
||||||
|
"page-not-supported",
|
||||||
|
"message type should be correct"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(async function test_sidebar_analysis_status_unprocessable() {
|
||||||
|
// Disable OHTTP for now to get this landed; we'll re-enable with proper
|
||||||
|
// mocking in the near future.
|
||||||
|
await SpecialPowers.pushPrefEnv({
|
||||||
|
set: [
|
||||||
|
["toolkit.shopping.ohttpRelayURL", ""],
|
||||||
|
["toolkit.shopping.ohttpConfigURL", ""],
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Unprocessable status
|
||||||
|
await BrowserTestUtils.withNewTab(UNPROCESSABLE_TEST_URL, async browser => {
|
||||||
|
let sidebar = gBrowser.getPanel(browser).querySelector("shopping-sidebar");
|
||||||
|
|
||||||
|
Assert.ok(sidebar, "Sidebar should exist");
|
||||||
|
|
||||||
|
Assert.ok(
|
||||||
|
BrowserTestUtils.is_visible(sidebar),
|
||||||
|
"Sidebar should be visible."
|
||||||
|
);
|
||||||
|
info("Waiting for sidebar to update.");
|
||||||
|
await promiseSidebarUpdated(sidebar, UNPROCESSABLE_TEST_URL);
|
||||||
|
|
||||||
|
info("Verifying a generic error is shown.");
|
||||||
|
await SpecialPowers.spawn(
|
||||||
|
sidebar.querySelector("browser"),
|
||||||
|
[],
|
||||||
|
async prodInfo => {
|
||||||
|
let doc = content.document;
|
||||||
|
let shoppingContainer =
|
||||||
|
doc.querySelector("shopping-container").wrappedJSObject;
|
||||||
|
|
||||||
|
ok(
|
||||||
|
shoppingContainer.shoppingMessageBarEl,
|
||||||
|
"Got shopping-message-bar element"
|
||||||
|
);
|
||||||
|
is(
|
||||||
|
shoppingContainer.shoppingMessageBarEl.getAttribute("type"),
|
||||||
|
"generic-error",
|
||||||
|
"message type should be correct"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue