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. 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..fa71722fe --- /dev/null +++ b/models/order/src/order-from-quote-draft/builder.spec.ts @@ -0,0 +1,73 @@ +/* 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: expect.any(Boolean), + 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: expect.any(Boolean), + 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', + }), + quoteStateToAccepted: expect.any(Boolean), + orderNumber: expect.any(String), + paymentState: expect.any(String), + shipmentState: expect.any(String), + orderState: expect.any(String), + state: expect.objectContaining({ + typeId: 'state', + }), + }) + ) + ); +}); 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..02b8ef288 --- /dev/null +++ b/models/order/src/order-from-quote-draft/generator.ts @@ -0,0 +1,26 @@ +import { ReferenceDraft } 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(() => 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(() => ReferenceDraft.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;