-
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.
PRC-3862: Add new models for CartDiscountPatternTarget, CountOnLineIt…
…emUnits, CountOnCustomLineItemUnits (#744) * feat(cart-discount): add drafts builders * feat(cart-discount): adapt pattern target models * test(): update tests * chore(cart-discount): update package.json * chore(cart-discount): update graphql-types dependency specification * refactor(cart-discount): simplify type imports and update draft types * chore(cart-discount): move lodash types to dependencies and clean up package.json
- Loading branch information
Showing
40 changed files
with
794 additions
and
1 deletion.
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/cart-discount': minor | ||
--- | ||
|
||
Introducing the new CartDiscountPatternTarget, CountOnLineItemUnits and CountOnCustomLineItemUnitsInput models for cart discount |
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
86 changes: 86 additions & 0 deletions
86
models/cart-discount/src/cart-discount-pattern-target/builders.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,86 @@ | ||
import { | ||
CartDiscountPatternTargetRest, | ||
CartDiscountPatternTargetGraphql, | ||
} from './index'; | ||
|
||
describe('CartDiscountPatternTarget Builder', () => { | ||
it('should build properties for the REST representation', () => { | ||
const restModel = CartDiscountPatternTargetRest.random().build(); | ||
|
||
expect(restModel).toEqual( | ||
expect.objectContaining({ | ||
type: 'pattern', | ||
maxOccurrence: expect.toBeOneOf([expect.any(Number), null]), | ||
selectionMode: expect.any(String), | ||
targetPattern: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
type: expect.toBeOneOf([ | ||
'CountOnLineItemUnits', | ||
'CountOnCustomLineItemUnits', | ||
]), | ||
predicate: expect.any(String), | ||
minCount: expect.any(Number), | ||
maxCount: expect.toBeOneOf([expect.any(Number), null]), | ||
excludeCount: expect.any(Number), | ||
}), | ||
]), | ||
triggerPattern: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
type: expect.toBeOneOf([ | ||
'CountOnLineItemUnits', | ||
'CountOnCustomLineItemUnits', | ||
]), | ||
predicate: expect.any(String), | ||
minCount: expect.any(Number), | ||
maxCount: expect.toBeOneOf([expect.any(Number), null]), | ||
excludeCount: expect.any(Number), | ||
}), | ||
]), | ||
}) | ||
); | ||
}); | ||
|
||
it('should build properties for the GraphQL representation', () => { | ||
const graphqlModel = CartDiscountPatternTargetGraphql.random().build(); | ||
|
||
expect(graphqlModel).toEqual( | ||
expect.objectContaining({ | ||
__typename: 'CartDiscountPatternTarget', | ||
type: 'pattern', | ||
maxOccurrence: expect.toBeOneOf([expect.any(Number), null]), | ||
selectionMode: expect.any(String), | ||
targetPattern: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
__typename: expect.toBeOneOf([ | ||
'CountOnLineItemUnits', | ||
'CountOnCustomLineItemUnits', | ||
]), | ||
type: expect.toBeOneOf([ | ||
'CountOnLineItemUnits', | ||
'CountOnCustomLineItemUnits', | ||
]), | ||
predicate: expect.any(String), | ||
minCount: expect.any(Number), | ||
maxCount: expect.toBeOneOf([expect.any(Number), null]), | ||
excludeCount: expect.any(Number), | ||
}), | ||
]), | ||
triggerPattern: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
__typename: expect.toBeOneOf([ | ||
'CountOnLineItemUnits', | ||
'CountOnCustomLineItemUnits', | ||
]), | ||
type: expect.toBeOneOf([ | ||
'CountOnLineItemUnits', | ||
'CountOnCustomLineItemUnits', | ||
]), | ||
predicate: expect.any(String), | ||
minCount: expect.any(Number), | ||
maxCount: expect.toBeOneOf([expect.any(Number), null]), | ||
}), | ||
]), | ||
}) | ||
); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
models/cart-discount/src/cart-discount-pattern-target/builders.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,25 @@ | ||
import { createSpecializedBuilder } from '@commercetools-test-data/core'; | ||
import { restFieldsConfig, graphqlFieldsConfig } from './fields-config'; | ||
import type { | ||
TCreateCartDiscountPatternTargetBuilder, | ||
TCartDiscountPatternTargetGraphql, | ||
TCartDiscountPatternTargetRest, | ||
} from './types'; | ||
|
||
export const RestModelBuilder: TCreateCartDiscountPatternTargetBuilder< | ||
TCartDiscountPatternTargetRest | ||
> = () => | ||
createSpecializedBuilder({ | ||
name: 'CartDiscountPatternTargetRestBuilder', | ||
type: 'rest', | ||
modelFieldsConfig: restFieldsConfig, | ||
}); | ||
|
||
export const GraphqlModelBuilder: TCreateCartDiscountPatternTargetBuilder< | ||
TCartDiscountPatternTargetGraphql | ||
> = () => | ||
createSpecializedBuilder({ | ||
name: 'CartDiscountPatternTargetGraphqlBuilder', | ||
type: 'graphql', | ||
modelFieldsConfig: graphqlFieldsConfig, | ||
}); |
86 changes: 86 additions & 0 deletions
86
models/cart-discount/src/cart-discount-pattern-target/fields-config.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,86 @@ | ||
import { fake, type TModelFieldsConfig } from '@commercetools-test-data/core'; | ||
import { TCtpSelectionMode } from '@commercetools-test-data/graphql-types'; | ||
import omit from 'lodash/omit'; | ||
import { | ||
CountOnCustomLineItemUnitsGraphql, | ||
CountOnCustomLineItemUnitsRest, | ||
} from '../count-on-custom-line-item-units'; | ||
import { | ||
CountOnLineItemUnitsGraphql, | ||
CountOnLineItemUnitsRest, | ||
} from '../count-on-line-item-units'; | ||
import type { | ||
TCartDiscountPatternTargetGraphql, | ||
TCartDiscountPatternTargetRest, | ||
} from './types'; | ||
|
||
const commonFieldsConfig = { | ||
type: 'pattern', | ||
maxOccurrence: fake((f) => | ||
f.helpers.arrayElement([null, 1, f.number.int({ min: 2, max: 10 })]) | ||
), | ||
selectionMode: fake((f) => | ||
f.helpers.arrayElement(Object.values(TCtpSelectionMode)) | ||
), | ||
}; | ||
|
||
export const restFieldsConfig: TModelFieldsConfig<TCartDiscountPatternTargetRest> = | ||
{ | ||
fields: { | ||
...commonFieldsConfig, | ||
targetPattern: fake((f) => | ||
f.helpers.multiple( | ||
() => | ||
f.helpers.arrayElement([ | ||
CountOnLineItemUnitsRest.random(), | ||
CountOnCustomLineItemUnitsRest.random(), | ||
]), | ||
{ count: { min: 1, max: 8 } } | ||
) | ||
), | ||
triggerPattern: fake((f) => | ||
f.helpers.multiple( | ||
() => | ||
f.helpers.arrayElement([ | ||
CountOnLineItemUnitsRest.random(), | ||
CountOnCustomLineItemUnitsRest.random(), | ||
]), | ||
{ count: { min: 1, max: 8 } } | ||
) | ||
), | ||
}, | ||
}; | ||
|
||
export const graphqlFieldsConfig: TModelFieldsConfig<TCartDiscountPatternTargetGraphql> = | ||
{ | ||
fields: { | ||
...commonFieldsConfig, | ||
targetPattern: fake((f) => | ||
f.helpers.multiple( | ||
() => | ||
f.helpers.arrayElement([ | ||
CountOnLineItemUnitsGraphql.random(), | ||
CountOnCustomLineItemUnitsGraphql.random(), | ||
]), | ||
{ count: { min: 1, max: 8 } } | ||
) | ||
), | ||
triggerPattern: fake((f) => | ||
f.helpers.multiple( | ||
() => | ||
f.helpers.arrayElement([ | ||
CountOnLineItemUnitsGraphql.random(), | ||
CountOnCustomLineItemUnitsGraphql.random(), | ||
]), | ||
{ count: { min: 1, max: 8 } } | ||
) | ||
), | ||
__typename: 'CartDiscountPatternTarget', | ||
}, | ||
postBuild: (fields) => ({ | ||
...fields, | ||
triggerPattern: fields.triggerPattern.map((pattern) => | ||
omit(pattern, 'excludeCount') | ||
), | ||
}), | ||
}; |
14 changes: 14 additions & 0 deletions
14
models/cart-discount/src/cart-discount-pattern-target/index.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,14 @@ | ||
import { RestModelBuilder, GraphqlModelBuilder } from './builders'; | ||
import * as CartDiscountPatternTargetPresets from './presets'; | ||
export * from './src/cart-discount-pattern-target-draft'; | ||
export * from './types'; | ||
|
||
export const CartDiscountPatternTargetRest = { | ||
random: RestModelBuilder, | ||
presets: CartDiscountPatternTargetPresets.restPresets, | ||
}; | ||
|
||
export const CartDiscountPatternTargetGraphql = { | ||
random: GraphqlModelBuilder, | ||
presets: CartDiscountPatternTargetPresets.graphqlPresets, | ||
}; |
2 changes: 2 additions & 0 deletions
2
models/cart-discount/src/cart-discount-pattern-target/presets/index.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,2 @@ | ||
export const restPresets = {}; | ||
export const graphqlPresets = {}; |
30 changes: 30 additions & 0 deletions
30
.../src/cart-discount-pattern-target/src/cart-discount-pattern-target-draft/builders.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,30 @@ | ||
import { CartDiscountPatternTargetDraftGraphql } from './index'; | ||
|
||
describe('CartDiscountPatternTargetDraft Builder', () => { | ||
it('should build properties for the GraphQL representation', () => { | ||
const graphqlModel = CartDiscountPatternTargetDraftGraphql.random().build(); | ||
|
||
expect(graphqlModel).toEqual( | ||
expect.objectContaining({ | ||
maxOccurrence: expect.toBeOneOf([expect.any(Number), null]), | ||
selectionMode: expect.any(String), | ||
targetPattern: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
excludeCount: expect.any(Number), | ||
maxCount: expect.toBeOneOf([expect.any(Number), null]), | ||
minCount: expect.any(Number), | ||
predicate: expect.any(String), | ||
}), | ||
]), | ||
triggerPattern: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
excludeCount: expect.any(Number), | ||
maxCount: expect.toBeOneOf([expect.any(Number), null]), | ||
minCount: expect.any(Number), | ||
predicate: expect.any(String), | ||
}), | ||
]), | ||
}) | ||
); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
...count/src/cart-discount-pattern-target/src/cart-discount-pattern-target-draft/builders.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,15 @@ | ||
import { createSpecializedBuilder } from '@commercetools-test-data/core'; | ||
import { graphqlFieldsConfig } from './fields-config'; | ||
import type { | ||
TCreateCartDiscountPatternTargetDraftBuilder, | ||
TCartDiscountPatternTargetDraftGraphql, | ||
} from './types'; | ||
|
||
export const GraphqlModelBuilder: TCreateCartDiscountPatternTargetDraftBuilder< | ||
TCartDiscountPatternTargetDraftGraphql | ||
> = () => | ||
createSpecializedBuilder({ | ||
name: 'CartDiscountPatternTargetDraftGraphqlBuilder', | ||
type: 'graphql', | ||
modelFieldsConfig: graphqlFieldsConfig, | ||
}); |
38 changes: 38 additions & 0 deletions
38
.../src/cart-discount-pattern-target/src/cart-discount-pattern-target-draft/fields-config.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,38 @@ | ||
import { fake, type TModelFieldsConfig } from '@commercetools-test-data/core'; | ||
import { TCtpSelectionMode } from '@commercetools-test-data/graphql-types'; | ||
import { CountOnCustomLineItemUnitsDraftGraphql } from '../../../count-on-custom-line-item-units'; | ||
import { CountOnLineItemUnitsDraftGraphql } from '../../../count-on-line-item-units'; | ||
|
||
import type { TCartDiscountPatternTargetDraftGraphql } from './types'; | ||
|
||
export const graphqlFieldsConfig: TModelFieldsConfig<TCartDiscountPatternTargetDraftGraphql> = | ||
{ | ||
fields: { | ||
maxOccurrence: fake((f) => | ||
f.helpers.arrayElement([null, 1, f.number.int({ min: 2, max: 10 })]) | ||
), | ||
selectionMode: fake((f) => | ||
f.helpers.arrayElement(Object.values(TCtpSelectionMode)) | ||
), | ||
targetPattern: fake((f) => | ||
f.helpers.multiple( | ||
() => | ||
f.helpers.arrayElement([ | ||
CountOnLineItemUnitsDraftGraphql.random(), | ||
CountOnCustomLineItemUnitsDraftGraphql.random(), | ||
]), | ||
{ count: { min: 1, max: 8 } } | ||
) | ||
), | ||
triggerPattern: fake((f) => | ||
f.helpers.multiple( | ||
() => | ||
f.helpers.arrayElement([ | ||
CountOnLineItemUnitsDraftGraphql.random(), | ||
CountOnCustomLineItemUnitsDraftGraphql.random(), | ||
]), | ||
{ count: { min: 1, max: 8 } } | ||
) | ||
), | ||
}, | ||
}; |
7 changes: 7 additions & 0 deletions
7
...discount/src/cart-discount-pattern-target/src/cart-discount-pattern-target-draft/index.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,7 @@ | ||
import { GraphqlModelBuilder } from './builders'; | ||
import * as CartDiscountPatternTargetDraftPresets from './presets'; | ||
|
||
export const CartDiscountPatternTargetDraftGraphql = { | ||
random: GraphqlModelBuilder, | ||
presets: CartDiscountPatternTargetDraftPresets.graphqlPresets, | ||
}; |
2 changes: 2 additions & 0 deletions
2
.../src/cart-discount-pattern-target/src/cart-discount-pattern-target-draft/presets/index.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,2 @@ | ||
export const restPresets = {}; | ||
export const graphqlPresets = {}; |
9 changes: 9 additions & 0 deletions
9
...discount/src/cart-discount-pattern-target/src/cart-discount-pattern-target-draft/types.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,9 @@ | ||
import type { TBuilder } from '@commercetools-test-data/core'; | ||
import { TCtpCartDiscountPatternTargetInput } from '@commercetools-test-data/graphql-types'; | ||
|
||
export type TCartDiscountPatternTargetDraftGraphql = | ||
TCtpCartDiscountPatternTargetInput; | ||
|
||
export type TCreateCartDiscountPatternTargetDraftBuilder< | ||
TModel extends TCartDiscountPatternTargetDraftGraphql, | ||
> = () => TBuilder<TModel>; |
18 changes: 18 additions & 0 deletions
18
models/cart-discount/src/cart-discount-pattern-target/types.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 { CartDiscountPatternTarget } from '@commercetools/platform-sdk'; | ||
import type { TBuilder } from '@commercetools-test-data/core'; | ||
import { | ||
TCtpCartDiscountPatternTarget, | ||
TCtpCartDiscountPatternTargetInput, | ||
} from '@commercetools-test-data/graphql-types'; | ||
|
||
export type TCartDiscountPatternTargetRest = CartDiscountPatternTarget; | ||
export type TCartDiscountPatternTargetGraphql = TCtpCartDiscountPatternTarget; | ||
export type TCartDiscountPatternTargetDraftGraphql = | ||
TCtpCartDiscountPatternTargetInput; | ||
|
||
export type TCreateCartDiscountPatternTargetBuilder< | ||
TModel extends | ||
| TCartDiscountPatternTargetRest | ||
| TCartDiscountPatternTargetGraphql | ||
| TCartDiscountPatternTargetDraftGraphql, | ||
> = () => TBuilder<TModel>; |
35 changes: 35 additions & 0 deletions
35
models/cart-discount/src/count-on-custom-line-item-units/builders.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,35 @@ | ||
import { | ||
CountOnCustomLineItemUnitsRest, | ||
CountOnCustomLineItemUnitsGraphql, | ||
} from './index'; | ||
|
||
describe('CountOnCustomLineItemUnits Builder', () => { | ||
it('should build properties for the REST representation', () => { | ||
const restModel = CountOnCustomLineItemUnitsRest.random().build(); | ||
|
||
expect(restModel).toEqual( | ||
expect.objectContaining({ | ||
type: 'CountOnCustomLineItemUnits', | ||
predicate: expect.any(String), | ||
minCount: expect.any(Number), | ||
maxCount: expect.toBeOneOf([expect.any(Number), null]), | ||
excludeCount: expect.any(Number), | ||
}) | ||
); | ||
}); | ||
|
||
it('should build properties for the GraphQL representation', () => { | ||
const graphqlModel = CountOnCustomLineItemUnitsGraphql.random().build(); | ||
|
||
expect(graphqlModel).toEqual( | ||
expect.objectContaining({ | ||
__typename: 'CountOnCustomLineItemUnits', | ||
type: 'CountOnCustomLineItemUnits', | ||
predicate: expect.any(String), | ||
minCount: expect.any(Number), | ||
maxCount: expect.toBeOneOf([expect.any(Number), null]), | ||
excludeCount: expect.any(Number), | ||
}) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.