forked from lunanting/cangku
36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const test = require('node:test');
|
|
|
|
const {
|
|
buildExpiryNotification,
|
|
selectExpiryAlertStage,
|
|
} = require('../src/jobs/alibaba1688ImageSearchExpiryJob');
|
|
|
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
|
|
test('expiry alerts are selected at two days, one day and expiration', () => {
|
|
assert.equal(selectExpiryAlertStage({ tracked: false, remainingMs: null }), '');
|
|
assert.equal(selectExpiryAlertStage({ tracked: true, remainingMs: 3 * DAY_MS }), '');
|
|
assert.equal(selectExpiryAlertStage({ tracked: true, remainingMs: 2 * DAY_MS }), 'two_days');
|
|
assert.equal(selectExpiryAlertStage({ tracked: true, remainingMs: DAY_MS }), 'one_day');
|
|
assert.equal(selectExpiryAlertStage({ tracked: true, remainingMs: 0 }), 'expired');
|
|
});
|
|
|
|
test('expiry notification identifies Su Shi and uses a stable stage-specific idempotency key', () => {
|
|
const validity = {
|
|
tracked: true,
|
|
remainingMs: DAY_MS,
|
|
expiresAt: '2026-09-12T01:00:00.000Z',
|
|
};
|
|
const first = buildExpiryNotification({ validity, stage: 'one_day', recipientAlias: '苏适' });
|
|
const second = buildExpiryNotification({ validity, stage: 'one_day', recipientAlias: '苏适' });
|
|
|
|
assert.equal(first.recipientAlias, '苏适');
|
|
assert.equal(first.idempotencyKey, second.idempotencyKey);
|
|
assert.match(first.idempotencyKey, /:one_day:v1$/);
|
|
assert.match(first.content, /7 天有效期/);
|
|
assert.equal(first.actionTitle, '立即替换');
|
|
});
|