'use strict'; const { assert } = require('egg-mock/bootstrap'); const DgjService = require('../../../app/lib/printPlatform/dgj'); describe('lib/printPlatform/dgj 订单查询报文口径', () => { /** * 造一个只用于报文断言的服务实例 * @return {Object} 店管家服务实例 */ function buildService() { return new DgjService({ platform: { code: 'dgj', name: '店管家', url: 'fxdd.dgjapp.com', fetch_waybill_no: 1 }, account: { id: 1, account: 'tester', password: 'pwd', token: 'token', cookie: '' }, }); } it('ErpState 过滤的 Contract 必须是单个等号(写成 == 抖店老分区会回「服务器繁忙」)', async () => { const service = buildService(); let captured = null; service.request = async (url, options) => { captured = new URLSearchParams(options.body); return { status: 200, json: { Success: true, Data: { Rows: [], Total: 0 } }, text: '', setCookies: [] }; }; await service.fetchOrderPage('fxdd.dgjapp.com', { traceId: 'trace', dbname: 'dzh93a8yur84Y3Yln2ha9RbPovVMhBTc', startTime: new Date('2026-10-09T00:00:00+08:00'), endTime: new Date('2026-11-07T23:59:59+08:00'), pageIndex: 1, erpState: 'waitsellersend', merchantFxUserId: '953516', }); const contracts = []; for (let index = 0; index < 5; index += 1) { const name = captured.get(`Filters[${index}][Name]`); if (!name) break; contracts.push(`${name}:${captured.get(`Filters[${index}][Contract]`)}`); } console.log('过滤条件:', contracts.join(' | ')); assert.deepStrictEqual(contracts, [ 'CreateTime:between', 'ErpState:=', 'UpFxUserId:in' ]); }); it('不传状态时只带时间窗', async () => { const service = buildService(); let captured = null; service.request = async (url, options) => { captured = new URLSearchParams(options.body); return { status: 200, json: { Success: true, Data: { Rows: [], Total: 0 } }, text: '', setCookies: [] }; }; await service.fetchOrderPage('fxali.dgjapp.com', { traceId: 'trace', dbname: '', startTime: new Date('2026-11-01T00:00:00+08:00'), endTime: new Date('2026-11-07T00:00:00+08:00'), pageIndex: 1, }); assert.strictEqual(captured.get('Filters[1][Name]'), null); assert.strictEqual(captured.get('Filters[0][Contract]'), 'between'); assert.strictEqual(captured.get('PageSize'), '500'); }); });