From 984b369998b0269409af0cba24ffe051231cf1af Mon Sep 17 00:00:00 2001 From: Rafa Ga <13467563+ragafus@users.noreply.github.com> Date: Thu, 4 Jul 2024 14:18:06 +0200 Subject: [PATCH] fix: wrong `__typenames` props (CustomFieldEnumType, CustomFieldEnumValue, CustomFieldLocalizedEnumValue) (#619) --- .changeset/spotty-kids-cover.md | 5 +++++ .../custom-field-enum-type/builder.spec.ts | 2 +- .../custom-field-enum-type/transformers.ts | 4 ++-- .../type/src/custom-field-enum-type/types.ts | 2 +- .../custom-field-enum-value/builder.spec.ts | 22 ++++--------------- .../src/custom-field-enum-value/generator.ts | 3 +-- .../custom-field-enum-value/transformers.ts | 10 ++++----- .../type/src/custom-field-enum-value/types.ts | 10 ++------- .../builder.spec.ts | 2 +- .../builder.spec.ts | 2 +- .../transformers.ts | 2 +- .../types.ts | 2 +- 12 files changed, 24 insertions(+), 42 deletions(-) create mode 100644 .changeset/spotty-kids-cover.md diff --git a/.changeset/spotty-kids-cover.md b/.changeset/spotty-kids-cover.md new file mode 100644 index 000000000..46128dbcb --- /dev/null +++ b/.changeset/spotty-kids-cover.md @@ -0,0 +1,5 @@ +--- +'@commercetools-test-data/type': patch +--- + +Fixes wrong `__typenames` props (CustomFieldEnumType, CustomFieldEnumValue, CustomFieldLocalizedEnumValue) diff --git a/models/type/src/custom-field-enum-type/builder.spec.ts b/models/type/src/custom-field-enum-type/builder.spec.ts index 08e487427..77076e7d3 100644 --- a/models/type/src/custom-field-enum-type/builder.spec.ts +++ b/models/type/src/custom-field-enum-type/builder.spec.ts @@ -34,7 +34,7 @@ describe('builder', () => { expect.objectContaining({ name: 'Enum', values: [], - __typename: 'EnumCustomFieldType', + __typename: 'EnumType', }) ) ); diff --git a/models/type/src/custom-field-enum-type/transformers.ts b/models/type/src/custom-field-enum-type/transformers.ts index 2682a9325..9899d17e3 100644 --- a/models/type/src/custom-field-enum-type/transformers.ts +++ b/models/type/src/custom-field-enum-type/transformers.ts @@ -12,8 +12,8 @@ const transformers = { 'graphql', { buildFields: [], - addFields: ({ fields }) => ({ - __typename: 'EnumCustomFieldType', + addFields: () => ({ + __typename: 'EnumType', }), } ), diff --git a/models/type/src/custom-field-enum-type/types.ts b/models/type/src/custom-field-enum-type/types.ts index c3d5f7c2b..9da0b20e6 100644 --- a/models/type/src/custom-field-enum-type/types.ts +++ b/models/type/src/custom-field-enum-type/types.ts @@ -8,7 +8,7 @@ export type TCustomFieldEnumType = CustomFieldEnumType; export type TCustomFieldEnumTypeDraft = CustomFieldEnumType; export type TCustomFieldEnumTypeGraphql = CustomFieldEnumType & { - __typename: 'EnumCustomFieldType'; + __typename: 'EnumType'; }; export type TCustomFieldEnumTypeDraftGraphql = { enum: { values: Array }; diff --git a/models/type/src/custom-field-enum-value/builder.spec.ts b/models/type/src/custom-field-enum-value/builder.spec.ts index b4e735559..6b9c84af2 100644 --- a/models/type/src/custom-field-enum-value/builder.spec.ts +++ b/models/type/src/custom-field-enum-value/builder.spec.ts @@ -14,11 +14,7 @@ describe('builder', () => { CustomFieldEnumValue.random(), expect.objectContaining({ key: expect.any(String), - label: expect.objectContaining({ - de: expect.any(String), - en: expect.any(String), - fr: expect.any(String), - }), + label: expect.any(String), }) ) ); @@ -29,11 +25,7 @@ describe('builder', () => { CustomFieldEnumValue.random(), expect.objectContaining({ key: expect.any(String), - label: expect.objectContaining({ - de: expect.any(String), - en: expect.any(String), - fr: expect.any(String), - }), + label: expect.any(String), }) ) ); @@ -44,14 +36,8 @@ describe('builder', () => { CustomFieldEnumValue.random(), expect.objectContaining({ key: expect.any(String), - labelAllLocales: expect.arrayContaining([ - expect.objectContaining({ - locale: 'en', - value: expect.any(String), - __typename: 'LocalizedString', - }), - ]), - __typename: 'LocalizableEnumValueType', + label: expect.any(String), + __typename: 'EnumValue', }) ) ); diff --git a/models/type/src/custom-field-enum-value/generator.ts b/models/type/src/custom-field-enum-value/generator.ts index 0a4d6d8a6..f764c7024 100644 --- a/models/type/src/custom-field-enum-value/generator.ts +++ b/models/type/src/custom-field-enum-value/generator.ts @@ -1,4 +1,3 @@ -import { LocalizedString } from '@commercetools-test-data/commons'; import { fake, Generator } from '@commercetools-test-data/core'; import { type TCustomFieldEnumValue } from './types'; @@ -7,7 +6,7 @@ import { type TCustomFieldEnumValue } from './types'; const generator = Generator({ fields: { key: fake((f) => f.lorem.slug(2)), - label: fake(() => LocalizedString.random()), + label: fake((f) => f.word.words({ count: { min: 3, max: 5 } })), }, }); diff --git a/models/type/src/custom-field-enum-value/transformers.ts b/models/type/src/custom-field-enum-value/transformers.ts index daf0822e9..6e0a2c36d 100644 --- a/models/type/src/custom-field-enum-value/transformers.ts +++ b/models/type/src/custom-field-enum-value/transformers.ts @@ -8,19 +8,17 @@ import { const transformers = { default: Transformer( 'default', - { buildFields: ['label'] } + { buildFields: [] } ), rest: Transformer('rest', { - buildFields: ['label'], + buildFields: [], }), graphql: Transformer( 'graphql', { buildFields: [], - removeFields: ['label'], - addFields: ({ fields }) => ({ - labelAllLocales: LocalizedString.toLocalizedField(fields.label), - __typename: 'LocalizableEnumValueType', + addFields: () => ({ + __typename: 'EnumValue', }), } ), diff --git a/models/type/src/custom-field-enum-value/types.ts b/models/type/src/custom-field-enum-value/types.ts index 2bf23ddc8..0378b1526 100644 --- a/models/type/src/custom-field-enum-value/types.ts +++ b/models/type/src/custom-field-enum-value/types.ts @@ -1,17 +1,11 @@ import { CustomFieldEnumValue } from '@commercetools/platform-sdk'; -import { TLocalizedStringGraphql } from '@commercetools-test-data/commons/src'; import type { TBuilder } from '@commercetools-test-data/core'; export type TCustomFieldEnumValue = CustomFieldEnumValue; export type TCustomFieldEnumValueDraft = CustomFieldEnumValue; -export type TCustomFieldEnumValueGraphql = Omit< - TCustomFieldEnumValue, - // In GraphQL, we prefer to use `nameAllLocales` instead of `name`. - 'label' -> & { - labelAllLocales: TLocalizedStringGraphql | null; - __typename: 'LocalizableEnumValueType'; +export type TCustomFieldEnumValueGraphql = TCustomFieldEnumValue & { + __typename: 'EnumValue'; }; export type TCustomFieldEnumValueDraftGraphql = TCustomFieldEnumValueDraft; diff --git a/models/type/src/custom-field-localized-enum-type/builder.spec.ts b/models/type/src/custom-field-localized-enum-type/builder.spec.ts index 029af8aab..29cd2acfa 100644 --- a/models/type/src/custom-field-localized-enum-type/builder.spec.ts +++ b/models/type/src/custom-field-localized-enum-type/builder.spec.ts @@ -71,7 +71,7 @@ describe('builder', () => { __typename: 'LocalizedString', }), ]), - __typename: 'LocalizableEnumValueType', + __typename: 'LocalizedEnumValue', }), ], __typename: 'LocalizableEnumValueTypeResult', diff --git a/models/type/src/custom-field-localized-enum-value/builder.spec.ts b/models/type/src/custom-field-localized-enum-value/builder.spec.ts index c7253cfef..15f0a8339 100644 --- a/models/type/src/custom-field-localized-enum-value/builder.spec.ts +++ b/models/type/src/custom-field-localized-enum-value/builder.spec.ts @@ -60,7 +60,7 @@ describe('builder', () => { __typename: 'LocalizedString', }), ]), - __typename: 'LocalizableEnumValueType', + __typename: 'LocalizedEnumValue', }) ) ); diff --git a/models/type/src/custom-field-localized-enum-value/transformers.ts b/models/type/src/custom-field-localized-enum-value/transformers.ts index 0b5c408e6..cf231e660 100644 --- a/models/type/src/custom-field-localized-enum-value/transformers.ts +++ b/models/type/src/custom-field-localized-enum-value/transformers.ts @@ -22,7 +22,7 @@ const transformers = { removeFields: ['label'], addFields: ({ fields }) => ({ labelAllLocales: LocalizedString.toLocalizedField(fields.label), - __typename: 'LocalizableEnumValueType', + __typename: 'LocalizedEnumValue', }), }), }; diff --git a/models/type/src/custom-field-localized-enum-value/types.ts b/models/type/src/custom-field-localized-enum-value/types.ts index 0afd6d914..c3b4ec8f4 100644 --- a/models/type/src/custom-field-localized-enum-value/types.ts +++ b/models/type/src/custom-field-localized-enum-value/types.ts @@ -11,7 +11,7 @@ export type TCustomFieldLocalizedEnumValueGraphql = Omit< 'label' > & { labelAllLocales: TLocalizedStringGraphql | null; - __typename: 'LocalizableEnumValueType'; + __typename: 'LocalizedEnumValue'; }; export type TCustomFieldLocalizedEnumValueDraftGraphql = TCustomFieldLocalizedEnumValueDraft;