|
@@ -2,6 +2,7 @@ import { AdjustmentType } from '@vendure/common/lib/generated-types';
|
|
|
import { summate } from '@vendure/common/lib/shared-utils';
|
|
import { summate } from '@vendure/common/lib/shared-utils';
|
|
|
|
|
|
|
|
import { createOrder, createRequestContext, taxCategoryStandard } from '../../testing/order-test-utils';
|
|
import { createOrder, createRequestContext, taxCategoryStandard } from '../../testing/order-test-utils';
|
|
|
|
|
+import { ShippingLine } from '../shipping-line/shipping-line.entity';
|
|
|
|
|
|
|
|
import { Order } from './order.entity';
|
|
import { Order } from './order.entity';
|
|
|
|
|
|
|
@@ -280,6 +281,57 @@ describe('Order entity methods', () => {
|
|
|
]);
|
|
]);
|
|
|
assertOrderTaxesAddsUp(order);
|
|
assertOrderTaxesAddsUp(order);
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ it('with shipping', () => {
|
|
|
|
|
+ const ctx = createRequestContext({ pricesIncludeTax: false });
|
|
|
|
|
+ const order = createOrder({
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ lines: [
|
|
|
|
|
+ {
|
|
|
|
|
+ listPrice: 300,
|
|
|
|
|
+ taxCategory: taxCategoryStandard,
|
|
|
|
|
+ quantity: 2,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ listPrice: 1000,
|
|
|
|
|
+ taxCategory: taxCategoryStandard,
|
|
|
|
|
+ quantity: 1,
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ });
|
|
|
|
|
+ order.lines[0].items.forEach(i => (i.taxLines = [{ taxRate: 5, description: 'tax a' }]));
|
|
|
|
|
+ order.lines[1].items.forEach(i => (i.taxLines = [{ taxRate: 5, description: 'tax a' }]));
|
|
|
|
|
+ order.shippingLines = [
|
|
|
|
|
+ new ShippingLine({
|
|
|
|
|
+ listPrice: 500,
|
|
|
|
|
+ listPriceIncludesTax: false,
|
|
|
|
|
+ taxLines: [
|
|
|
|
|
+ {
|
|
|
|
|
+ taxRate: 20,
|
|
|
|
|
+ description: 'shipping tax',
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ }),
|
|
|
|
|
+ ];
|
|
|
|
|
+ order.shipping = 500;
|
|
|
|
|
+ order.shippingWithTax = 600;
|
|
|
|
|
+
|
|
|
|
|
+ expect(order.taxSummary).toEqual([
|
|
|
|
|
+ {
|
|
|
|
|
+ description: 'tax a',
|
|
|
|
|
+ taxRate: 5,
|
|
|
|
|
+ taxBase: 1600,
|
|
|
|
|
+ taxTotal: 80,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ description: 'shipping tax',
|
|
|
|
|
+ taxRate: 20,
|
|
|
|
|
+ taxBase: 500,
|
|
|
|
|
+ taxTotal: 100,
|
|
|
|
|
+ },
|
|
|
|
|
+ ]);
|
|
|
|
|
+ assertOrderTaxesAddsUp(order);
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -287,5 +339,6 @@ function assertOrderTaxesAddsUp(order: Order) {
|
|
|
const summaryTaxTotal = summate(order.taxSummary, 'taxTotal');
|
|
const summaryTaxTotal = summate(order.taxSummary, 'taxTotal');
|
|
|
const lineTotal = summate(order.lines, 'proratedLinePrice');
|
|
const lineTotal = summate(order.lines, 'proratedLinePrice');
|
|
|
const lineTotalWithTax = summate(order.lines, 'proratedLinePriceWithTax');
|
|
const lineTotalWithTax = summate(order.lines, 'proratedLinePriceWithTax');
|
|
|
- expect(lineTotalWithTax - lineTotal).toBe(summaryTaxTotal);
|
|
|
|
|
|
|
+ const shippingTax = (order.shippingWithTax ?? 0) - (order.shipping ?? 0);
|
|
|
|
|
+ expect(lineTotalWithTax - lineTotal + shippingTax).toBe(summaryTaxTotal);
|
|
|
}
|
|
}
|