75 lines
1.9 KiB
JavaScript
75 lines
1.9 KiB
JavaScript
import test from "node:test";
|
||
import assert from "node:assert/strict";
|
||
import { retryableStatuses, pendingRetryItems } from "../src/retryQueue.js";
|
||
|
||
test("retry queue includes platforms whose latest result is not final", () => {
|
||
const history = {
|
||
programs: {
|
||
"百变职喵": {
|
||
name: "百变职喵",
|
||
runs: ["2026-05-12T00:00:00.000Z"],
|
||
platforms: {
|
||
tencent: {
|
||
values: {
|
||
"2026-05-12T00:00:00.000Z": { status: "ok", number: 123 },
|
||
},
|
||
},
|
||
iqiyi: {
|
||
values: {
|
||
"2026-05-12T00:00:00.000Z": { status: "no_match", error: "not online yet" },
|
||
},
|
||
},
|
||
mgtv: {
|
||
values: {
|
||
"2026-05-12T00:00:00.000Z": { status: "no_metric", url: "https://www.mgtv.com/h/1.html" },
|
||
},
|
||
},
|
||
},
|
||
},
|
||
},
|
||
};
|
||
|
||
assert.deepEqual(pendingRetryItems(history), [
|
||
{
|
||
name: "百变职喵",
|
||
platforms: ["iqiyi", "mgtv"],
|
||
reason: "爱奇艺:no_match;芒果TV:no_metric",
|
||
},
|
||
]);
|
||
});
|
||
|
||
test("retry queue treats blocked and error as retryable but skips healthy latest values", () => {
|
||
assert.deepEqual([...retryableStatuses], ["no_match", "no_metric", "blocked", "error"]);
|
||
|
||
const history = {
|
||
programs: {
|
||
"星愿甜心": {
|
||
name: "星愿甜心",
|
||
runs: ["old", "new"],
|
||
platforms: {
|
||
youku: {
|
||
values: {
|
||
old: { status: "error" },
|
||
new: { status: "ok", number: 500 },
|
||
},
|
||
},
|
||
iqiyi: {
|
||
values: {
|
||
old: { status: "ok", number: 100 },
|
||
new: { status: "blocked", error: "captcha" },
|
||
},
|
||
},
|
||
},
|
||
},
|
||
},
|
||
};
|
||
|
||
assert.deepEqual(pendingRetryItems(history), [
|
||
{
|
||
name: "星愿甜心",
|
||
platforms: ["iqiyi"],
|
||
reason: "爱奇艺:blocked",
|
||
},
|
||
]);
|
||
});
|