Skip to content

Commit

Permalink
feat(): add StagedStandalonePrice model (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
nima-ct authored Aug 15, 2024
1 parent 6e207af commit 0be63dc
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-news-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-test-data/standalone-price': minor
---

Added StagedStandalonePrice model within the StandalonePrice entity
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-disable jest/no-disabled-tests */
/* eslint-disable jest/valid-title */
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils';
import { TStagedStandalonePrice, TStagedStandalonePriceGraphql } from './types';
import * as StagedStandalonePrice from '.';

describe('builder', () => {
it(
...createBuilderSpec<TStagedStandalonePrice, TStagedStandalonePrice>(
'default',
StagedStandalonePrice.random(),
expect.objectContaining({
value: expect.objectContaining({
currencyCode: expect.any(String),
centAmount: expect.any(Number),
}),
})
)
);

it(
...createBuilderSpec<TStagedStandalonePrice, TStagedStandalonePrice>(
'rest',
StagedStandalonePrice.random(),
expect.objectContaining({
value: expect.objectContaining({
currencyCode: expect.any(String),
centAmount: expect.any(Number),
}),
})
)
);

it(
...createBuilderSpec<TStagedStandalonePrice, TStagedStandalonePriceGraphql>(
'graphql',
StagedStandalonePrice.random(),
expect.objectContaining({
value: expect.objectContaining({
currencyCode: expect.any(String),
centAmount: expect.any(Number),
}),
})
)
);
});
15 changes: 15 additions & 0 deletions models/standalone-price/src/staged-standalone-price/builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Builder } from '@commercetools-test-data/core';
import generator from './generator';
import transformers from './transformers';
import type {
TStagedStandalonePrice,
TCreateStagedStandalonePriceBuilder,
} from './types';

const Model: TCreateStagedStandalonePriceBuilder = () =>
Builder<TStagedStandalonePrice>({
generator,
transformers,
});

export default Model;
14 changes: 14 additions & 0 deletions models/standalone-price/src/staged-standalone-price/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Money } from '@commercetools-test-data/commons';
import { fake, Generator } from '@commercetools-test-data/core';
import { TStagedStandalonePrice } from './types';

// https://docs.commercetools.com/api/projects/standalone-prices#stagedstandaloneprice

const generator = Generator<TStagedStandalonePrice>({
fields: {
value: fake(() => Money.random()),
discounted: null,
},
});

export default generator;
2 changes: 2 additions & 0 deletions models/standalone-price/src/staged-standalone-price/index.ts
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';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const presets = {};

export default presets;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Transformer } from '@commercetools-test-data/core';
import type {
TStagedStandalonePrice,
TStagedStandalonePriceGraphql,
} from './types';

const transformers = {
default: Transformer<TStagedStandalonePrice, TStagedStandalonePrice>(
'default',
{
buildFields: ['value'],
}
),
rest: Transformer<TStagedStandalonePrice, TStagedStandalonePrice>('rest', {
buildFields: ['value'],
}),
graphql: Transformer<TStagedStandalonePrice, TStagedStandalonePriceGraphql>(
'graphql',
{
buildFields: ['value'],
}
),
};

export default transformers;
10 changes: 10 additions & 0 deletions models/standalone-price/src/staged-standalone-price/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { StagedStandalonePrice } from '@commercetools/platform-sdk';
import { TBuilder } from '@commercetools-test-data/core';

export type TStagedStandalonePrice = StagedStandalonePrice;

export type TStagedStandalonePriceGraphql = TStagedStandalonePrice;

export type TStagedStandalonePriceBuilder = TBuilder<TStagedStandalonePrice>;
export type TCreateStagedStandalonePriceBuilder =
() => TStagedStandalonePriceBuilder;

0 comments on commit 0be63dc

Please sign in to comment.