Skip to content

Commit

Permalink
fix: wrong __typenames props (CustomFieldEnumType, CustomFieldEnumV…
Browse files Browse the repository at this point in the history
…alue, CustomFieldLocalizedEnumValue) (#619)
  • Loading branch information
ragafus authored Jul 4, 2024
1 parent 9334f96 commit 984b369
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-kids-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-test-data/type': patch
---

Fixes wrong `__typenames` props (CustomFieldEnumType, CustomFieldEnumValue, CustomFieldLocalizedEnumValue)
2 changes: 1 addition & 1 deletion models/type/src/custom-field-enum-type/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('builder', () => {
expect.objectContaining({
name: 'Enum',
values: [],
__typename: 'EnumCustomFieldType',
__typename: 'EnumType',
})
)
);
Expand Down
4 changes: 2 additions & 2 deletions models/type/src/custom-field-enum-type/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const transformers = {
'graphql',
{
buildFields: [],
addFields: ({ fields }) => ({
__typename: 'EnumCustomFieldType',
addFields: () => ({
__typename: 'EnumType',
}),
}
),
Expand Down
2 changes: 1 addition & 1 deletion models/type/src/custom-field-enum-type/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CustomFieldEnumValue> };
Expand Down
22 changes: 4 additions & 18 deletions models/type/src/custom-field-enum-value/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
)
);
Expand All @@ -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),
})
)
);
Expand All @@ -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',
})
)
);
Expand Down
3 changes: 1 addition & 2 deletions models/type/src/custom-field-enum-value/generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { LocalizedString } from '@commercetools-test-data/commons';
import { fake, Generator } from '@commercetools-test-data/core';
import { type TCustomFieldEnumValue } from './types';

Expand All @@ -7,7 +6,7 @@ import { type TCustomFieldEnumValue } from './types';
const generator = Generator<TCustomFieldEnumValue>({
fields: {
key: fake((f) => f.lorem.slug(2)),
label: fake(() => LocalizedString.random()),
label: fake((f) => f.word.words({ count: { min: 3, max: 5 } })),
},
});

Expand Down
10 changes: 4 additions & 6 deletions models/type/src/custom-field-enum-value/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ import {
const transformers = {
default: Transformer<TCustomFieldEnumValue, TCustomFieldEnumValue>(
'default',
{ buildFields: ['label'] }
{ buildFields: [] }
),
rest: Transformer<TCustomFieldEnumValue, TCustomFieldEnumValue>('rest', {
buildFields: ['label'],
buildFields: [],
}),
graphql: Transformer<TCustomFieldEnumValue, TCustomFieldEnumValueGraphql>(
'graphql',
{
buildFields: [],
removeFields: ['label'],
addFields: ({ fields }) => ({
labelAllLocales: LocalizedString.toLocalizedField(fields.label),
__typename: 'LocalizableEnumValueType',
addFields: () => ({
__typename: 'EnumValue',
}),
}
),
Expand Down
10 changes: 2 additions & 8 deletions models/type/src/custom-field-enum-value/types.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('builder', () => {
__typename: 'LocalizedString',
}),
]),
__typename: 'LocalizableEnumValueType',
__typename: 'LocalizedEnumValue',
}),
],
__typename: 'LocalizableEnumValueTypeResult',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('builder', () => {
__typename: 'LocalizedString',
}),
]),
__typename: 'LocalizableEnumValueType',
__typename: 'LocalizedEnumValue',
})
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const transformers = {
removeFields: ['label'],
addFields: ({ fields }) => ({
labelAllLocales: LocalizedString.toLocalizedField(fields.label),
__typename: 'LocalizableEnumValueType',
__typename: 'LocalizedEnumValue',
}),
}),
};
Expand Down
2 changes: 1 addition & 1 deletion models/type/src/custom-field-localized-enum-value/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type TCustomFieldLocalizedEnumValueGraphql = Omit<
'label'
> & {
labelAllLocales: TLocalizedStringGraphql | null;
__typename: 'LocalizableEnumValueType';
__typename: 'LocalizedEnumValue';
};
export type TCustomFieldLocalizedEnumValueDraftGraphql =
TCustomFieldLocalizedEnumValueDraft;
Expand Down

0 comments on commit 984b369

Please sign in to comment.