Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(order): add orderFromQuoteDraft model #476

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slimy-rocks-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-test-data/order': minor
---

Adds the `OrderFromQuoteDraft` model.
4 changes: 4 additions & 0 deletions models/order/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<TOrder>();
const orderFromCartDraft =
OrderFromCartDraft.random().build<TOrderFromCartDraft>();
const orderFromQuoteDraft =
OrderFromQuoteDraft.random().build<TOrderFromQuoteDraft>();
```
73 changes: 73 additions & 0 deletions models/order/src/order-from-quote-draft/builder.spec.ts
Original file line number Diff line number Diff line change
@@ -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<TOrderFromQuoteDraft, TOrderFromQuoteDraft>(
'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<TOrderFromQuoteDraft, TOrderFromQuoteDraft>(
'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<TOrderFromQuoteDraft, TOrderFromQuoteDraftGraphql>(
'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',
}),
})
)
);
});
15 changes: 15 additions & 0 deletions models/order/src/order-from-quote-draft/builder.ts
Original file line number Diff line number Diff line change
@@ -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<TOrderFromQuoteDraft>({
generator,
transformers,
});

export default Model;
26 changes: 26 additions & 0 deletions models/order/src/order-from-quote-draft/generator.ts
Original file line number Diff line number Diff line change
@@ -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<TOrderFromQuoteDraft>({
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;
2 changes: 2 additions & 0 deletions models/order/src/order-from-quote-draft/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as random } from './builder';
export { default as presets } from './presets';
18 changes: 18 additions & 0 deletions models/order/src/order-from-quote-draft/presets/empty.spec.ts
Original file line number Diff line number Diff line change
@@ -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<TOrderFromQuoteDraft>();
expect(emptyOrderFromCartDraft).toEqual({
quote: expect.objectContaining({
typeId: 'quote',
}),
version: expect.any(Number),
quoteStateToAccepted: undefined,
orderNumber: undefined,
paymentState: undefined,
shipmentState: undefined,
orderState: undefined,
state: undefined,
});
});
13 changes: 13 additions & 0 deletions models/order/src/order-from-quote-draft/presets/empty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { TOrderFromQuoteDraftBuilder } from '../../types';
import OrderFromQuoteDraft from '../builder';

const empty = (): TOrderFromQuoteDraftBuilder =>
tylermorrisford marked this conversation as resolved.
Show resolved Hide resolved
OrderFromQuoteDraft()
.quoteStateToAccepted(undefined)
.orderNumber(undefined)
.paymentState(undefined)
.shipmentState(undefined)
.orderState(undefined)
.state(undefined);

export default empty;
5 changes: 5 additions & 0 deletions models/order/src/order-from-quote-draft/presets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import empty from './empty';

const presets = { empty };

export default presets;
22 changes: 22 additions & 0 deletions models/order/src/order-from-quote-draft/transformers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Transformer } from '@commercetools-test-data/core';
import type {
TOrderFromQuoteDraft,
TOrderFromQuoteDraftGraphql,
} from '../types';

const transformers = {
default: Transformer<TOrderFromQuoteDraft, TOrderFromQuoteDraft>('default', {
buildFields: ['quote', 'state'],
}),
rest: Transformer<TOrderFromQuoteDraft, TOrderFromQuoteDraft>('rest', {
buildFields: ['quote', 'state'],
}),
graphql: Transformer<TOrderFromQuoteDraft, TOrderFromQuoteDraftGraphql>(
'graphql',
{
buildFields: ['quote', 'state'],
}
),
};

export default transformers;
7 changes: 7 additions & 0 deletions models/order/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CustomerGroup,
Order,
OrderFromCartDraft,
OrderFromQuoteDraft,
Quote,
State,
Store,
Expand Down Expand Up @@ -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<TOrder>;
export type TOrderFromCartDraftBuilder = TBuilder<TOrderFromCartDraft>;
export type TOrderFromQuoteDraftBuilder = TBuilder<TOrderFromQuoteDraft>;

export type TCreateOrderBuilder = () => TOrderBuilder;
export type TCreateOrderFromCartDraftBuilder = () => TOrderFromCartDraftBuilder;
export type TCreateOrderFromQuoteDraftBuilder =
() => TOrderFromQuoteDraftBuilder;
Loading