-
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(cart): added shipping-info child model * feat(commons): new dicounted line models * refactor(cart): add new children models * refactor(tax-category): add missing preset * fix(cart): adjust child models * fix(common): fix discounted-line-item-portion model * refactor(commons): docs improved * ci: changesets added
- Loading branch information
1 parent
f3dfbaf
commit 3afc6db
Showing
55 changed files
with
1,195 additions
and
3 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/tax-category': minor | ||
--- | ||
|
||
Added a new preset called `withAllFields` to the 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,9 @@ | ||
--- | ||
'@commercetools-test-data/cart': minor | ||
--- | ||
|
||
Added new child models used within the `Cart` one: | ||
|
||
- `TaxedItemPrice` | ||
- `TaxPortion` | ||
- `ShippingInfo` |
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 @@ | ||
--- | ||
'@commercetools-test-data/commons': minor | ||
--- | ||
|
||
Added three new test data models: | ||
|
||
- `DicountedLineItemPortion` | ||
- `DicountedLineItemPortionDraft` | ||
- `DiscountedLitemItemPrice` |
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
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,57 @@ | ||
import { ShippingInfoRest, ShippingInfoGraphql } from './index'; | ||
|
||
describe('ShippingInfo Builder', () => { | ||
it('should build properties for the REST representation', () => { | ||
const restModel = ShippingInfoRest.random().build(); | ||
|
||
expect(restModel).toEqual( | ||
expect.objectContaining({ | ||
deliveries: [], | ||
discountedPrice: null, | ||
price: expect.objectContaining({ | ||
type: 'centPrecision', | ||
}), | ||
shippingMethod: null, | ||
shippingMethodName: expect.any(String), | ||
shippingMethodState: expect.stringMatching( | ||
/DoesNotMatchCart|MatchesCart/ | ||
), | ||
shippingRate: expect.objectContaining({ | ||
price: expect.objectContaining({ | ||
type: 'centPrecision', | ||
}), | ||
}), | ||
taxCategory: null, | ||
taxRate: null, | ||
taxedPrice: null, | ||
}) | ||
); | ||
}); | ||
it('should build properties for the GraphQL representation', () => { | ||
const graphqlModel = ShippingInfoGraphql.random().build(); | ||
|
||
expect(graphqlModel).toEqual( | ||
expect.objectContaining({ | ||
deliveries: [], | ||
discountedPrice: null, | ||
price: expect.objectContaining({ | ||
__typename: 'Money', | ||
}), | ||
shippingMethod: null, | ||
shippingMethodName: expect.any(String), | ||
shippingMethodState: expect.stringMatching( | ||
/DoesNotMatchCart|MatchesCart/ | ||
), | ||
shippingRate: expect.objectContaining({ | ||
__typename: 'ShippingRate', | ||
}), | ||
taxCategory: null, | ||
taxRate: null, | ||
taxedPrice: null, | ||
shippingMethodRef: null, | ||
taxCategoryRef: null, | ||
__typename: 'ShippingInfo', | ||
}) | ||
); | ||
}); | ||
}); |
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 { | ||
TCreateShippingInfoBuilder, | ||
TShippingInfoGraphql, | ||
TShippingInfoRest, | ||
} from './types'; | ||
|
||
export const RestModelBuilder: TCreateShippingInfoBuilder< | ||
TShippingInfoRest | ||
> = () => | ||
createSpecializedBuilder({ | ||
name: 'ShippingInfoRestBuilder', | ||
type: 'rest', | ||
modelFieldsConfig: restFieldsConfig, | ||
}); | ||
|
||
export const GraphqlModelBuilder: TCreateShippingInfoBuilder< | ||
TShippingInfoGraphql | ||
> = () => | ||
createSpecializedBuilder({ | ||
name: 'ShippingInfoGraphqlBuilder', | ||
type: 'graphql', | ||
modelFieldsConfig: graphqlFieldsConfig, | ||
}); |
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,47 @@ | ||
import { | ||
CentPrecisionMoney, | ||
Reference, | ||
} from '@commercetools-test-data/commons'; | ||
import { fake, type TModelFieldsConfig } from '@commercetools-test-data/core'; | ||
import { ShippingRate } from '@commercetools-test-data/shipping-method'; | ||
import type { TShippingInfoGraphql, TShippingInfoRest } from './types'; | ||
|
||
const commonFieldsConfig = { | ||
deliveries: [], | ||
discountedPrice: null, | ||
price: fake(() => CentPrecisionMoney.random()), | ||
shippingMethod: null, | ||
shippingMethodName: fake((f) => f.lorem.words(2)), | ||
shippingMethodState: fake((f) => | ||
f.helpers.arrayElement(['DoesNotMatchCart', 'MatchesCart']) | ||
), | ||
shippingRate: fake(() => ShippingRate.random()), | ||
taxCategory: null, | ||
taxRate: null, | ||
taxedPrice: null, | ||
}; | ||
|
||
export const restFieldsConfig: TModelFieldsConfig<TShippingInfoRest> = { | ||
fields: { | ||
...commonFieldsConfig, | ||
}, | ||
}; | ||
|
||
export const graphqlFieldsConfig: TModelFieldsConfig<TShippingInfoGraphql> = { | ||
fields: { | ||
...commonFieldsConfig, | ||
shippingMethodRef: null, | ||
taxCategoryRef: null, | ||
__typename: 'ShippingInfo', | ||
}, | ||
postBuild: (model) => { | ||
return { | ||
shippingMethodRef: model.shippingMethod | ||
? Reference.presets | ||
.shippingMethodReference() | ||
.id(model.shippingMethod.id) | ||
.buildGraphql() | ||
: model.shippingMethodRef, | ||
}; | ||
}, | ||
}; |
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 { RestModelBuilder, GraphqlModelBuilder } from './builders'; | ||
import * as ShippingInfoPresets from './presets'; | ||
export * from './types'; | ||
|
||
export const ShippingInfoRest = { | ||
random: RestModelBuilder, | ||
presets: ShippingInfoPresets.restPresets, | ||
}; | ||
|
||
export const ShippingInfoGraphql = { | ||
random: GraphqlModelBuilder, | ||
presets: ShippingInfoPresets.graphqlPresets, | ||
}; |
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 = {}; |
77 changes: 77 additions & 0 deletions
77
models/cart/src/shipping-info/presets/with-all-fields/with-all-fields-presets.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,77 @@ | ||
import * as withAllPresets from './with-all-fields-presets'; | ||
|
||
describe('with all fields', () => { | ||
it(`should create the expected object preset - rest`, () => { | ||
const restExamplePreset = withAllPresets.restPreset().build(); | ||
|
||
expect(restExamplePreset).toEqual( | ||
expect.objectContaining({ | ||
deliveries: expect.any(Array), | ||
price: expect.objectContaining({ | ||
currencyCode: 'EUR', | ||
}), | ||
shippingMethod: expect.objectContaining({ | ||
typeId: 'shipping-method', | ||
}), | ||
shippingMethodName: 'shipping-method-name', | ||
shippingRate: expect.objectContaining({ | ||
price: expect.objectContaining({ | ||
currencyCode: expect.any(String), | ||
}), | ||
}), | ||
taxCategory: expect.objectContaining({ | ||
typeId: 'tax-category', | ||
}), | ||
taxRate: expect.objectContaining({ | ||
id: expect.any(String), | ||
name: expect.any(String), | ||
amount: expect.any(Number), | ||
}), | ||
taxedPrice: expect.objectContaining({ | ||
totalNet: expect.objectContaining({ | ||
currencyCode: 'EUR', | ||
}), | ||
totalGross: expect.objectContaining({ | ||
currencyCode: 'EUR', | ||
}), | ||
totalTax: expect.objectContaining({ | ||
currencyCode: 'EUR', | ||
}), | ||
taxPortions: expect.any(Array), | ||
}), | ||
}) | ||
); | ||
}); | ||
|
||
it(`should create the expected object preset - graphql`, () => { | ||
const graphqlExamplePreset = withAllPresets.graphqlPreset().build(); | ||
|
||
expect(graphqlExamplePreset).toEqual( | ||
expect.objectContaining({ | ||
deliveries: expect.any(Array), | ||
price: expect.objectContaining({ | ||
currencyCode: 'EUR', | ||
__typename: 'Money', | ||
}), | ||
shippingMethod: expect.objectContaining({ | ||
__typename: 'ShippingMethod', | ||
}), | ||
shippingMethodRef: expect.objectContaining({ | ||
typeId: 'shipping-method', | ||
__typename: 'Reference', | ||
}), | ||
shippingMethodName: 'shipping-method-name', | ||
shippingRate: expect.objectContaining({ | ||
__typename: 'ShippingRate', | ||
}), | ||
taxCategory: expect.objectContaining({ | ||
typeId: 'tax-category', | ||
}), | ||
taxRate: expect.objectContaining({ | ||
__typename: 'TaxRate', | ||
}), | ||
__typename: 'ShippingInfo', | ||
}) | ||
); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
models/cart/src/shipping-info/presets/with-all-fields/with-all-fields-presets.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,34 @@ | ||
import { Money, Reference } from '@commercetools-test-data/commons'; | ||
import type { TBuilder } from '@commercetools-test-data/core'; | ||
import { | ||
ShippingMethod, | ||
ShippingRate, | ||
} from '@commercetools-test-data/shipping-method'; | ||
import { TaxRate } from '@commercetools-test-data/tax-category'; | ||
import { | ||
TaxedItemPriceGraphql, | ||
TaxedItemPriceRest, | ||
} from '../../../taxed-item-price'; | ||
import { ShippingInfoGraphql, ShippingInfoRest } from '../../index'; | ||
import { TShippingInfoGraphql, TShippingInfoRest } from '../../types'; | ||
|
||
const populatePreset = <T extends TShippingInfoRest | TShippingInfoGraphql>( | ||
builder: TBuilder<T> | ||
): TBuilder<T> => | ||
builder | ||
.deliveries([]) | ||
.price(Money.presets.withCurrency('EUR')) | ||
.shippingMethodName('shipping-method-name') | ||
.shippingRate(ShippingRate.random()) | ||
.taxCategory(Reference.presets.taxCategoryReference()) | ||
.taxRate(TaxRate.presets.withAllFields()); | ||
|
||
export const restPreset = (): TBuilder<TShippingInfoRest> => | ||
populatePreset(ShippingInfoRest.random()) | ||
.shippingMethod(Reference.presets.shippingMethodReference()) | ||
.taxedPrice(TaxedItemPriceRest.presets.withAllFields()); | ||
|
||
export const graphqlPreset = (): TBuilder<TShippingInfoGraphql> => | ||
populatePreset(ShippingInfoGraphql.random()) | ||
.shippingMethod(ShippingMethod.random()) | ||
.taxedPrice(TaxedItemPriceGraphql.presets.withAllFields()); |
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,11 @@ | ||
import { ShippingInfo } from '@commercetools/platform-sdk'; | ||
import type { TBuilder } from '@commercetools-test-data/core'; | ||
import { TCtpShippingInfo } from '@commercetools-test-data/graphql-types'; | ||
|
||
export type TShippingInfoRest = ShippingInfo; | ||
|
||
export type TShippingInfoGraphql = TCtpShippingInfo; | ||
|
||
export type TCreateShippingInfoBuilder< | ||
TModel extends TShippingInfoRest | TShippingInfoGraphql, | ||
> = () => TBuilder<TModel>; |
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 { TaxPortionRest, TaxPortionGraphql } from './index'; | ||
|
||
describe('TaxPortion Builder', () => { | ||
it('should build properties for the REST representation', () => { | ||
const restModel = TaxPortionRest.random().build(); | ||
|
||
expect(restModel).toEqual( | ||
expect.objectContaining({ | ||
name: null, | ||
rate: expect.any(Number), | ||
amount: expect.objectContaining({ | ||
currencyCode: expect.any(String), | ||
centAmount: expect.any(Number), | ||
}), | ||
}) | ||
); | ||
}); | ||
|
||
it('should build properties for the GraphQL representation', () => { | ||
const graphqlModel = TaxPortionGraphql.random().build(); | ||
|
||
expect(graphqlModel).toEqual( | ||
expect.objectContaining({ | ||
name: null, | ||
rate: expect.any(Number), | ||
amount: expect.objectContaining({ | ||
currencyCode: expect.any(String), | ||
centAmount: expect.any(Number), | ||
__typename: 'Money', | ||
}), | ||
__typename: 'TaxPortion', | ||
}) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.