Skip to content

Commit ea92940

Browse files
author
Gerald Baulig
committed
fix(tests): fix all tests vs DHL sandbox
1 parent 51ee979 commit ea92940

File tree

3 files changed

+100
-65
lines changed

3 files changed

+100
-65
lines changed

cfg/config.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"INVALID": "fulfillmentInvalid",
7575
"SUBMITTED": "fulfillmentSubmitted",
7676
"IN_TRANSFER": "fulfillmentInTransfer",
77-
"FULFILLED": "fulfillmentFulfilled",
77+
"COMPLETED": "fulfillmentCompleted",
7878
"WITHDRAWN": "fulfillmentWithdrawn",
7979
"CANCELLED": "fulfillmentCancelled",
8080
"CREATE_INVOICES": "createInvoices"
@@ -101,7 +101,7 @@
101101
"fulfillmentInTransfer": {
102102
"messageObject": "io.restorecommerce.fulfillment.Fulfillment"
103103
},
104-
"fulfillmentFulfilled": {
104+
"fulfillmentCompleted": {
105105
"messageObject": "io.restorecommerce.fulfillment.Fulfillment"
106106
},
107107
"fulfillmentFailed": {

src/stubs/dhl_soap.ts

+68-56
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ type ClientMap = { [id: string]: soap.Client };
2424

2525
interface Origin
2626
{
27-
country: string;
28-
countryISOCode: string;
27+
'cis:country': string;
28+
'cis:countryISOCode': string;
2929
}
3030

3131
interface Communication
3232
{
33-
phone?: string;
34-
email?: string;
35-
contactPerson?: string;
33+
'cis:phone'?: string;
34+
'cis:email'?: string;
35+
'cis:contactPerson'?: string;
3636
}
3737

3838
interface Shipper
3939
{
4040
Name: {
41-
name1: string;
42-
name2?: string;
43-
name3?: string;
41+
'cis:name1': string;
42+
'cis:name2'?: string;
43+
'cis:name3'?: string;
4444
};
4545
Address: {
46-
streetName: string;
47-
streetNumber: string;
48-
zip: string;
49-
city: string;
50-
Origin: Origin;
46+
'cis:streetName': string;
47+
'cis:streetNumber': string;
48+
'cis:zip': string;
49+
'cis:city': string;
50+
'cis:Origin': Origin;
5151
};
5252
Communication: Communication;
5353
}
@@ -58,11 +58,11 @@ interface Receiver
5858
Address: {
5959
name2?: string;
6060
name3?: string;
61-
streetName: string;
62-
streetNumber: string;
63-
zip: string;
64-
city: string;
65-
Origin: Origin;
61+
'cis:streetName': string;
62+
'cis:streetNumber': string;
63+
'cis:zip': string;
64+
'cis:city': string;
65+
'cis:Origin': Origin;
6666
};
6767
Communication: Communication;
6868
}
@@ -421,8 +421,8 @@ class DHLSoap extends Stub {
421421
}
422422

423423
return fulfillments.map((fulfillment, i) => {
424-
const dhl_state = response?.CreationFulfillmentState?.find((state: any) => state.sequenceNumber === (i + 1).toString());
425-
const code = dhl_state?.LabelData.Status.statusCode;
424+
const dhl_state = response?.CreationState?.find((state: any) => state.sequenceNumber === (i + 1).toString());
425+
const code = dhl_state?.LabelData?.Status?.statusCode;
426426
const state = code === 0 ? FulfillmentState.SUBMITTED : FulfillmentState.INVALID;
427427
const status = this.DHLCode2StatusCode(
428428
code,
@@ -466,44 +466,44 @@ class DHLSoap extends Stub {
466466
Shipment: {
467467
Shipper: {
468468
Name: {
469-
name1: packaging.sender.address.residential_address?.family_name ?? packaging.sender.address.business_address?.name,
470-
name2: packaging.sender.address.residential_address?.given_name,
471-
name3: packaging.sender.address.residential_address?.mid_name,
469+
'cis:name1': packaging.sender.address.residential_address?.family_name ?? packaging.sender.address.business_address?.name,
470+
'cis:name2': packaging.sender.address.residential_address?.given_name,
471+
'cis:name3': packaging.sender.address.residential_address?.mid_name,
472472
},
473473
Address: {
474-
streetName: packaging.sender.address?.street,
475-
streetNumber: packaging.sender.address?.building_number,
476-
zip: packaging.sender.address?.postcode,
477-
city: packaging.sender.address?.region,
478-
Origin: {
479-
country: request.sender_country?.name,
480-
countryISOCode: request.sender_country?.country_code
474+
'cis:streetName': packaging.sender.address?.street,
475+
'cis:streetNumber': packaging.sender.address?.building_number,
476+
'cis:zip': packaging.sender.address?.postcode,
477+
'cis:city': packaging.sender.address?.region,
478+
'cis:Origin': {
479+
'cis:country': request.sender_country?.name,
480+
'cis:countryISOCode': request.sender_country?.country_code
481481
}
482482
},
483483
Communication: {
484-
contactPerson: packaging.sender?.contact?.name,
485-
email: packaging.sender?.contact.email,
486-
phone: packaging.sender?.contact.phone,
484+
'cis:contactPerson': packaging.sender?.contact?.name,
485+
'cis:email': packaging.sender?.contact.email,
486+
'cis:phone': packaging.sender?.contact.phone,
487487
}
488488
},
489489
Receiver: {
490490
name1: packaging.recipient.address.residential_address?.family_name ?? packaging.recipient.address.business_address?.name,
491491
Address: {
492492
name2: packaging.recipient.address.residential_address?.given_name,
493493
name3: packaging.recipient.address.residential_address?.mid_name,
494-
streetName: packaging.recipient.address?.street,
495-
streetNumber: packaging.recipient.address?.building_number,
496-
zip: packaging.recipient.address?.postcode,
497-
city: packaging.recipient.address?.region,
498-
Origin: {
499-
country: request.recipient_country?.name,
500-
countryISOCode: request.recipient_country?.country_code
494+
'cis:streetName': packaging.recipient.address?.street,
495+
'cis:streetNumber': packaging.recipient.address?.building_number,
496+
'cis:zip': packaging.recipient.address?.postcode,
497+
'cis:city': packaging.recipient.address?.region,
498+
'cis:Origin': {
499+
'cis:country': request.recipient_country?.name,
500+
'cis:countryISOCode': request.recipient_country?.country_code
501501
},
502502
},
503503
Communication: {
504-
contactPerson: packaging.recipient.contact?.name,
505-
email: packaging.recipient.contact?.email,
506-
phone: packaging.recipient.contact?.phone,
504+
'cis:contactPerson': packaging.recipient.contact?.name,
505+
'cis:email': packaging.recipient.contact?.email,
506+
'cis:phone': packaging.recipient.contact?.phone,
507507
}
508508
},
509509
ShipmentDetails: {
@@ -589,13 +589,18 @@ class DHLSoap extends Stub {
589589
if (fulfillments.length === 0) return [];
590590
const dhl_order_request = this.AggregatedFulfillmentRequests2DHLShipmentOrderRequest(fulfillments);
591591
const client = await this.registerSoapClient();
592-
return new Promise<FlatAggregatedFulfillment[]>((resolve, reject): void => {
592+
return await new Promise<FlatAggregatedFulfillment[]>((resolve, reject): void => {
593593
const timer = setTimeout(reject, 30000, this.operation_status_codes.TIMEOUT);
594594
client.GVAPI_2_0_de.GKVAPISOAP11port0.createShipmentOrder(
595595
dhl_order_request,
596596
(error: any, result: any): any => {
597597
clearTimeout(timer);
598-
resolve(this.DHLShipmentLabels2FulfillmentResponses(fulfillments, result, error));
598+
try {
599+
resolve(this.DHLShipmentLabels2FulfillmentResponses(fulfillments, result, error));
600+
}
601+
catch (e: any) {
602+
reject(e);
603+
}
599604
}
600605
);
601606
});
@@ -627,16 +632,16 @@ class DHLSoap extends Stub {
627632
const params = new URLSearchParams();
628633
params.append('xml', xml);
629634
const payload = {
630-
method: 'post',
635+
method: 'get',
631636
headers: {
632637
Host: 'cig.dhl.de',
633638
Authorization: auth,
634639
Connection: 'Keep-Alive',
635640
},
636-
body: params,
641+
// body: params,
637642
};
638643

639-
return await fetch(client.endpoint, payload).then(
644+
return await fetch(`${client.endpoint}?${params}`, payload).then(
640645
response => DHLTracking2FulfillmentTracking(item, response),
641646
err => {
642647
this.logger?.error(`${this.constructor.name}: ${err}`);
@@ -666,20 +671,27 @@ class DHLSoap extends Stub {
666671
const dhl_cancel_request = this.AggregatedFulfillment2DHLShipmentCancelRequest(fulfillments);
667672
const client = await this.registerSoapClient();
668673
return await new Promise<FlatAggregatedFulfillment[]>((resolve, reject: (v: FlatAggregatedFulfillment[]) => void): void => {
674+
const timer = setTimeout(reject, 30000, this.operation_status_codes.TIMEOUT);
669675
client.GVAPI_2_0_de.GKVAPISOAP11port0.deleteShipmentOrder(dhl_cancel_request,
670676
(err: any, result: any): any => {
671-
if (err) {
672-
if (result?.html) {
673-
this.logger?.error(`${this.constructor.name}: ${result.html.head.title}`);
674-
reject(DHLShipmentCancelResponse2AggregatedFulfillment(fulfillment_map, null, result.html.head.title));
677+
clearTimeout(timer);
678+
try {
679+
if (err) {
680+
if (result?.html) {
681+
this.logger?.error(`${this.constructor.name}: ${result.html.head.title}`);
682+
reject(DHLShipmentCancelResponse2AggregatedFulfillment(fulfillment_map, null, result.html.head.title));
683+
}
684+
else {
685+
this.logger?.error(`${this.constructor.name}: ${err}`);
686+
reject(DHLShipmentCancelResponse2AggregatedFulfillment(fulfillment_map, null, err));
687+
}
675688
}
676689
else {
677-
this.logger?.error(`${this.constructor.name}: ${err}`);
678-
reject(DHLShipmentCancelResponse2AggregatedFulfillment(fulfillment_map, null, err));
690+
resolve(DHLShipmentCancelResponse2AggregatedFulfillment(fulfillment_map, result));
679691
}
680692
}
681-
else {
682-
resolve(DHLShipmentCancelResponse2AggregatedFulfillment(fulfillment_map, result));
693+
catch (e: any) {
694+
reject(e);
683695
}
684696
});
685697
});

test/fulfillment-srv-dhl.spec.ts

+30-7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ describe('Testing Fulfillment Service Cluster:', () => {
7070
FulfillmentServiceDefinition,
7171
createChannel(cfg.get('client:fulfillment:address'))
7272
) as Client<FulfillmentServiceDefinition>;
73+
74+
await Promise.allSettled([
75+
courier_client?.delete({
76+
collection: true,
77+
subject: {
78+
id: 'superadmin',
79+
token: 'superadmin',
80+
},
81+
}),
82+
product_client?.delete({
83+
collection: true,
84+
subject: {
85+
id: 'superadmin',
86+
token: 'superadmin',
87+
},
88+
}),
89+
fulfillment_client?.delete({
90+
collection: true,
91+
subject: {
92+
id: 'superadmin',
93+
token: 'superadmin',
94+
},
95+
}),
96+
]);
7397
});
7498

7599
after(async function() {
@@ -191,7 +215,7 @@ describe('Testing Fulfillment Service Cluster:', () => {
191215
describe('The Fulfillment Service:', () => {
192216
const fulfillmentCreatedSemaphore = new Semaphore(0);
193217
const fulfillmentSubmittedSemaphore = new Semaphore(0);
194-
const fulfillmentFulfilledSemaphore = new Semaphore(0);
218+
const fulfillmentCompletedSemaphore = new Semaphore(0);
195219
const fulfillmentWithdrawnSemaphore = new Semaphore(0);
196220
const fulfillmentCancelledSemaphore = new Semaphore(0);
197221

@@ -205,9 +229,9 @@ describe('Testing Fulfillment Service Cluster:', () => {
205229
fulfillmentSubmittedSemaphore.release(1);
206230
};
207231

208-
const onFulfillmentFulfilled = (msg: Fulfillment, context?:any): void => {
232+
const onFulfillmentCompleted = (msg: Fulfillment, context?:any): void => {
209233
should.equal(msg?.fulfillment_state, FulfillmentState.COMPLETED);
210-
fulfillmentFulfilledSemaphore.release(1);
234+
fulfillmentCompletedSemaphore.release(1);
211235
};
212236

213237
const onFulfillmentWithdrawn = (msg: Fulfillment, context?:any): void => {
@@ -225,7 +249,7 @@ describe('Testing Fulfillment Service Cluster:', () => {
225249
await Promise.all([
226250
topics.on('fulfillmentCreated', onFulfillmentCreated),
227251
topics.on('fulfillmentSubmitted', onFulfillmentSubmitted),
228-
topics.on('fulfillmentFulfilled', onFulfillmentFulfilled),
252+
topics.on('fulfillmentCompleted', onFulfillmentCompleted),
229253
topics.on('fulfillmentWithdrawn', onFulfillmentWithdrawn),
230254
topics.on('fulfillmentCancelled', onFulfillmentCancelled),
231255
]);
@@ -236,7 +260,7 @@ describe('Testing Fulfillment Service Cluster:', () => {
236260
await Promise.all([
237261
topics.removeListener('fulfillmentCreated', onFulfillmentCreated),
238262
topics.removeListener('fulfillmentSubmitted', onFulfillmentSubmitted),
239-
topics.removeListener('fulfillmentFulfilled', onFulfillmentFulfilled),
263+
topics.removeListener('fulfillmentCompleted', onFulfillmentCompleted),
240264
topics.removeListener('fulfillmentWithdrawn', onFulfillmentWithdrawn),
241265
topics.removeListener('fulfillmentCancelled', onFulfillmentCancelled),
242266
]);
@@ -271,7 +295,6 @@ describe('Testing Fulfillment Service Cluster:', () => {
271295
it(`should submit fulfillment by valid samples: ${sample_name}`, async function() {
272296
this.timeout(60000);
273297
const response = await fulfillment_client.submit(sample);
274-
console.log(JSON.stringify(response, null, 2));
275298
should.equal(
276299
response?.operationStatus?.code, 200,
277300
'response.operationStatus.code expected to be 200',
@@ -316,7 +339,7 @@ describe('Testing Fulfillment Service Cluster:', () => {
316339

317340
it(`should have received fulfillment tracking event for ${sample_name}`, async function() {
318341
this.timeout(5000);
319-
await fulfillmentFulfilledSemaphore.acquire(1);
342+
await fulfillmentCompletedSemaphore.acquire(1);
320343
});
321344
}
322345

0 commit comments

Comments
 (0)