223 lines
6.0 KiB
JavaScript
223 lines
6.0 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const PoloApiService = require('../../../../app/service/systems/polo_api');
|
|
|
|
describe('test/app/service/systems/polo_api.test.js', () => {
|
|
it('should call test request with fixed options', async () => {
|
|
const expectedResult = { ok: true, source: 'request-result' };
|
|
let receivedOptions = null;
|
|
|
|
const service = new PoloApiService({
|
|
app: {
|
|
config: {},
|
|
},
|
|
});
|
|
service.client.request = async options => {
|
|
receivedOptions = options;
|
|
return expectedResult;
|
|
};
|
|
|
|
const result = await service.test();
|
|
|
|
assert.deepEqual(receivedOptions, {
|
|
method: 'Differ.JH.LogisticsPlatFeatures',
|
|
platid: 556,
|
|
bizcontent: {},
|
|
});
|
|
assert.strictEqual(result, expectedResult);
|
|
});
|
|
|
|
it('should build kuaishou request with structured inputs', async () => {
|
|
const expectedResult = { ok: true, source: 'kuaishou-request' };
|
|
let receivedOptions = null;
|
|
|
|
const service = new PoloApiService({
|
|
app: {
|
|
config: {},
|
|
},
|
|
});
|
|
|
|
service.client.request = async options => {
|
|
receivedOptions = options;
|
|
return expectedResult;
|
|
};
|
|
|
|
const result = await service.kuaishou({
|
|
express_id: 'KS-556',
|
|
wmsOrder: {
|
|
sourceId: 'TX-20260416-001',
|
|
sourceOrderCode: 'ORDER-20260416-001',
|
|
postcode: 'p03',
|
|
wareHouseId: 1000,
|
|
storeId: 2000,
|
|
items: 'SKU001,1,测试商品',
|
|
goodsCount: 2,
|
|
orderWeight: 3.5,
|
|
address: '广东省广州市天河区测试路 1 号',
|
|
name: '张三',
|
|
expAreaName: '天河区',
|
|
cityName: '广州市',
|
|
province: '广东省',
|
|
tempMobile: '13800000000',
|
|
tel: '13900000000',
|
|
},
|
|
expressConfig: {
|
|
storeName: '快手店铺',
|
|
address: '广东省广州市白云区仓库路 2 号',
|
|
senderName: '李四',
|
|
districtName: '白云区;太和镇',
|
|
cityName: '广州市',
|
|
senderTel: '020-12345678',
|
|
provinceName: '广东省',
|
|
siteCode: 'SITE-001',
|
|
clientId: 'CLIENT-001',
|
|
},
|
|
});
|
|
|
|
assert.deepEqual(receivedOptions, {
|
|
method: 'Differ.JH.Logistics.PostOrder',
|
|
platid: 556,
|
|
bizcontent: {
|
|
orders: [{
|
|
businessplat: 'OTHERS',
|
|
ismultiplepieces: '0',
|
|
businesstype: 'JH_Normal',
|
|
cpcode: 'KS-556',
|
|
customercode: '',
|
|
customername: '快手店铺',
|
|
goods: [{
|
|
cnname: '测试商品',
|
|
count: '2',
|
|
unit: '属性',
|
|
currencytype: 'CNY',
|
|
Unit: '',
|
|
weight: '3.5',
|
|
price: '0.0',
|
|
}],
|
|
logisticsproductname: 'JH_02',
|
|
logistictype: 'KS-556',
|
|
mainsubpaymode: '1',
|
|
needencrypt: '1',
|
|
numpackage: '1',
|
|
orderno: 'ORDER-20260416-001',
|
|
ordersource: 'KUAI_SHOU',
|
|
ordertype: 'JH_Normal',
|
|
plattradeno: 'ORDER-20260416-001',
|
|
ProviderID: 1327,
|
|
providercode: 'KS-556',
|
|
receiver: {
|
|
address: '广东省广州市天河区测试路 1 号',
|
|
name: '张三',
|
|
area: '天河区',
|
|
city: '广州市',
|
|
mobile: '13800000000',
|
|
province: '广东省',
|
|
},
|
|
sender: {
|
|
country: 'CN',
|
|
Company: '快手店铺',
|
|
address: '广东省广州市白云区仓库路 2 号',
|
|
name: '李四',
|
|
area: '白云区',
|
|
town: '太和镇',
|
|
city: '广州市',
|
|
phone: '020-12345678',
|
|
mobile: '020-12345678',
|
|
tel: '020-12345678',
|
|
province: '广东省',
|
|
},
|
|
shipperno: 'CLIENT-001',
|
|
sitecode: 'SITE-001',
|
|
Inputsite: 'SITE-001',
|
|
transtype: '0',
|
|
}],
|
|
shoptype: 'JH_001',
|
|
},
|
|
});
|
|
assert.strictEqual(result, expectedResult);
|
|
});
|
|
|
|
it('should keep kuaishou fixed when a caller passes a different method and omit optional fields', async () => {
|
|
const expectedResult = { ok: true, source: 'kuaishou-defaults' };
|
|
let receivedOptions = null;
|
|
|
|
const service = new PoloApiService({
|
|
app: {
|
|
config: {},
|
|
},
|
|
});
|
|
|
|
service.client.request = async options => {
|
|
receivedOptions = options;
|
|
return expectedResult;
|
|
};
|
|
|
|
const result = await service.kuaishou({
|
|
method: 'Bad.Method.Should.Be.Ignored',
|
|
});
|
|
|
|
assert.deepEqual(receivedOptions, {
|
|
method: 'Differ.JH.Logistics.PostOrder',
|
|
platid: 556,
|
|
bizcontent: {
|
|
orders: [{
|
|
businessplat: 'OTHERS',
|
|
ismultiplepieces: '0',
|
|
businesstype: 'JH_Normal',
|
|
cpcode: '',
|
|
customercode: '',
|
|
customername: '测试',
|
|
goods: [{
|
|
cnname: '',
|
|
count: '0',
|
|
unit: '属性',
|
|
currencytype: 'CNY',
|
|
Unit: '',
|
|
weight: '0',
|
|
price: '0.0',
|
|
}],
|
|
logisticsproductname: 'JH_02',
|
|
logistictype: '',
|
|
mainsubpaymode: '1',
|
|
needencrypt: '1',
|
|
numpackage: '1',
|
|
orderno: '',
|
|
ordersource: 'KUAI_SHOU',
|
|
ordertype: 'JH_Normal',
|
|
plattradeno: '',
|
|
ProviderID: '',
|
|
providercode: '',
|
|
receiver: {
|
|
address: '',
|
|
name: '',
|
|
area: '',
|
|
city: '',
|
|
mobile: '',
|
|
province: '',
|
|
},
|
|
sender: {
|
|
country: 'CN',
|
|
Company: '',
|
|
address: '',
|
|
name: '',
|
|
area: '',
|
|
town: '',
|
|
city: '',
|
|
phone: '',
|
|
mobile: '',
|
|
tel: '',
|
|
province: '',
|
|
},
|
|
shipperno: '',
|
|
sitecode: '',
|
|
Inputsite: '',
|
|
transtype: '0',
|
|
}],
|
|
shoptype: 'JH_001',
|
|
},
|
|
});
|
|
assert.strictEqual(result, expectedResult);
|
|
});
|
|
});
|