diff --git a/.changeset/thick-experts-thank.md b/.changeset/thick-experts-thank.md new file mode 100644 index 000000000..4fcf3c9c8 --- /dev/null +++ b/.changeset/thick-experts-thank.md @@ -0,0 +1,17 @@ +--- +'@commercetools-test-data/product-type': minor +'@commercetools-test-data/commons': minor +'@commercetools-test-data/inventory-entry': patch +--- + +### Common Model (`common`) + +- Introduced a new model called `discounted-price`. + +### Inventory Entry Model (`inventory-entry`) + +- Updated the transformer file to conditionally send the supply channel, making it optional. + +### Product Type (`product-type`) + +- Added new presets for enum and localized enum types. diff --git a/graphql-types/src/generated/core.ts b/graphql-types/src/generated/core.ts index 0f9ca0e2e..06c3a0181 100644 --- a/graphql-types/src/generated/core.ts +++ b/graphql-types/src/generated/core.ts @@ -9,10 +9,9 @@ type MakeOptional = Omit & { type MakeMaybe = Omit & { [SubKey in K]: Maybe; }; -type MakeEmpty< - T extends { [key: string]: unknown }, - K extends keyof T, -> = { [_ in K]?: never }; +type MakeEmpty = { + [_ in K]?: never; +}; type Incremental = | T | { diff --git a/graphql-types/src/generated/ctp.ts b/graphql-types/src/generated/ctp.ts index 8c595ce96..2d437f627 100644 --- a/graphql-types/src/generated/ctp.ts +++ b/graphql-types/src/generated/ctp.ts @@ -9,10 +9,9 @@ type MakeOptional = Omit & { type MakeMaybe = Omit & { [SubKey in K]: Maybe; }; -type MakeEmpty< - T extends { [key: string]: unknown }, - K extends keyof T, -> = { [_ in K]?: never }; +type MakeEmpty = { + [_ in K]?: never; +}; type Incremental = | T | { diff --git a/graphql-types/src/generated/mc.ts b/graphql-types/src/generated/mc.ts index 2f78efb8a..0a5eb26a1 100644 --- a/graphql-types/src/generated/mc.ts +++ b/graphql-types/src/generated/mc.ts @@ -9,10 +9,9 @@ type MakeOptional = Omit & { type MakeMaybe = Omit & { [SubKey in K]: Maybe; }; -type MakeEmpty< - T extends { [key: string]: unknown }, - K extends keyof T, -> = { [_ in K]?: never }; +type MakeEmpty = { + [_ in K]?: never; +}; type Incremental = | T | { diff --git a/graphql-types/src/generated/settings.ts b/graphql-types/src/generated/settings.ts index f68ffde3b..4b41d256b 100644 --- a/graphql-types/src/generated/settings.ts +++ b/graphql-types/src/generated/settings.ts @@ -9,10 +9,9 @@ type MakeOptional = Omit & { type MakeMaybe = Omit & { [SubKey in K]: Maybe; }; -type MakeEmpty< - T extends { [key: string]: unknown }, - K extends keyof T, -> = { [_ in K]?: never }; +type MakeEmpty = { + [_ in K]?: never; +}; type Incremental = | T | { diff --git a/models/commons/src/discounted-price/builders.spec.ts b/models/commons/src/discounted-price/builders.spec.ts index 37599ce93..2b1174e08 100644 --- a/models/commons/src/discounted-price/builders.spec.ts +++ b/models/commons/src/discounted-price/builders.spec.ts @@ -34,7 +34,7 @@ describe('DiscountedPrice Builder', () => { __typename: 'ProductDiscount', }), discountRef: expect.objectContaining({ - id: expect.any(String), + id: graphqlModel.discount?.id, typeId: 'product-discount', __typename: 'Reference', }), diff --git a/models/commons/src/discounted-price/discounted-price-draft/builders.spec.ts b/models/commons/src/discounted-price/discounted-price-draft/builders.spec.ts index 07a584f6f..283f4db5b 100644 --- a/models/commons/src/discounted-price/discounted-price-draft/builders.spec.ts +++ b/models/commons/src/discounted-price/discounted-price-draft/builders.spec.ts @@ -23,7 +23,6 @@ describe('DiscountedPriceDraft Builder', () => { expect(graphqlDraftModel).toEqual( expect.objectContaining({ - __typename: 'DiscountedProductPriceValue', value: expect.objectContaining({ centAmount: expect.any(Number), currencyCode: expect.any(String), diff --git a/models/commons/src/discounted-price/discounted-price-draft/fields-config.ts b/models/commons/src/discounted-price/discounted-price-draft/fields-config.ts index 979a2873f..881e6dfa9 100644 --- a/models/commons/src/discounted-price/discounted-price-draft/fields-config.ts +++ b/models/commons/src/discounted-price/discounted-price-draft/fields-config.ts @@ -26,6 +26,5 @@ export const graphqlFieldsConfig: TModelFieldsConfig = discount: fake(() => ProductDiscount.random()), discountRef: fake(() => Reference.presets.productDiscountReference()), }, + postBuild: (model) => { + if (model.discount) { + model.discountRef = Reference.presets + .productDiscountReference() + .id(model.discount.id) + .buildGraphql(); + } + + return model; + }, }; diff --git a/models/commons/src/discounted-price/types.ts b/models/commons/src/discounted-price/types.ts index d5ed58e39..76b9dd5e9 100644 --- a/models/commons/src/discounted-price/types.ts +++ b/models/commons/src/discounted-price/types.ts @@ -3,25 +3,17 @@ import { DiscountedPriceDraft, } from '@commercetools/platform-sdk'; import type { TBuilder } from '@commercetools-test-data/core'; -import { TProductDiscountGraphql } from '@commercetools-test-data/product-discount'; -import { TReferenceGraphql, TReferenceDraftGraphql } from '../reference/types'; +import type { + TCtpDiscountedProductPriceValue, + TCtpDiscountedProductPriceValueInput, +} from '@commercetools-test-data/graphql-types'; export type TDiscountedPriceRest = DiscountedPrice; -export type TDiscountedPriceGraphql = Omit & { - __typename: 'DiscountedProductPriceValue'; - discount: TProductDiscountGraphql; - discountRef: TReferenceGraphql<'product-discount'>; -}; +export type TDiscountedPriceGraphql = TCtpDiscountedProductPriceValue; export type TDiscountedPriceDraftRest = DiscountedPriceDraft; -export type TDiscountedPriceDraftGraphql = Omit< - DiscountedPriceDraft, - 'discount' -> & { - __typename: 'DiscountedProductPriceValue'; - discount: TReferenceDraftGraphql<'product-discount'>; -}; +export type TDiscountedPriceDraftGraphql = TCtpDiscountedProductPriceValueInput; export type TCreateDiscountedPriceBuilder< TModel extends diff --git a/models/commons/src/reference/types.ts b/models/commons/src/reference/types.ts index 2fd633148..645e16b6a 100644 --- a/models/commons/src/reference/types.ts +++ b/models/commons/src/reference/types.ts @@ -1,4 +1,5 @@ import type { TBuilder } from '@commercetools-test-data/core'; +import { TCtpReference } from '@commercetools-test-data/graphql-types'; export type TReferenceBuilder = TBuilder>; @@ -17,15 +18,18 @@ export type TCreateReferenceBuilder = export type TReferenceRest< TypeId = string, - ExpandedObject extends TExpandedReferenceObject = TExpandedReferenceObject + ExpandedObject extends + TExpandedReferenceObject = TExpandedReferenceObject, > = TReference & { obj: ExpandedObject; }; -export type TReferenceGraphql = - TExpandedReferenceObject & { - __typename: 'Reference'; - }; +export type TReferenceGraphql = Omit< + TCtpReference, + 'typeId' +> & { + typeId: TypeId; +}; // Draft representation export interface TReferenceDraft { diff --git a/models/inventory-entry/package.json b/models/inventory-entry/package.json index 99c9cfb7b..1bad876b4 100644 --- a/models/inventory-entry/package.json +++ b/models/inventory-entry/package.json @@ -22,6 +22,7 @@ "@commercetools-test-data/channel": "10.10.1", "@commercetools-test-data/commons": "10.10.1", "@commercetools-test-data/core": "10.10.1", + "@commercetools-test-data/graphql-types": "10.10.1", "@commercetools-test-data/product": "10.10.1", "@commercetools-test-data/utils": "10.10.1", "@commercetools/platform-sdk": "7.14.0", diff --git a/models/inventory-entry/src/builders.spec.ts b/models/inventory-entry/src/builders.spec.ts index 6761367ee..2450eac3c 100644 --- a/models/inventory-entry/src/builders.spec.ts +++ b/models/inventory-entry/src/builders.spec.ts @@ -22,7 +22,7 @@ describe('InventoryEntry model builders', () => { restockableInDays: expect.any(Number), availableQuantity: expect.any(Number), expectedDelivery: expect.any(String), - supplyChannel: expect.any(Object), + supplyChannel: null, custom: null, }) ); @@ -45,17 +45,8 @@ describe('InventoryEntry model builders', () => { restockableInDays: expect.any(Number), availableQuantity: expect.any(Number), expectedDelivery: expect.any(String), - supplyChannel: expect.objectContaining({ - __typename: 'Channel', - address: expect.objectContaining({ - country: expect.any(String), - }), - }), - supplyChannelRef: expect.objectContaining({ - __typename: 'Reference', - id: expect.any(String), - typeId: 'channel', - }), + supplyChannel: null, + supplyChannelRef: null, custom: null, __typename: 'InventoryEntry', }) @@ -81,7 +72,7 @@ describe('InventoryEntry model compatibility builders', () => { restockableInDays: expect.any(Number), availableQuantity: expect.any(Number), expectedDelivery: expect.any(String), - supplyChannel: expect.any(Object), + supplyChannel: null, custom: null, }) ); @@ -104,9 +95,8 @@ describe('InventoryEntry model compatibility builders', () => { quantityOnStock: expect.any(Number), restockableInDays: expect.any(Number), expectedDelivery: expect.any(String), - supplyChannel: expect.objectContaining({ - __typename: 'Channel', - }), + supplyChannel: null, + supplyChannelRef: null, custom: null, }) ); diff --git a/models/inventory-entry/src/fields-config.ts b/models/inventory-entry/src/fields-config.ts index a14747cf7..b3ca9c2d9 100644 --- a/models/inventory-entry/src/fields-config.ts +++ b/models/inventory-entry/src/fields-config.ts @@ -1,4 +1,3 @@ -import { ChannelGraphql } from '@commercetools-test-data/channel'; import { ClientLogging, Reference, @@ -27,20 +26,19 @@ const commonFieldsConfig = { availableQuantity: fake((f) => f.number.int()), restockableInDays: fake((f) => f.number.int()), expectedDelivery: fake(getFutureDate), + supplyChannel: null, custom: null, }; export const restFieldsConfig: TModelFieldsConfig = { fields: { ...commonFieldsConfig, - supplyChannel: fake(() => Reference.presets.channelReference()), }, }; export const graphqlFieldsConfig: TModelFieldsConfig = { fields: { ...commonFieldsConfig, __typename: 'InventoryEntry', - supplyChannel: fake(() => ChannelGraphql.random()), - supplyChannelRef: fake((f) => Reference.presets.channelReference()), + supplyChannelRef: null, }, postBuild: (model) => { const supplyChannelRef = model.supplyChannel diff --git a/models/inventory-entry/src/types.ts b/models/inventory-entry/src/types.ts index 77c483aa6..93a930838 100644 --- a/models/inventory-entry/src/types.ts +++ b/models/inventory-entry/src/types.ts @@ -2,15 +2,20 @@ import { InventoryEntry, InventoryEntryDraft, } from '@commercetools/platform-sdk'; -import { TChannelGraphql } from '@commercetools-test-data/channel'; -import type { TReferenceGraphql } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; +import type { + TCtpInventoryEntry, + TCtpInventoryEntryDraft, +} from '@commercetools-test-data/graphql-types'; // Default /** * @deprecated use `TInventoryEntryRest` instead */ export type TInventoryEntry = InventoryEntry; +/** + * @deprecated use `TInventoryEntryDraftRest` instead + */ export type TInventoryEntryDraft = InventoryEntryDraft; // REST @@ -18,12 +23,8 @@ export type TInventoryEntryRest = InventoryEntry; export type TInventoryEntryDraftRest = InventoryEntryDraft; // GraphQL -export type TInventoryEntryGraphql = Omit & { - __typename: 'InventoryEntry'; - supplyChannel?: TChannelGraphql | null; - supplyChannelRef?: TReferenceGraphql<'channel'> | null; -}; -export type TInventoryEntryDraftGraphql = TInventoryEntryDraft; +export type TInventoryEntryGraphql = TCtpInventoryEntry; +export type TInventoryEntryDraftGraphql = TCtpInventoryEntryDraft; export type TInventoryEntryBuilder = TBuilder; export type TInventoryEntryDraftBuilder = TBuilder; diff --git a/models/product-type/src/attribute-definition/presets/index.ts b/models/product-type/src/attribute-definition/presets/index.ts index 763e57fe0..ba5d84508 100644 --- a/models/product-type/src/attribute-definition/presets/index.ts +++ b/models/product-type/src/attribute-definition/presets/index.ts @@ -1,3 +1,45 @@ -const presets = {}; +import { LocalizedString } from '@commercetools-test-data/commons'; +import { + AttributeEnumType, + AttributeNumberType, + AttributeTextType, +} from '../..'; +import AttributeDefinition from '../builder'; + +const presets = { + number: () => + AttributeDefinition() + .type(AttributeNumberType.random()) + .name('Number Attribute Definition') + .label( + LocalizedString.presets + .empty() + .en(`Number Attribute Definition's Label`) + ) + .inputTip( + LocalizedString.presets + .empty() + .en(`Number Attribute Definition's Input Tip`) + ), + + countryOfOrigin: () => + AttributeDefinition() + .attributeConstraint('None') + .name('country-of-origin') + .label(LocalizedString.presets.empty().en('Country of Origin')) + .isRequired(true) + .type(AttributeTextType.random()), + + size: () => + AttributeDefinition() + .attributeConstraint('None') + .name('size') + .label(LocalizedString.presets.empty().en('Size')) + .inputTip(LocalizedString.presets.empty().en('Size of a product')) + .inputHint('SingleLine') + .isRequired(true) + .isSearchable(true) + .type(AttributeEnumType.presets.allSizesEnum()), +}; export default presets; diff --git a/models/product-type/src/attribute-enum-type/presets/index.ts b/models/product-type/src/attribute-enum-type/presets/index.ts index 763e57fe0..9e8a87cb0 100644 --- a/models/product-type/src/attribute-enum-type/presets/index.ts +++ b/models/product-type/src/attribute-enum-type/presets/index.ts @@ -1,3 +1,25 @@ -const presets = {}; +import { AttributePlainEnumValue } from '../..'; +import AttributeEnumType from '../builder'; + +const presets = { + allSizesEnum: () => + AttributeEnumType().values([ + AttributePlainEnumValue.presets.s(), + AttributePlainEnumValue.presets.m(), + AttributePlainEnumValue.presets.l(), + AttributePlainEnumValue.presets.xl(), + ]), + smallSizesEnum: () => + AttributeEnumType().values([ + AttributePlainEnumValue.presets.s(), + AttributePlainEnumValue.presets.m(), + ]), + + bigSizesEnum: () => + AttributeEnumType().values([ + AttributePlainEnumValue.presets.l(), + AttributePlainEnumValue.presets.xl(), + ]), +}; export default presets; diff --git a/models/product-type/src/attribute-localized-enum-type/presets/index.ts b/models/product-type/src/attribute-localized-enum-type/presets/index.ts index 763e57fe0..e796e6687 100644 --- a/models/product-type/src/attribute-localized-enum-type/presets/index.ts +++ b/models/product-type/src/attribute-localized-enum-type/presets/index.ts @@ -1,3 +1,26 @@ -const presets = {}; +import { AttributeLocalizedEnumValue } from '../..'; +import AttributeLocalizedEnumType from '../builder'; + +const presets = { + allSizesLenum: () => + AttributeLocalizedEnumType().values([ + AttributeLocalizedEnumValue.presets.s(), + AttributeLocalizedEnumValue.presets.m(), + AttributeLocalizedEnumValue.presets.l(), + AttributeLocalizedEnumValue.presets.xl(), + ]), + + smallSizesLenum: () => + AttributeLocalizedEnumType().values([ + AttributeLocalizedEnumValue.presets.s(), + AttributeLocalizedEnumValue.presets.m(), + ]), + + bigSizesLenum: () => + AttributeLocalizedEnumType().values([ + AttributeLocalizedEnumValue.presets.l(), + AttributeLocalizedEnumValue.presets.xl(), + ]), +}; export default presets; diff --git a/models/product-type/src/attribute-localized-enum-type/transformers.ts b/models/product-type/src/attribute-localized-enum-type/transformers.ts index 1911563ce..c8c90c858 100644 --- a/models/product-type/src/attribute-localized-enum-type/transformers.ts +++ b/models/product-type/src/attribute-localized-enum-type/transformers.ts @@ -25,6 +25,7 @@ const transformers = { results: fields.values!.map((value) => buildField(value, 'graphql') ) as unknown as Array, + total: fields.values.length, __typename: 'LocalizableEnumValueTypeResult', }, __typename: 'LocalizableEnumAttributeDefinitionType', diff --git a/models/product-type/src/attribute-localized-enum-value/presets/index.ts b/models/product-type/src/attribute-localized-enum-value/presets/index.ts index 763e57fe0..3b2880537 100644 --- a/models/product-type/src/attribute-localized-enum-value/presets/index.ts +++ b/models/product-type/src/attribute-localized-enum-value/presets/index.ts @@ -1,3 +1,23 @@ -const presets = {}; +import { LocalizedString } from '@commercetools-test-data/commons'; +import AttributeLocalizedEnumValue from '../builder'; + +const presets = { + s: () => + AttributeLocalizedEnumValue() + .key('s') + .label(LocalizedString.presets.empty().en('Size S').de('Größe S')), + m: () => + AttributeLocalizedEnumValue() + .key('m') + .label(LocalizedString.presets.empty().en('Size M').de('Größe M')), + l: () => + AttributeLocalizedEnumValue() + .key('l') + .label(LocalizedString.presets.empty().en('Size L').de('Größe L')), + xl: () => + AttributeLocalizedEnumValue() + .key('xl') + .label(LocalizedString.presets.empty().en('Size XL').de('Größe XL')), +}; export default presets; diff --git a/models/product-type/src/attribute-plain-enum-value/presets/index.ts b/models/product-type/src/attribute-plain-enum-value/presets/index.ts index 763e57fe0..e7cb3ece6 100644 --- a/models/product-type/src/attribute-plain-enum-value/presets/index.ts +++ b/models/product-type/src/attribute-plain-enum-value/presets/index.ts @@ -1,3 +1,13 @@ -const presets = {}; +import AttributePlainEnumValue from '../builder'; + +const presets = { + red: () => AttributePlainEnumValue().key('red').label('Red color'), + blue: () => AttributePlainEnumValue().key('blue').label('Blue color'), + green: () => AttributePlainEnumValue().key('green').label('Green color'), + s: () => AttributePlainEnumValue().key('s').label('Size S'), + m: () => AttributePlainEnumValue().key('m').label('Size M'), + l: () => AttributePlainEnumValue().key('l').label('Size L'), + xl: () => AttributePlainEnumValue().key('xl').label('Size XL'), +}; export default presets; diff --git a/models/product-type/src/product-type/transformers.ts b/models/product-type/src/product-type/transformers.ts index e3d29e9bc..afcb86639 100644 --- a/models/product-type/src/product-type/transformers.ts +++ b/models/product-type/src/product-type/transformers.ts @@ -17,6 +17,7 @@ const transformers = { results: fields.attributes!.map((attribute) => buildField(attribute, 'graphql') ) as unknown as Array, + total: fields.attributes!.length, __typename: 'AttributeDefinitionResult', }, }), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 321fbf091..525c81762 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -699,6 +699,9 @@ importers: '@commercetools-test-data/core': specifier: 10.10.1 version: link:../../core + '@commercetools-test-data/graphql-types': + specifier: 10.10.1 + version: link:../../graphql-types '@commercetools-test-data/product': specifier: 10.10.1 version: link:../product