Skip to content

Commit 8c1ed9c

Browse files
committed
update
1 parent 8bea2e9 commit 8c1ed9c

1 file changed

Lines changed: 36 additions & 19 deletions

File tree

cypress/e2e/export-manager/orders-export-to-a-vendor/export-order-with-currency-different-from-default.cy.js

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,41 @@ const EXPORT_WAIT_TIME_MS = 10_000;
5151

5252
const FOREIGN_CURRENCIES = ['AUD', 'CAD', 'CHF', 'EUR', 'GBP', 'JPY', 'PLN'];
5353

54-
const toEdiAmount = (value) => Number(value)
55-
.toFixed(2)
56-
.replace(/\.0+$/, '')
57-
.replace(/(\.\d*[1-9])0+$/, '$1');
54+
const toEdiAmount = (value) => {
55+
const amount = Number(value);
56+
const rounded = Math.round((amount + Number.EPSILON) * 100) / 100;
57+
const normalized = String(rounded);
58+
59+
if (Number.isInteger(rounded)) {
60+
return normalized.replace(/$/, '.0');
61+
}
62+
63+
return normalized.replace(/(\.\d*[1-9])0+$/, '$1').replace(/\.0+$/, '');
64+
};
5865

5966
const createOrderLinesCleanup = (orderLines) => () => {
6067
orderLines.forEach((orderLine) => {
6168
OrderLines.deleteOrderLineViaApi(orderLine.id, false);
6269
});
6370
};
6471

65-
const assertSegmentExists = (segments, expectedPrefix) => {
66-
expect(segments.some((segment) => segment.startsWith(expectedPrefix))).to.equal(true);
72+
const assertSegmentExists = (segments, expectedPrefix, options = {}) => {
73+
const { exact = false } = options;
74+
75+
expect(
76+
segments.some((segment) => {
77+
return exact ? segment === expectedPrefix : segment.startsWith(expectedPrefix);
78+
}),
79+
).to.equal(true);
6780
};
6881

69-
const assertCurrencySegments = (segments, currencies) => {
70-
const hasAnyOrderCurrency = [currencies.pol1Currency, currencies.pol2Currency].some(
71-
(currency) => {
72-
return segments.some((segment) => segment.startsWith(`CUX+2:${currency}:`));
73-
},
74-
);
82+
const assertSegmentCount = (segments, expectedPrefix, expectedCount) => {
83+
const actualCount = segments.filter((segment) => segment.startsWith(expectedPrefix)).length;
84+
expect(actualCount).to.equal(expectedCount);
85+
};
7586

76-
expect(hasAnyOrderCurrency).to.equal(true);
87+
const assertCurrencySegments = (segments, currencies) => {
88+
assertSegmentCount(segments, 'CUX+2:', 3); // 2 order lines + 1 order level currency segment
7789
assertSegmentExists(segments, `CUX+2:${currencies.pol1Currency}:`);
7890
assertSegmentExists(segments, `CUX+2:${currencies.pol2Currency}:`);
7991
};
@@ -83,11 +95,16 @@ const assertAddressSegments = (segments, shipToAddress) => {
8395
expect(segments.join("'")).to.include(shipToAddress.address);
8496
};
8597

86-
const assertPriceSegments = (segments) => {
87-
assertSegmentExists(segments, `PRI+AAF:${toEdiAmount(PRICE.POL1_TOTAL)}`);
88-
assertSegmentExists(segments, `PRI+AAB:${toEdiAmount(PRICE.POL1_TOTAL)}`);
89-
assertSegmentExists(segments, `PRI+AAF:${toEdiAmount(PRICE.POL2_TOTAL)}`);
90-
assertSegmentExists(segments, `PRI+AAB:${toEdiAmount(PRICE.POL2_UNIT * PRICE.POL2_QUANTITY)}`);
98+
const assertPriceSegments = (flow, segments) => {
99+
const [poLine1, poLine2] = flow.ctx().orderLines;
100+
const assertExists = (expected) => assertSegmentExists(segments, expected, { exact: true });
101+
102+
assertExists(`PRI+AAF:${toEdiAmount(+poLine1.cost.poLineEstimatedPrice)}`);
103+
assertExists(`PRI+AAB:${toEdiAmount(+poLine1.cost.poLineEstimatedPrice)}`);
104+
assertExists(`PRI+AAF:${toEdiAmount(+poLine2.cost.poLineEstimatedPrice)}`);
105+
assertExists(
106+
`PRI+AAB:${toEdiAmount(Number(poLine2.cost.listUnitPrice) * Number(poLine2.cost.quantityPhysical))}`,
107+
);
91108
};
92109

93110
const createOrderLine = ({
@@ -402,7 +419,7 @@ describe('Export Manager', () => {
402419
assertAddressSegments(segments, shipToAddress);
403420

404421
cy.log('< --- STEP 7: Check calculation price --- >');
405-
assertPriceSegments(segments);
422+
assertPriceSegments(flow, segments);
406423
});
407424
});
408425
},

0 commit comments

Comments
 (0)