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

chore(test-data): create AttributeNumberType model #485

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/light-seals-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-test-data/product-type': minor
---

Create AttributeNumberType product-type model and associated draft
16 changes: 15 additions & 1 deletion models/product-type/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ $ pnpm add -D @commercetools-test-data/product-type
- [AttributeEnumType](#attributeenumtype)<br>
- [AttributeLocalizedEnumType](#attributelocalizedenumtype)<br>
- [AttributeLocalizedEnumValue](#attributelocalizedenumvalue)<br>
- [attributeLocalizableTextType](#attributelocalizabletexttype)<br>
- [AttributeLocalizableTextType](#attributelocalizabletexttype)<br>
- [AttributeNumberType](#attributenumbertype)<br>
- [AttributePlainEnumValue](#attributeplainenumvalue)<br>
- [AttributeSetType](#attributesettype)<br>
- [AttributeReferenceType](#attributereferencetype)<br>
Expand Down Expand Up @@ -108,6 +109,18 @@ const attributeLocalizableTextType =
AttributeLocalizableTextType.random().build<TattributeLocalizableTextType>();
```

## `AttributeNumberType`

```ts
import {
AttributeNumberType,
type TAttributeNumberType,
} from '@commercetools-test-data/product-type';

const attributeNumberType =
AttributeNumberType.random().build<TAttributeNumberType>();
```

## `AttributePlainEnumValue`

```ts
Expand All @@ -130,6 +143,7 @@ import {
} from '@commercetools-test-data/product-type';

const attributeSetType = AttributeSetType.random().build<TAttributeSetType>();
```

## `AttributeReferenceType`

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable jest/no-disabled-tests */
/* eslint-disable jest/valid-title */
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils';
import {
TAttributeNumberType,
TAttributeNumberTypeDraft,
TAttributeNumberTypeDraftGraphql,
} from '../types';
import * as AttributeNumberTypeDraft from './index';

describe('builder', () => {
it(
...createBuilderSpec<TAttributeNumberType, TAttributeNumberTypeDraft>(
'default',
AttributeNumberTypeDraft.random(),
expect.objectContaining({
name: 'number',
})
)
);

it(
...createBuilderSpec<
TAttributeNumberType,
TAttributeNumberTypeDraftGraphql
>(
'graphql',
AttributeNumberTypeDraft.random(),
expect.objectContaining({
number: {
dummy: null,
},
})
)
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Builder } from '@commercetools-test-data/core';
import {
TAttributeNumberType,
TCreateAttributeNumberTypeDraftBuilder,
} from '../types';
import { generator } from './generator';
import transformers from './transformers';

const Model: TCreateAttributeNumberTypeDraftBuilder = () =>
Builder<TAttributeNumberType>({
generator,
transformers,
});

export default Model;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Generator } from '@commercetools-test-data/core';
import { TAttributeNumberTypeDraft } from '../types';

// https://docs.commercetools.com/api/projects/productTypes#attributeenumtype

export const generator = Generator<TAttributeNumberTypeDraft>({
fields: {
name: 'number',
},
});
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,27 @@
import { Transformer } from '@commercetools-test-data/core';
import {
TAttributeNumberTypeDraftGraphql,
TAttributeNumberTypeDraft,
} from '../types';

const transformers = {
default: Transformer<TAttributeNumberTypeDraft, TAttributeNumberTypeDraft>(
'default',
{
buildFields: [],
}
),
graphql: Transformer<
TAttributeNumberTypeDraft,
TAttributeNumberTypeDraftGraphql
>('graphql', {
buildFields: [],
replaceFields: () => ({
number: {
dummy: null,
},
}),
}),
};

export default transformers;
38 changes: 38 additions & 0 deletions models/product-type/src/attribute-number-type/builder.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable jest/no-disabled-tests */
/* eslint-disable jest/valid-title */
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils';
import { TAttributeNumberType, TAttributeNumberTypeGraphql } from './types';
import * as AttributeEnumType from './index';

describe('builder', () => {
it(
...createBuilderSpec<TAttributeNumberType, TAttributeNumberType>(
'default',
AttributeEnumType.random(),
expect.objectContaining({
name: 'number',
})
)
);

it(
...createBuilderSpec<TAttributeNumberType, TAttributeNumberType>(
'rest',
AttributeEnumType.random(),
expect.objectContaining({
name: 'number',
})
)
);

it(
...createBuilderSpec<TAttributeNumberType, TAttributeNumberTypeGraphql>(
'graphql',
AttributeEnumType.random(),
expect.objectContaining({
name: 'number',
__typename: 'NumberAttributeDefinitionType',
})
)
);
});
15 changes: 15 additions & 0 deletions models/product-type/src/attribute-number-type/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 {
TAttributeNumberType,
TCreateAttributeNumberTypeBuilder,
} from './types';

const Model: TCreateAttributeNumberTypeBuilder = () =>
Builder<TAttributeNumberType>({
generator,
transformers,
});

export default Model;
10 changes: 10 additions & 0 deletions models/product-type/src/attribute-number-type/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Generator } from '@commercetools-test-data/core';
import { TAttributeNumberType } from './types';

// https://docs.commercetools.com/api/projects/productTypes#attributenumbertype

export const generator = Generator<TAttributeNumberType>({
fields: {
name: 'number',
},
});
3 changes: 3 additions & 0 deletions models/product-type/src/attribute-number-type/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';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const presets = {};

export default presets;
22 changes: 22 additions & 0 deletions models/product-type/src/attribute-number-type/transformers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Transformer } from '@commercetools-test-data/core';
import { TAttributeNumberTypeGraphql, TAttributeNumberType } from './types';

const transformers = {
default: Transformer<TAttributeNumberType, TAttributeNumberType>('default', {
buildFields: [],
}),
rest: Transformer<TAttributeNumberType, TAttributeNumberType>('rest', {
buildFields: [],
}),
graphql: Transformer<TAttributeNumberType, TAttributeNumberTypeGraphql>(
'graphql',
{
buildFields: [],
addFields: () => ({
__typename: 'NumberAttributeDefinitionType',
}),
}
),
};

export default transformers;
23 changes: 23 additions & 0 deletions models/product-type/src/attribute-number-type/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { AttributeNumberType } from '@commercetools/platform-sdk';
import type { TBuilder } from '@commercetools-test-data/core';

export type TAttributeNumberType = AttributeNumberType;
export type TAttributeNumberTypeDraft = AttributeNumberType;

export type TAttributeNumberTypeGraphql = AttributeNumberType & {
__typename: 'NumberAttributeDefinitionType';
};
export type TAttributeNumberTypeDraftGraphql = {
number: {
dummy: string | null;
};
};

export type TAttributeNumberTypeBuilder = TBuilder<TAttributeNumberType>;
export type TAttributeNumberTypeDraftBuilder =
TBuilder<TAttributeNumberTypeDraft>;

export type TCreateAttributeNumberTypeBuilder =
() => TAttributeNumberTypeBuilder;
export type TCreateAttributeNumberTypeDraftBuilder =
() => TAttributeNumberTypeDraftBuilder;
3 changes: 3 additions & 0 deletions models/product-type/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './attribute-enum-type/types';
export * from './attribute-localized-enum-type/types';
export * from './attribute-localized-enum-value/types';
export * from './attribute-localizable-text-type/types';
export * from './attribute-number-type/types';
export * from './attribute-plain-enum-value/types';
export * from './attribute-set-type/types';
export * from './attribute-reference-type/types';
Expand All @@ -25,6 +26,8 @@ export * as AttributeLocalizedEnumValue from './attribute-localized-enum-value';
export * as AttributeLocalizedEnumValueDraft from './attribute-localized-enum-value/attribute-localized-enum-value-draft';
export * as AttributeLocalizableTextType from './attribute-localizable-text-type';
export * as AttributeLocalizableTextTypeDraft from './attribute-localizable-text-type/attribute-localized-text-type-draft';
export * as AttributeNumberType from './attribute-number-type';
export * as AttributeNumberTypeDraft from './attribute-number-type/attribute-number-type-draft';
export * as AttributeSetType from './attribute-set-type';
export * as AttributeSetTypeDraft from './attribute-set-type/attribute-set-type-draft';
export * as AttributeReferenceType from './attribute-reference-type';
Expand Down
Loading