@adtrackify/at-service-common 4.0.35 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -144,17 +144,17 @@ describe('CostCalculatorService', () => {
144
144
  const liCosts = initLineItemCosts();
145
145
  expect(cost_calculator_service_1.CostCalculatorService.calculateHandlingCost(configs, lineItems, liCosts, 'USD', emptyRatesMap)).toBe(0);
146
146
  });
147
- it('should apply flat fee per line item (not multiplied by quantity)', () => {
147
+ it('should apply the fee per unit, multiplied by quantity', () => {
148
148
  const configs = createConfigs({
149
149
  globalProductOverride: { globalHandlingFee: 2, currency: 'USD' },
150
150
  });
151
151
  const lineItems = [createLineItem({ lineItemId: '1', quantity: 3 })];
152
152
  const liCosts = initLineItemCosts();
153
153
  const result = cost_calculator_service_1.CostCalculatorService.calculateHandlingCost(configs, lineItems, liCosts, 'USD', emptyRatesMap);
154
- expect(result).toBe(2);
155
- expect(liCosts['1'].totalLineItemHandlingCost).toBe(2);
154
+ expect(result).toBe(6);
155
+ expect(liCosts['1'].totalLineItemHandlingCost).toBe(6);
156
156
  });
157
- it('should sum across multiple line items', () => {
157
+ it('should sum across multiple line items using each quantity', () => {
158
158
  const configs = createConfigs({
159
159
  globalProductOverride: { globalHandlingFee: 2, currency: 'USD' },
160
160
  });
@@ -164,9 +164,21 @@ describe('CostCalculatorService', () => {
164
164
  ];
165
165
  const liCosts = initLineItemCosts(['1', '2']);
166
166
  const result = cost_calculator_service_1.CostCalculatorService.calculateHandlingCost(configs, lineItems, liCosts, 'USD', emptyRatesMap);
167
- expect(result).toBe(4);
168
- expect(liCosts['1'].totalLineItemHandlingCost).toBe(2);
169
- expect(liCosts['2'].totalLineItemHandlingCost).toBe(2);
167
+ expect(result).toBe(10);
168
+ expect(liCosts['1'].totalLineItemHandlingCost).toBe(4);
169
+ expect(liCosts['2'].totalLineItemHandlingCost).toBe(6);
170
+ });
171
+ it('should match the variant-level fee when both are the same amount', () => {
172
+ const configs = createConfigs({
173
+ globalProductOverride: { globalHandlingFee: 2, currency: 'USD' },
174
+ });
175
+ const quantity = 4;
176
+ const globalCosts = initLineItemCosts();
177
+ const globalTotal = cost_calculator_service_1.CostCalculatorService.calculateHandlingCost(configs, [createLineItem({ lineItemId: '1', quantity })], globalCosts, 'USD', emptyRatesMap);
178
+ const variantTotal = cost_calculator_service_1.CostCalculatorService.calculateLineItemHandlingCosts([
179
+ createLineItem({ lineItemId: '1', quantity, variantHandlingFee: 2 }),
180
+ ]);
181
+ expect(globalTotal).toBe(variantTotal['1']);
170
182
  });
171
183
  it('should convert currency when config currency differs from order currency', () => {
172
184
  const configs = createConfigs({