From 67d41047ef79c1a6d422a7700977edca94c193dd Mon Sep 17 00:00:00 2001 From: Tyler Ford Date: Tue, 6 Feb 2024 12:09:35 -0700 Subject: [PATCH 1/5] feat(order): add orderFromQuoteDraft model --- models/order/README.md | 4 + .../order-from-quote-draft/builder.spec.ts | 75 +++++++++++++++++++ .../src/order-from-quote-draft/builder.ts | 15 ++++ .../src/order-from-quote-draft/generator.ts | 26 +++++++ .../order/src/order-from-quote-draft/index.ts | 2 + .../presets/empty.spec.ts | 18 +++++ .../order-from-quote-draft/presets/empty.ts | 13 ++++ .../order-from-quote-draft/presets/index.ts | 5 ++ .../order-from-quote-draft/transformers.ts | 22 ++++++ models/order/src/types.ts | 7 ++ 10 files changed, 187 insertions(+) create mode 100644 models/order/src/order-from-quote-draft/builder.spec.ts create mode 100644 models/order/src/order-from-quote-draft/builder.ts create mode 100644 models/order/src/order-from-quote-draft/generator.ts create mode 100644 models/order/src/order-from-quote-draft/index.ts create mode 100644 models/order/src/order-from-quote-draft/presets/empty.spec.ts create mode 100644 models/order/src/order-from-quote-draft/presets/empty.ts create mode 100644 models/order/src/order-from-quote-draft/presets/index.ts create mode 100644 models/order/src/order-from-quote-draft/transformers.ts diff --git a/models/order/README.md b/models/order/README.md index 5e23be468..9b6485038 100644 --- a/models/order/README.md +++ b/models/order/README.md @@ -16,11 +16,15 @@ $ pnpm add -D @commercetools-test-data/order import { Order, OrderFromCartDraft, + OrderFromQuoteDraft, type TOrder, type TOrderFromCartDraft, + type TOrderFromQuoteDraft, } from '@commercetools-test-data/order'; const order = Order.random().build(); const orderFromCartDraft = OrderFromCartDraft.random().build(); +const orderFromQuoteDraft = + OrderFromQuoteDraft.random().build(); ``` diff --git a/models/order/src/order-from-quote-draft/builder.spec.ts b/models/order/src/order-from-quote-draft/builder.spec.ts new file mode 100644 index 000000000..75f214f17 --- /dev/null +++ b/models/order/src/order-from-quote-draft/builder.spec.ts @@ -0,0 +1,75 @@ +/* eslint-disable jest/no-disabled-tests */ +/* eslint-disable jest/valid-title */ +import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; +import type { + TOrderFromQuoteDraft, + TOrderFromQuoteDraftGraphql, +} from '../types'; +import * as OrderFromQuoteDraftDraft from '.'; + +describe('builder', () => { + it( + ...createBuilderSpec( + 'default', + OrderFromQuoteDraftDraft.random(), + expect.objectContaining({ + version: expect.any(Number), + quote: expect.objectContaining({ + typeId: 'quote', + }), + quoteStateToAccepted: false, + orderNumber: expect.any(String), + paymentState: expect.any(String), + shipmentState: expect.any(String), + orderState: expect.any(String), + state: expect.objectContaining({ + typeId: 'state', + }), + }) + ) + ); + + it( + ...createBuilderSpec( + 'rest', + OrderFromQuoteDraftDraft.random(), + expect.objectContaining({ + version: expect.any(Number), + quote: expect.objectContaining({ + typeId: 'quote', + }), + quoteStateToAccepted: false, + orderNumber: expect.any(String), + paymentState: expect.any(String), + shipmentState: expect.any(String), + orderState: expect.any(String), + state: expect.objectContaining({ + typeId: 'state', + }), + }) + ) + ); + + it( + ...createBuilderSpec( + 'graphql', + OrderFromQuoteDraftDraft.random(), + expect.objectContaining({ + version: expect.any(Number), + quote: expect.objectContaining({ + typeId: 'quote', + __typename: 'Reference', + }), + quoteStateToAccepted: false, + orderNumber: expect.any(String), + paymentState: expect.any(String), + shipmentState: expect.any(String), + orderState: expect.any(String), + state: expect.objectContaining({ + typeId: 'state', + __typename: 'Reference', + }), + }) + ) + ); +}); diff --git a/models/order/src/order-from-quote-draft/builder.ts b/models/order/src/order-from-quote-draft/builder.ts new file mode 100644 index 000000000..41caa3a40 --- /dev/null +++ b/models/order/src/order-from-quote-draft/builder.ts @@ -0,0 +1,15 @@ +import { Builder } from '@commercetools-test-data/core'; +import type { + TOrderFromQuoteDraft, + TCreateOrderFromQuoteDraftBuilder, +} from '../types'; +import generator from './generator'; +import transformers from './transformers'; + +const Model: TCreateOrderFromQuoteDraftBuilder = () => + Builder({ + generator, + transformers, + }); + +export default Model; diff --git a/models/order/src/order-from-quote-draft/generator.ts b/models/order/src/order-from-quote-draft/generator.ts new file mode 100644 index 000000000..d7528df44 --- /dev/null +++ b/models/order/src/order-from-quote-draft/generator.ts @@ -0,0 +1,26 @@ +import { Reference } from '@commercetools-test-data/commons'; +import { + fake, + Generator, + oneOf, + sequence, +} from '@commercetools-test-data/core'; +import { orderState, paymentState, shipmentState } from '../constants'; +import { TOrderFromQuoteDraft } from '../types'; + +// https://docs.commercetools.com/api/projects/orders#orderfromquotedraft + +const generator = Generator({ + fields: { + version: sequence(), + quote: fake(() => Reference.random().typeId('quote')), + quoteStateToAccepted: fake(() => false), + orderNumber: fake((f) => String(f.number.int({ min: 100000 }))), + paymentState: oneOf(...Object.values(paymentState)), + shipmentState: oneOf(...Object.values(shipmentState)), + orderState: oneOf(...Object.values(orderState)), + state: fake(() => Reference.random().typeId('state')), + }, +}); + +export default generator; diff --git a/models/order/src/order-from-quote-draft/index.ts b/models/order/src/order-from-quote-draft/index.ts new file mode 100644 index 000000000..96e2519e1 --- /dev/null +++ b/models/order/src/order-from-quote-draft/index.ts @@ -0,0 +1,2 @@ +export { default as random } from './builder'; +export { default as presets } from './presets'; diff --git a/models/order/src/order-from-quote-draft/presets/empty.spec.ts b/models/order/src/order-from-quote-draft/presets/empty.spec.ts new file mode 100644 index 000000000..26de2b68e --- /dev/null +++ b/models/order/src/order-from-quote-draft/presets/empty.spec.ts @@ -0,0 +1,18 @@ +import type { TOrderFromQuoteDraft } from '../../types'; +import empty from './empty'; + +it(`should set the specified fields to undefined`, () => { + const emptyOrderFromCartDraft = empty().build(); + expect(emptyOrderFromCartDraft).toEqual({ + quote: expect.objectContaining({ + typeId: 'quote', + }), + version: expect.any(Number), + quoteStateToAccepted: undefined, + orderNumber: undefined, + paymentState: undefined, + shipmentState: undefined, + orderState: undefined, + state: undefined, + }); +}); diff --git a/models/order/src/order-from-quote-draft/presets/empty.ts b/models/order/src/order-from-quote-draft/presets/empty.ts new file mode 100644 index 000000000..7c657452b --- /dev/null +++ b/models/order/src/order-from-quote-draft/presets/empty.ts @@ -0,0 +1,13 @@ +import type { TOrderFromQuoteDraftBuilder } from '../../types'; +import OrderFromQuoteDraft from '../builder'; + +const empty = (): TOrderFromQuoteDraftBuilder => + OrderFromQuoteDraft() + .quoteStateToAccepted(undefined) + .orderNumber(undefined) + .paymentState(undefined) + .shipmentState(undefined) + .orderState(undefined) + .state(undefined); + +export default empty; diff --git a/models/order/src/order-from-quote-draft/presets/index.ts b/models/order/src/order-from-quote-draft/presets/index.ts new file mode 100644 index 000000000..10a4586b4 --- /dev/null +++ b/models/order/src/order-from-quote-draft/presets/index.ts @@ -0,0 +1,5 @@ +import empty from './empty'; + +const presets = { empty }; + +export default presets; diff --git a/models/order/src/order-from-quote-draft/transformers.ts b/models/order/src/order-from-quote-draft/transformers.ts new file mode 100644 index 000000000..bd074a680 --- /dev/null +++ b/models/order/src/order-from-quote-draft/transformers.ts @@ -0,0 +1,22 @@ +import { Transformer } from '@commercetools-test-data/core'; +import type { + TOrderFromQuoteDraft, + TOrderFromQuoteDraftGraphql, +} from '../types'; + +const transformers = { + default: Transformer('default', { + buildFields: ['quote', 'state'], + }), + rest: Transformer('rest', { + buildFields: ['quote', 'state'], + }), + graphql: Transformer( + 'graphql', + { + buildFields: ['quote', 'state'], + } + ), +}; + +export default transformers; diff --git a/models/order/src/types.ts b/models/order/src/types.ts index 728743f5c..5c360ad3f 100644 --- a/models/order/src/types.ts +++ b/models/order/src/types.ts @@ -5,6 +5,7 @@ import { CustomerGroup, Order, OrderFromCartDraft, + OrderFromQuoteDraft, Quote, State, Store, @@ -45,10 +46,16 @@ export type TOrderGraphql = TOrder & { }; export type TOrderFromCartDraft = OrderFromCartDraft; +export type TOrderFromQuoteDraft = OrderFromQuoteDraft; export type TOrderFromCartDraftGraphql = TOrderFromCartDraft; +export type TOrderFromQuoteDraftGraphql = TOrderFromQuoteDraft; export type TOrderBuilder = TBuilder; export type TOrderFromCartDraftBuilder = TBuilder; +export type TOrderFromQuoteDraftBuilder = TBuilder; + export type TCreateOrderBuilder = () => TOrderBuilder; export type TCreateOrderFromCartDraftBuilder = () => TOrderFromCartDraftBuilder; +export type TCreateOrderFromQuoteDraftBuilder = + () => TOrderFromQuoteDraftBuilder; From ad3e19d3f6833e832ce76b626f4f2bb0bee1be04 Mon Sep 17 00:00:00 2001 From: Tyler Ford Date: Tue, 6 Feb 2024 12:20:47 -0700 Subject: [PATCH 2/5] feat(order): add changeset --- .changeset/slimy-rocks-refuse.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/slimy-rocks-refuse.md diff --git a/.changeset/slimy-rocks-refuse.md b/.changeset/slimy-rocks-refuse.md new file mode 100644 index 000000000..e0d3017b4 --- /dev/null +++ b/.changeset/slimy-rocks-refuse.md @@ -0,0 +1,5 @@ +--- +'@commercetools-test-data/order': minor +--- + +Adds the `OrderFromQuoteDraft` model. From 96fb3c35aad6e710d9aa728572075d7058962e95 Mon Sep 17 00:00:00 2001 From: Tyler Ford Date: Tue, 6 Feb 2024 14:50:29 -0700 Subject: [PATCH 3/5] fix(order): prefer faker over a default generator value --- models/order/src/order-from-quote-draft/generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/order/src/order-from-quote-draft/generator.ts b/models/order/src/order-from-quote-draft/generator.ts index d7528df44..b36b19476 100644 --- a/models/order/src/order-from-quote-draft/generator.ts +++ b/models/order/src/order-from-quote-draft/generator.ts @@ -14,7 +14,7 @@ const generator = Generator({ fields: { version: sequence(), quote: fake(() => Reference.random().typeId('quote')), - quoteStateToAccepted: fake(() => false), + quoteStateToAccepted: fake((f) => f.datatype.boolean()), orderNumber: fake((f) => String(f.number.int({ min: 100000 }))), paymentState: oneOf(...Object.values(paymentState)), shipmentState: oneOf(...Object.values(shipmentState)), From 0ae3171b54116bc760c733fecbbf12162364e8ee Mon Sep 17 00:00:00 2001 From: Tyler Ford Date: Tue, 6 Feb 2024 15:09:49 -0700 Subject: [PATCH 4/5] fix(order): fix test --- models/order/src/order-from-quote-draft/builder.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/order/src/order-from-quote-draft/builder.spec.ts b/models/order/src/order-from-quote-draft/builder.spec.ts index 75f214f17..748095f2a 100644 --- a/models/order/src/order-from-quote-draft/builder.spec.ts +++ b/models/order/src/order-from-quote-draft/builder.spec.ts @@ -17,7 +17,7 @@ describe('builder', () => { quote: expect.objectContaining({ typeId: 'quote', }), - quoteStateToAccepted: false, + quoteStateToAccepted: expect.any(Boolean), orderNumber: expect.any(String), paymentState: expect.any(String), shipmentState: expect.any(String), @@ -38,7 +38,7 @@ describe('builder', () => { quote: expect.objectContaining({ typeId: 'quote', }), - quoteStateToAccepted: false, + quoteStateToAccepted: expect.any(Boolean), orderNumber: expect.any(String), paymentState: expect.any(String), shipmentState: expect.any(String), @@ -60,7 +60,7 @@ describe('builder', () => { typeId: 'quote', __typename: 'Reference', }), - quoteStateToAccepted: false, + quoteStateToAccepted: expect.any(Boolean), orderNumber: expect.any(String), paymentState: expect.any(String), shipmentState: expect.any(String), From 17c8c4f1be6410fc876360049a197de370909bdb Mon Sep 17 00:00:00 2001 From: Tyler Ford Date: Mon, 12 Feb 2024 12:48:45 -0700 Subject: [PATCH 5/5] fix(order-from-quote-draft): prefer new workflow sans typename --- models/order/src/order-from-quote-draft/builder.spec.ts | 2 -- models/order/src/order-from-quote-draft/generator.ts | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/models/order/src/order-from-quote-draft/builder.spec.ts b/models/order/src/order-from-quote-draft/builder.spec.ts index 748095f2a..fa71722fe 100644 --- a/models/order/src/order-from-quote-draft/builder.spec.ts +++ b/models/order/src/order-from-quote-draft/builder.spec.ts @@ -58,7 +58,6 @@ describe('builder', () => { version: expect.any(Number), quote: expect.objectContaining({ typeId: 'quote', - __typename: 'Reference', }), quoteStateToAccepted: expect.any(Boolean), orderNumber: expect.any(String), @@ -67,7 +66,6 @@ describe('builder', () => { orderState: expect.any(String), state: expect.objectContaining({ typeId: 'state', - __typename: 'Reference', }), }) ) diff --git a/models/order/src/order-from-quote-draft/generator.ts b/models/order/src/order-from-quote-draft/generator.ts index b36b19476..02b8ef288 100644 --- a/models/order/src/order-from-quote-draft/generator.ts +++ b/models/order/src/order-from-quote-draft/generator.ts @@ -1,4 +1,4 @@ -import { Reference } from '@commercetools-test-data/commons'; +import { ReferenceDraft } from '@commercetools-test-data/commons'; import { fake, Generator, @@ -13,13 +13,13 @@ import { TOrderFromQuoteDraft } from '../types'; const generator = Generator({ fields: { version: sequence(), - quote: fake(() => Reference.random().typeId('quote')), + quote: fake(() => ReferenceDraft.random().typeId('quote')), quoteStateToAccepted: fake((f) => f.datatype.boolean()), orderNumber: fake((f) => String(f.number.int({ min: 100000 }))), paymentState: oneOf(...Object.values(paymentState)), shipmentState: oneOf(...Object.values(shipmentState)), orderState: oneOf(...Object.values(orderState)), - state: fake(() => Reference.random().typeId('state')), + state: fake(() => ReferenceDraft.random().typeId('state')), }, });