Skip to content

Commit

Permalink
feat(test-data): create StandalonePrice model and associated draft (#…
Browse files Browse the repository at this point in the history
…472)

* chore(test-data): create standalone prices model with draft

* chore(test-data): generate changeset

* chore(test-data): revise package version

* chore(test-data): add pricess team as codeowner

* chore(test-data): remove duplicated field type

* chore(test-data): test public api for model
  • Loading branch information
jaikamat authored Feb 6, 2024
1 parent 445b03e commit f027639
Show file tree
Hide file tree
Showing 39 changed files with 1,809 additions and 22 deletions.
7 changes: 7 additions & 0 deletions .changeset/fuzzy-cats-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@commercetools-test-data/standalone-price': minor
'@commercetools-test-data/commons': minor
'@commercetools-test-data/graphql-types': minor
---

Create standalone prices model and associated draft, support channel key reference preset
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
/models/shipping-method @commercetools/checkout-team-fe
/models/shopping-list @commercetools/checkout-team-fe
/models/staged-quote @commercetools/customers-team-fe
/models/standalone-price @commercetools/priceless-team-fe
/models/store @commercetools/context-team-fe
/models/tax-category @commercetools/checkout-team-fe
/models/zone @commercetools/checkout-team-fe
Expand Down
77 changes: 77 additions & 0 deletions graphql-types/src/generated/settings.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions models/commons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ $ pnpm add -D @commercetools-test-data/commons
- [Money](#money)<br>
- [Price](#price)<br>
- [Reference](#reference)<br>
- [PriceTier](#pricetier)<br>

## `Address`

Expand Down Expand Up @@ -124,3 +125,14 @@ const categoryRef = Reference.presets
.category()
.build<TReference<'category'>>();
```

## `PriceTier`

```ts
import { PriceTier, type TPriceTier } from '@commercetools-test-data/commons';

const productRef = PriceTier.random().build<TPriceTier>();

// Presets
const categoryRef = PriceTier.presets.build<TPriceTier>();
```
3 changes: 3 additions & 0 deletions models/commons/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './localized-string/types';
export * from './money/types';
export * from './price/types';
export * from './reference/types';
export * from './price-tier/types';

// Export models
export * as Address from './address';
Expand All @@ -22,3 +23,5 @@ export * as Money from './money';
export * as Price from './price';
export * as PriceDraft from './price/price-draft';
export * as Reference from './reference';
export * as PriceTier from './price-tier';
export * as PriceTierDraft from './price-tier/price-tier-draft';
10 changes: 10 additions & 0 deletions models/commons/src/key-reference/presets/channel-reference.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { TKeyReference } from '../types';
import channelReference from './channel-reference';

it('should build channel reference', () => {
const built = channelReference().build<TKeyReference>();
expect(built).toEqual({
key: expect.any(String),
typeId: 'channel',
});
});
6 changes: 6 additions & 0 deletions models/commons/src/key-reference/presets/channel-reference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import KeyReference from '../builder';
import type { TKeyReferenceBuilder } from '../types';

const channel = (): TKeyReferenceBuilder => KeyReference().typeId('channel');

export default channel;
2 changes: 2 additions & 0 deletions models/commons/src/key-reference/presets/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import associateRole from './associate-role-reference';
import businessUnit from './business-unit-reference';
import category from './category-reference';
import channel from './channel-reference';
import customerGroup from './customer-group-reference';
import customer from './customer-reference';
import productType from './product-type-reference';
Expand All @@ -13,6 +14,7 @@ const presets = {
associateRole,
businessUnit,
category,
channel,
customer,
customerGroup,
productType,
Expand Down
57 changes: 57 additions & 0 deletions models/commons/src/price-tier/builder.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint-disable jest/no-disabled-tests */
/* eslint-disable jest/valid-title */
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils';
import { TPriceTier, TPriceTierGraphql } from './types';
import * as PriceTier from '.';

describe('builder', () => {
it(
...createBuilderSpec<TPriceTier, TPriceTier>(
'default',
PriceTier.random(),
expect.objectContaining({
minimumQuantity: expect.any(Number),
value: expect.objectContaining({
type: 'centPrecision',
currencyCode: expect.any(String),
centAmount: expect.any(Number),
fractionDigits: expect.any(Number),
}),
})
)
);

it(
...createBuilderSpec<TPriceTier, TPriceTier>(
'rest',
PriceTier.random(),
expect.objectContaining({
minimumQuantity: expect.any(Number),
value: expect.objectContaining({
type: 'centPrecision',
currencyCode: expect.any(String),
centAmount: expect.any(Number),
fractionDigits: expect.any(Number),
}),
})
)
);

it(
...createBuilderSpec<TPriceTier, TPriceTierGraphql>(
'graphql',
PriceTier.random(),
expect.objectContaining({
minimumQuantity: expect.any(Number),
value: expect.objectContaining({
type: 'centPrecision',
currencyCode: expect.any(String),
centAmount: expect.any(Number),
fractionDigits: expect.any(Number),
__typename: 'Money',
}),
__typename: 'ProductPriceTier',
})
)
);
});
12 changes: 12 additions & 0 deletions models/commons/src/price-tier/builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Builder } from '@commercetools-test-data/core';
import generator from './generator';
import transformers from './transformers';
import type { TPriceTier, TCreatePriceTierBuilder } from './types';

const Model: TCreatePriceTierBuilder = () =>
Builder<TPriceTier>({
generator,
transformers,
});

export default Model;
14 changes: 14 additions & 0 deletions models/commons/src/price-tier/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Generator, fake } from '@commercetools-test-data/core';
import * as CentPrecisionMoney from '../cent-precision-money';
import { TPriceTier } from './types';

// https://docs.commercetools.com/api/types#pricetier

const generator = Generator<TPriceTier>({
fields: {
minimumQuantity: fake((f) => f.number.int()),
value: fake(() => CentPrecisionMoney.random()),
},
});

export default generator;
3 changes: 3 additions & 0 deletions models/commons/src/price-tier/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as random } from './builder';
export { default as presets } from './presets';
export * from './types';
3 changes: 3 additions & 0 deletions models/commons/src/price-tier/presets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const presets = {};

export default presets;
Loading

0 comments on commit f027639

Please sign in to comment.