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(test-data): create StandalonePrice model and associated draft #472

Merged
merged 6 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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';
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',
});
});
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
Loading