From c6ac637fa6ca714ac87172a2c1d2ce3726cb8d4a Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Mon, 17 Jan 2022 09:37:45 -0300 Subject: [PATCH 01/19] Bump ts-jest to same version of jest ^27 --- packages/js/api/package.json | 2 +- pnpm-lock.yaml | 37 ++++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/js/api/package.json b/packages/js/api/package.json index eded9fafdd6..cb61042dbd2 100644 --- a/packages/js/api/package.json +++ b/packages/js/api/package.json @@ -48,7 +48,7 @@ "axios-mock-adapter": "^1.20.0", "eslint": "^8.2.0", "jest": "^27.3.1", - "ts-jest": "25.5.0", + "ts-jest": "^27", "typescript": "^4.4.4" }, "publishConfig": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 30a2a4bfb6b..41b3c83c30d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -66,7 +66,7 @@ importers: eslint: ^8.2.0 jest: ^27.3.1 oauth-1.0a: 2.2.6 - ts-jest: 25.5.0 + ts-jest: ^27 typescript: ^4.4.4 dependencies: axios: 0.24.0 @@ -81,7 +81,7 @@ importers: axios-mock-adapter: 1.20.0_axios@0.24.0 eslint: 8.2.0 jest: 27.3.1 - ts-jest: 25.5.0_jest@27.3.1+typescript@4.4.4 + ts-jest: 27.1.2_f41fed5da8d4caa8e32db7d6695d4125 typescript: 4.4.4 packages/js/api-core-tests: @@ -19364,26 +19364,39 @@ packages: resolution: {integrity: sha512-rvuRbTarPXmMb79SmzEp8aqXNKcK+y0XaB298IXueQ8I2PsrATcPBCSPyK/dDNa2iWOhKlfNnOjdAOTBU/nkFA==} dev: true - /ts-jest/25.5.0_jest@27.3.1+typescript@4.4.4: - resolution: {integrity: sha512-govrjbOk1UEzcJ5cX5k8X8IUtFuP3lp3mrF3ZuKtCdAOQzdeCM7qualhb/U8s8SWFwEDutOqfF5PLkJ+oaYD4w==} - engines: {node: '>= 8'} + /ts-jest/27.1.2_f41fed5da8d4caa8e32db7d6695d4125: + resolution: {integrity: sha512-eSOiJOWq6Hhs6Khzk5wKC5sgWIXgXqOCiIl1+3lfnearu58Hj4QpE5tUhQcA3xtZrELbcvAGCsd6HB8OsaVaTA==} + engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} hasBin: true peerDependencies: - jest: '>=25 <26' - typescript: '>=3.4 <4.0' + '@babel/core': '>=7.0.0-beta.0 <8' + '@types/jest': ^27.0.0 + babel-jest: '>=27.0.0 <28' + esbuild: ~0.14.0 + jest: ^27.0.0 + typescript: '>=3.8 <5.0' + peerDependenciesMeta: + '@babel/core': + optional: true + '@types/jest': + optional: true + babel-jest: + optional: true + esbuild: + optional: true dependencies: + '@babel/core': 7.12.9 + '@types/jest': 27.0.2 bs-logger: 0.2.6 - buffer-from: 1.1.2 fast-json-stable-stringify: 2.1.0 jest: 27.3.1 + jest-util: 27.3.1 json5: 2.2.0 lodash.memoize: 4.1.2 make-error: 1.3.6 - micromatch: 4.0.4 - mkdirp: 0.5.5 - semver: 6.3.0 + semver: 7.3.5 typescript: 4.4.4 - yargs-parser: 18.1.3 + yargs-parser: 20.2.9 dev: true /ts-loader/9.2.6_typescript@4.2.4+webpack@5.64.1: From 770bd181ce9ac8a276daa3fddc9cc05961966237 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Mon, 17 Jan 2022 16:25:23 -0300 Subject: [PATCH 02/19] Split Shipping and Billing Addresses as they have different properties --- packages/js/api/src/models/orders/orders.ts | 17 +++--- .../api/src/models/orders/shared/classes.ts | 54 ++++++++++++++++--- .../js/api/src/models/orders/shared/types.ts | 10 +++- .../repositories/rest/orders/transformer.ts | 46 ++++++++++++++-- 4 files changed, 107 insertions(+), 20 deletions(-) diff --git a/packages/js/api/src/models/orders/orders.ts b/packages/js/api/src/models/orders/orders.ts index d23c4ca7611..400b4124fa9 100644 --- a/packages/js/api/src/models/orders/orders.ts +++ b/packages/js/api/src/models/orders/orders.ts @@ -9,7 +9,8 @@ import { DeletesModels, } from '../../framework'; import { - OrderAddressUpdateParams, + BillingOrderAddressUpdateParams, + ShippingOrderAddressUpdateParams, OrderCouponUpdateParams, OrderDataUpdateParams, OrderFeeUpdateParams, @@ -19,7 +20,8 @@ import { OrderTaxUpdateParams, OrderTotalUpdateParams, OrderItemMeta, - OrderAddress, + BillingOrderAddress, + ShippingOrderAddress, OrderCouponLine, OrderFeeLine, OrderLineItem, @@ -33,7 +35,8 @@ import { ObjectLinks } from '../shared-types'; /** * The parameters that orders can update. */ -type OrderUpdateParams = OrderAddressUpdateParams +type OrderUpdateParams = BillingOrderAddressUpdateParams + & ShippingOrderAddressUpdateParams & OrderCouponUpdateParams & OrderDataUpdateParams & OrderFeeUpdateParams @@ -194,16 +197,16 @@ export class Order extends OrderItemMeta { /** * The billing address. * - * @type {OrderAddress} + * @type {BillingOrderAddress} */ - public readonly billing: OrderAddress | null = null; + public readonly billing: BillingOrderAddress | null = null; /** * The shipping address. * - * @type {OrderAddress} + * @type {ShippingOrderAddress} */ - public readonly shipping: OrderAddress | null = null; + public readonly shipping: ShippingOrderAddress | null = null; /** * Name of the payment method. diff --git a/packages/js/api/src/models/orders/shared/classes.ts b/packages/js/api/src/models/orders/shared/classes.ts index 540c543d4ae..49e55f2eea4 100644 --- a/packages/js/api/src/models/orders/shared/classes.ts +++ b/packages/js/api/src/models/orders/shared/classes.ts @@ -36,7 +36,7 @@ export class OrderItemTax extends Model { /** * An order address. */ -export class OrderAddress extends Model { +export class ShippingOrderAddress extends Model { /** * The first name of the person in the address. * @@ -56,7 +56,7 @@ export class OrderAddress extends Model { * * @type {string} */ - public readonly companyName: string = ''; + public readonly company: string = ''; /** * The first address line in the address. @@ -98,21 +98,61 @@ export class OrderAddress extends Model { * * @type {string} */ - public readonly countryCode: string = ''; + public readonly country: string = ''; + /** + * Adapter to keep backward compatibility with renamed property. + * + * @type {string|null} + */ + get companyName() { + return this.company; + } + + /** + * Adapter to keep backward compatibility with renamed property. + * + * @type {string|null} + */ + get countryCode() { + return this.country; + } + + /** + * Creates a new order instance with the given properties + * + * @param {Object} properties The properties to set in the object. + */ + public constructor( properties?: Partial< ShippingOrderAddress > ) { + super(); + Object.assign( this, properties ); + } +} + +export class BillingOrderAddress extends ShippingOrderAddress { /** * The email address of the person in the address. * - * @type {string} + * @type {string|null} */ - public readonly email: string = ''; + public readonly email: undefined | string = ''; /** * The phone number of the person in the address. * - * @type {string} + * @type {string|null} */ - public readonly phone: string = ''; + public readonly phone: undefined | string = ''; + + /** + * Creates a new order instance with the given properties + * + * @param {Object} properties The properties to set in the object. + */ + public constructor( properties?: Partial< BillingOrderAddress > ) { + super(); + Object.assign( this, properties ); + } } /** diff --git a/packages/js/api/src/models/orders/shared/types.ts b/packages/js/api/src/models/orders/shared/types.ts index adeba0128c4..cb5454b755b 100644 --- a/packages/js/api/src/models/orders/shared/types.ts +++ b/packages/js/api/src/models/orders/shared/types.ts @@ -28,11 +28,17 @@ export type OrderDataUpdateParams = 'id' | 'parentId' | 'status' | 'currency' | export type OrderTotalUpdateParams = 'total' | 'totalTax'; /** - * Order address properties + * Billing address properties */ -export type OrderAddressUpdateParams = 'firstName' | 'lastName' | 'companyName' | 'address1' +export type BillingOrderAddressUpdateParams = 'firstName' | 'lastName' | 'companyName' | 'address1' | 'address2' | 'city' | 'state' | 'postCode' | 'countryCode' | 'email' | 'phone'; +/** + * Shipping address properties + */ +export type ShippingOrderAddressUpdateParams = 'firstName' | 'lastName' | 'companyName' | 'address1' + | 'address2' | 'city' | 'state' | 'postCode' | 'countryCode'; + /** * Line item properties */ diff --git a/packages/js/api/src/repositories/rest/orders/transformer.ts b/packages/js/api/src/repositories/rest/orders/transformer.ts index 5cd3c0e2b6f..5206c324609 100644 --- a/packages/js/api/src/repositories/rest/orders/transformer.ts +++ b/packages/js/api/src/repositories/rest/orders/transformer.ts @@ -8,7 +8,8 @@ import { } from '../../../framework'; import { Order, - OrderAddress, + BillingOrderAddress, + ShippingOrderAddress, OrderCouponLine, OrderFeeLine, OrderLineItem, @@ -26,7 +27,8 @@ export function createOrderTransformer(): ModelTransformer< Order > { return new ModelTransformer( [ new IgnorePropertyTransformation( [ 'date_created', 'date_modified' ] ), - new ModelTransformerTransformation( 'billing', OrderAddress, createOrderAddressTransformer() ), + new ModelTransformerTransformation( 'billing', BillingOrderAddress, createBillingAddressTransformer() ), + new ModelTransformerTransformation( 'shipping', ShippingOrderAddress, createShippingAddressTransformer() ), new ModelTransformerTransformation( 'tax_lines', OrderTaxRate, createOrderTaxRateTransformer() ), new ModelTransformerTransformation( 'refunds', OrderRefundLine, createOrderRefundLineTransformer() ), new ModelTransformerTransformation( 'coupon_lines', OrderCouponLine, createOrdeCouponLineTransformer() ), @@ -78,7 +80,7 @@ export function createOrderTransformer(): ModelTransformer< Order > { * * @return {ModelTransformer} The created transformer. */ -export function createOrderAddressTransformer(): ModelTransformer< OrderAddress > { +export function createBillingAddressTransformer(): ModelTransformer< BillingOrderAddress > { return new ModelTransformer( [ new PropertyTypeTransformation( @@ -92,9 +94,45 @@ export function createOrderAddressTransformer(): ModelTransformer< OrderAddress state: PropertyType.String, postCode: PropertyType.String, country: PropertyType.String, + phone: PropertyType.String, + email: PropertyType.String, }, ), - new KeyChangeTransformation< OrderAddress >( + new KeyChangeTransformation< BillingOrderAddress >( + { + firstName: 'first_name', + lastName: 'last_name', + address1: 'address_1', + address2: 'address_2', + postCode: 'postcode', + }, + ), + ], + ); +} + +/** + * Creates a transformer for an order address object. + * + * @return {ModelTransformer} The created transformer. + */ +export function createShippingAddressTransformer(): ModelTransformer< ShippingOrderAddress > { + return new ModelTransformer( + [ + new PropertyTypeTransformation( + { + firstName: PropertyType.String, + lastName: PropertyType.String, + company: PropertyType.String, + address1: PropertyType.String, + address2: PropertyType.String, + city: PropertyType.String, + state: PropertyType.String, + postCode: PropertyType.String, + country: PropertyType.String + }, + ), + new KeyChangeTransformation< ShippingOrderAddress >( { firstName: 'first_name', lastName: 'last_name', From b75f8adbb5b8b20c0f7afccc1143767c1e7c5296 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Mon, 17 Jan 2022 16:25:49 -0300 Subject: [PATCH 03/19] Test that a JSON payload is transformed as expected (WIP) --- .../__tests__/payload-transformer.spec.ts | 270 ++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 packages/js/api/src/framework/__tests__/payload-transformer.spec.ts diff --git a/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts b/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts new file mode 100644 index 00000000000..748938be8b6 --- /dev/null +++ b/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts @@ -0,0 +1,270 @@ +import {Order, BillingOrderAddress, ShippingOrderAddress} from "../../models"; +import {createBillingAddressTransformer, createOrderTransformer, createShippingAddressTransformer} from "../../repositories/rest/orders/transformer"; + +const jsonPayloadFull = JSON.stringify({ + id: 1218, + parent_id: 0, + status: 'pending', + currency: 'USD', + version: '6.1.0', + prices_include_tax: false, + date_created: '2021-12-01T05:43:38', + date_modified: '2021-12-01T07:31:05', + discount_total: '5.00', + discount_tax: '0.60', + shipping_total: '0.00', + shipping_tax: '0.00', + cart_tax: '6.00', + total: '56.00', + total_tax: '6.00', + customer_id: 0, + order_key: 'wc_order_GFHWVmAiamh0B', + billing: { + first_name: 'Billing First Name', + last_name: 'Billing Last Name', + company: 'Billing Company', + address_1: 'Billing Address 1', + address_2: 'Billing Address 2', + city: 'Billing City', + state: 'Billing State', + postcode: 'Billing Postcode', + country: 'Billing Country', + email: 'Billing Email', + phone: 'Billing Phone' + }, + shipping: { + first_name: 'Shipping First Name', + last_name: 'Shipping Last Name', + company: 'Shipping Company', + address_1: 'Shipping Address 1', + address_2: 'Shipping Address 2', + city: 'Shipping City', + state: 'Shipping State', + postcode: 'Shipping Postcode', + country: 'Shipping Country', + phone: 'Shipping Phone' + }, + payment_method: 'Foo Payment Method', + payment_method_title: 'Foo Payment Method Title', + transaction_id: 'Foo Transaction ID', + customer_ip_address: 'Foo Customer IP Address', + customer_user_agent: 'Foo Customer User Agent', + created_via: 'admin', + customer_note: 'Foo Customer Note', + date_completed: 'Foo Date Completed', + date_paid: 'Foo Date Paid', + cart_hash: 'Foo Cart Hash', + number: '1218', + meta_data: [], + line_items: [ + { + id: 6137, + name: 'Belt', + product_id: 16, + variation_id: 0, + quantity: 1, + tax_class: '', + subtotal: '55.00', + subtotal_tax: '6.60', + total: '50.00', + total_tax: '6.00', + taxes: [ { id: 1, total: '6', subtotal: '6.6' } ], + meta_data: [], + sku: 'woo-belt', + price: 50, + parent_name: null + } + ], + tax_lines: [ + { + id: 6139, + rate_code: 'US-TAX-1', + rate_id: 1, + label: 'Tax', + compound: false, + tax_total: '6.00', + shipping_tax_total: '0.00', + rate_percent: 12, + meta_data: [] + } + ], + shipping_lines: [], + fee_lines: [], + coupon_lines: [ + { + id: 6138, + code: 'save5', + discount: '5', + discount_tax: '0.6', + meta_data: [ + { + id: 57112, + key: 'coupon_data', + value: { + id: 171, + code: 'save5', + amount: '5', + date_created: { + date: '2021-05-19 04:28:31.000000', + timezone_type: 3, + timezone: 'Pacific/Auckland' + }, + date_modified: { + date: '2021-05-19 04:28:31.000000', + timezone_type: 3, + timezone: 'Pacific/Auckland' + }, + date_expires: null, + discount_type: 'fixed_cart', + description: '', + usage_count: 3, + individual_use: false, + product_ids: [], + excluded_product_ids: [], + usage_limit: 0, + usage_limit_per_user: 0, + limit_usage_to_x_items: null, + free_shipping: false, + product_categories: [], + excluded_product_categories: [], + exclude_sale_items: false, + minimum_amount: '', + maximum_amount: '', + email_restrictions: [], + virtual: false, + meta_data: [] + }, + display_key: 'coupon_data', + display_value: { + id: 171, + code: 'save5', + amount: '5', + date_created: { + date: '2021-05-19 04:28:31.000000', + timezone_type: 3, + timezone: 'Pacific/Auckland' + }, + date_modified: { + date: '2021-05-19 04:28:31.000000', + timezone_type: 3, + timezone: 'Pacific/Auckland' + }, + date_expires: null, + discount_type: 'fixed_cart', + description: '', + usage_count: 3, + individual_use: false, + product_ids: [], + excluded_product_ids: [], + usage_limit: 0, + usage_limit_per_user: 0, + limit_usage_to_x_items: null, + free_shipping: false, + product_categories: [], + excluded_product_categories: [], + exclude_sale_items: false, + minimum_amount: '', + maximum_amount: '', + email_restrictions: [], + virtual: false, + meta_data: [] + } + } + ] + } + ], + refunds: [], + date_created_gmt: '2021-11-30T16:43:38', + date_modified_gmt: '2021-11-30T18:31:05', + date_completed_gmt: null, + date_paid_gmt: null, + currency_symbol: '$', + _links: { + self: [ + { + href: 'http://local.wordpress.test/wp-json/wc/v3/orders/1218' + } + ], + collection: [ + { + href: 'http://local.wordpress.test/wp-json/wc/v3/orders' + } + ] + } +}); + +describe( 'OrderTransformer', () => { + it( 'should transform an order JSON', () => { + const order = createOrderTransformer().toModel( Order, JSON.parse(jsonPayloadFull) ); + const billing = createBillingAddressTransformer().toModel(BillingOrderAddress, JSON.parse(jsonPayloadFull).billing); + const shipping = createShippingAddressTransformer().toModel(ShippingOrderAddress, JSON.parse(jsonPayloadFull).shipping); + + // Order + expect( order ).toBeInstanceOf( Order ); + expect( order.id ).toStrictEqual(1218); + expect( order.parentId ).toStrictEqual(0); + expect( order.status ).toStrictEqual('pending'); + expect( order.currency ).toStrictEqual('USD'); + expect( order.version ).toStrictEqual('6.1.0'); + expect( order.pricesIncludeTax ).toStrictEqual(false); + //expect( model.dateCreated ).toStrictEqual('2021-12-01T05:43:38'); + //expect( model.dateModified ).toStrictEqual('2021-12-01T07:31:05'); + expect( order.discountTotal ).toStrictEqual('5.00'); + expect( order.discountTax ).toStrictEqual('0.60'); + expect( order.shippingTotal ).toStrictEqual('0.00'); + expect( order.shippingTax ).toStrictEqual('0.00'); + expect( order.cartTax ).toStrictEqual('6.00'); + expect( order.total ).toStrictEqual('56.00'); + expect( order.totalTax ).toStrictEqual('6.00'); + expect( order.customerId ).toStrictEqual(0); + //expect( model.orderKey ).toStrictEqual('wc_order_GFHWVmAiamh0B'); + expect( order.billing ).toStrictEqual(billing); + expect( order.shipping ).toStrictEqual(shipping); + expect( order.paymentMethod ).toStrictEqual('Foo Payment Method'); + //expect( order.paymentMethodTitle ).toStrictEqual('Foo Payment Method Title'); + expect( order.transactionId ).toStrictEqual('Foo Transaction ID'); + //expect( order.customerIpAddress ).toStrictEqual('Foo Customer IP Address'); + //expect( order.customerUserAgent ).toStrictEqual('Foo Customer User Agent'); + //expect( order.createdVia ).toStrictEqual('admin'); + expect( order.customerNote ).toStrictEqual('Foo Customer Note'); + //expect( order.dateCompleted ).toStrictEqual('Foo Date Completed'); + //expect( order.datePaid ).toStrictEqual('Foo Date Paid'); + //expect( order.cartHash ).toStrictEqual('Foo Cart Hash'); + //expect( order.orderNumber ).toStrictEqual('1218'); + + // Billing + expect(billing.firstName).toStrictEqual('Billing First Name'); + expect(billing.lastName).toStrictEqual('Billing Last Name'); + expect(billing.company).toStrictEqual('Billing Company'); + expect(billing.address1).toStrictEqual('Billing Address 1'); + expect(billing.address2).toStrictEqual('Billing Address 2'); + expect(billing.city).toStrictEqual('Billing City'); + expect(billing.state).toStrictEqual('Billing State'); + expect(billing.postCode).toStrictEqual('Billing Postcode'); + expect(billing.country).toStrictEqual('Billing Country'); + expect(billing.email).toStrictEqual('Billing Email'); + expect(billing.phone).toStrictEqual('Billing Phone'); + expect( createBillingAddressTransformer().fromModel(billing) ).toStrictEqual(JSON.parse(jsonPayloadFull).billing); + + // Shipping + expect(shipping.firstName).toStrictEqual('Shipping First Name'); + expect(shipping.lastName).toStrictEqual('Shipping Last Name'); + expect(shipping.company).toStrictEqual('Shipping Company'); + expect(shipping.address1).toStrictEqual('Shipping Address 1'); + expect(shipping.address2).toStrictEqual('Shipping Address 2'); + expect(shipping.city).toStrictEqual('Shipping City'); + expect(shipping.state).toStrictEqual('Shipping State'); + expect(shipping.postCode).toStrictEqual('Shipping Postcode'); + expect(shipping.country).toStrictEqual('Shipping Country'); + + /* + * Shipping Address does not have e-mail or phone fields according to WooCommerce API + * @link https://woocommerce.github.io/woocommerce-rest-api-docs/#order-shipping-properties + */ + //expect(shipping.email).toStrictEqual('Shipping Email'); + //expect(shipping.phone).toStrictEqual('Shipping Phone'); + expect( createShippingAddressTransformer().fromModel(shipping) ).toStrictEqual(JSON.parse(jsonPayloadFull).shipping); + + + } ); +} ); From 6a6ceaa3f4ab80b3f54091aae6408c9354e2642d Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Tue, 18 Jan 2022 19:35:38 -0300 Subject: [PATCH 04/19] Add more keys to be converted --- packages/js/api/src/repositories/rest/orders/transformer.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/js/api/src/repositories/rest/orders/transformer.ts b/packages/js/api/src/repositories/rest/orders/transformer.ts index 5206c324609..88b1f099250 100644 --- a/packages/js/api/src/repositories/rest/orders/transformer.ts +++ b/packages/js/api/src/repositories/rest/orders/transformer.ts @@ -69,6 +69,11 @@ export function createOrderTransformer(): ModelTransformer< Order > { paymentMethod: 'payment_method', transactionId: 'transaction_id', setPaid: 'set_paid', + lineItems: 'line_items', + taxLines: 'tax_lines', + shippingLines: 'shipping_lines', + feeLines: 'fee_lines', + couponLines: 'coupon_lines', }, ), ], @@ -213,6 +218,7 @@ function createOrdeCouponLineTransformer(): ModelTransformer< OrderCouponLine > new KeyChangeTransformation< OrderCouponLine >( { discountTax: 'discount_tax', + metaData: 'meta_data' }, ), ], From 3c8c6e7718862867cabd41ccd024e0ea157bad88 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Tue, 18 Jan 2022 19:35:56 -0300 Subject: [PATCH 05/19] Rename properties according to WooCommerce API --- packages/js/api/src/models/orders/shared/types.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/js/api/src/models/orders/shared/types.ts b/packages/js/api/src/models/orders/shared/types.ts index cb5454b755b..86f15051d13 100644 --- a/packages/js/api/src/models/orders/shared/types.ts +++ b/packages/js/api/src/models/orders/shared/types.ts @@ -30,14 +30,14 @@ export type OrderTotalUpdateParams = 'total' | 'totalTax'; /** * Billing address properties */ -export type BillingOrderAddressUpdateParams = 'firstName' | 'lastName' | 'companyName' | 'address1' - | 'address2' | 'city' | 'state' | 'postCode' | 'countryCode' | 'email' | 'phone'; +export type BillingOrderAddressUpdateParams = 'firstName' | 'lastName' | 'company' | 'address1' + | 'address2' | 'city' | 'state' | 'postCode' | 'country' | 'email' | 'phone'; /** * Shipping address properties */ -export type ShippingOrderAddressUpdateParams = 'firstName' | 'lastName' | 'companyName' | 'address1' - | 'address2' | 'city' | 'state' | 'postCode' | 'countryCode'; +export type ShippingOrderAddressUpdateParams = 'firstName' | 'lastName' | 'company' | 'address1' + | 'address2' | 'city' | 'state' | 'postCode' | 'country'; /** * Line item properties From 46af82a842d3b4894d1823b75cb048f1fc761603 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Tue, 18 Jan 2022 19:36:06 -0300 Subject: [PATCH 06/19] Make OrderLineItem hydratable --- packages/js/api/src/models/orders/shared/classes.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/js/api/src/models/orders/shared/classes.ts b/packages/js/api/src/models/orders/shared/classes.ts index 49e55f2eea4..83f4dabc7b3 100644 --- a/packages/js/api/src/models/orders/shared/classes.ts +++ b/packages/js/api/src/models/orders/shared/classes.ts @@ -249,6 +249,16 @@ export class OrderLineItem extends OrderItemMeta { * @type {string|null} */ public readonly parentName: string | null = null; + + /** + * Creates a new order instance with the given properties + * + * @param {Object} properties The properties to set in the object. + */ + public constructor( properties?: Partial< OrderLineItem > ) { + super(); + Object.assign( this, properties ); + } } /** From 2120c08eb067f788d92300a34db50f1449c98104 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Tue, 18 Jan 2022 19:36:18 -0300 Subject: [PATCH 07/19] Tests WIP --- .../__tests__/payload-transformer.spec.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 748938be8b6..c7772ea5226 100644 --- a/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts +++ b/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts @@ -55,7 +55,13 @@ const jsonPayloadFull = JSON.stringify({ date_paid: 'Foo Date Paid', cart_hash: 'Foo Cart Hash', number: '1218', - meta_data: [], + meta_data: [ + { + id: 123, + key: "Foo Metadata Key 1", + value: "Foo Metadata Value 1" + } + ], line_items: [ { id: 6137, @@ -265,6 +271,14 @@ describe( 'OrderTransformer', () => { //expect(shipping.phone).toStrictEqual('Shipping Phone'); expect( createShippingAddressTransformer().fromModel(shipping) ).toStrictEqual(JSON.parse(jsonPayloadFull).shipping); + // Metadata + //expect(order.metaData).toHaveLength(1); + //expect(order.metaData[0]['id']).toStrictEqual(123); + //expect(order.metaData[0]['key']).toStrictEqual('Foo Metadata Key 1'); + //expect(order.metaData[0]['value']).toStrictEqual('Foo Metadata Value 1'); + // Line Items + console.log(order.lineItems); + expect(order.lineItems).toHaveLength(1); } ); } ); From 6489025273cb704dbd7b297b3908dc70a1804ddc Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Tue, 18 Jan 2022 19:36:38 -0300 Subject: [PATCH 08/19] Hydrate from snake_case or camelCase, depending on applied transformers --- .../model-transformer-transformation.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/js/api/src/framework/transformations/model-transformer-transformation.ts b/packages/js/api/src/framework/transformations/model-transformer-transformation.ts index ba4b5415f74..f5b53085987 100644 --- a/packages/js/api/src/framework/transformations/model-transformer-transformation.ts +++ b/packages/js/api/src/framework/transformations/model-transformer-transformation.ts @@ -74,12 +74,27 @@ export class ModelTransformerTransformation< T extends Model > implements ModelT * @return {*} The transformed properties. */ public toModel( properties: any ): any { - const val = properties[ this.property ]; + let propertyName = this.property; + let val = properties[ propertyName ]; + + if ( ! val ) { + /* + * Properties are defined in snake_case format, but the properties in the models are camelCase. + * Due to how the hydration of the model works, using TypeScript's Partial, the properties object + * might have been transformed from snake_case to camelCase already, so we try to convert + * the property name to camelCase before giving up. + */ + propertyName = propertyName.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, function (_match, chr) { + return chr.toUpperCase(); + }); + val = properties[ propertyName ]; + } + if ( val ) { if ( Array.isArray( val ) ) { - properties[ this.property ] = val.map( ( v ) => this.transformer.toModel( this.modelClass, v ) ); + properties[ propertyName ] = val.map( ( v ) => this.transformer.toModel( this.modelClass, v ) ); } else { - properties[ this.property ] = this.transformer.toModel( this.modelClass, val ); + properties[ propertyName ] = this.transformer.toModel( this.modelClass, val ); } } From f23587cde6c6be61fd6ad33a531aabf782b54e2a Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 19 Jan 2022 13:11:59 -0300 Subject: [PATCH 09/19] Add tests and partially fix line_items, fee_lines, shipping_lines --- .../__tests__/payload-transformer.spec.ts | 83 +++++++++++++++++-- .../api/src/models/orders/shared/classes.ts | 26 +++++- .../repositories/rest/orders/transformer.ts | 7 +- 3 files changed, 104 insertions(+), 12 deletions(-) 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 c7772ea5226..e9b3d89c9a1 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} from "../../models"; +import {Order, BillingOrderAddress, ShippingOrderAddress, OrderLineItem, OrderShippingLine, OrderFeeLine} from "../../models"; import {createBillingAddressTransformer, createOrderTransformer, createShippingAddressTransformer} from "../../repositories/rest/orders/transformer"; const jsonPayloadFull = JSON.stringify({ @@ -94,8 +94,28 @@ const jsonPayloadFull = JSON.stringify({ meta_data: [] } ], - shipping_lines: [], - fee_lines: [], + shipping_lines: [ + { + id: 123, + method_title: 'Foo Method Title', + method_id: 456, + total: '5.00', + total_taxes: '10.00', + taxes: [ { id: 1, total: '6', subtotal: '6.6' } ], + meta_data: [] + } + ], + fee_lines: [ + { + id: 123, + name: 'Foo Name', + tax_class: 456, + total: '5.00', + total_taxes: '10.00', + taxes: [ { id: 1, total: '6', subtotal: '6.6' } ], + meta_data: [] + } + ], coupon_lines: [ { id: 6138, @@ -272,13 +292,62 @@ describe( 'OrderTransformer', () => { expect( createShippingAddressTransformer().fromModel(shipping) ).toStrictEqual(JSON.parse(jsonPayloadFull).shipping); // Metadata - //expect(order.metaData).toHaveLength(1); + expect(order.metaData).toHaveLength(1); //expect(order.metaData[0]['id']).toStrictEqual(123); - //expect(order.metaData[0]['key']).toStrictEqual('Foo Metadata Key 1'); - //expect(order.metaData[0]['value']).toStrictEqual('Foo Metadata Value 1'); + expect(order.metaData[0]['key']).toStrictEqual('Foo Metadata Key 1'); + expect(order.metaData[0]['value']).toStrictEqual('Foo Metadata Value 1'); // Line Items - console.log(order.lineItems); expect(order.lineItems).toHaveLength(1); + expect(order.lineItems[0]).toBeInstanceOf(OrderLineItem); + expect(order.lineItems[0].id).toStrictEqual(6137); + expect(order.lineItems[0].name).toStrictEqual('Belt'); + expect(order.lineItems[0].productId).toStrictEqual(16); + expect(order.lineItems[0].variationId).toStrictEqual(0); + expect(order.lineItems[0].quantity).toStrictEqual(1); + expect(order.lineItems[0].taxClass).toStrictEqual(''); + expect(order.lineItems[0].subtotal).toStrictEqual('55.00'); + expect(order.lineItems[0].subtotalTax).toStrictEqual('6.60'); + expect(order.lineItems[0].total).toStrictEqual('50.00'); + expect(order.lineItems[0].totalTax).toStrictEqual('6.00'); + //expect(order.lineItems[0].taxes).toStrictEqual([ { id: 1, total: '6', subtotal: '6.6' } ]); + expect(order.lineItems[0].metaData).toStrictEqual([]); + expect(order.lineItems[0].sku).toStrictEqual('woo-belt'); + expect(order.lineItems[0].price).toStrictEqual(50); + expect(order.lineItems[0].parentName).toStrictEqual(null); + + // Shipping Lines + expect(order.shippingLines).toHaveLength(1); + expect(order.shippingLines[0]).toBeInstanceOf(OrderShippingLine); + //expect(order.shippingLines[0].id).toStrictEqual(123); + expect(order.shippingLines[0].methodTitle).toStrictEqual('Foo Method Title'); + expect(order.shippingLines[0].methodId).toStrictEqual(456); + expect(order.shippingLines[0].total).toStrictEqual('5.00'); + //expect(order.shippingLines[0].totalTaxes).toStrictEqual('5.00'); + //expect(order.shippingLines[0].totalTax).toStrictEqual('10.00'); + //expect(order.shippingLines[0].taxes).toStrictEqual([ { id: 1, total: '6', subtotal: '6.6' } ]); + expect(order.shippingLines[0].metaData).toStrictEqual([]); + + // Fee Lines + expect(order.feeLines).toHaveLength(1); + expect(order.feeLines[0]).toBeInstanceOf(OrderFeeLine); + //expect(order.feeLines[0].id).toStrictEqual(123); + expect(order.feeLines[0].name).toStrictEqual('Foo Name'); + 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].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 83f4dabc7b3..7c34435dc8e 100644 --- a/packages/js/api/src/models/orders/shared/classes.ts +++ b/packages/js/api/src/models/orders/shared/classes.ts @@ -1,5 +1,5 @@ import { MetaData } from '../../shared-types'; -import { Model } from '../../model'; +import {Model, ModelID} from '../../model'; import { TaxStatus } from './types'; /** @@ -329,9 +329,9 @@ export class OrderShippingLine extends OrderItemMeta { /** * The shipping method id. * - * @type {string} + * @type {string|number} */ - public readonly methodId: string = ''; + public readonly methodId: ModelID | undefined; /** * The shipping method instance id. @@ -360,6 +360,16 @@ export class OrderShippingLine extends OrderItemMeta { * @type {ReadonlyArray.} */ public readonly taxes: OrderItemTax[] = []; + + /** + * Creates a new order instance with the given properties + * + * @param {Object} properties The properties to set in the object. + */ + public constructor( properties?: Partial< OrderShippingLine > ) { + super(); + Object.assign( this, properties ); + } } /** @@ -414,6 +424,16 @@ export class OrderFeeLine extends OrderItemMeta { * @type {ReadonlyArray.} */ public readonly taxes: OrderItemTax[] = []; + + /** + * Creates a new order instance with the given properties + * + * @param {Object} properties The properties to set in the object. + */ + public constructor( properties?: Partial< OrderFeeLine > ) { + 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 88b1f099250..56d86ec3f96 100644 --- a/packages/js/api/src/repositories/rest/orders/transformer.ts +++ b/packages/js/api/src/repositories/rest/orders/transformer.ts @@ -15,8 +15,9 @@ import { OrderLineItem, OrderRefundLine, OrderShippingLine, - OrderTaxRate, + OrderTaxRate, MetaData, } from '../../../models'; +import {createMetaDataTransformer} from "../shared"; /** * Creates a transformer for an order object. @@ -35,6 +36,7 @@ export function createOrderTransformer(): ModelTransformer< Order > { new ModelTransformerTransformation( 'fee_lines', OrderFeeLine, createOrderFeeLineTransformer() ), new ModelTransformerTransformation( 'line_items', OrderLineItem, createOrderLineItemTransformer() ), new ModelTransformerTransformation( 'shipping_lines', OrderShippingLine, createOrderShippingItemTransformer() ), + new ModelTransformerTransformation( 'meta_data', MetaData, createMetaDataTransformer() ), new PropertyTypeTransformation( { @@ -74,6 +76,7 @@ export function createOrderTransformer(): ModelTransformer< Order > { shippingLines: 'shipping_lines', feeLines: 'fee_lines', couponLines: 'coupon_lines', + metaData: 'meta_data', }, ), ], @@ -304,7 +307,7 @@ function createOrderShippingItemTransformer(): ModelTransformer< OrderShippingLi new PropertyTypeTransformation( { methodTitle: PropertyType.String, - methodId: PropertyType.String, + methodId: PropertyType.Integer, total: PropertyType.String, totalTax: PropertyType.String, }, From 5ea6f671d3aae864f47918ed4fbd0f89094b245d Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 19 Jan 2022 13:16:45 -0300 Subject: [PATCH 10/19] Add tests and partial fix of tax_lines --- .../__tests__/payload-transformer.spec.ts | 28 ++++++++++--------- .../api/src/models/orders/shared/classes.ts | 10 +++++++ .../repositories/rest/orders/transformer.ts | 1 + 3 files changed, 26 insertions(+), 13 deletions(-) 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', From 5deef1b4b2819839551c00ee0676b7827db1ad22 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 19 Jan 2022 13:28:16 -0300 Subject: [PATCH 11/19] Add tests and partial fix of coupon_lines and refunds --- .../__tests__/payload-transformer.spec.ts | 32 +++++++++++++++++-- .../api/src/models/orders/shared/classes.ts | 20 ++++++++++++ .../repositories/rest/orders/transformer.ts | 3 +- 3 files changed, 52 insertions(+), 3 deletions(-) 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 9f70d2607ee..e3c3b2e397b 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, OrderTaxRate} from "../../models"; +import {Order, BillingOrderAddress, ShippingOrderAddress, OrderLineItem, OrderShippingLine, OrderFeeLine, OrderTaxRate, OrderCouponLine, MetaData, OrderRefundLine} from "../../models"; import {createBillingAddressTransformer, createOrderTransformer, createShippingAddressTransformer} from "../../repositories/rest/orders/transformer"; const jsonPayloadFull = JSON.stringify({ @@ -199,7 +199,13 @@ const jsonPayloadFull = JSON.stringify({ ] } ], - refunds: [], + refunds: [ + { + id: 123, + reason: 'Foo Reason', + total: '5.00' + } + ], date_created_gmt: '2021-11-30T16:43:38', date_modified_gmt: '2021-11-30T18:31:05', date_completed_gmt: null, @@ -351,5 +357,27 @@ describe( 'OrderTransformer', () => { //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].metaData).toStrictEqual([]); + + // Coupon Lines + expect(order.couponLines).toHaveLength(1); + expect(order.couponLines[0]).toBeInstanceOf(OrderCouponLine); + //expect(order.couponLines[0].id).toStrictEqual(6138); + expect(order.couponLines[0].code).toStrictEqual('save5'); + expect(order.couponLines[0].discount).toStrictEqual('5'); + expect(order.couponLines[0].discountTax).toStrictEqual('0.6'); + expect(order.couponLines[0].metaData).toHaveLength(1); + expect(order.couponLines[0].metaData[0]).toBeInstanceOf(MetaData); + //expect(order.couponLines[0].metaData[0].id).toStrictEqual(57112); + expect(order.couponLines[0].metaData[0].key).toStrictEqual('coupon_data'); + expect(order.couponLines[0].metaData[0].value).toStrictEqual( JSON.parse(jsonPayloadFull).coupon_lines[0].meta_data[0].value); + expect(order.couponLines[0].metaData[0].displayKey).toStrictEqual('coupon_data'); + expect(order.couponLines[0].metaData[0].displayValue).toStrictEqual( JSON.parse(jsonPayloadFull).coupon_lines[0].meta_data[0].display_value); + + // Refunds + expect(order.refunds).toHaveLength(1); + expect(order.refunds[0]).toBeInstanceOf(OrderRefundLine); + //expect(order.refunds[0].id).toStrictEqual(123); + expect(order.refunds[0].reason).toStrictEqual('Foo Reason'); + expect(order.refunds[0].total).toStrictEqual('5.00'); } ); } ); diff --git a/packages/js/api/src/models/orders/shared/classes.ts b/packages/js/api/src/models/orders/shared/classes.ts index 7f80d40dad6..4313e0830c5 100644 --- a/packages/js/api/src/models/orders/shared/classes.ts +++ b/packages/js/api/src/models/orders/shared/classes.ts @@ -470,6 +470,16 @@ export class OrderCouponLine extends OrderItemMeta { * @type {string} */ public readonly discountTax: string = ''; + + /** + * Creates a new order instance with the given properties + * + * @param {Object} properties The properties to set in the object. + */ + public constructor( properties?: Partial< OrderCouponLine > ) { + super(); + Object.assign( this, properties ); + } } /** @@ -489,4 +499,14 @@ export class OrderRefundLine extends Model { * @type {string} */ public readonly total: string = ''; + + /** + * Creates a new order instance with the given properties + * + * @param {Object} properties The properties to set in the object. + */ + public constructor( properties?: Partial< OrderRefundLine > ) { + 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 c87c32b8e34..78f6a327ea6 100644 --- a/packages/js/api/src/repositories/rest/orders/transformer.ts +++ b/packages/js/api/src/repositories/rest/orders/transformer.ts @@ -212,10 +212,11 @@ function createOrderRefundLineTransformer(): ModelTransformer< OrderRefundLine > function createOrdeCouponLineTransformer(): ModelTransformer< OrderCouponLine > { return new ModelTransformer( [ + new ModelTransformerTransformation( 'meta_data', MetaData, createMetaDataTransformer() ), new PropertyTypeTransformation( { code: PropertyType.String, - discount: PropertyType.Integer, + discount: PropertyType.String, discountTax: PropertyType.String, }, ), From baa2d15c2d84d9793e6fcdbc62eff870de6348d5 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 19 Jan 2022 13:47:29 -0300 Subject: [PATCH 12/19] ts-jest ^27 is incompatible with chalk <3.0.0 This breaks the build in the monorepo due to some package using chalk <3.0.0, reverting back to jest/ts-jest ^25 seems like the lesser evil --- packages/js/api/package.json | 4 +- pnpm-lock.yaml | 358 +++++------------------------------ 2 files changed, 48 insertions(+), 314 deletions(-) diff --git a/packages/js/api/package.json b/packages/js/api/package.json index cb61042dbd2..f6139656b26 100644 --- a/packages/js/api/package.json +++ b/packages/js/api/package.json @@ -47,8 +47,8 @@ "@typescript-eslint/parser": "^5.3.1", "axios-mock-adapter": "^1.20.0", "eslint": "^8.2.0", - "jest": "^27.3.1", - "ts-jest": "^27", + "jest": "^25", + "ts-jest": "^25", "typescript": "^4.4.4" }, "publishConfig": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 41b3c83c30d..9d5db2e0c6c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -64,9 +64,9 @@ importers: axios-mock-adapter: ^1.20.0 create-hmac: 1.1.7 eslint: ^8.2.0 - jest: ^27.3.1 + jest: ^25 oauth-1.0a: 2.2.6 - ts-jest: ^27 + ts-jest: ^25 typescript: ^4.4.4 dependencies: axios: 0.24.0 @@ -80,8 +80,8 @@ importers: '@typescript-eslint/parser': 5.4.0_eslint@8.2.0+typescript@4.4.4 axios-mock-adapter: 1.20.0_axios@0.24.0 eslint: 8.2.0 - jest: 27.3.1 - ts-jest: 27.1.2_f41fed5da8d4caa8e32db7d6695d4125 + jest: 25.5.4 + ts-jest: 25.5.1_jest@25.5.4+typescript@4.4.4 typescript: 4.4.4 packages/js/api-core-tests: @@ -433,10 +433,6 @@ packages: dependencies: '@babel/highlight': 7.16.0 - /@babel/compat-data/7.15.0: - resolution: {integrity: sha512-0NqAC1IJE0S0+lL1SWFMxMkz1pKCNCjI4tr2Zx4LJSXxCLAdr6KyArnY+sno5m3yH9g737ygOyPABDsnXkpxiA==} - engines: {node: '>=6.9.0'} - /@babel/compat-data/7.16.4: resolution: {integrity: sha512-1o/jo7D+kC9ZjHX5v+EHrdjl3PhxMrLSOTGsOdHJ+KL8HCaEK6ehrVL2RS6oHDZp+L7xLirLrPmQtEng769J/Q==} engines: {node: '>=6.9.0'} @@ -464,28 +460,6 @@ packages: transitivePeerDependencies: - supports-color - /@babel/core/7.15.8: - resolution: {integrity: sha512-3UG9dsxvYBMYwRv+gS41WKHno4K60/9GPy1CJaH6xy3Elq8CTtvtjT5R5jmNhXfCYLX2mTw+7/aq5ak/gOE0og==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/code-frame': 7.16.0 - '@babel/generator': 7.16.0 - '@babel/helper-compilation-targets': 7.15.4_@babel+core@7.15.8 - '@babel/helper-module-transforms': 7.15.8 - '@babel/helpers': 7.15.4 - '@babel/parser': 7.16.4 - '@babel/template': 7.16.0 - '@babel/traverse': 7.16.3 - '@babel/types': 7.16.0 - convert-source-map: 1.8.0 - debug: 4.3.2 - gensync: 1.0.0-beta.2 - json5: 2.2.0 - semver: 6.3.0 - source-map: 0.5.7 - transitivePeerDependencies: - - supports-color - /@babel/core/7.16.0: resolution: {integrity: sha512-mYZEvshBRHGsIAiyH5PzCFTCfbWfoYbO/jcSdXQSUQu1/pW0xDZAUP7KEc32heqWTAfAHhV9j1vH8Sav7l+JNQ==} engines: {node: '>=6.9.0'} @@ -529,18 +503,6 @@ packages: '@babel/helper-explode-assignable-expression': 7.16.0 '@babel/types': 7.16.0 - /@babel/helper-compilation-targets/7.15.4_@babel+core@7.15.8: - resolution: {integrity: sha512-rMWPCirulnPSe4d+gwdWXLfAXTTBj8M3guAf5xFQJ0nvFY7tfNAFnWdqaHegHlgDZOCT4qvhF3BYlSJag8yhqQ==} - engines: {node: '>=6.9.0'} - peerDependencies: - '@babel/core': ^7.0.0 - dependencies: - '@babel/compat-data': 7.15.0 - '@babel/core': 7.15.8 - '@babel/helper-validator-option': 7.14.5 - browserslist: 4.17.6 - semver: 6.3.0 - /@babel/helper-compilation-targets/7.16.3_@babel+core@7.12.9: resolution: {integrity: sha512-vKsoSQAyBmxS35JUOOt+07cLc6Nk/2ljLIHwmq2/NM6hdioUaqEXq/S+nXvbvXbZkNDlWOymPanJGOc4CBjSJA==} engines: {node: '>=6.9.0'} @@ -687,33 +649,12 @@ packages: dependencies: '@babel/types': 7.16.0 - /@babel/helper-module-imports/7.15.4: - resolution: {integrity: sha512-jeAHZbzUwdW/xHgHQ3QmWR4Jg6j15q4w/gCfwZvtqOxoo5DKtLHk8Bsf4c5RZRC7NmLEs+ohkdq8jFefuvIxAA==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/types': 7.16.0 - /@babel/helper-module-imports/7.16.0: resolution: {integrity: sha512-kkH7sWzKPq0xt3H1n+ghb4xEMP8k0U7XV3kkB+ZGy69kDk2ySFW1qPi06sjKzFY3t1j6XbJSqr4mF9L7CYVyhg==} engines: {node: '>=6.9.0'} dependencies: '@babel/types': 7.16.0 - /@babel/helper-module-transforms/7.15.8: - resolution: {integrity: sha512-DfAfA6PfpG8t4S6npwzLvTUpp0sS7JrcuaMiy1Y5645laRJIp/LiLGIBbQKaXSInK8tiGNI7FL7L8UvB8gdUZg==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/helper-module-imports': 7.15.4 - '@babel/helper-replace-supers': 7.16.0 - '@babel/helper-simple-access': 7.15.4 - '@babel/helper-split-export-declaration': 7.16.0 - '@babel/helper-validator-identifier': 7.15.7 - '@babel/template': 7.16.0 - '@babel/traverse': 7.16.3 - '@babel/types': 7.16.0 - transitivePeerDependencies: - - supports-color - /@babel/helper-module-transforms/7.16.0: resolution: {integrity: sha512-My4cr9ATcaBbmaEa8M0dZNA74cfI6gitvUAskgDtAFmAqyFKDSHQo5YstxPbN+lzHl2D9l/YOEFqb2mtUh4gfA==} engines: {node: '>=6.9.0'} @@ -760,12 +701,6 @@ packages: transitivePeerDependencies: - supports-color - /@babel/helper-simple-access/7.15.4: - resolution: {integrity: sha512-UzazrDoIVOZZcTeHHEPYrr1MvTR/K+wgLg6MY6e1CJyaRhbibftF6fR2KU2sFRtI/nERUZR9fBd6aKgBlIBaPg==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/types': 7.16.0 - /@babel/helper-simple-access/7.16.0: resolution: {integrity: sha512-o1rjBT/gppAqKsYfUdfHq5Rk03lMQrkPHG1OWzHWpLgVXRH4HnMM9Et9CVdIqwkCQlobnGHEJMsgWP/jE1zUiw==} engines: {node: '>=6.9.0'} @@ -803,16 +738,6 @@ packages: transitivePeerDependencies: - supports-color - /@babel/helpers/7.15.4: - resolution: {integrity: sha512-V45u6dqEJ3w2rlryYYXf6i9rQ5YMNu4FLS6ngs8ikblhu2VdR1AqAd6aJjBzmf2Qzh6KOLqKHxEN9+TFbAkAVQ==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/template': 7.16.0 - '@babel/traverse': 7.16.3 - '@babel/types': 7.16.0 - transitivePeerDependencies: - - supports-color - /@babel/helpers/7.16.3: resolution: {integrity: sha512-Xn8IhDlBPhvYTvgewPKawhADichOsbkZuzN7qz2BusOM0brChsyXMDJvldWaYMMUNiCQdQzNEioXTp3sC8Nt8w==} engines: {node: '>=6.9.0'} @@ -831,11 +756,6 @@ packages: chalk: 2.4.2 js-tokens: 4.0.0 - /@babel/parser/7.16.2: - resolution: {integrity: sha512-RUVpT0G2h6rOZwqLDTrKk7ksNv7YpAilTnYe1/Q+eDjxEceRMKVWbCsX7t8h6C1qCFi/1Y8WZjcEPBAFG27GPw==} - engines: {node: '>=6.0.0'} - hasBin: true - /@babel/parser/7.16.4: resolution: {integrity: sha512-6V0qdPUaiVHH3RtZeLIsc+6pDhbYzHR8ogA8w+f+Wc77DuXto19g2QUwveINoS34Uw+W8/hQDGJCx+i4n7xcng==} engines: {node: '>=6.0.0'} @@ -1205,14 +1125,6 @@ packages: '@babel/core': 7.12.9 '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-async-generators/7.8.4_@babel+core@7.15.8: - resolution: {integrity: sha512-tycmZxkGfZaxhMRbXlPXuVFpdWlXpir2W4AMhSJgRKzk/eDlIXOhb2LHWoLpDF7TEHylV5zNhykX6KAgHJmTNw==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.15.8 - '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-async-generators/7.8.4_@babel+core@7.16.0: resolution: {integrity: sha512-tycmZxkGfZaxhMRbXlPXuVFpdWlXpir2W4AMhSJgRKzk/eDlIXOhb2LHWoLpDF7TEHylV5zNhykX6KAgHJmTNw==} peerDependencies: @@ -1230,14 +1142,6 @@ packages: '@babel/helper-plugin-utils': 7.14.5 dev: false - /@babel/plugin-syntax-bigint/7.8.3_@babel+core@7.15.8: - resolution: {integrity: sha512-wnTnFlG+YxQm3vDxpGE57Pj0srRU4sHE/mDkt1qv2YJJSeUAec2ma4WLUnUPeKjyrfntVwe/N6dCXpU+zL3Npg==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.15.8 - '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-bigint/7.8.3_@babel+core@7.16.0: resolution: {integrity: sha512-wnTnFlG+YxQm3vDxpGE57Pj0srRU4sHE/mDkt1qv2YJJSeUAec2ma4WLUnUPeKjyrfntVwe/N6dCXpU+zL3Npg==} peerDependencies: @@ -1245,7 +1149,6 @@ packages: dependencies: '@babel/core': 7.16.0 '@babel/helper-plugin-utils': 7.14.5 - dev: true /@babel/plugin-syntax-class-properties/7.12.13_@babel+core@7.12.9: resolution: {integrity: sha512-fm4idjKla0YahUNgFNLCB0qySdsoPiZP3iQE3rky0mBUtMZ23yDJ9SJdg6dXTSDnulOVqiF3Hgr9nbXvXTQZYA==} @@ -1255,14 +1158,6 @@ packages: '@babel/core': 7.12.9 '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-class-properties/7.12.13_@babel+core@7.15.8: - resolution: {integrity: sha512-fm4idjKla0YahUNgFNLCB0qySdsoPiZP3iQE3rky0mBUtMZ23yDJ9SJdg6dXTSDnulOVqiF3Hgr9nbXvXTQZYA==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.15.8 - '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-class-properties/7.12.13_@babel+core@7.16.0: resolution: {integrity: sha512-fm4idjKla0YahUNgFNLCB0qySdsoPiZP3iQE3rky0mBUtMZ23yDJ9SJdg6dXTSDnulOVqiF3Hgr9nbXvXTQZYA==} peerDependencies: @@ -1333,14 +1228,6 @@ packages: '@babel/helper-plugin-utils': 7.14.5 dev: false - /@babel/plugin-syntax-import-meta/7.10.4_@babel+core@7.15.8: - resolution: {integrity: sha512-Yqfm+XDx0+Prh3VSeEQCPU81yC+JWZ2pDPFSS4ZdpfZhp4MkFMaDC1UqseovEKwSUpnIL7+vK+Clp7bfh0iD7g==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.15.8 - '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-import-meta/7.10.4_@babel+core@7.16.0: resolution: {integrity: sha512-Yqfm+XDx0+Prh3VSeEQCPU81yC+JWZ2pDPFSS4ZdpfZhp4MkFMaDC1UqseovEKwSUpnIL7+vK+Clp7bfh0iD7g==} peerDependencies: @@ -1348,7 +1235,6 @@ packages: dependencies: '@babel/core': 7.16.0 '@babel/helper-plugin-utils': 7.14.5 - dev: true /@babel/plugin-syntax-json-strings/7.8.3_@babel+core@7.12.9: resolution: {integrity: sha512-lY6kdGpWHvjoe2vk4WrAapEuBR69EMxZl+RoGRhrFGNYVK8mOPAW8VfbT/ZgrFbXlDNiiaxQnAtgVCZ6jv30EA==} @@ -1358,14 +1244,6 @@ packages: '@babel/core': 7.12.9 '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-json-strings/7.8.3_@babel+core@7.15.8: - resolution: {integrity: sha512-lY6kdGpWHvjoe2vk4WrAapEuBR69EMxZl+RoGRhrFGNYVK8mOPAW8VfbT/ZgrFbXlDNiiaxQnAtgVCZ6jv30EA==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.15.8 - '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-json-strings/7.8.3_@babel+core@7.16.0: resolution: {integrity: sha512-lY6kdGpWHvjoe2vk4WrAapEuBR69EMxZl+RoGRhrFGNYVK8mOPAW8VfbT/ZgrFbXlDNiiaxQnAtgVCZ6jv30EA==} peerDependencies: @@ -1401,14 +1279,6 @@ packages: '@babel/core': 7.12.9 '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-logical-assignment-operators/7.10.4_@babel+core@7.15.8: - resolution: {integrity: sha512-d8waShlpFDinQ5MtvGU9xDAOzKH47+FFoney2baFIoMr952hKOLp1HR7VszoZvOsV/4+RRszNY7D17ba0te0ig==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.15.8 - '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-logical-assignment-operators/7.10.4_@babel+core@7.16.0: resolution: {integrity: sha512-d8waShlpFDinQ5MtvGU9xDAOzKH47+FFoney2baFIoMr952hKOLp1HR7VszoZvOsV/4+RRszNY7D17ba0te0ig==} peerDependencies: @@ -1425,14 +1295,6 @@ packages: '@babel/core': 7.12.9 '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-nullish-coalescing-operator/7.8.3_@babel+core@7.15.8: - resolution: {integrity: sha512-aSff4zPII1u2QD7y+F8oDsz19ew4IGEJg9SVW+bqwpwtfFleiQDMdzA/R+UlWDzfnHFCxxleFT0PMIrR36XLNQ==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.15.8 - '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-nullish-coalescing-operator/7.8.3_@babel+core@7.16.0: resolution: {integrity: sha512-aSff4zPII1u2QD7y+F8oDsz19ew4IGEJg9SVW+bqwpwtfFleiQDMdzA/R+UlWDzfnHFCxxleFT0PMIrR36XLNQ==} peerDependencies: @@ -1449,14 +1311,6 @@ packages: '@babel/core': 7.12.9 '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-numeric-separator/7.10.4_@babel+core@7.15.8: - resolution: {integrity: sha512-9H6YdfkcK/uOnY/K7/aA2xpzaAgkQn37yzWUMRK7OaPOqOpGS1+n0H5hxT9AUw9EsSjPW8SVyMJwYRtWs3X3ug==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.15.8 - '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-numeric-separator/7.10.4_@babel+core@7.16.0: resolution: {integrity: sha512-9H6YdfkcK/uOnY/K7/aA2xpzaAgkQn37yzWUMRK7OaPOqOpGS1+n0H5hxT9AUw9EsSjPW8SVyMJwYRtWs3X3ug==} peerDependencies: @@ -1473,14 +1327,6 @@ packages: '@babel/core': 7.12.9 '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-object-rest-spread/7.8.3_@babel+core@7.15.8: - resolution: {integrity: sha512-XoqMijGZb9y3y2XskN+P1wUGiVwWZ5JmoDRwx5+3GmEplNyVM2s2Dg8ILFQm8rWM48orGy5YpI5Bl8U1y7ydlA==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.15.8 - '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-object-rest-spread/7.8.3_@babel+core@7.16.0: resolution: {integrity: sha512-XoqMijGZb9y3y2XskN+P1wUGiVwWZ5JmoDRwx5+3GmEplNyVM2s2Dg8ILFQm8rWM48orGy5YpI5Bl8U1y7ydlA==} peerDependencies: @@ -1497,14 +1343,6 @@ packages: '@babel/core': 7.12.9 '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-optional-catch-binding/7.8.3_@babel+core@7.15.8: - resolution: {integrity: sha512-6VPD0Pc1lpTqw0aKoeRTMiB+kWhAoT24PA+ksWSBrFtl5SIRVpZlwN3NNPQjehA2E/91FV3RjLWoVTglWcSV3Q==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.15.8 - '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-optional-catch-binding/7.8.3_@babel+core@7.16.0: resolution: {integrity: sha512-6VPD0Pc1lpTqw0aKoeRTMiB+kWhAoT24PA+ksWSBrFtl5SIRVpZlwN3NNPQjehA2E/91FV3RjLWoVTglWcSV3Q==} peerDependencies: @@ -1521,14 +1359,6 @@ packages: '@babel/core': 7.12.9 '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-optional-chaining/7.8.3_@babel+core@7.15.8: - resolution: {integrity: sha512-KoK9ErH1MBlCPxV0VANkXW2/dw4vlbGDrFgz8bmUsBGYkFRcbRwMh6cIJubdPrkxRwuGdtCk0v/wPTKbQgBjkg==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.15.8 - '@babel/helper-plugin-utils': 7.14.5 - /@babel/plugin-syntax-optional-chaining/7.8.3_@babel+core@7.16.0: resolution: {integrity: sha512-KoK9ErH1MBlCPxV0VANkXW2/dw4vlbGDrFgz8bmUsBGYkFRcbRwMh6cIJubdPrkxRwuGdtCk0v/wPTKbQgBjkg==} peerDependencies: @@ -2578,22 +2408,6 @@ packages: '@babel/parser': 7.16.4 '@babel/types': 7.16.0 - /@babel/traverse/7.16.0: - resolution: {integrity: sha512-qQ84jIs1aRQxaGaxSysII9TuDaguZ5yVrEuC0BN2vcPlalwfLovVmCjbFDPECPXcYM/wLvNFfp8uDOliLxIoUQ==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/code-frame': 7.16.0 - '@babel/generator': 7.16.0 - '@babel/helper-function-name': 7.16.0 - '@babel/helper-hoist-variables': 7.16.0 - '@babel/helper-split-export-declaration': 7.16.0 - '@babel/parser': 7.16.2 - '@babel/types': 7.16.0 - debug: 4.3.2 - globals: 11.12.0 - transitivePeerDependencies: - - supports-color - /@babel/traverse/7.16.3: resolution: {integrity: sha512-eolumr1vVMjqevCpwVO99yN/LoGL0EyHiLO5I043aYQvwOJ9eR5UsZSClHVCzfhBduMAsSzgA/6AyqPjNayJag==} engines: {node: '>=6.9.0'} @@ -3076,11 +2890,11 @@ packages: exit: 0.1.2 glob: 7.2.0 graceful-fs: 4.2.8 - istanbul-lib-coverage: 3.0.1 + istanbul-lib-coverage: 3.2.0 istanbul-lib-instrument: 4.0.3 istanbul-lib-report: 3.0.0 - istanbul-lib-source-maps: 4.0.0 - istanbul-reports: 3.0.3 + istanbul-lib-source-maps: 4.0.1 + istanbul-reports: 3.0.5 jest-haste-map: 25.5.1 jest-resolve: 25.5.1 jest-util: 25.5.0 @@ -3301,9 +3115,9 @@ packages: resolution: {integrity: sha512-Y8CEoVwXb4QwA6Y/9uDkn0Xfz0finGkieuV0xkdF9UtZGJeLukD5nLkaVrVsODB1ojRWlaoD0AJZpVHCSnJEvg==} engines: {node: '>= 8.3'} dependencies: - '@babel/core': 7.15.8 + '@babel/core': 7.16.0 '@jest/types': 25.5.0 - babel-plugin-istanbul: 6.0.0 + babel-plugin-istanbul: 6.1.1 chalk: 3.0.0 convert-source-map: 1.8.0 fast-json-stable-stringify: 2.1.0 @@ -6237,18 +6051,18 @@ packages: - supports-color dev: false - /babel-jest/25.5.1_@babel+core@7.15.8: + /babel-jest/25.5.1_@babel+core@7.16.0: resolution: {integrity: sha512-9dA9+GmMjIzgPnYtkhBg73gOo/RHqPmLruP3BaGL4KEX3Dwz6pI8auSN8G8+iuEG90+GSswyKvslN+JYSaacaQ==} engines: {node: '>= 8.3'} peerDependencies: '@babel/core': ^7.0.0 dependencies: - '@babel/core': 7.15.8 + '@babel/core': 7.16.0 '@jest/transform': 25.5.1 '@jest/types': 25.5.0 '@types/babel__core': 7.1.16 babel-plugin-istanbul: 6.1.1 - babel-preset-jest: 25.5.0_@babel+core@7.15.8 + babel-preset-jest: 25.5.0_@babel+core@7.16.0 chalk: 3.0.0 graceful-fs: 4.2.8 slash: 3.0.0 @@ -6344,18 +6158,6 @@ packages: - supports-color dev: false - /babel-plugin-istanbul/6.0.0: - resolution: {integrity: sha512-AF55rZXpe7trmEylbaE1Gv54wn6rwU03aptvRoVIGP8YykoSxqdVLV1TfwflBCE/QtHmqtP8SWlTENqbK8GCSQ==} - engines: {node: '>=8'} - dependencies: - '@babel/helper-plugin-utils': 7.14.5 - '@istanbuljs/load-nyc-config': 1.1.0 - '@istanbuljs/schema': 0.1.3 - istanbul-lib-instrument: 4.0.3 - test-exclude: 6.0.0 - transitivePeerDependencies: - - supports-color - /babel-plugin-istanbul/6.1.1: resolution: {integrity: sha512-Y1IQok9821cC9onCx5otgFfRm7Lm+I+wwxOx738M/WLPZ9Q42m4IG5W0FNX8WLL2gYMZo3JkuXIH2DOpWM+qwA==} engines: {node: '>=8'} @@ -6490,23 +6292,23 @@ packages: '@babel/helper-plugin-utils': 7.14.5 dev: true - /babel-preset-current-node-syntax/0.1.4_@babel+core@7.15.8: + /babel-preset-current-node-syntax/0.1.4_@babel+core@7.16.0: resolution: {integrity: sha512-5/INNCYhUGqw7VbVjT/hb3ucjgkVHKXY7lX3ZjlN4gm565VyFmJUrJ/h+h16ECVB38R/9SF6aACydpKMLZ/c9w==} peerDependencies: '@babel/core': ^7.0.0 dependencies: - '@babel/core': 7.15.8 - '@babel/plugin-syntax-async-generators': 7.8.4_@babel+core@7.15.8 - '@babel/plugin-syntax-bigint': 7.8.3_@babel+core@7.15.8 - '@babel/plugin-syntax-class-properties': 7.12.13_@babel+core@7.15.8 - '@babel/plugin-syntax-import-meta': 7.10.4_@babel+core@7.15.8 - '@babel/plugin-syntax-json-strings': 7.8.3_@babel+core@7.15.8 - '@babel/plugin-syntax-logical-assignment-operators': 7.10.4_@babel+core@7.15.8 - '@babel/plugin-syntax-nullish-coalescing-operator': 7.8.3_@babel+core@7.15.8 - '@babel/plugin-syntax-numeric-separator': 7.10.4_@babel+core@7.15.8 - '@babel/plugin-syntax-object-rest-spread': 7.8.3_@babel+core@7.15.8 - '@babel/plugin-syntax-optional-catch-binding': 7.8.3_@babel+core@7.15.8 - '@babel/plugin-syntax-optional-chaining': 7.8.3_@babel+core@7.15.8 + '@babel/core': 7.16.0 + '@babel/plugin-syntax-async-generators': 7.8.4_@babel+core@7.16.0 + '@babel/plugin-syntax-bigint': 7.8.3_@babel+core@7.16.0 + '@babel/plugin-syntax-class-properties': 7.12.13_@babel+core@7.16.0 + '@babel/plugin-syntax-import-meta': 7.10.4_@babel+core@7.16.0 + '@babel/plugin-syntax-json-strings': 7.8.3_@babel+core@7.16.0 + '@babel/plugin-syntax-logical-assignment-operators': 7.10.4_@babel+core@7.16.0 + '@babel/plugin-syntax-nullish-coalescing-operator': 7.8.3_@babel+core@7.16.0 + '@babel/plugin-syntax-numeric-separator': 7.10.4_@babel+core@7.16.0 + '@babel/plugin-syntax-object-rest-spread': 7.8.3_@babel+core@7.16.0 + '@babel/plugin-syntax-optional-catch-binding': 7.8.3_@babel+core@7.16.0 + '@babel/plugin-syntax-optional-chaining': 7.8.3_@babel+core@7.16.0 /babel-preset-current-node-syntax/1.0.1_@babel+core@7.12.9: resolution: {integrity: sha512-M7LQ0bxarkxQoN+vz5aJPsLBn77n8QgTFmo8WK0/44auK2xlCXrYcUxHFxgU7qW5Yzw/CjmLRK2uJzaCd7LvqQ==} @@ -6559,15 +6361,15 @@ packages: babel-plugin-jest-hoist: 24.9.0 dev: false - /babel-preset-jest/25.5.0_@babel+core@7.15.8: + /babel-preset-jest/25.5.0_@babel+core@7.16.0: resolution: {integrity: sha512-8ZczygctQkBU+63DtSOKGh7tFL0CeCuz+1ieud9lJ1WPQ9O6A1a/r+LGn6Y705PA6whHQ3T1XuB/PmpfNYf8Fw==} engines: {node: '>= 8.3'} peerDependencies: '@babel/core': ^7.0.0 dependencies: - '@babel/core': 7.15.8 + '@babel/core': 7.16.0 babel-plugin-jest-hoist: 25.5.0 - babel-preset-current-node-syntax: 0.1.4_@babel+core@7.15.8 + babel-preset-current-node-syntax: 0.1.4_@babel+core@7.16.0 /babel-preset-jest/26.6.2_@babel+core@7.12.9: resolution: {integrity: sha512-YvdtlVm9t3k777c5NPQIv6cxFFFapys25HiUmuSgHwIZhfifweR5c5Sf5nwE3MAbfu327CYSvps8Yx6ANLyleQ==} @@ -6867,17 +6669,6 @@ packages: node-releases: 1.1.77 dev: true - /browserslist/4.17.6: - resolution: {integrity: sha512-uPgz3vyRTlEiCv4ee9KlsKgo2V6qPk7Jsn0KAn2OBqbqKo3iNcPEC1Ti6J4dwnz+aIRfEEEuOzC9IBk8tXUomw==} - engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} - hasBin: true - dependencies: - caniuse-lite: 1.0.30001278 - electron-to-chromium: 1.3.889 - escalade: 3.1.1 - node-releases: 2.0.1 - picocolors: 1.0.0 - /browserslist/4.18.1: resolution: {integrity: sha512-8ScCzdpPwR2wQh8IT82CA2VgDwjHyqMovPBZSNH54+tm4Jk2pCuv90gmAdH6J84OCRWi0b4gMe6O6XPXuJnjgQ==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} @@ -7072,9 +6863,6 @@ packages: resolution: {integrity: sha512-VAy5RHDfTJhpxnDdp2n40GPPLp3KqNrXz1QqFv4J64HvArKs8nuNMOWkB3ICOaBTU/Aj4rYAo/ytdQDDFF/Pug==} dev: true - /caniuse-lite/1.0.30001278: - resolution: {integrity: sha512-mpF9KeH8u5cMoEmIic/cr7PNS+F5LWBk0t2ekGT60lFf0Wq+n9LspAj0g3P+o7DQhD3sUdlMln4YFAWhFYn9jg==} - /caniuse-lite/1.0.30001280: resolution: {integrity: sha512-kFXwYvHe5rix25uwueBxC569o53J6TpnGu0BEEn+6Lhl2vsnAumRFWEBhDft1fwyo6m1r4i+RqA4+163FpeFcA==} @@ -8543,9 +8331,6 @@ packages: jake: 10.8.2 dev: true - /electron-to-chromium/1.3.889: - resolution: {integrity: sha512-suEUoPTD1mExjL9TdmH7cvEiWJVM2oEiAi+Y1p0QKxI2HcRlT44qDTP2c1aZmVwRemIPYOpxmV7CxQCOWcm4XQ==} - /electron-to-chromium/1.3.899: resolution: {integrity: sha512-w16Dtd2zl7VZ4N4Db+FIa7n36sgPGCKjrKvUUmp5ialsikvcQLjcJR9RWnlYNxIyEHLdHaoIZEqKsPxU9MdyBg==} @@ -12199,10 +11984,6 @@ packages: engines: {node: '>=6'} dev: false - /istanbul-lib-coverage/3.0.1: - resolution: {integrity: sha512-GvCYYTxaCPqwMjobtVcVKvSHtAGe48MNhGjpK8LtVF8K0ISX7hCKl85LgtuaSneWVyQmaGcW3iXVV3GaZSLpmQ==} - engines: {node: '>=8'} - /istanbul-lib-coverage/3.2.0: resolution: {integrity: sha512-eOeJ5BHCmHYvQK7xt9GkdHuzuCGS1Y6g9Gvnx3Ym33fz/HpLRYxiS0wHNr+m/MBC8B647Xt608vCDEvhl9c6Mw==} engines: {node: '>=8'} @@ -12312,16 +12093,6 @@ packages: - supports-color dev: false - /istanbul-lib-source-maps/4.0.0: - resolution: {integrity: sha512-c16LpFRkR8vQXyHZ5nLpY35JZtzj1PQY1iZmesUbf1FZHbIupcWfjgOXBY9YHkLEQ6puz1u4Dgj6qmU/DisrZg==} - engines: {node: '>=8'} - dependencies: - debug: 4.3.2 - istanbul-lib-coverage: 3.0.1 - source-map: 0.6.1 - transitivePeerDependencies: - - supports-color - /istanbul-lib-source-maps/4.0.1: resolution: {integrity: sha512-n3s8EwkdFIJCG3BPKBYvskgXGoy88ARzvegkitk60NxRdwltLOTaH7CUiMRXvwYorl0Q712iEjcWB+fK/MrWVw==} engines: {node: '>=10'} @@ -12331,7 +12102,6 @@ packages: source-map: 0.6.1 transitivePeerDependencies: - supports-color - dev: true /istanbul-reports/1.5.1: resolution: {integrity: sha512-+cfoZ0UXzWjhAdzosCPP3AN8vvef8XDkWtTfgaN+7L3YTpNYITnCaEkceo5SEYy644VkHka/P1FvkWvrG/rrJw==} @@ -12346,20 +12116,12 @@ packages: html-escaper: 2.0.2 dev: false - /istanbul-reports/3.0.3: - resolution: {integrity: sha512-0i77ZFLsb9U3DHi22WzmIngVzfoyxxbQcZRqlF3KoKmCJGq9nhFHoGi8FqBztN2rE8w6hURnZghetn0xpkVb6A==} - engines: {node: '>=8'} - dependencies: - html-escaper: 2.0.2 - istanbul-lib-report: 3.0.0 - /istanbul-reports/3.0.5: resolution: {integrity: sha512-5+19PlhnGabNWB7kOFnuxT8H3T/iIyQzIbQMxXsURmmvKg86P2sbkrGOT77VnHw0Qr0gc2XzRaRfMZYYbSQCJQ==} engines: {node: '>=8'} dependencies: html-escaper: 2.0.2 istanbul-lib-report: 3.0.0 - dev: true /istanbul/1.0.0-alpha.2: resolution: {integrity: sha1-BglrwI6Yuq10Sq5Gli2N+frGPQg=} @@ -12500,7 +12262,7 @@ packages: jest-config: 25.5.4 jest-util: 25.5.0 jest-validate: 25.5.0 - prompts: 2.4.1 + prompts: 2.4.2 realpath-native: 2.0.0 yargs: 15.4.1 transitivePeerDependencies: @@ -12568,10 +12330,10 @@ packages: resolution: {integrity: sha512-SZwR91SwcdK6bz7Gco8qL7YY2sx8tFJYzvg216DLihTWf+LKY/DoJXpM9nTzYakSyfblbqeU48p/p7Jzy05Atg==} engines: {node: '>= 8.3'} dependencies: - '@babel/core': 7.15.8 + '@babel/core': 7.16.0 '@jest/test-sequencer': 25.5.4 '@jest/types': 25.5.0 - babel-jest: 25.5.1_@babel+core@7.15.8 + babel-jest: 25.5.1_@babel+core@7.16.0 chalk: 3.0.0 deepmerge: 4.2.2 glob: 7.2.0 @@ -12954,7 +12716,7 @@ packages: jest-worker: 25.5.0 micromatch: 4.0.4 sane: 4.1.0 - walker: 1.0.7 + walker: 1.0.8 which: 2.0.2 optionalDependencies: fsevents: 2.3.2 @@ -13028,7 +12790,7 @@ packages: resolution: {integrity: sha512-9acbWEfbmS8UpdcfqnDO+uBUgKa/9hcRh983IHdM+pKmJPL77G0sWAAK0V0kr5LK3a8cSBfkFSoncXwQlRZfkQ==} engines: {node: '>= 8.3'} dependencies: - '@babel/traverse': 7.16.0 + '@babel/traverse': 7.16.3 '@jest/environment': 25.5.0 '@jest/source-map': 25.5.0 '@jest/test-result': 25.5.0 @@ -14590,11 +14352,6 @@ packages: kind-of: 6.0.3 dev: true - /makeerror/1.0.11: - resolution: {integrity: sha1-4BpckQnyr3lmDk6LlYd5AYT1qWw=} - dependencies: - tmpl: 1.0.5 - /makeerror/1.0.12: resolution: {integrity: sha512-JmqCvUhmt43madlpFzG4BQzG2Z3m6tvQDNKdClZnO3VbIudJYmxsT0FNJMeiB2+JTSlTQTSbU8QdesVmwJcmLg==} dependencies: @@ -16938,13 +16695,6 @@ packages: engines: {node: '>=0.12'} dev: true - /prompts/2.4.1: - resolution: {integrity: sha512-EQyfIuO2hPDsX1L/blblV+H7I0knhgAd82cVneCwcdND9B8AuCDuRcBH6yIcG4dFzlOUqbazQqwGjx5xmsNLuQ==} - engines: {node: '>= 6'} - dependencies: - kleur: 3.0.3 - sisteransi: 1.0.5 - /prompts/2.4.2: resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} engines: {node: '>= 6'} @@ -18225,6 +17975,7 @@ packages: /source-map-resolve/0.5.3: resolution: {integrity: sha512-Htz+RnsXWk5+P2slx5Jh3Q66vhQj1Cllm0zvnaY98+NFx+Dv2CF/f5O/t8x+KaNdrdIAsruNzoh/KpialbqAnw==} + deprecated: See https://github.com/lydell/source-map-resolve#deprecated dependencies: atob: 2.1.2 decode-uri-component: 0.2.0 @@ -18247,6 +17998,7 @@ packages: /source-map-url/0.4.1: resolution: {integrity: sha512-cPiFOTLUKvJFIg4SKVScy4ilPPW6rFgMgfuZJPNoDuMs3nC1HbMUycBoJw77xFIp6z1UJQJOfx6C9GMH80DiTw==} + deprecated: See https://github.com/lydell/source-map-url#deprecated /source-map/0.5.7: resolution: {integrity: sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=} @@ -19364,39 +19116,26 @@ packages: resolution: {integrity: sha512-rvuRbTarPXmMb79SmzEp8aqXNKcK+y0XaB298IXueQ8I2PsrATcPBCSPyK/dDNa2iWOhKlfNnOjdAOTBU/nkFA==} dev: true - /ts-jest/27.1.2_f41fed5da8d4caa8e32db7d6695d4125: - resolution: {integrity: sha512-eSOiJOWq6Hhs6Khzk5wKC5sgWIXgXqOCiIl1+3lfnearu58Hj4QpE5tUhQcA3xtZrELbcvAGCsd6HB8OsaVaTA==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} + /ts-jest/25.5.1_jest@25.5.4+typescript@4.4.4: + resolution: {integrity: sha512-kHEUlZMK8fn8vkxDjwbHlxXRB9dHYpyzqKIGDNxbzs+Rz+ssNDSDNusEK8Fk/sDd4xE6iKoQLfFkFVaskmTJyw==} + engines: {node: '>= 8'} hasBin: true peerDependencies: - '@babel/core': '>=7.0.0-beta.0 <8' - '@types/jest': ^27.0.0 - babel-jest: '>=27.0.0 <28' - esbuild: ~0.14.0 - jest: ^27.0.0 - typescript: '>=3.8 <5.0' - peerDependenciesMeta: - '@babel/core': - optional: true - '@types/jest': - optional: true - babel-jest: - optional: true - esbuild: - optional: true + jest: '>=25 <26' + typescript: '>=3.4 <4.0' dependencies: - '@babel/core': 7.12.9 - '@types/jest': 27.0.2 bs-logger: 0.2.6 + buffer-from: 1.1.2 fast-json-stable-stringify: 2.1.0 - jest: 27.3.1 - jest-util: 27.3.1 + jest: 25.5.4 json5: 2.2.0 lodash.memoize: 4.1.2 make-error: 1.3.6 - semver: 7.3.5 + micromatch: 4.0.4 + mkdirp: 0.5.5 + semver: 6.3.0 typescript: 4.4.4 - yargs-parser: 20.2.9 + yargs-parser: 18.1.3 dev: true /ts-loader/9.2.6_typescript@4.2.4+webpack@5.64.1: @@ -19917,11 +19656,6 @@ packages: - supports-color dev: false - /walker/1.0.7: - resolution: {integrity: sha1-L3+bj9ENZ3JisYqITijRlhjgKPs=} - dependencies: - makeerror: 1.0.11 - /walker/1.0.8: resolution: {integrity: sha512-ts/8E8l5b7kY0vlWLewOkDXMmPdLcVV4GmOQLyxuSswIJsweeFZtAsMF7k1Nszz+TYBQrlYRmzOnr398y1JemQ==} dependencies: From c1cf58437f29fbff9365dde7131a8eb7df89e94a Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Thu, 3 Feb 2022 11:26:49 -0300 Subject: [PATCH 13/19] Remove tweak to work with both snake_case and camelCase --- .../model-transformer-transformation.ts | 25 ++++++------------- .../repositories/rest/orders/transformer.ts | 14 +++++------ 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/packages/js/api/src/framework/transformations/model-transformer-transformation.ts b/packages/js/api/src/framework/transformations/model-transformer-transformation.ts index f5b53085987..11b85bae761 100644 --- a/packages/js/api/src/framework/transformations/model-transformer-transformation.ts +++ b/packages/js/api/src/framework/transformations/model-transformer-transformation.ts @@ -43,6 +43,10 @@ export class ModelTransformerTransformation< T extends Model > implements ModelT * @template T */ public constructor( property: string, modelClass: ModelConstructor< T >, transformer: ModelTransformer< T > ) { + // Developer-friendly error to make sure this doesn't go unnoticed. + if (property.includes('_')) { + throw new Error('The property must be camelCase'); + } this.property = property; this.modelClass = modelClass; this.transformer = transformer; @@ -74,27 +78,12 @@ export class ModelTransformerTransformation< T extends Model > implements ModelT * @return {*} The transformed properties. */ public toModel( properties: any ): any { - let propertyName = this.property; - let val = properties[ propertyName ]; - - if ( ! val ) { - /* - * Properties are defined in snake_case format, but the properties in the models are camelCase. - * Due to how the hydration of the model works, using TypeScript's Partial, the properties object - * might have been transformed from snake_case to camelCase already, so we try to convert - * the property name to camelCase before giving up. - */ - propertyName = propertyName.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, function (_match, chr) { - return chr.toUpperCase(); - }); - val = properties[ propertyName ]; - } - + const val = properties[ this.property ]; if ( val ) { if ( Array.isArray( val ) ) { - properties[ propertyName ] = val.map( ( v ) => this.transformer.toModel( this.modelClass, v ) ); + properties[ this.property ] = val.map( ( v ) => this.transformer.toModel( this.modelClass, v ) ); } else { - properties[ propertyName ] = this.transformer.toModel( this.modelClass, val ); + properties[ this.property ] = this.transformer.toModel( this.modelClass, val ); } } diff --git a/packages/js/api/src/repositories/rest/orders/transformer.ts b/packages/js/api/src/repositories/rest/orders/transformer.ts index 78f6a327ea6..e050506199f 100644 --- a/packages/js/api/src/repositories/rest/orders/transformer.ts +++ b/packages/js/api/src/repositories/rest/orders/transformer.ts @@ -30,13 +30,13 @@ export function createOrderTransformer(): ModelTransformer< Order > { new IgnorePropertyTransformation( [ 'date_created', 'date_modified' ] ), new ModelTransformerTransformation( 'billing', BillingOrderAddress, createBillingAddressTransformer() ), new ModelTransformerTransformation( 'shipping', ShippingOrderAddress, createShippingAddressTransformer() ), - new ModelTransformerTransformation( 'tax_lines', OrderTaxRate, createOrderTaxRateTransformer() ), + new ModelTransformerTransformation( 'taxLines', OrderTaxRate, createOrderTaxRateTransformer() ), new ModelTransformerTransformation( 'refunds', OrderRefundLine, createOrderRefundLineTransformer() ), - new ModelTransformerTransformation( 'coupon_lines', OrderCouponLine, createOrdeCouponLineTransformer() ), - new ModelTransformerTransformation( 'fee_lines', OrderFeeLine, createOrderFeeLineTransformer() ), - new ModelTransformerTransformation( 'line_items', OrderLineItem, createOrderLineItemTransformer() ), - new ModelTransformerTransformation( 'shipping_lines', OrderShippingLine, createOrderShippingItemTransformer() ), - new ModelTransformerTransformation( 'meta_data', MetaData, createMetaDataTransformer() ), + new ModelTransformerTransformation( 'couponLines', OrderCouponLine, createOrdeCouponLineTransformer() ), + new ModelTransformerTransformation( 'feeLines', OrderFeeLine, createOrderFeeLineTransformer() ), + new ModelTransformerTransformation( 'lineItems', OrderLineItem, createOrderLineItemTransformer() ), + new ModelTransformerTransformation( 'shippingLines', OrderShippingLine, createOrderShippingItemTransformer() ), + new ModelTransformerTransformation( 'metaData', MetaData, createMetaDataTransformer() ), new PropertyTypeTransformation( { @@ -212,7 +212,7 @@ function createOrderRefundLineTransformer(): ModelTransformer< OrderRefundLine > function createOrdeCouponLineTransformer(): ModelTransformer< OrderCouponLine > { return new ModelTransformer( [ - new ModelTransformerTransformation( 'meta_data', MetaData, createMetaDataTransformer() ), + new ModelTransformerTransformation( 'metaData', MetaData, createMetaDataTransformer() ), new PropertyTypeTransformation( { code: PropertyType.String, From ae5d23ce9f6148c1bb2bae8c08fffa846373fb9b Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Mon, 7 Feb 2022 18:05:06 -0300 Subject: [PATCH 14/19] Rename property, code style changes, add developer comment --- .../__tests__/payload-transformer.spec.ts | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) 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 e3c3b2e397b..be0cc72075b 100644 --- a/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts +++ b/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts @@ -1,7 +1,31 @@ -import {Order, BillingOrderAddress, ShippingOrderAddress, OrderLineItem, OrderShippingLine, OrderFeeLine, OrderTaxRate, OrderCouponLine, MetaData, OrderRefundLine} from "../../models"; -import {createBillingAddressTransformer, createOrderTransformer, createShippingAddressTransformer} from "../../repositories/rest/orders/transformer"; +import { + Order, + BillingOrderAddress, + ShippingOrderAddress, + OrderLineItem, + OrderShippingLine, + OrderFeeLine, + OrderTaxRate, + OrderCouponLine, + MetaData, + OrderRefundLine +} from "../../models"; -const jsonPayloadFull = JSON.stringify({ +import { + createBillingAddressTransformer, + createOrderTransformer, + createShippingAddressTransformer +} from "../../repositories/rest/orders/transformer"; + +/* + This Object is a JSON representation of single Order GET operation from the WooCommerce REST API. + + Developer note: + We use JSON.stringify here to convert an Object into a String. + This is done like this because JavaScript passes Objects around by reference, + and we don't want tests to modify the original `jsonPayloadFull` variable. + */ +const responseOrderJson = JSON.stringify({ id: 1218, parent_id: 0, status: 'pending', @@ -227,9 +251,9 @@ const jsonPayloadFull = JSON.stringify({ describe( 'OrderTransformer', () => { it( 'should transform an order JSON', () => { - const order = createOrderTransformer().toModel( Order, JSON.parse(jsonPayloadFull) ); - const billing = createBillingAddressTransformer().toModel(BillingOrderAddress, JSON.parse(jsonPayloadFull).billing); - const shipping = createShippingAddressTransformer().toModel(ShippingOrderAddress, JSON.parse(jsonPayloadFull).shipping); + const order = createOrderTransformer().toModel( Order, JSON.parse(responseOrderJson) ); + const billing = createBillingAddressTransformer().toModel(BillingOrderAddress, JSON.parse(responseOrderJson).billing); + const shipping = createShippingAddressTransformer().toModel(ShippingOrderAddress, JSON.parse(responseOrderJson).shipping); // Order expect( order ).toBeInstanceOf( Order ); @@ -276,7 +300,7 @@ describe( 'OrderTransformer', () => { expect(billing.country).toStrictEqual('Billing Country'); expect(billing.email).toStrictEqual('Billing Email'); expect(billing.phone).toStrictEqual('Billing Phone'); - expect( createBillingAddressTransformer().fromModel(billing) ).toStrictEqual(JSON.parse(jsonPayloadFull).billing); + expect( createBillingAddressTransformer().fromModel(billing) ).toStrictEqual(JSON.parse(responseOrderJson).billing); // Shipping expect(shipping.firstName).toStrictEqual('Shipping First Name'); @@ -295,7 +319,7 @@ describe( 'OrderTransformer', () => { */ //expect(shipping.email).toStrictEqual('Shipping Email'); //expect(shipping.phone).toStrictEqual('Shipping Phone'); - expect( createShippingAddressTransformer().fromModel(shipping) ).toStrictEqual(JSON.parse(jsonPayloadFull).shipping); + expect( createShippingAddressTransformer().fromModel(shipping) ).toStrictEqual(JSON.parse(responseOrderJson).shipping); // Metadata expect(order.metaData).toHaveLength(1); @@ -369,9 +393,9 @@ describe( 'OrderTransformer', () => { expect(order.couponLines[0].metaData[0]).toBeInstanceOf(MetaData); //expect(order.couponLines[0].metaData[0].id).toStrictEqual(57112); expect(order.couponLines[0].metaData[0].key).toStrictEqual('coupon_data'); - expect(order.couponLines[0].metaData[0].value).toStrictEqual( JSON.parse(jsonPayloadFull).coupon_lines[0].meta_data[0].value); + expect(order.couponLines[0].metaData[0].value).toStrictEqual( JSON.parse(responseOrderJson).coupon_lines[0].meta_data[0].value); expect(order.couponLines[0].metaData[0].displayKey).toStrictEqual('coupon_data'); - expect(order.couponLines[0].metaData[0].displayValue).toStrictEqual( JSON.parse(jsonPayloadFull).coupon_lines[0].meta_data[0].display_value); + expect(order.couponLines[0].metaData[0].displayValue).toStrictEqual( JSON.parse(responseOrderJson).coupon_lines[0].meta_data[0].display_value); // Refunds expect(order.refunds).toHaveLength(1); From 299b7c0bddd90e4641d105d82e84db23d8d4f4c4 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Mon, 7 Feb 2022 18:08:26 -0300 Subject: [PATCH 15/19] Remove display_key/display_value from coupon_line on Order test --- .../__tests__/payload-transformer.spec.ts | 37 ------------------- 1 file changed, 37 deletions(-) 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 be0cc72075b..9c51be1d9e8 100644 --- a/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts +++ b/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts @@ -184,41 +184,6 @@ const responseOrderJson = JSON.stringify({ virtual: false, meta_data: [] }, - display_key: 'coupon_data', - display_value: { - id: 171, - code: 'save5', - amount: '5', - date_created: { - date: '2021-05-19 04:28:31.000000', - timezone_type: 3, - timezone: 'Pacific/Auckland' - }, - date_modified: { - date: '2021-05-19 04:28:31.000000', - timezone_type: 3, - timezone: 'Pacific/Auckland' - }, - date_expires: null, - discount_type: 'fixed_cart', - description: '', - usage_count: 3, - individual_use: false, - product_ids: [], - excluded_product_ids: [], - usage_limit: 0, - usage_limit_per_user: 0, - limit_usage_to_x_items: null, - free_shipping: false, - product_categories: [], - excluded_product_categories: [], - exclude_sale_items: false, - minimum_amount: '', - maximum_amount: '', - email_restrictions: [], - virtual: false, - meta_data: [] - } } ] } @@ -394,8 +359,6 @@ describe( 'OrderTransformer', () => { //expect(order.couponLines[0].metaData[0].id).toStrictEqual(57112); expect(order.couponLines[0].metaData[0].key).toStrictEqual('coupon_data'); expect(order.couponLines[0].metaData[0].value).toStrictEqual( JSON.parse(responseOrderJson).coupon_lines[0].meta_data[0].value); - expect(order.couponLines[0].metaData[0].displayKey).toStrictEqual('coupon_data'); - expect(order.couponLines[0].metaData[0].displayValue).toStrictEqual( JSON.parse(responseOrderJson).coupon_lines[0].meta_data[0].display_value); // Refunds expect(order.refunds).toHaveLength(1); From cd2ed1720035678094f01759435d078479c1caef Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Mon, 7 Feb 2022 18:10:02 -0300 Subject: [PATCH 16/19] CR: Simplify code --- packages/js/api/src/models/orders/shared/types.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/js/api/src/models/orders/shared/types.ts b/packages/js/api/src/models/orders/shared/types.ts index 86f15051d13..a1ca13d3882 100644 --- a/packages/js/api/src/models/orders/shared/types.ts +++ b/packages/js/api/src/models/orders/shared/types.ts @@ -30,8 +30,7 @@ export type OrderTotalUpdateParams = 'total' | 'totalTax'; /** * Billing address properties */ -export type BillingOrderAddressUpdateParams = 'firstName' | 'lastName' | 'company' | 'address1' - | 'address2' | 'city' | 'state' | 'postCode' | 'country' | 'email' | 'phone'; +export type BillingOrderAddressUpdateParams = ShippingOrderAddressUpdateParams | 'email' | 'phone'; /** * Shipping address properties From 0bc908f8d2416b930bc1709820858aefce3d136e Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Mon, 7 Feb 2022 18:10:31 -0300 Subject: [PATCH 17/19] CR: Spacing --- packages/js/api/src/repositories/rest/orders/transformer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/js/api/src/repositories/rest/orders/transformer.ts b/packages/js/api/src/repositories/rest/orders/transformer.ts index e050506199f..e080c71cf6f 100644 --- a/packages/js/api/src/repositories/rest/orders/transformer.ts +++ b/packages/js/api/src/repositories/rest/orders/transformer.ts @@ -15,7 +15,8 @@ import { OrderLineItem, OrderRefundLine, OrderShippingLine, - OrderTaxRate, MetaData, + OrderTaxRate, + MetaData, } from '../../../models'; import {createMetaDataTransformer} from "../shared"; From 0cf1b69c7ae96ba2f2058c7547198239fdf0db7e Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Mon, 7 Feb 2022 18:13:02 -0300 Subject: [PATCH 18/19] Rename/move test to more appropriate location --- .../rest/orders/__tests__/order-transformer.spec.ts} | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename packages/js/api/src/{framework/__tests__/payload-transformer.spec.ts => repositories/rest/orders/__tests__/order-transformer.spec.ts} (99%) diff --git a/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts b/packages/js/api/src/repositories/rest/orders/__tests__/order-transformer.spec.ts similarity index 99% rename from packages/js/api/src/framework/__tests__/payload-transformer.spec.ts rename to packages/js/api/src/repositories/rest/orders/__tests__/order-transformer.spec.ts index 9c51be1d9e8..5feb07c20cb 100644 --- a/packages/js/api/src/framework/__tests__/payload-transformer.spec.ts +++ b/packages/js/api/src/repositories/rest/orders/__tests__/order-transformer.spec.ts @@ -9,14 +9,13 @@ import { OrderCouponLine, MetaData, OrderRefundLine -} from "../../models"; +} from "../../../../models"; import { createBillingAddressTransformer, createOrderTransformer, createShippingAddressTransformer -} from "../../repositories/rest/orders/transformer"; - +} from "../transformer"; /* This Object is a JSON representation of single Order GET operation from the WooCommerce REST API. From 03614e54ae282f70013d9b274e80ae10493bee3e Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Mon, 7 Feb 2022 18:16:37 -0300 Subject: [PATCH 19/19] Tweak comment --- .../rest/orders/__tests__/order-transformer.spec.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/js/api/src/repositories/rest/orders/__tests__/order-transformer.spec.ts b/packages/js/api/src/repositories/rest/orders/__tests__/order-transformer.spec.ts index 5feb07c20cb..4700333ae53 100644 --- a/packages/js/api/src/repositories/rest/orders/__tests__/order-transformer.spec.ts +++ b/packages/js/api/src/repositories/rest/orders/__tests__/order-transformer.spec.ts @@ -20,9 +20,8 @@ import { This Object is a JSON representation of single Order GET operation from the WooCommerce REST API. Developer note: - We use JSON.stringify here to convert an Object into a String. - This is done like this because JavaScript passes Objects around by reference, - and we don't want tests to modify the original `jsonPayloadFull` variable. + We use JSON.stringify here to convert an Object into a String, as JavaScript passes Objects + around by reference, and we don't want tests to modify the original `responseOrderJson` variable. */ const responseOrderJson = JSON.stringify({ id: 1218,