forked from lunanting/cangku
37 lines
2.1 KiB
JavaScript
37 lines
2.1 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const Module = require('node:module');
|
|
const express = require('express');
|
|
|
|
test('retired market endpoints return 404 while retained incentive and calculator endpoints work', async () => {
|
|
const originalLoad = Module._load;
|
|
Module._load = function (id, parent, ...rest) {
|
|
if (parent?.filename.endsWith('/api/planningUpload.js')) {
|
|
if (id.endsWith('/pageAccess')) return { getResolvedUserWithPageAccess: async () => ({ role: 'admin' }) };
|
|
if (id.endsWith('/opsBIncentiveBoardService')) return {
|
|
getOpsBIncentiveBoard: async () => ({ rows: [] }), getOpsBIncentiveBatches: async () => [], getOpsBIncentiveDaily: async () => [],
|
|
};
|
|
if (id.endsWith('/alibaba1688ProductService')) return { getAlibaba1688Product: async (id) => ({ id }) };
|
|
if (id.endsWith('/alibaba1688ProductEncodingRegistry')) return { attachEncodingDetail: async (value) => value };
|
|
}
|
|
return originalLoad.call(this, id, parent, ...rest);
|
|
};
|
|
let router;
|
|
try { router = require('../src/api/planningUpload'); } finally { Module._load = originalLoad; }
|
|
const app = express();
|
|
app.use((req, _res, next) => { req.user = { sub: 1 }; next(); });
|
|
app.use('/api/planning-upload', router);
|
|
const server = await new Promise((resolve) => { const listener = app.listen(0, '127.0.0.1', () => resolve(listener)); });
|
|
try {
|
|
const base = `http://127.0.0.1:${server.address().port}/api/planning-upload`;
|
|
for (const path of ['/analysis/rank-board', '/analysis/market-selection/categories', '/analysis/market-replica/insight', '/analysis/social-market/jd', '/selection-fission/plans']) {
|
|
assert.equal((await fetch(base + path)).status, 404, path);
|
|
}
|
|
for (const path of ['/analysis/ops-b-incentive', '/analysis/ops-b-incentive/batches', '/analysis/ops-b-incentive/daily', '/selection-fission/1688-products/123']) {
|
|
const response = await fetch(base + path);
|
|
assert.equal(response.status, 200, path);
|
|
assert.equal((await response.json()).success, true);
|
|
}
|
|
} finally { await new Promise((resolve) => server.close(resolve)); }
|
|
});
|