135 lines
3.6 KiB
JavaScript
135 lines
3.6 KiB
JavaScript
const test = require("node:test");
|
||
const assert = require("node:assert/strict");
|
||
|
||
const api = require("./yuntuReportFilling.user.js");
|
||
|
||
test("isTargetCreateReportRequest matches the segmented market create endpoint", () => {
|
||
assert.equal(
|
||
api.isTargetCreateReportRequest(
|
||
"https://yuntu.oceanengine.com/product_node/v2/api/segmentedMarket/createSegmentedMarket?aadvid=1648829117232140",
|
||
"POST",
|
||
),
|
||
true,
|
||
);
|
||
|
||
assert.equal(
|
||
api.isTargetCreateReportRequest(
|
||
"https://yuntu.oceanengine.com/product_node/v2/api/industry/insightBrandStats?aadvid=1648829117232140",
|
||
"POST",
|
||
),
|
||
false,
|
||
);
|
||
});
|
||
|
||
test("isSupportedPageUrl covers both creation and detail pages", () => {
|
||
assert.equal(
|
||
api.isSupportedPageUrl(
|
||
"https://yuntu.oceanengine.com/yuntu_brand/ecom/product/segmentedMarketcreation?aadvid=1648829117232140",
|
||
),
|
||
true,
|
||
);
|
||
|
||
assert.equal(
|
||
api.isSupportedPageUrl(
|
||
"https://yuntu.oceanengine.com/yuntu_brand/ecom/product/segmentedMarketDetail/marketOverview?aadvid=1710507483282439&reportId=441518",
|
||
),
|
||
true,
|
||
);
|
||
|
||
assert.equal(
|
||
api.isSupportedPageUrl(
|
||
"https://yuntu.oceanengine.com/yuntu_brand/ecom/product/otherPage?aadvid=1710507483282439",
|
||
),
|
||
false,
|
||
);
|
||
});
|
||
|
||
test("getLocalApiBaseCandidates prefers localhost and falls back to 127.0.0.1", () => {
|
||
assert.deepEqual(api.getLocalApiBaseCandidates(), [
|
||
"http://localhost:3000",
|
||
"http://127.0.0.1:3000",
|
||
]);
|
||
});
|
||
|
||
test("extractReportId returns response.data.reportId when present", () => {
|
||
assert.equal(
|
||
api.extractReportId({
|
||
data: {
|
||
reportId: "987654321",
|
||
},
|
||
}),
|
||
"987654321",
|
||
);
|
||
|
||
assert.equal(api.extractReportId({ data: {} }), null);
|
||
});
|
||
|
||
test("shiftDateBackOneYear keeps month/day and clamps leap day", () => {
|
||
assert.equal(api.shiftDateBackOneYear("2025-03-01"), "2024-03-01");
|
||
assert.equal(api.shiftDateBackOneYear("2024-02-29"), "2023-02-28");
|
||
});
|
||
|
||
test("buildAutoCopyPayload deep clones payload, shifts top-level dates, and appends the year range to name", () => {
|
||
const original = {
|
||
name: "测试(近一年)",
|
||
startTime: "2025-03-01",
|
||
endTime: "2026-02-28",
|
||
nested: {
|
||
startTime: "SHOULD_NOT_CHANGE",
|
||
},
|
||
};
|
||
|
||
const copied = api.buildAutoCopyPayload(original);
|
||
|
||
assert.deepEqual(copied, {
|
||
name: "测试(近一年)2024-2025",
|
||
startTime: "2024-03-01",
|
||
endTime: "2025-02-28",
|
||
nested: {
|
||
startTime: "SHOULD_NOT_CHANGE",
|
||
},
|
||
});
|
||
assert.notEqual(copied, original);
|
||
assert.notEqual(copied.nested, original.nested);
|
||
});
|
||
|
||
test("buildPersistRequest maps manual capture payload into backend request format", () => {
|
||
const payload = {
|
||
name: "测试",
|
||
price: ["1,100", "101,100000"],
|
||
rules: [{ keywords: ["奶粉"], op: "INCLUDE" }],
|
||
analysisDims: ["MARKETOVERVIEW"],
|
||
categories: [{ id: "20028" }],
|
||
channels: ["ALL"],
|
||
startTime: "2025-03-01",
|
||
endTime: "2026-02-28",
|
||
periodType: "MONTH",
|
||
userName: "tester@example.com",
|
||
};
|
||
const request = api.buildPersistRequest({
|
||
payload,
|
||
aadvid: "1648829117232140",
|
||
reportId: "report-001",
|
||
sourceType: "MANUAL_CAPTURE",
|
||
sourceReportId: null,
|
||
});
|
||
|
||
assert.deepEqual(request, {
|
||
reportId: "report-001",
|
||
sourceType: "MANUAL_CAPTURE",
|
||
sourceReportId: null,
|
||
aadvid: "1648829117232140",
|
||
name: "测试",
|
||
price: ["1,100", "101,100000"],
|
||
rules: [{ keywords: ["奶粉"], op: "INCLUDE" }],
|
||
analysisDims: ["MARKETOVERVIEW"],
|
||
categories: [{ id: "20028" }],
|
||
channels: ["ALL"],
|
||
startTime: "2025-03-01",
|
||
endTime: "2026-02-28",
|
||
periodType: "MONTH",
|
||
userName: "tester@example.com",
|
||
payload,
|
||
});
|
||
});
|