diff --git a/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts b/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts index e9b3d89c9a1..9f70d2607ee 100644 --- a/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts +++ b/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts @@ -1,4 +1,4 @@ -import {Order, BillingOrderAddress, ShippingOrderAddress, OrderLineItem, OrderShippingLine, OrderFeeLine} from "../../models"; +import {Order, BillingOrderAddress, ShippingOrderAddress, OrderLineItem, OrderShippingLine, OrderFeeLine, OrderTaxRate} from "../../models"; import {createBillingAddressTransformer, createOrderTransformer, createShippingAddressTransformer} from "../../repositories/rest/orders/transformer"; const jsonPayloadFull = JSON.stringify({ @@ -316,6 +316,19 @@ describe( 'OrderTransformer', () => { expect(order.lineItems[0].price).toStrictEqual(50); expect(order.lineItems[0].parentName).toStrictEqual(null); + // Tax Lines + expect(order.taxLines).toHaveLength(1); + expect(order.taxLines[0]).toBeInstanceOf(OrderTaxRate); + //expect(order.taxLines[0].id).toStrictEqual(6139); + expect(order.taxLines[0].rateCode).toStrictEqual('US-TAX-1'); + expect(order.taxLines[0].rateId).toStrictEqual(1); + expect(order.taxLines[0].label).toStrictEqual('Tax'); + //expect(order.taxLines[0].compound).toStrictEqual(false); + expect(order.taxLines[0].taxTotal).toStrictEqual('6.00'); + expect(order.taxLines[0].shippingTaxTotal).toStrictEqual('0.00'); + expect(order.taxLines[0].ratePercent).toStrictEqual(12); + //expect(order.taxLines[0].metaData).toStrictEqual([]); + // Shipping Lines expect(order.shippingLines).toHaveLength(1); expect(order.shippingLines[0]).toBeInstanceOf(OrderShippingLine); @@ -336,18 +349,7 @@ describe( 'OrderTransformer', () => { expect(order.feeLines[0].total).toStrictEqual('5.00'); //expect(order.feeLines[0].totalTaxes).toStrictEqual('5.00'); //expect(order.feeLines[0].totalTax).toStrictEqual('10.00'); - expect(order.feeLines[0].taxes).toStrictEqual([ { id: 1, total: '6', subtotal: '6.6' } ]); + //expect(order.feeLines[0].taxes).toStrictEqual([ { id: 1, total: '6', subtotal: '6.6' } ]); expect(order.feeLines[0].metaData).toStrictEqual([]); - - // Tax Lines - //expect(order.lineItems[0].rateCode).toStrictEqual('US-TAX-1'); - //expect(order.lineItems[0].rateId).toStrictEqual(1); - //expect(order.lineItems[0].label).toStrictEqual('Tax'); - //expect(order.lineItems[0].compound).toStrictEqual(false); - //expect(order.lineItems[0].taxTotal).toStrictEqual('6.00'); - expect(order.lineItems[0].totalTax).toStrictEqual('6.00'); - //expect(order.lineItems[0].shippingTaxTotal).toStrictEqual('0.00'); - //expect(order.lineItems[0].ratePercent).toStrictEqual(12); - expect(order.lineItems[0].metaData).toStrictEqual([]); } ); } ); diff --git a/packages/js/api/src/models/orders/shared/classes.ts b/packages/js/api/src/models/orders/shared/classes.ts index 7c34435dc8e..7f80d40dad6 100644 --- a/packages/js/api/src/models/orders/shared/classes.ts +++ b/packages/js/api/src/models/orders/shared/classes.ts @@ -313,6 +313,16 @@ export class OrderTaxRate extends Model { * @type {number} */ public readonly ratePercent: number = 0; + + /** + * Creates a new order instance with the given properties + * + * @param {Object} properties The properties to set in the object. + */ + public constructor( properties?: Partial< OrderTaxRate > ) { + super(); + Object.assign( this, properties ); + } } /** diff --git a/packages/js/api/src/repositories/rest/orders/transformer.ts b/packages/js/api/src/repositories/rest/orders/transformer.ts index 56d86ec3f96..c87c32b8e34 100644 --- a/packages/js/api/src/repositories/rest/orders/transformer.ts +++ b/packages/js/api/src/repositories/rest/orders/transformer.ts @@ -175,6 +175,7 @@ function createOrderTaxRateTransformer(): ModelTransformer< OrderTaxRate > { new KeyChangeTransformation< OrderTaxRate >( { rateCode: 'rate_code', + ratePercent: 'rate_percent', rateId: 'rate_id', compoundRate: 'compound', taxTotal: 'tax_total',