Skip to content

Commit

Permalink
fix(attribute-enum-type): add missing results wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dogayuksel committed Aug 7, 2024
1 parent 827861f commit 654693d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
18 changes: 11 additions & 7 deletions models/product-type/src/attribute-enum-type/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ describe('builder', () => {
AttributeEnumType.random(),
expect.objectContaining({
name: 'enum',
values: expect.arrayContaining([
expect.objectContaining({
key: expect.any(String),
label: expect.any(String),
}),
]),
__typename: 'EnumAttributionDefinitionType',
values: expect.objectContaining({
results: [
expect.objectContaining({
key: expect.any(String),
label: expect.any(String),
__typename: 'PlainEnumValue',
}),
],
__typename: 'PlainEnumValueResult',
}),
__typename: 'EnumAttributeDefinitionType',
})
)
);
Expand Down
12 changes: 8 additions & 4 deletions models/product-type/src/attribute-enum-type/transformers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Transformer } from '@commercetools-test-data/core';
import { Transformer, buildField } from '@commercetools-test-data/core';
import { TAttributeEnumTypeGraphql, TAttributeEnumType } from './types';

const transformers = {
Expand All @@ -11,9 +11,13 @@ const transformers = {
graphql: Transformer<TAttributeEnumType, TAttributeEnumTypeGraphql>(
'graphql',
{
buildFields: ['values'],
addFields: ({ fields }) => ({
__typename: 'EnumAttributionDefinitionType',
replaceFields: ({ fields }) => ({
...fields,
values: {
results: fields.values.map((value) => buildField(value, 'graphql')),
__typename: 'PlainEnumValueResult',
},
__typename: 'EnumAttributeDefinitionType',
}),
}
),
Expand Down
19 changes: 12 additions & 7 deletions models/product-type/src/attribute-enum-type/types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import type {
AttributeEnumType,
AttributePlainEnumValue,
} from '@commercetools/platform-sdk';
import type { AttributeEnumType } from '@commercetools/platform-sdk';
import type { TBuilder } from '@commercetools-test-data/core';
import {
TAttributePlainEnumValueDraftGraphql,
TAttributePlainEnumValue,
} from '../attribute-plain-enum-value';

export type TAttributeEnumType = AttributeEnumType;
export type TAttributeEnumTypeDraft = AttributeEnumType;

export type TAttributeEnumTypeGraphql = AttributeEnumType & {
__typename: 'EnumAttributionDefinitionType';
export type TAttributeEnumTypeGraphql = Omit<TAttributeEnumType, 'values'> & {
values: {
results: Array<TAttributePlainEnumValue>;
__typename: 'PlainEnumValueResult';
};
__typename: 'EnumAttributeDefinitionType';
};
export type TAttributeEnumTypeDraftGraphql = {
enum: { values: Array<AttributePlainEnumValue> };
enum: { values: Array<TAttributePlainEnumValueDraftGraphql> };
};

export type TAttributeEnumTypeBuilder = TBuilder<TAttributeEnumType>;
Expand Down

0 comments on commit 654693d

Please sign in to comment.