-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(order): add orderFromQuoteDraft model (#476)
* feat(order): add orderFromQuoteDraft model * feat(order): add changeset * fix(order): prefer faker over a default generator value * fix(order): fix test * fix(order-from-quote-draft): prefer new workflow sans typename
- Loading branch information
1 parent
e76ae3a
commit c191608
Showing
11 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@commercetools-test-data/order': minor | ||
--- | ||
|
||
Adds the `OrderFromQuoteDraft` model. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}), | ||
}) | ||
) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
models/order/src/order-from-quote-draft/presets/empty.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => | ||
OrderFromQuoteDraft() | ||
.quoteStateToAccepted(undefined) | ||
.orderNumber(undefined) | ||
.paymentState(undefined) | ||
.shipmentState(undefined) | ||
.orderState(undefined) | ||
.state(undefined); | ||
|
||
export default empty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import empty from './empty'; | ||
|
||
const presets = { empty }; | ||
|
||
export default presets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters