From 9a34027f59a9a9075645a74095673c00564809b2 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Mon, 19 Aug 2024 18:28:42 +0200 Subject: [PATCH 01/17] refactor(product-projection): working on ref attributes --- models/commons/src/reference/generator.ts | 1 + models/commons/src/reference/transformers.ts | 38 +- models/commons/src/reference/types.ts | 35 +- models/product-projection/src/builder.spec.ts | 363 ++++++++++-------- models/product-projection/src/generator.ts | 8 +- models/product-projection/src/transformers.ts | 95 +++-- models/product-projection/src/types.ts | 18 +- 7 files changed, 350 insertions(+), 208 deletions(-) diff --git a/models/commons/src/reference/generator.ts b/models/commons/src/reference/generator.ts index bcbe91c1f..78be9b02e 100644 --- a/models/commons/src/reference/generator.ts +++ b/models/commons/src/reference/generator.ts @@ -6,6 +6,7 @@ const generator = Generator({ fields: { id: fake((f) => f.string.uuid()), typeId: null, + obj: null, }, }); diff --git a/models/commons/src/reference/transformers.ts b/models/commons/src/reference/transformers.ts index d585a166e..96138b37d 100644 --- a/models/commons/src/reference/transformers.ts +++ b/models/commons/src/reference/transformers.ts @@ -1,22 +1,44 @@ import { Transformer } from '@commercetools-test-data/core'; import omit from 'lodash/omit'; -import type { TReference, TReferenceGraphql, TReferenceRest } from './types'; +import type { + TExpandedReferenceObject, + TReference, + TReferenceGraphql, + TReferenceRest, +} from './types'; const transformers = { default: Transformer('default', {}), rest: Transformer('rest', { - replaceFields: ({ fields }) => ({ - ...fields, - obj: omit(fields, ['typeId']), - }), + replaceFields: ({ fields }) => { + const obj = fields.obj + ? fields.obj.buildRest() + : { + id: fields.id, + }; + + return { + ...fields, + id: obj.id, + obj, + }; + }, }), // we do not add the expanded object ourselves // since some fields are pure `*Ref`, e.g `channelsRef` // with no option to expand. graphql: Transformer('graphql', { - addFields: () => ({ - __typename: 'Reference', - }), + replaceFields: ({ fields }) => { + const id = fields.obj + ? fields.obj.buildGraphql().id + : fields.id; + + return { + id, + typeId: fields.typeId, + __typename: 'Reference', + }; + }, }), }; diff --git a/models/commons/src/reference/types.ts b/models/commons/src/reference/types.ts index 2fd633148..d7aed2dbc 100644 --- a/models/commons/src/reference/types.ts +++ b/models/commons/src/reference/types.ts @@ -1,31 +1,25 @@ import type { TBuilder } from '@commercetools-test-data/core'; -export type TReferenceBuilder = TBuilder>; +export type TExpandedReferenceObject = { + id: string; + version?: number; +}; export interface TReference { typeId: TypeId; id: string; + obj?: TBuilder; } -export type TExpandedReferenceObject = { - id: TReference['id']; - version?: number; -}; - -export type TCreateReferenceBuilder = - () => TReferenceBuilder; - export type TReferenceRest< - TypeId = string, - ExpandedObject extends TExpandedReferenceObject = TExpandedReferenceObject -> = TReference & { - obj: ExpandedObject; + ExpandedObject extends TExpandedReferenceObject = TExpandedReferenceObject, +> = Omit & { + obj?: ExpandedObject; }; -export type TReferenceGraphql = - TExpandedReferenceObject & { - __typename: 'Reference'; - }; +export type TReferenceGraphql = Omit & { + __typename: 'Reference'; +}; // Draft representation export interface TReferenceDraft { @@ -33,8 +27,11 @@ export interface TReferenceDraft { id: string; } -export type TReferenceDraftGraphql = - TExpandedReferenceObject; +export type TReferenceDraftGraphql = TExpandedReferenceObject; + +export type TReferenceBuilder = TBuilder>; +export type TCreateReferenceBuilder = + () => TReferenceBuilder; export type TReferenceDraftBuilder = TBuilder< TReferenceDraft diff --git a/models/product-projection/src/builder.spec.ts b/models/product-projection/src/builder.spec.ts index 709e044ec..31be16299 100644 --- a/models/product-projection/src/builder.spec.ts +++ b/models/product-projection/src/builder.spec.ts @@ -4,13 +4,18 @@ import { Category } from '@commercetools-test-data/category'; import { LocalizedString, Reference } from '@commercetools-test-data/commons'; import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; import { ProductVariant } from '@commercetools-test-data/product'; -import { ProductType } from '@commercetools-test-data/product-type'; +import { + ProductType, + TProductType, +} from '@commercetools-test-data/product-type'; import { TProductProjection, TProductProjectionGraphql, TProductProjectionRest, } from './types'; import * as ProductProjection from './index'; +import { State } from '@commercetools-test-data/state'; +import { TaxCategory } from '@commercetools-test-data/tax-category'; describe('builder', () => { const expectedGeneralLocalizedString = expect.objectContaining({ @@ -26,6 +31,40 @@ describe('builder', () => { }), ]); + it('Base', () => { + const restProductProjection = ProductProjection.random() + .productType( + Reference.presets + .productTypeReference() + .obj(ProductType.presets.milk().id('product-type-id')) + ) + .buildRest(); + // const graphqlProductProjection = + // ProductProjection.random().buildGraphql(); + // console.log({ + // rest: restProductProjection.productType, + // graphql: graphqlProductProjection.productType, + // gqlProductTypeRef: graphqlProductProjection.productTypeRef, + // }); + + // const productTypeRef = Reference.presets + // .productTypeReference() + // .typeId('product-type') + // .obj(ProductType.presets.milk().id('product-type-id')) + // .buildRest(); + + console.log({ restProductProjection: restProductProjection.productType }); + + // const ref = Reference.random() + // .typeId('product-type') + // .obj(ProductType.random().id('isla-bonita')); + // console.log({ + // rawRef: ref, + // restRef: ref.buildRest(), + // graphqlRef: ref.buildGraphql(), + // }); + }); + it( ...createBuilderSpec( 'default', @@ -126,30 +165,26 @@ describe('builder', () => { key: expect.any(String), productType: expect.objectContaining({ id: expect.any(String), - key: expect.any(String), - version: expect.any(Number), - createdAt: expect.any(String), - createdBy: expect.objectContaining({ - customer: expect.objectContaining({ typeId: 'customer' }), - }), - lastModifiedAt: expect.any(String), - lastModifiedBy: expect.objectContaining({ - customer: expect.objectContaining({ typeId: 'customer' }), + typeId: expect.any(String), + obj: expect.objectContaining({ + id: expect.any(String), + key: expect.any(String), + version: expect.any(Number), + name: expect.any(String), + description: expect.any(String), + attributes: expect.arrayContaining([ + expect.objectContaining({ + type: expect.objectContaining({ name: expect.any(String) }), + name: expect.any(String), + label: expectedGeneralLocalizedString, + isRequired: expect.any(Boolean), + attributeConstraint: expect.any(String), + inputTip: expectedGeneralLocalizedString, + inputHint: expect.any(String), + isSearchable: expect.any(Boolean), + }), + ]), }), - name: expect.any(String), - description: expect.any(String), - attributes: expect.arrayContaining([ - expect.objectContaining({ - type: expect.objectContaining({ name: expect.any(String) }), - name: expect.any(String), - label: expectedGeneralLocalizedString, - isRequired: expect.any(Boolean), - attributeConstraint: expect.any(String), - inputTip: expectedGeneralLocalizedString, - inputHint: expect.any(String), - isSearchable: expect.any(Boolean), - }), - ]), }), name: expectedGeneralLocalizedString, description: expectedGeneralLocalizedString, @@ -246,7 +281,7 @@ describe('builder', () => { ) ); - it('should allow customization', () => { + describe('when customizing the model', () => { const productProjectionMock = ProductProjection.presets .happyCowMilkProductProjection() .categories([ @@ -261,7 +296,12 @@ describe('builder', () => { .key('happy-cow-milk-key') .metaKeywords(LocalizedString.presets.empty().en('happy')) .priceMode('Embedded') - .productType(ProductType.presets.milk().id('product-type-id')) + // .productType(ProductType.presets.milk().id('product-type-id')) + .productType( + Reference.presets + .productTypeReference() + .obj(ProductType.presets.milk().id('product-type-id')) + ) .reviewRatingStatistics({ averageRating: 3.12345, highestRating: 4.9, @@ -272,141 +312,160 @@ describe('builder', () => { .searchKeywords({ en: [{ text: 'product search keyword' }], }) - .state(Reference.presets.stateReference()) - .taxCategory(Reference.presets.taxCategoryReference()) + .state( + Reference.presets.stateReference().obj(State.random().id('state-id')) + ) + .taxCategory( + Reference.presets + .taxCategoryReference() + .obj(TaxCategory.random().id('tax-category-id')) + ) .variants([ProductVariant.random().key('alternative-variant-key')]) - .version(222) - .buildGraphql(); + .version(222); - const expectedLocalizedName = expect.arrayContaining([ - expect.objectContaining({ - locale: 'en', - value: 'Happy Cow Milk', - }), - expect.objectContaining({ - locale: 'de', - value: 'Fröhliche Kuhmilch', - }), - ]); - const expectedLocalizedDescription = expect.arrayContaining([ - expect.objectContaining({ - locale: 'en', - value: 'Very happy milk produced by very happy cow!', - }), - expect.objectContaining({ - locale: 'de', - value: 'Sehr glückliche Milch von sehr glücklicher Kuh!', - }), - ]); + it.todo('should build the right rest model'); - expect(productProjectionMock).toEqual( - expect.objectContaining({ - categories: expect.arrayContaining([ - expect.objectContaining({ - id: 'category-id', - name: 'category-name', - __typename: 'Category', - }), - ]), - categoryOrderHints: expect.arrayContaining([ - { - categoryId: 'category-1', - orderHint: '0.4', - __typename: 'CategoryOrderHint', - }, - ]), - categoriesRef: expect.arrayContaining([ - expect.objectContaining({ - typeId: 'category', - id: 'category-id', - __typename: 'Reference', - }), - ]), - description: 'Very happy milk produced by very happy cow!', - descriptionAllLocales: expectedLocalizedDescription, - hasStagedChanges: false, - id: 'happy-cow-milk-id', - key: 'happy-cow-milk-key', - masterVariant: expect.objectContaining({ - __typename: 'ProductVariant', - key: 'happy-cow-master-variant-key', - sku: 'happy-cow-master-variant-sku', + it.only('should build the right graphql model', () => { + const grapqlProductProjection = + productProjectionMock.buildGraphql(); + + console.log({ + productType: grapqlProductProjection.taxCategory, + productTypeRef: grapqlProductProjection.taxCategoryRef, + }); + + const expectedLocalizedName = expect.arrayContaining([ + expect.objectContaining({ + locale: 'en', + value: 'Happy Cow Milk', }), - metaDescription: 'Very happy milk produced by very happy cow!', - metaDescriptionAllLocales: expectedLocalizedDescription, - metaKeywords: 'happy', - metaKeywordsAllLocales: expect.arrayContaining([ - expect.objectContaining({ - locale: 'en', - value: 'happy', - }), - ]), - metaTitle: 'Happy Cow Milk', - metaTitleAllLocales: expectedLocalizedName, - name: 'Happy Cow Milk', - nameAllLocales: expectedLocalizedName, - priceMode: 'Embedded', - productType: expect.objectContaining({ - __typename: 'ProductTypeDefinition', - name: 'Milk Product Type', + expect.objectContaining({ + locale: 'de', + value: 'Fröhliche Kuhmilch', }), - productTypeRef: expect.objectContaining({ - typeId: 'product-type', - id: 'product-type-id', - __typename: 'Reference', + ]); + const expectedLocalizedDescription = expect.arrayContaining([ + expect.objectContaining({ + locale: 'en', + value: 'Very happy milk produced by very happy cow!', }), - published: true, - reviewRatingStatistics: expect.objectContaining({ - averageRating: 3.12345, - highestRating: 4.9, - lowestRating: 2.1, - count: 25, - ratingsDistribution: {}, - __typename: 'ReviewRatingStatistics', + expect.objectContaining({ + locale: 'de', + value: 'Sehr glückliche Milch von sehr glücklicher Kuh!', }), - searchKeywords: expect.arrayContaining([ - expect.objectContaining({ - locale: 'en', - searchKeywords: [ - { - text: 'product search keyword', - suggestTokenizer: undefined, - }, - ], - __typename: 'SearchKeywordsProductSearch', + ]); + + expect(grapqlProductProjection).toEqual( + expect.objectContaining({ + categories: expect.arrayContaining([ + expect.objectContaining({ + id: 'category-id', + name: 'category-name', + __typename: 'Category', + }), + ]), + categoryOrderHints: expect.arrayContaining([ + { + categoryId: 'category-1', + orderHint: '0.4', + __typename: 'CategoryOrderHint', + }, + ]), + categoriesRef: expect.arrayContaining([ + expect.objectContaining({ + typeId: 'category', + id: 'category-id', + __typename: 'Reference', + }), + ]), + description: 'Very happy milk produced by very happy cow!', + descriptionAllLocales: expectedLocalizedDescription, + hasStagedChanges: false, + id: 'happy-cow-milk-id', + key: 'happy-cow-milk-key', + masterVariant: expect.objectContaining({ + __typename: 'ProductVariant', + key: 'happy-cow-master-variant-key', + sku: 'happy-cow-master-variant-sku', }), - ]), - slug: 'happy-cow-milk-slug', - slugAllLocales: expect.arrayContaining([ - expect.objectContaining({ - locale: 'en', - value: 'happy-cow-milk-slug', + metaDescription: 'Very happy milk produced by very happy cow!', + metaDescriptionAllLocales: expectedLocalizedDescription, + metaKeywords: 'happy', + metaKeywordsAllLocales: expect.arrayContaining([ + expect.objectContaining({ + locale: 'en', + value: 'happy', + }), + ]), + metaTitle: 'Happy Cow Milk', + metaTitleAllLocales: expectedLocalizedName, + name: 'Happy Cow Milk', + nameAllLocales: expectedLocalizedName, + priceMode: 'Embedded', + productType: expect.objectContaining({ + __typename: 'ProductTypeDefinition', + name: 'Milk Product Type', }), - ]), - state: expect.objectContaining({ - id: 'product-type-id', - __typename: 'State', - }), - stateRef: expect.objectContaining({ - typeId: 'state', - __typename: 'Reference', - }), - taxCategory: expect.objectContaining({ - id: 'product-type-id', - __typename: 'TaxCategory', - }), - taxCategoryRef: expect.objectContaining({ - typeId: 'tax-category', - __typename: 'Reference', - }), - variants: expect.arrayContaining([ - expect.objectContaining({ - key: 'alternative-variant-key', - __typename: 'ProductVariant', + productTypeRef: expect.objectContaining({ + typeId: 'product-type', + id: 'product-type-id', + __typename: 'Reference', }), - ]), - version: 222, - }) - ); + published: true, + reviewRatingStatistics: expect.objectContaining({ + averageRating: 3.12345, + highestRating: 4.9, + lowestRating: 2.1, + count: 25, + ratingsDistribution: {}, + __typename: 'ReviewRatingStatistics', + }), + searchKeywords: expect.arrayContaining([ + expect.objectContaining({ + locale: 'en', + searchKeywords: [ + { + text: 'product search keyword', + suggestTokenizer: undefined, + }, + ], + __typename: 'SearchKeywordsProductSearch', + }), + ]), + slug: 'happy-cow-milk-slug', + slugAllLocales: expect.arrayContaining([ + expect.objectContaining({ + locale: 'en', + value: 'happy-cow-milk-slug', + }), + ]), + state: expect.objectContaining({ + id: 'state-id', + __typename: 'State', + }), + stateRef: expect.objectContaining({ + id: 'state-id', + typeId: 'state', + __typename: 'Reference', + }), + taxCategory: expect.objectContaining({ + id: 'tax-category-id', + __typename: 'TaxCategory', + }), + taxCategoryRef: expect.objectContaining({ + id: 'tax-category-id', + typeId: 'tax-category', + __typename: 'Reference', + }), + variants: expect.arrayContaining([ + expect.objectContaining({ + key: 'alternative-variant-key', + __typename: 'ProductVariant', + }), + ]), + version: 222, + }) + ); + }); }); }); diff --git a/models/product-projection/src/generator.ts b/models/product-projection/src/generator.ts index 4f80eb2ed..c30a6430e 100644 --- a/models/product-projection/src/generator.ts +++ b/models/product-projection/src/generator.ts @@ -1,4 +1,4 @@ -import { LocalizedString } from '@commercetools-test-data/commons'; +import { LocalizedString, Reference } from '@commercetools-test-data/commons'; import { Generator, fake, sequence } from '@commercetools-test-data/core'; import { ProductVariant } from '@commercetools-test-data/product'; import { ProductType } from '@commercetools-test-data/product-type'; @@ -14,7 +14,11 @@ export default Generator({ version: sequence(), createdAt: fake(getOlderDate), lastModifiedAt: fake(getNewerDate), - productType: fake(() => ProductType.random()), + productType: fake(() => + Reference.random() + .typeId('product-type') + .obj(ProductType.random().id('isla-bonita')) + ), name: fake(() => LocalizedString.random()), description: fake(() => LocalizedString.random()), slug: fake(() => LocalizedString.presets.ofSlugs()), diff --git a/models/product-projection/src/transformers.ts b/models/product-projection/src/transformers.ts index 602dd518c..bec9d96b7 100644 --- a/models/product-projection/src/transformers.ts +++ b/models/product-projection/src/transformers.ts @@ -3,8 +3,12 @@ import { Reference, type TReferenceGraphql, } from '@commercetools-test-data/commons'; -import { Transformer } from '@commercetools-test-data/core'; -import { State, TState } from '@commercetools-test-data/state'; +import { Transformer, buildField } from '@commercetools-test-data/core'; +import { + ProductType, + TProductTypeGraphql, +} from '@commercetools-test-data/product-type'; +import { State, TState, TStateGraphql } from '@commercetools-test-data/state'; import { TaxCategory, TTaxCategory, @@ -20,7 +24,6 @@ import type { const transformers = { default: Transformer('default', { buildFields: [ - 'productType', 'name', 'description', 'slug', @@ -57,12 +60,11 @@ const transformers = { 'graphql', { buildFields: [ - 'productType', 'categories', 'masterVariant', 'variants', - 'taxCategory', - 'state', + // 'taxCategory', + // 'state', ], replaceFields: ({ fields }) => { const nameAllLocales = LocalizedString.toLocalizedField(fields.name)!; @@ -79,30 +81,70 @@ const transformers = { const metaDescriptionAllLocales = LocalizedString.toLocalizedField( fields.metaDescription ); - const productTypeRef = Reference.random() - .id(fields.productType.id) - .typeId('product-type') - .buildGraphql(); - const state = fields.state - ? State.random().id(fields.productType.id).buildGraphql() - : undefined; - const stateRef = fields.state - ? Reference.random() - .id(fields.productType.id) - .typeId('state') - .buildGraphql() + + const restProductType = buildField(fields.productType, 'rest'); + const productTypeRef = buildField( + fields.productType, + 'graphql' + ) as TReferenceGraphql; + const productType = ProductType.random() + .description(restProductType.obj?.description || '') + .id(restProductType.id) + .key(restProductType.obj?.key || '') + .name(restProductType.obj?.name || '') + .buildGraphql(); + + // const restState = fields.state + // ? buildField(fields.state, 'rest') + // : buildField(State.random().id(fields.productType.id), 'rest'); + const restState = buildField(fields.state, 'rest'); + const stateRef = buildField( + fields.state, + 'graphql' + ) as TReferenceGraphql; + const state = restState + ? State.random() + .id(restState.id) + .key(restState.obj?.key || '') + .version(restState.obj?.version || 1) + .type(restState.obj?.type || 'unknown') + .buildGraphql() : undefined; - const taxCategory = fields.taxCategory + // const stateRef = fields.state + // ? Reference.random() + // .id(fields.productType.id) + // .typeId('state') + // .buildGraphql() + // : undefined; + + console.log('ProductProjection graphql transformer', { + taxCategory: fields.taxCategory, + }); + + const restTaxCategory = buildField(fields.taxCategory, 'rest'); + const taxCategory = restTaxCategory ? TaxCategory.random() - .id(fields.productType.id) + .id(restTaxCategory.id) + .key(restTaxCategory.obj?.key || '') + .name(restTaxCategory.obj?.name || '') + .description(restTaxCategory.obj?.description || '') + .version(restTaxCategory.obj?.version || 1) .buildGraphql() : undefined; - const taxCategoryRef = fields.taxCategory - ? Reference.random() - .id(fields.productType.id) - .typeId('tax-category') - .buildGraphql() - : undefined; + console.log('ProductProjection graphql transformer', { + input: fields.taxCategory, + output: taxCategory, + }); + // const taxCategoryRef = fields.taxCategory + // ? Reference.random() + // .id(fields.productType.id) + // .typeId('tax-category') + // .buildGraphql() + // : undefined; + const taxCategoryRef = buildField( + fields.taxCategory, + 'graphql' + ) as TReferenceGraphql; const categoriesRef = fields.categories.map((category) => ({ id: category.id, typeId: 'category' as const, @@ -161,6 +203,7 @@ const transformers = { ), metaDescriptionAllLocales, reviewRatingStatistics, + productType, productTypeRef, state, stateRef, diff --git a/models/product-projection/src/types.ts b/models/product-projection/src/types.ts index bd464cd9b..ac789b2e6 100644 --- a/models/product-projection/src/types.ts +++ b/models/product-projection/src/types.ts @@ -3,17 +3,31 @@ import { ReviewRatingStatistics, SuggestTokenizer, } from '@commercetools/platform-sdk'; +import { TCategory } from '@commercetools-test-data/category'; import { TLocalizedStringDraftGraphql, + TReferenceRest, TReferenceGraphql, } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; +import { + TProductType, + TProductTypeGraphql, +} from '@commercetools-test-data/product-type'; import { TState } from '@commercetools-test-data/state'; import { TTaxCategory } from '@commercetools-test-data/tax-category'; export type TProductProjection = ProductProjection; -export type TProductProjectionRest = TProductProjection; +export type TProductProjectionRest = Omit< + TProductProjection, + 'productType' | 'categories' | 'taxCategory' | 'state' +> & { + productType: TReferenceRest; + categories: TReferenceRest[]; + taxCategory?: TReferenceRest; + state?: TReferenceRest; +}; export type TCategoryOrderHintGraphql = { categoryId: string; @@ -39,6 +53,7 @@ export type TProductProjectionGraphql = Omit< | 'metaDescription' | 'metaKeywords' | 'name' + | 'productType' | 'searchKeywords' | 'slug' | 'state' @@ -56,6 +71,7 @@ export type TProductProjectionGraphql = Omit< metaKeywordsAllLocales?: TLocalizedStringDraftGraphql | null; metaTitle?: string; metaTitleAllLocales?: TLocalizedStringDraftGraphql | null; + productType: TProductTypeGraphql; productTypeRef: TReferenceGraphql; reviewRatingStatistics?: ReviewRatingStatistics & { __typename: 'ReviewRatingStatistics'; From 4024e50892baef391ce68cfc0e8c784ff7dd39db Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Tue, 20 Aug 2024 12:30:33 +0200 Subject: [PATCH 02/17] refactor(reference): allow obj property customization --- models/commons/src/reference/builder.spec.ts | 57 ++++++++++++++++++++ models/commons/src/reference/generator.ts | 2 +- models/commons/src/reference/transformers.ts | 5 +- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/models/commons/src/reference/builder.spec.ts b/models/commons/src/reference/builder.spec.ts index ef4c9a6c1..f23eeace3 100644 --- a/models/commons/src/reference/builder.spec.ts +++ b/models/commons/src/reference/builder.spec.ts @@ -1,9 +1,32 @@ /* eslint-disable jest/no-disabled-tests */ /* eslint-disable jest/valid-title */ +import { + Builder, + fake, + Generator, + Transformer, +} from '@commercetools-test-data/core'; import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; import type { TReference, TReferenceGraphql, TReferenceRest } from './types'; import * as Reference from './index'; +// We use this dummy model in the customization tests. +// It is a simple model so we don't need to depend on other models. +const DummyModel = () => + Builder<{ id: string; name: string }>({ + generator: Generator<{ id: string; name: string }>({ + fields: { + id: fake((f) => f.string.uuid()), + name: fake((f) => f.person.fullName()), + }, + }), + transformers: { + default: Transformer('default', {}), + rest: Transformer('rest', {}), + graphql: Transformer('graphql', {}), + }, + }); + describe('builder', () => { it( ...createBuilderSpec( @@ -39,4 +62,38 @@ describe('builder', () => { } ) ); + + describe('when customizing the model', () => { + const referenceMock = Reference.random() + .typeId('dummy-type') + .obj(DummyModel().id('dummy-id').name('dummy-name')); + + it('should build the right rest model', () => { + const restReference = referenceMock.buildRest(); + console.log(restReference); + expect(restReference).toEqual( + expect.objectContaining({ + id: 'dummy-id', + typeId: 'dummy-type', + obj: { + id: 'dummy-id', + name: 'dummy-name', + }, + }) + ); + }); + it('should build the right graphql model', () => { + const graphqlReference = referenceMock.buildGraphql(); + expect(graphqlReference).toEqual( + expect.objectContaining({ + __typename: 'Reference', + id: 'dummy-id', + typeId: 'dummy-type', + }) + ); + // @ts-expect-error "obj" is not defined in the graphql model + // but we want to make sure the built model does not include it + expect(graphqlReference.obj).toBeUndefined(); + }); + }); }); diff --git a/models/commons/src/reference/generator.ts b/models/commons/src/reference/generator.ts index 78be9b02e..f98bcd735 100644 --- a/models/commons/src/reference/generator.ts +++ b/models/commons/src/reference/generator.ts @@ -6,7 +6,7 @@ const generator = Generator({ fields: { id: fake((f) => f.string.uuid()), typeId: null, - obj: null, + obj: undefined, }, }); diff --git a/models/commons/src/reference/transformers.ts b/models/commons/src/reference/transformers.ts index 96138b37d..bce87f102 100644 --- a/models/commons/src/reference/transformers.ts +++ b/models/commons/src/reference/transformers.ts @@ -1,5 +1,4 @@ import { Transformer } from '@commercetools-test-data/core'; -import omit from 'lodash/omit'; import type { TExpandedReferenceObject, TReference, @@ -8,7 +7,9 @@ import type { } from './types'; const transformers = { - default: Transformer('default', {}), + default: Transformer('default', { + buildFields: ['obj'], + }), rest: Transformer('rest', { replaceFields: ({ fields }) => { const obj = fields.obj From fd9218531c2b61e421cd02ae17ec9f97dc096477 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Tue, 20 Aug 2024 12:32:24 +0200 Subject: [PATCH 03/17] fix(product-projection): fix references properties management --- models/product-projection/src/builder.spec.ts | 231 +++++++++++------- models/product-projection/src/generator.ts | 4 +- models/product-projection/src/transformers.ts | 127 +++++----- models/product-projection/src/types.ts | 31 ++- 4 files changed, 227 insertions(+), 166 deletions(-) diff --git a/models/product-projection/src/builder.spec.ts b/models/product-projection/src/builder.spec.ts index 31be16299..453a4204b 100644 --- a/models/product-projection/src/builder.spec.ts +++ b/models/product-projection/src/builder.spec.ts @@ -4,18 +4,15 @@ import { Category } from '@commercetools-test-data/category'; import { LocalizedString, Reference } from '@commercetools-test-data/commons'; import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; import { ProductVariant } from '@commercetools-test-data/product'; -import { - ProductType, - TProductType, -} from '@commercetools-test-data/product-type'; +import { ProductType } from '@commercetools-test-data/product-type'; +import { State } from '@commercetools-test-data/state'; +import { TaxCategory } from '@commercetools-test-data/tax-category'; import { TProductProjection, TProductProjectionGraphql, TProductProjectionRest, } from './types'; import * as ProductProjection from './index'; -import { State } from '@commercetools-test-data/state'; -import { TaxCategory } from '@commercetools-test-data/tax-category'; describe('builder', () => { const expectedGeneralLocalizedString = expect.objectContaining({ @@ -31,40 +28,6 @@ describe('builder', () => { }), ]); - it('Base', () => { - const restProductProjection = ProductProjection.random() - .productType( - Reference.presets - .productTypeReference() - .obj(ProductType.presets.milk().id('product-type-id')) - ) - .buildRest(); - // const graphqlProductProjection = - // ProductProjection.random().buildGraphql(); - // console.log({ - // rest: restProductProjection.productType, - // graphql: graphqlProductProjection.productType, - // gqlProductTypeRef: graphqlProductProjection.productTypeRef, - // }); - - // const productTypeRef = Reference.presets - // .productTypeReference() - // .typeId('product-type') - // .obj(ProductType.presets.milk().id('product-type-id')) - // .buildRest(); - - console.log({ restProductProjection: restProductProjection.productType }); - - // const ref = Reference.random() - // .typeId('product-type') - // .obj(ProductType.random().id('isla-bonita')); - // console.log({ - // rawRef: ref, - // restRef: ref.buildRest(), - // graphqlRef: ref.buildGraphql(), - // }); - }); - it( ...createBuilderSpec( 'default', @@ -75,38 +38,42 @@ describe('builder', () => { key: expect.any(String), productType: expect.objectContaining({ id: expect.any(String), - key: expect.any(String), - version: expect.any(Number), - createdAt: expect.any(String), - createdBy: expect.objectContaining({ - customer: expect.objectContaining({ typeId: 'customer' }), - }), - lastModifiedAt: expect.any(String), - lastModifiedBy: expect.objectContaining({ - customer: expect.objectContaining({ typeId: 'customer' }), - }), - name: expect.any(String), - description: expect.any(String), - attributes: expect.arrayContaining([ - expect.objectContaining({ - type: expect.objectContaining({ name: expect.any(String) }), - name: expect.any(String), - label: expect.objectContaining({ - de: expect.any(String), - en: expect.any(String), - fr: expect.any(String), - }), - isRequired: expect.any(Boolean), - attributeConstraint: expect.any(String), - inputTip: expect.objectContaining({ - de: expect.any(String), - en: expect.any(String), - fr: expect.any(String), - }), - inputHint: expect.any(String), - isSearchable: expect.any(Boolean), + typeId: expect.any(String), + obj: expect.objectContaining({ + id: expect.any(String), + key: expect.any(String), + version: expect.any(Number), + createdAt: expect.any(String), + createdBy: expect.objectContaining({ + customer: expect.objectContaining({ typeId: 'customer' }), }), - ]), + lastModifiedAt: expect.any(String), + lastModifiedBy: expect.objectContaining({ + customer: expect.objectContaining({ typeId: 'customer' }), + }), + name: expect.any(String), + description: expect.any(String), + attributes: expect.arrayContaining([ + expect.objectContaining({ + type: expect.objectContaining({ name: expect.any(String) }), + name: expect.any(String), + label: expect.objectContaining({ + de: expect.any(String), + en: expect.any(String), + fr: expect.any(String), + }), + isRequired: expect.any(Boolean), + attributeConstraint: expect.any(String), + inputTip: expect.objectContaining({ + de: expect.any(String), + en: expect.any(String), + fr: expect.any(String), + }), + inputHint: expect.any(String), + isSearchable: expect.any(Boolean), + }), + ]), + }), }), name: expectedGeneralLocalizedString, description: expectedGeneralLocalizedString, @@ -271,8 +238,8 @@ describe('builder', () => { sku: expect.any(String), }), variants: [], - taxCategory: undefined, - state: undefined, + taxCategory: null, + state: null, createdAt: expect.any(String), lastModifiedAt: expect.any(String), reviewRatingStatistics: undefined, @@ -285,9 +252,13 @@ describe('builder', () => { const productProjectionMock = ProductProjection.presets .happyCowMilkProductProjection() .categories([ - Category.random() - .id('category-id') - .name(LocalizedString.presets.empty().en('category-name')), + Reference.presets + .categoryReference() + .obj( + Category.random() + .id('category-id') + .name(LocalizedString.presets.empty().en('category-name')) + ), ]) .categoryOrderHints({ 'category-1': '0.4', @@ -296,7 +267,6 @@ describe('builder', () => { .key('happy-cow-milk-key') .metaKeywords(LocalizedString.presets.empty().en('happy')) .priceMode('Embedded') - // .productType(ProductType.presets.milk().id('product-type-id')) .productType( Reference.presets .productTypeReference() @@ -323,17 +293,110 @@ describe('builder', () => { .variants([ProductVariant.random().key('alternative-variant-key')]) .version(222); - it.todo('should build the right rest model'); + it('should build the right rest model', () => { + const restProductProjection = + productProjectionMock.buildRest(); + + expect(restProductProjection).toEqual( + expect.objectContaining({ + categories: expect.arrayContaining([ + expect.objectContaining({ + typeId: 'category', + id: 'category-id', + obj: expect.objectContaining({ + id: 'category-id', + name: expect.objectContaining({ + en: 'category-name', + }), + }), + }), + ]), + categoryOrderHints: expect.objectContaining({ + 'category-1': '0.4', + }), + description: expect.objectContaining({ + en: 'Very happy milk produced by very happy cow!', + }), + hasStagedChanges: false, + id: 'happy-cow-milk-id', + key: 'happy-cow-milk-key', + masterVariant: expect.objectContaining({ + key: 'happy-cow-master-variant-key', + sku: 'happy-cow-master-variant-sku', + }), + metaDescription: expect.objectContaining({ + en: 'Very happy milk produced by very happy cow!', + }), + metaKeywords: expect.objectContaining({ + en: 'happy', + }), + metaTitle: expect.objectContaining({ + en: 'Happy Cow Milk', + }), + name: expect.objectContaining({ + en: 'Happy Cow Milk', + }), + priceMode: 'Embedded', + productType: expect.objectContaining({ + id: 'product-type-id', + typeId: 'product-type', + obj: expect.objectContaining({ + id: 'product-type-id', + name: 'Milk Product Type', + attributes: expect.any(Array), + }), + }), + published: true, + reviewRatingStatistics: expect.objectContaining({ + averageRating: 3.12345, + highestRating: 4.9, + lowestRating: 2.1, + count: 25, + ratingsDistribution: {}, + }), + searchKeywords: expect.objectContaining({ + en: expect.arrayContaining([ + { + text: 'product search keyword', + }, + ]), + }), + slug: expect.objectContaining({ + en: 'happy-cow-milk-slug', + }), + state: expect.objectContaining({ + id: 'state-id', + typeId: 'state', + obj: expect.objectContaining({ + id: 'state-id', + type: expect.any(String), + initial: expect.any(Boolean), + }), + }), + taxCategory: expect.objectContaining({ + id: 'tax-category-id', + typeId: 'tax-category', + obj: expect.objectContaining({ + id: 'tax-category-id', + name: expect.any(String), + rates: expect.any(Array), + }), + }), + variants: expect.arrayContaining([ + expect.objectContaining({ + key: 'alternative-variant-key', + sku: expect.any(String), + }), + ]), + version: 222, + }) + ); + }); - it.only('should build the right graphql model', () => { + it('should build the right graphql model', () => { const grapqlProductProjection = productProjectionMock.buildGraphql(); - console.log({ - productType: grapqlProductProjection.taxCategory, - productTypeRef: grapqlProductProjection.taxCategoryRef, - }); - const expectedLocalizedName = expect.arrayContaining([ expect.objectContaining({ locale: 'en', diff --git a/models/product-projection/src/generator.ts b/models/product-projection/src/generator.ts index c30a6430e..b1d9761c4 100644 --- a/models/product-projection/src/generator.ts +++ b/models/product-projection/src/generator.ts @@ -15,9 +15,7 @@ export default Generator({ createdAt: fake(getOlderDate), lastModifiedAt: fake(getNewerDate), productType: fake(() => - Reference.random() - .typeId('product-type') - .obj(ProductType.random().id('isla-bonita')) + Reference.random().typeId('product-type').obj(ProductType.random()) ), name: fake(() => LocalizedString.random()), description: fake(() => LocalizedString.random()), diff --git a/models/product-projection/src/transformers.ts b/models/product-projection/src/transformers.ts index bec9d96b7..b206d9aad 100644 --- a/models/product-projection/src/transformers.ts +++ b/models/product-projection/src/transformers.ts @@ -1,17 +1,21 @@ +import { Category, TCategoryGraphql } from '@commercetools-test-data/category'; import { LocalizedString, - Reference, type TReferenceGraphql, } from '@commercetools-test-data/commons'; -import { Transformer, buildField } from '@commercetools-test-data/core'; +import { + Transformer, + buildField, + buildFields, +} from '@commercetools-test-data/core'; import { ProductType, TProductTypeGraphql, } from '@commercetools-test-data/product-type'; -import { State, TState, TStateGraphql } from '@commercetools-test-data/state'; +import { State, TStateGraphql } from '@commercetools-test-data/state'; import { TaxCategory, - TTaxCategory, + TTaxCategoryGraphql, } from '@commercetools-test-data/tax-category'; import type { TCategoryOrderHintGraphql, @@ -24,6 +28,7 @@ import type { const transformers = { default: Transformer('default', { buildFields: [ + 'productType', 'name', 'description', 'slug', @@ -46,7 +51,6 @@ const transformers = { 'description', 'slug', 'categories', - 'categoryOrderHints', 'metaTitle', 'metaDescription', 'metaKeywords', @@ -59,13 +63,7 @@ const transformers = { graphql: Transformer( 'graphql', { - buildFields: [ - 'categories', - 'masterVariant', - 'variants', - // 'taxCategory', - // 'state', - ], + buildFields: ['masterVariant', 'variants'], replaceFields: ({ fields }) => { const nameAllLocales = LocalizedString.toLocalizedField(fields.name)!; const descriptionAllLocales = LocalizedString.toLocalizedField( @@ -94,62 +92,56 @@ const transformers = { .name(restProductType.obj?.name || '') .buildGraphql(); - // const restState = fields.state - // ? buildField(fields.state, 'rest') - // : buildField(State.random().id(fields.productType.id), 'rest'); - const restState = buildField(fields.state, 'rest'); - const stateRef = buildField( - fields.state, - 'graphql' - ) as TReferenceGraphql; - const state = restState - ? State.random() - .id(restState.id) - .key(restState.obj?.key || '') - .version(restState.obj?.version || 1) - .type(restState.obj?.type || 'unknown') - .buildGraphql() - : undefined; - // const stateRef = fields.state - // ? Reference.random() - // .id(fields.productType.id) - // .typeId('state') - // .buildGraphql() - // : undefined; + let state: TStateGraphql | null = null; + let stateRef: TReferenceGraphql | null = null; + if (fields.state) { + const restState = buildField(fields.state, 'rest'); + stateRef = buildField(fields.state, 'graphql') as TReferenceGraphql; + state = State.random() + .id(restState.id) + .key(restState.obj?.key || '') + .version(restState.obj?.version || 1) + .type(restState.obj?.type || 'unknown') + .buildGraphql(); + } - console.log('ProductProjection graphql transformer', { - taxCategory: fields.taxCategory, - }); + let taxCategory: TTaxCategoryGraphql | null = null; + let taxCategoryRef: TReferenceGraphql | null = null; + if (fields.taxCategory) { + const restTaxCategory = buildField(fields.taxCategory, 'rest'); + taxCategory = TaxCategory.random() + .id(restTaxCategory.id) + .key(restTaxCategory.obj?.key || '') + .name(restTaxCategory.obj?.name || '') + .description(restTaxCategory.obj?.description || '') + .version(restTaxCategory.obj?.version || 1) + .buildGraphql(); + taxCategoryRef = buildField( + fields.taxCategory, + 'graphql' + ) as TReferenceGraphql; + } - const restTaxCategory = buildField(fields.taxCategory, 'rest'); - const taxCategory = restTaxCategory - ? TaxCategory.random() - .id(restTaxCategory.id) - .key(restTaxCategory.obj?.key || '') - .name(restTaxCategory.obj?.name || '') - .description(restTaxCategory.obj?.description || '') - .version(restTaxCategory.obj?.version || 1) - .buildGraphql() - : undefined; - console.log('ProductProjection graphql transformer', { - input: fields.taxCategory, - output: taxCategory, - }); - // const taxCategoryRef = fields.taxCategory - // ? Reference.random() - // .id(fields.productType.id) - // .typeId('tax-category') - // .buildGraphql() - // : undefined; - const taxCategoryRef = buildField( - fields.taxCategory, + const categories = fields.categories + .map((category) => { + const restCategory = buildField(category, 'rest'); + const categoryObj = restCategory.obj; + if (categoryObj) { + return Category.random() + .id(categoryObj.id) + .key(categoryObj.key || '') + .name(LocalizedString.presets.empty().en(categoryObj.name.en)) + .version(categoryObj.version || 1) + .buildGraphql(); + } + return undefined; + }) + .filter((category) => !!category); + const categoriesRef = buildFields( + fields.categories, 'graphql' - ) as TReferenceGraphql; - const categoriesRef = fields.categories.map((category) => ({ - id: category.id, - typeId: 'category' as const, - __typename: 'Reference' as const, - })); + ) as TReferenceGraphql[]; + const categoryOrderHints: Array = Object.entries(fields.categoryOrderHints || {}).map( ([key, value]) => ({ @@ -158,6 +150,7 @@ const transformers = { __typename: 'CategoryOrderHint', }) ); + const searchKeywords: Array = Object.entries( fields.searchKeywords || {} ).map(([locale, searchKeywords]) => ({ @@ -168,6 +161,7 @@ const transformers = { })), __typename: 'SearchKeywordsProductSearch', })); + const reviewRatingStatistics = fields.reviewRatingStatistics ? { ...fields.reviewRatingStatistics, @@ -178,7 +172,7 @@ const transformers = { return { ...fields, name: LocalizedString.resolveGraphqlDefaultLocaleValue( - nameAllLocales + nameAllLocales! )!, nameAllLocales, description: LocalizedString.resolveGraphqlDefaultLocaleValue( @@ -209,6 +203,7 @@ const transformers = { stateRef, taxCategory, taxCategoryRef, + categories, categoriesRef, categoryOrderHints, searchKeywords, diff --git a/models/product-projection/src/types.ts b/models/product-projection/src/types.ts index ac789b2e6..975a15dca 100644 --- a/models/product-projection/src/types.ts +++ b/models/product-projection/src/types.ts @@ -3,9 +3,9 @@ import { ReviewRatingStatistics, SuggestTokenizer, } from '@commercetools/platform-sdk'; -import { TCategory } from '@commercetools-test-data/category'; +import { TCategory, TCategoryGraphql } from '@commercetools-test-data/category'; import { - TLocalizedStringDraftGraphql, + TLocalizedStringGraphql, TReferenceRest, TReferenceGraphql, } from '@commercetools-test-data/commons'; @@ -14,8 +14,11 @@ import { TProductType, TProductTypeGraphql, } from '@commercetools-test-data/product-type'; -import { TState } from '@commercetools-test-data/state'; -import { TTaxCategory } from '@commercetools-test-data/tax-category'; +import { TState, TStateGraphql } from '@commercetools-test-data/state'; +import { + TTaxCategory, + TTaxCategoryGraphql, +} from '@commercetools-test-data/tax-category'; export type TProductProjection = ProductProjection; @@ -47,6 +50,7 @@ export type TSearchKeywords = { export type TProductProjectionGraphql = Omit< TProductProjection, + | 'categories' | 'categoryOrderHints' | 'description' | 'metaTitle' @@ -60,17 +64,18 @@ export type TProductProjectionGraphql = Omit< | 'taxCategory' > & { categoryOrderHints: TCategoryOrderHintGraphql[]; + categories: TCategoryGraphql[]; categoriesRef: TReferenceGraphql[]; description?: string; - descriptionAllLocales?: TLocalizedStringDraftGraphql | null; + descriptionAllLocales?: TLocalizedStringGraphql | null; name: string; - nameAllLocales: TLocalizedStringDraftGraphql; + nameAllLocales: TLocalizedStringGraphql; metaDescription?: string; - metaDescriptionAllLocales?: TLocalizedStringDraftGraphql | null; + metaDescriptionAllLocales?: TLocalizedStringGraphql | null; metaKeywords?: string; - metaKeywordsAllLocales?: TLocalizedStringDraftGraphql | null; + metaKeywordsAllLocales?: TLocalizedStringGraphql | null; metaTitle?: string; - metaTitleAllLocales?: TLocalizedStringDraftGraphql | null; + metaTitleAllLocales?: TLocalizedStringGraphql | null; productType: TProductTypeGraphql; productTypeRef: TReferenceGraphql; reviewRatingStatistics?: ReviewRatingStatistics & { @@ -78,10 +83,10 @@ export type TProductProjectionGraphql = Omit< }; searchKeywords: TSearchKeywords[]; slug: string; - slugAllLocales: TLocalizedStringDraftGraphql; - state?: TState; - stateRef?: TReferenceGraphql; - taxCategory?: TTaxCategory | null; + slugAllLocales: TLocalizedStringGraphql; + state?: TStateGraphql | null; + stateRef?: TReferenceGraphql | null; + taxCategory?: TTaxCategoryGraphql | null; taxCategoryRef?: TReferenceGraphql | null; }; From 1d88affff96c0f7849f609c093eafa60f42a9371 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Tue, 20 Aug 2024 12:34:04 +0200 Subject: [PATCH 04/17] refactor(reference): remove debug log --- models/commons/src/reference/builder.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/commons/src/reference/builder.spec.ts b/models/commons/src/reference/builder.spec.ts index f23eeace3..08bbcdc33 100644 --- a/models/commons/src/reference/builder.spec.ts +++ b/models/commons/src/reference/builder.spec.ts @@ -70,7 +70,7 @@ describe('builder', () => { it('should build the right rest model', () => { const restReference = referenceMock.buildRest(); - console.log(restReference); + expect(restReference).toEqual( expect.objectContaining({ id: 'dummy-id', @@ -84,6 +84,7 @@ describe('builder', () => { }); it('should build the right graphql model', () => { const graphqlReference = referenceMock.buildGraphql(); + expect(graphqlReference).toEqual( expect.objectContaining({ __typename: 'Reference', From 7104b7b056a98489db22ec0aea10c79b80e260db Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Tue, 20 Aug 2024 18:04:13 +0200 Subject: [PATCH 05/17] refactor: update models which have reference properties --- .../src/associate/builder.spec.ts | 4 ++ .../src/associate/transformers.ts | 11 ----- models/business-unit/src/associate/types.ts | 11 ++++- models/inventory-entry/src/builder.spec.ts | 5 +-- models/inventory-entry/src/generator.ts | 4 +- models/inventory-entry/src/transformers.ts | 32 +++++++-------- models/inventory-entry/src/types.ts | 13 ++++-- models/payment/src/payment/builder.spec.ts | 6 ++- models/payment/src/payment/generator.ts | 8 ++-- models/payment/src/payment/transformers.ts | 41 ++++++++++--------- models/payment/src/payment/types.ts | 11 ++++- models/product-projection/src/transformers.ts | 12 +++++- models/quote-request/package.json | 1 + models/quote-request/src/transformers.ts | 18 ++++++-- models/quote-request/src/types.ts | 15 ++++++- models/quote/package.json | 1 + models/quote/src/transformers.ts | 17 +++++--- models/quote/src/types.ts | 17 +++++++- models/staged-quote/package.json | 1 + models/staged-quote/src/transformers.ts | 14 ++++--- models/staged-quote/src/types.ts | 15 ++++++- models/standalone-price/src/transformers.ts | 15 +++---- models/standalone-price/src/types.ts | 13 +++++- pnpm-lock.yaml | 9 ++++ 24 files changed, 201 insertions(+), 93 deletions(-) diff --git a/models/business-unit/src/associate/builder.spec.ts b/models/business-unit/src/associate/builder.spec.ts index b168cb728..748ac5feb 100644 --- a/models/business-unit/src/associate/builder.spec.ts +++ b/models/business-unit/src/associate/builder.spec.ts @@ -40,6 +40,10 @@ describe('builder', () => { ]), customer: expect.objectContaining({ id: expect.any(String), + typeId: 'customer', + obj: expect.objectContaining({ + id: expect.any(String), + }), }), }) ) diff --git a/models/business-unit/src/associate/transformers.ts b/models/business-unit/src/associate/transformers.ts index b1c609f02..778aa42a8 100644 --- a/models/business-unit/src/associate/transformers.ts +++ b/models/business-unit/src/associate/transformers.ts @@ -1,5 +1,4 @@ import { - type TReference, type TReferenceGraphql, Reference, } from '@commercetools-test-data/commons'; @@ -16,16 +15,6 @@ const transformers = { }), rest: Transformer('rest', { buildFields: ['associateRoleAssignments', 'customer'], - replaceFields: ({ fields }) => { - const customer: TReference<'customer'> = Reference.presets - .customerReference() - .id(fields.customer.id) - .build(); - return { - ...fields, - customer, - }; - }, }), graphql: Transformer('graphql', { buildFields: ['associateRoleAssignments', 'customer'], diff --git a/models/business-unit/src/associate/types.ts b/models/business-unit/src/associate/types.ts index 76019ff61..027c422ed 100644 --- a/models/business-unit/src/associate/types.ts +++ b/models/business-unit/src/associate/types.ts @@ -3,8 +3,12 @@ import type { AssociateDraft, Customer, } from '@commercetools/platform-sdk'; -import { TReferenceGraphql } from '@commercetools-test-data/commons'; +import { + TReferenceGraphql, + TReferenceRest, +} from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; +import { TCustomer } from '@commercetools-test-data/customer'; export type TAssociateDraft = AssociateDraft; export type TAssociateDraftGraphql = TAssociateDraft; @@ -12,7 +16,10 @@ export type TAssociateDraftGraphql = TAssociateDraft; export type TAssociateDefault = Omit & { customer: Customer; }; -export type TAssociateRest = Associate; +export type TAssociateRest = Omit & { + customer: TReferenceRest; +}; + export type TAssociateGraphql = TAssociateDefault & { customerRef: TReferenceGraphql | null; __typename: 'Associate'; diff --git a/models/inventory-entry/src/builder.spec.ts b/models/inventory-entry/src/builder.spec.ts index f61daf664..d3773680d 100644 --- a/models/inventory-entry/src/builder.spec.ts +++ b/models/inventory-entry/src/builder.spec.ts @@ -27,9 +27,8 @@ describe('builder', () => { restockableInDays: expect.any(Number), expectedDelivery: expect.any(String), supplyChannel: expect.objectContaining({ - address: expect.objectContaining({ - country: expect.any(String), - }), + id: expect.any(String), + typeId: 'channel', }), custom: null, }) diff --git a/models/inventory-entry/src/generator.ts b/models/inventory-entry/src/generator.ts index 9f1c837f8..71995439c 100644 --- a/models/inventory-entry/src/generator.ts +++ b/models/inventory-entry/src/generator.ts @@ -1,4 +1,4 @@ -import { Channel } from '@commercetools-test-data/channel'; +import { Reference } from '@commercetools-test-data/commons'; import { fake, Generator } from '@commercetools-test-data/core'; import { createRelatedDates } from '@commercetools-test-data/utils'; import { TInventoryEntry } from './types'; @@ -17,7 +17,7 @@ const generator = Generator({ lastModifiedAt: fake(getNewerDate), lastModifiedBy: null, sku: fake((f) => f.lorem.words()), - supplyChannel: fake(() => Channel.random()), + supplyChannel: fake(() => Reference.presets.channelReference()), quantityOnStock: fake((f) => f.number.int()), availableQuantity: fake((f) => f.number.int()), restockableInDays: fake((f) => f.number.int()), diff --git a/models/inventory-entry/src/transformers.ts b/models/inventory-entry/src/transformers.ts index dfa6e9a3c..3bb376bd0 100644 --- a/models/inventory-entry/src/transformers.ts +++ b/models/inventory-entry/src/transformers.ts @@ -1,9 +1,6 @@ -import { - Reference, - TReference, - TReferenceGraphql, -} from '@commercetools-test-data/commons'; -import { Transformer } from '@commercetools-test-data/core'; +import { Channel, TChannelGraphql } from '@commercetools-test-data/channel'; +import { Reference, TReferenceGraphql } from '@commercetools-test-data/commons'; +import { buildField, Transformer } from '@commercetools-test-data/core'; import type { TInventoryEntry, TInventoryEntryRest, @@ -16,26 +13,25 @@ const transformers = { }), rest: Transformer('rest', { buildFields: ['supplyChannel'], - replaceFields: ({ fields }) => { - const supplyChannel = Reference.presets - .channelReference() - .id(fields.supplyChannel.id) - .build>(); - return { - ...fields, - supplyChannel, - }; - }, }), graphql: Transformer('graphql', { - buildFields: ['supplyChannel'], replaceFields: ({ fields }) => { + const restSupplyChannel = buildField(fields.supplyChannel, 'rest'); const supplyChannelRef = Reference.presets .channelReference() .id(fields.supplyChannel.id) - .buildGraphql>(); + .buildGraphql(); + + const supplyChannel = Channel.random() + .description(restSupplyChannel.description) + .id(restSupplyChannel.id) + .key(restSupplyChannel.key) + .name(restSupplyChannel.name) + .buildGraphql(); + return { ...fields, + supplyChannel, supplyChannelRef, __typename: 'InventoryEntry', }; diff --git a/models/inventory-entry/src/types.ts b/models/inventory-entry/src/types.ts index 3ef2d11ff..2bb96f6d4 100644 --- a/models/inventory-entry/src/types.ts +++ b/models/inventory-entry/src/types.ts @@ -3,7 +3,11 @@ import { InventoryEntryDraft, Channel, } from '@commercetools/platform-sdk'; -import type { TReferenceGraphql } from '@commercetools-test-data/commons'; +import { TChannel, TChannelGraphql } from '@commercetools-test-data/channel'; +import type { + TReferenceGraphql, + TReferenceRest, +} from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; // Default @@ -13,12 +17,15 @@ export type TInventoryEntry = Omit & { export type TInventoryEntryDraft = InventoryEntryDraft; // REST -export type TInventoryEntryRest = InventoryEntry; +export type TInventoryEntryRest = Omit & { + supplyChannel: TReferenceRest; +}; export type TInventoryEntryDraftRest = InventoryEntryDraft; // GraphQL -export type TInventoryEntryGraphql = TInventoryEntry & { +export type TInventoryEntryGraphql = Omit & { __typename: 'InventoryEntry'; + supplyChannel: TChannelGraphql; supplyChannelRef: TReferenceGraphql; }; export type TInventoryEntryDraftGraphql = TInventoryEntryDraft; diff --git a/models/payment/src/payment/builder.spec.ts b/models/payment/src/payment/builder.spec.ts index 424f82fdc..05b43ed4f 100644 --- a/models/payment/src/payment/builder.spec.ts +++ b/models/payment/src/payment/builder.spec.ts @@ -12,7 +12,8 @@ describe('builder', () => { expect.objectContaining({ key: expect.any(String), customer: expect.objectContaining({ - email: expect.any(String), + id: expect.any(String), + typeId: 'customer', }), anonymousId: expect.any(String), interfaceId: expect.any(String), @@ -69,6 +70,9 @@ describe('builder', () => { customer: expect.objectContaining({ id: expect.any(String), typeId: expect.any(String), + obj: expect.objectContaining({ + id: expect.any(String), + }), }), anonymousId: expect.any(String), interfaceId: expect.any(String), diff --git a/models/payment/src/payment/generator.ts b/models/payment/src/payment/generator.ts index ca0ce74de..2e94a24a9 100644 --- a/models/payment/src/payment/generator.ts +++ b/models/payment/src/payment/generator.ts @@ -1,6 +1,8 @@ -import { CentPrecisionMoney } from '@commercetools-test-data/commons'; +import { + CentPrecisionMoney, + Reference, +} from '@commercetools-test-data/commons'; import { fake, Generator, sequence } from '@commercetools-test-data/core'; -import { Customer } from '@commercetools-test-data/customer'; import { createRelatedDates } from '@commercetools-test-data/utils'; import * as PaymentMethodInfo from '../payment-method-info'; import * as PaymentStatus from '../payment-status'; @@ -16,7 +18,7 @@ const generator = Generator({ id: fake((f) => f.string.uuid()), version: sequence(), key: fake((f) => f.string.uuid()), - customer: fake((f) => Customer.random()), + customer: fake((f) => Reference.presets.customerReference()), anonymousId: fake((f) => f.string.uuid()), interfaceId: fake((f) => f.string.uuid()), amountPlanned: fake((f) => CentPrecisionMoney.random()), diff --git a/models/payment/src/payment/transformers.ts b/models/payment/src/payment/transformers.ts index 844327a35..a4fe869fa 100644 --- a/models/payment/src/payment/transformers.ts +++ b/models/payment/src/payment/transformers.ts @@ -1,12 +1,10 @@ -import { - Reference, - TReference, - TReferenceGraphql, -} from '@commercetools-test-data/commons'; +import { TReferenceGraphql } from '@commercetools-test-data/commons'; import { Transformer, + buildField, toGraphqlPaginatedQueryResult, } from '@commercetools-test-data/core'; +import { Customer, TCustomerGraphql } from '@commercetools-test-data/customer'; import type { TPayment, TPaymentGraphql, TPaymentRest } from './types'; const transformers = { @@ -31,20 +29,9 @@ const transformers = { 'interfaceInteractions', 'custom', ], - replaceFields: ({ fields }) => { - const customer = Reference.presets - .customerReference() - .id(fields.customer.id) - .build>(); - return { - ...fields, - customer, - }; - }, }), graphql: Transformer('graphql', { buildFields: [ - 'customer', 'amountPlanned', 'paymentMethodInfo', 'paymentStatus', @@ -52,10 +39,23 @@ const transformers = { 'custom', ], replaceFields: ({ fields }) => { - const customerRef: TReferenceGraphql = Reference.presets - .customerReference() - .id(fields.customer.id) - .buildGraphql(); + const restCustomer = buildField(fields.customer, 'rest'); + const customerBuilder = restCustomer.email + ? Customer.random() + .id(restCustomer.id) + .firstName(restCustomer.firstName) + .lastName(restCustomer.lastName) + .key(restCustomer.key) + .customerNumber(restCustomer.customerNumber) + .externalId(restCustomer.externalId) + .email(restCustomer.email) + .title(restCustomer.title) + : Customer.random().id(restCustomer.id); + const customerRef: TReferenceGraphql = { + id: restCustomer.id, + typeId: 'customer', + __typename: 'Reference', + }; // TODO: This exists in the Graphql API, but not in the REST API // We're stubbing it out for now because it's non-nullable const interfaceInteractionsRaw = toGraphqlPaginatedQueryResult([], { @@ -63,6 +63,7 @@ const transformers = { }); return { ...fields, + customer: customerBuilder.buildGraphql(), customerRef, interfaceInteractionsRaw, __typename: 'Payment', diff --git a/models/payment/src/payment/types.ts b/models/payment/src/payment/types.ts index 9179c339b..00c6ca90e 100644 --- a/models/payment/src/payment/types.ts +++ b/models/payment/src/payment/types.ts @@ -1,9 +1,13 @@ import { Customer, Payment, PaymentDraft } from '@commercetools/platform-sdk'; -import type { TReferenceGraphql } from '@commercetools-test-data/commons'; +import type { + TReferenceGraphql, + TReferenceRest, +} from '@commercetools-test-data/commons'; import type { TBuilder, TPaginatedQueryResult, } from '@commercetools-test-data/core'; +import { TCustomer, TCustomerGraphql } from '@commercetools-test-data/customer'; // Default export type TPayment = Omit & { @@ -12,12 +16,15 @@ export type TPayment = Omit & { export type TPaymentDraft = PaymentDraft; // Rest -export type TPaymentRest = Payment; +export type TPaymentRest = Omit & { + customer?: TReferenceRest; +}; export type TPaymentDraftRest = PaymentDraft; // Graphql export type TPaymentGraphql = TPayment & { __typename: 'Payment'; + customer: TCustomerGraphql; customerRef: TReferenceGraphql; interfaceInteractionsRaw: TPaginatedQueryResult; }; diff --git a/models/product-projection/src/transformers.ts b/models/product-projection/src/transformers.ts index b206d9aad..17ad87d52 100644 --- a/models/product-projection/src/transformers.ts +++ b/models/product-projection/src/transformers.ts @@ -1,6 +1,12 @@ -import { Category, TCategoryGraphql } from '@commercetools-test-data/category'; +import { + Category, + TCategory, + TCategoryGraphql, +} from '@commercetools-test-data/category'; import { LocalizedString, + Reference, + TReferenceRest, type TReferenceGraphql, } from '@commercetools-test-data/commons'; import { @@ -10,11 +16,13 @@ import { } from '@commercetools-test-data/core'; import { ProductType, + TProductType, TProductTypeGraphql, } from '@commercetools-test-data/product-type'; -import { State, TStateGraphql } from '@commercetools-test-data/state'; +import { State, TState, TStateGraphql } from '@commercetools-test-data/state'; import { TaxCategory, + TTaxCategory, TTaxCategoryGraphql, } from '@commercetools-test-data/tax-category'; import type { diff --git a/models/quote-request/package.json b/models/quote-request/package.json index 696a60f98..3d61df556 100644 --- a/models/quote-request/package.json +++ b/models/quote-request/package.json @@ -25,6 +25,7 @@ "@commercetools-test-data/core": "10.1.1", "@commercetools-test-data/customer": "10.1.1", "@commercetools-test-data/customer-group": "10.1.1", + "@commercetools-test-data/state": "10.1.1", "@commercetools-test-data/store": "10.1.1", "@commercetools-test-data/utils": "10.1.1", "@commercetools/platform-sdk": "^7.0.0", diff --git a/models/quote-request/src/transformers.ts b/models/quote-request/src/transformers.ts index 82897328a..81bd3fd69 100644 --- a/models/quote-request/src/transformers.ts +++ b/models/quote-request/src/transformers.ts @@ -2,15 +2,19 @@ import { BusinessUnitKeyReference, StoreKeyReference, } from '@commercetools/platform-sdk'; +import { TCart } from '@commercetools-test-data/cart'; import { Reference, KeyReference, - TReference, TReferenceGraphql, TKeyReferenceGraphql, + TReferenceRest, } from '@commercetools-test-data/commons'; import { Transformer } from '@commercetools-test-data/core'; +import { TCustomer } from '@commercetools-test-data/customer'; +import { TCustomerGroup } from '@commercetools-test-data/customer-group'; +import { TState } from '@commercetools-test-data/state'; import type { TQuoteRequest, TQuoteRequestRest, @@ -57,12 +61,12 @@ const transformers = { const customer = Reference.presets .customerReference() .id(fields.customer.id) - .build>(); + .build>(); const customerGroup = Reference.presets .customerGroupReference() .id(fields.customerGroup?.id) - .build>(); + .build>(); const store = KeyReference.random() .typeId('store') @@ -72,15 +76,21 @@ const transformers = { const state = Reference.presets .stateReference() .id(fields.state?.id) - .build>(); + .build>(); const businessUnit = KeyReference.random() .typeId('business-unit') .key(fields.businessUnit?.key) .buildRest(); + const cart = Reference.presets + .cartReference() + .id(fields.cart?.id || '') + .build>(); + return { ...fields, + cart, customer, customerGroup: fields.customerGroup ? customerGroup : undefined, store: fields.store ? store : undefined, diff --git a/models/quote-request/src/types.ts b/models/quote-request/src/types.ts index ccadb304a..6faa2778c 100644 --- a/models/quote-request/src/types.ts +++ b/models/quote-request/src/types.ts @@ -7,11 +7,16 @@ import type { QuoteRequest, QuoteRequestDraft, } from '@commercetools/platform-sdk'; +import { TCart } from '@commercetools-test-data/cart'; import { TReferenceGraphql, TKeyReferenceGraphql, + TReferenceRest, } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; +import { TCustomer } from '@commercetools-test-data/customer'; +import { TCustomerGroup } from '@commercetools-test-data/customer-group'; +import { TState } from '@commercetools-test-data/state'; // Default export type TQuoteRequest = Omit< @@ -26,7 +31,15 @@ export type TQuoteRequest = Omit< }; // Rest -export type TQuoteRequestRest = QuoteRequest; +export type TQuoteRequestRest = Omit< + QuoteRequest, + 'cart' | 'customer' | 'customerGroup' | 'state' +> & { + cart?: TReferenceRest; + customer: TReferenceRest; + customerGroup?: TReferenceRest; + state?: TReferenceRest; +}; export type TQuoteRequestDraft = QuoteRequestDraft; export type TQuoteRequestGraphql = TQuoteRequest & { diff --git a/models/quote/package.json b/models/quote/package.json index 1a97f845a..c96a19d12 100644 --- a/models/quote/package.json +++ b/models/quote/package.json @@ -27,6 +27,7 @@ "@commercetools-test-data/customer-group": "10.1.1", "@commercetools-test-data/quote-request": "10.1.1", "@commercetools-test-data/staged-quote": "^10.1.1", + "@commercetools-test-data/state": "10.1.1", "@commercetools-test-data/store": "10.1.1", "@commercetools-test-data/utils": "10.1.1", "@commercetools/platform-sdk": "^7.0.0", diff --git a/models/quote/src/transformers.ts b/models/quote/src/transformers.ts index 8e3f26888..db46154aa 100644 --- a/models/quote/src/transformers.ts +++ b/models/quote/src/transformers.ts @@ -5,12 +5,17 @@ import { import { Reference, KeyReference, - TReference, TReferenceGraphql, TKeyReferenceGraphql, + TReferenceRest, } from '@commercetools-test-data/commons'; import { Transformer } from '@commercetools-test-data/core'; +import { TCustomer } from '@commercetools-test-data/customer'; +import { TCustomerGroup } from '@commercetools-test-data/customer-group'; +import { TQuoteRequestRest } from '@commercetools-test-data/quote-request'; +import { TStagedQuoteRest } from '@commercetools-test-data/staged-quote'; +import { TState } from '@commercetools-test-data/state'; import type { TQuote, TQuoteRest, TQuoteGraphql } from './types'; const transformers = { @@ -59,22 +64,22 @@ const transformers = { const quoteRequest = Reference.presets .quoteRequestReference() .id(fields.quoteRequest.id) - .build>(); + .build>(); const stagedQuote = Reference.presets .stagedQuoteReference() .id(fields.stagedQuote.id) - .build>(); + .build>(); const customer = Reference.presets .customerReference() .id(fields.customer.id) - .build>(); + .build>(); const customerGroup = Reference.presets .customerGroupReference() .id(fields.customerGroup?.id) - .build>(); + .build>(); const store = KeyReference.presets .store() @@ -84,7 +89,7 @@ const transformers = { const state = Reference.presets .stateReference() .id(fields.state?.id) - .build>(); + .build>(); const businessUnit = KeyReference.presets .businessUnit() diff --git a/models/quote/src/types.ts b/models/quote/src/types.ts index a9ca5c3a6..ed9684dcf 100644 --- a/models/quote/src/types.ts +++ b/models/quote/src/types.ts @@ -12,8 +12,14 @@ import type { import { TReferenceGraphql, TKeyReferenceGraphql, + TReferenceRest, } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; +import { TCustomer } from '@commercetools-test-data/customer'; +import { TCustomerGroup } from '@commercetools-test-data/customer-group'; +import { TQuoteRequestRest } from '@commercetools-test-data/quote-request'; +import { TStagedQuoteRest } from '@commercetools-test-data/staged-quote'; +import { TState } from '@commercetools-test-data/state'; // Default export type TQuote = Omit< @@ -36,7 +42,16 @@ export type TQuote = Omit< }; // Rest -export type TQuoteRest = Quote; +export type TQuoteRest = Omit< + Quote, + 'customer' | 'customerGroup' | 'quoteRequest' | 'stagedQuote' | 'state' +> & { + customer?: TReferenceRest; + customerGroup?: TReferenceRest; + quoteRequest: TReferenceRest; + stagedQuote: TReferenceRest; + state?: TReferenceRest; +}; export type TQuoteDraft = QuoteDraft; export type TQuoteGraphql = TQuote & { diff --git a/models/staged-quote/package.json b/models/staged-quote/package.json index 7228a778a..7db6aaa73 100644 --- a/models/staged-quote/package.json +++ b/models/staged-quote/package.json @@ -26,6 +26,7 @@ "@commercetools-test-data/customer": "10.1.1", "@commercetools-test-data/customer-group": "10.1.1", "@commercetools-test-data/quote-request": "10.1.1", + "@commercetools-test-data/state": "10.1.1", "@commercetools-test-data/store": "10.1.1", "@commercetools-test-data/utils": "10.1.1", "@commercetools/platform-sdk": "^7.0.0", diff --git a/models/staged-quote/src/transformers.ts b/models/staged-quote/src/transformers.ts index 9ab7851c2..2950ec3d8 100644 --- a/models/staged-quote/src/transformers.ts +++ b/models/staged-quote/src/transformers.ts @@ -1,13 +1,17 @@ import { BusinessUnitKeyReference } from '@commercetools/platform-sdk'; +import { TCart } from '@commercetools-test-data/cart'; import { Reference, KeyReference, - TReference, TReferenceGraphql, TKeyReferenceGraphql, + TReferenceRest, } from '@commercetools-test-data/commons'; import { Transformer } from '@commercetools-test-data/core'; +import { TCustomer } from '@commercetools-test-data/customer'; +import { TQuoteRequestRest } from '@commercetools-test-data/quote-request'; +import { TState } from '@commercetools-test-data/state'; import type { TStagedQuote, TStagedQuoteRest, @@ -42,22 +46,22 @@ const transformers = { const customer = Reference.presets .customerReference() .id(fields.customer.id) - .build>(); + .build>(); const quoteRequest = Reference.presets .quoteRequestReference() .id(fields.quoteRequest.id) - .build>(); + .build>(); const quotationCart = Reference.presets .cartReference() .id(fields.quotationCart.id) - .build>(); + .build>(); const state = Reference.presets .stateReference() .id(fields.state?.id) - .build>(); + .build>(); const businessUnit = KeyReference.presets .businessUnit() diff --git a/models/staged-quote/src/types.ts b/models/staged-quote/src/types.ts index 09c34c923..97c5ddaef 100644 --- a/models/staged-quote/src/types.ts +++ b/models/staged-quote/src/types.ts @@ -7,11 +7,16 @@ import type { State, QuoteRequest, } from '@commercetools/platform-sdk'; +import { TCart } from '@commercetools-test-data/cart'; import { TReferenceGraphql, TKeyReferenceGraphql, + TReferenceRest, } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; +import { TCustomer } from '@commercetools-test-data/customer'; +import { TQuoteRequestRest } from '@commercetools-test-data/quote-request'; +import { TState } from '@commercetools-test-data/state'; // Default export type TStagedQuote = Omit< @@ -26,7 +31,15 @@ export type TStagedQuote = Omit< }; // Rest -export type TStagedQuoteRest = StagedQuote; +export type TStagedQuoteRest = Omit< + StagedQuote, + 'customer' | 'quoteRequest' | 'quoteRequest' | 'quotationCart' | 'state' +> & { + customer?: TReferenceRest; + quotationCart: TReferenceRest; + quoteRequest: TReferenceRest; + state?: TReferenceRest; +}; export type TStagedQuoteDraft = StagedQuoteDraft; export type TStagedQuoteGraphql = TStagedQuote & { diff --git a/models/standalone-price/src/transformers.ts b/models/standalone-price/src/transformers.ts index b013c8719..0359c3844 100644 --- a/models/standalone-price/src/transformers.ts +++ b/models/standalone-price/src/transformers.ts @@ -1,8 +1,9 @@ +import { TChannel } from '@commercetools-test-data/channel'; import { Reference, KeyReference, - TReference, TReferenceGraphql, + TReferenceRest, } from '@commercetools-test-data/commons'; import { Transformer } from '@commercetools-test-data/core'; import { type TCustomerGroup } from '@commercetools-test-data/customer-group'; @@ -16,11 +17,11 @@ import type { function createCustomerGroupReference( customerGroup: TCustomerGroup, target: 'rest' -): TReference<'customer-group'>; +): TReferenceRest; function createCustomerGroupReference( customerGroup: TCustomerGroup, target: 'graphql' -): TReferenceGraphql<'customer-group'>; +): TReferenceGraphql; // Create a customer group reference depending on `id` or `key` field availability function createCustomerGroupReference( @@ -43,8 +44,8 @@ function createCustomerGroupReference( // Dynamically call buildRest or buildGraphql based on target if (referenceBuilder) { return target === 'rest' - ? referenceBuilder.buildRest>() - : referenceBuilder.buildGraphql>(); + ? referenceBuilder.buildRest>() + : referenceBuilder.buildGraphql(); } } @@ -76,7 +77,7 @@ const transformers = { ? KeyReference.random() .typeId('channel') .key(fields.channel.key) - .buildRest>() + .buildRest>() : undefined; return { @@ -105,7 +106,7 @@ const transformers = { ? KeyReference.random() .typeId('channel') .key(fields.channel.key) - .buildGraphql>() + .buildGraphql() : null; return { __typename: 'StandalonePrice', customerGroupRef, channelRef }; diff --git a/models/standalone-price/src/types.ts b/models/standalone-price/src/types.ts index 725a755aa..ef3f05cdf 100644 --- a/models/standalone-price/src/types.ts +++ b/models/standalone-price/src/types.ts @@ -4,13 +4,18 @@ import { CustomerGroup, Channel, } from '@commercetools/platform-sdk'; +import { TChannel } from '@commercetools-test-data/channel'; import { TMoneyGraphql, TReferenceGraphql, + TReferenceRest, } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; +import { TCustomerGroup } from '@commercetools-test-data/customer-group'; // Base representation +// TODO: This doesn't seem to be right. I don't understand why the default type should have customized fields. +// It seems to me that's something only transformed versions of the model should have. export type TStandalonePrice = Omit< StandalonePrice, 'customerGroup' | 'channel' @@ -21,7 +26,13 @@ export type TStandalonePrice = Omit< }; // REST representation -export type TStandalonePriceRest = StandalonePrice; +export type TStandalonePriceRest = Omit< + StandalonePrice, + 'channel' | 'customerGroup' +> & { + channel?: TReferenceRest; + customerGroup?: TReferenceRest; +}; export type TStandalonePriceDraft = StandalonePriceDraft; // Graphql representation diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6784bfb55..a9abc3e44 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -952,6 +952,9 @@ importers: '@commercetools-test-data/staged-quote': specifier: ^10.1.1 version: link:../staged-quote + '@commercetools-test-data/state': + specifier: 10.1.1 + version: link:../state '@commercetools-test-data/store': specifier: 10.1.1 version: link:../store @@ -991,6 +994,9 @@ importers: '@commercetools-test-data/customer-group': specifier: 10.1.1 version: link:../customer-group + '@commercetools-test-data/state': + specifier: 10.1.1 + version: link:../state '@commercetools-test-data/store': specifier: 10.1.1 version: link:../store @@ -1111,6 +1117,9 @@ importers: '@commercetools-test-data/quote-request': specifier: 10.1.1 version: link:../quote-request + '@commercetools-test-data/state': + specifier: 10.1.1 + version: link:../state '@commercetools-test-data/store': specifier: 10.1.1 version: link:../store From e7846c5ce1ac298ea8a0744692fe44e8d65f3755 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Tue, 20 Aug 2024 18:11:54 +0200 Subject: [PATCH 06/17] fix(product-projection): fix ts issue --- models/product-projection/src/transformers.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/models/product-projection/src/transformers.ts b/models/product-projection/src/transformers.ts index 17ad87d52..ac523a22d 100644 --- a/models/product-projection/src/transformers.ts +++ b/models/product-projection/src/transformers.ts @@ -1,12 +1,6 @@ -import { - Category, - TCategory, - TCategoryGraphql, -} from '@commercetools-test-data/category'; +import { Category, TCategoryGraphql } from '@commercetools-test-data/category'; import { LocalizedString, - Reference, - TReferenceRest, type TReferenceGraphql, } from '@commercetools-test-data/commons'; import { @@ -16,13 +10,11 @@ import { } from '@commercetools-test-data/core'; import { ProductType, - TProductType, TProductTypeGraphql, } from '@commercetools-test-data/product-type'; -import { State, TState, TStateGraphql } from '@commercetools-test-data/state'; +import { State, TStateGraphql } from '@commercetools-test-data/state'; import { TaxCategory, - TTaxCategory, TTaxCategoryGraphql, } from '@commercetools-test-data/tax-category'; import type { @@ -144,7 +136,7 @@ const transformers = { } return undefined; }) - .filter((category) => !!category); + .filter(Boolean) as TCategoryGraphql[]; const categoriesRef = buildFields( fields.categories, 'graphql' From c93911c5f25895ebc834d7614df658507962ae6d Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Wed, 21 Aug 2024 09:57:02 +0200 Subject: [PATCH 07/17] chore: refresh lock file --- pnpm-lock.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d1bb02cbb..7e90a42df 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -962,7 +962,7 @@ importers: specifier: ^10.1.3 version: link:../staged-quote '@commercetools-test-data/state': - specifier: 10.1.2 + specifier: 10.1.3 version: link:../state '@commercetools-test-data/store': specifier: 10.1.3 @@ -1004,7 +1004,7 @@ importers: specifier: 10.1.3 version: link:../customer-group '@commercetools-test-data/state': - specifier: 10.1.2 + specifier: 10.1.3 version: link:../state '@commercetools-test-data/store': specifier: 10.1.3 @@ -1127,7 +1127,7 @@ importers: specifier: 10.1.3 version: link:../quote-request '@commercetools-test-data/state': - specifier: 10.1.2 + specifier: 10.1.3 version: link:../state '@commercetools-test-data/store': specifier: 10.1.3 From 4fbb51bdf97be048c636e5c6f01b129e7cdb4f86 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Wed, 21 Aug 2024 16:08:36 +0200 Subject: [PATCH 08/17] fix: fix models with reference properties --- .../src/associate/builder.spec.ts | 4 +- .../src/associate/transformers.ts | 25 +- models/business-unit/src/associate/types.ts | 25 +- models/channel/src/builder.spec.ts | 1 + models/channel/src/transformers.ts | 16 +- models/channel/src/types.ts | 16 +- .../commons/src/localized-string/helpers.ts | 2 +- models/inventory-entry/src/builder.spec.ts | 81 +++++++ models/inventory-entry/src/transformers.ts | 39 ++- models/inventory-entry/src/types.ts | 20 +- models/payment/src/payment/transformers.ts | 44 ++-- models/payment/src/payment/types.ts | 23 +- models/product-projection/src/types.ts | 25 +- models/quote/src/builder.spec.ts | 49 +++- models/quote/src/generator.ts | 27 ++- models/quote/src/transformers.ts | 225 ++++++++++-------- models/quote/src/types.ts | 79 +++--- models/standalone-price/src/builder.spec.ts | 11 +- models/standalone-price/src/generator.ts | 10 +- models/standalone-price/src/transformers.ts | 124 ++++------ models/standalone-price/src/types.ts | 37 +-- 21 files changed, 489 insertions(+), 394 deletions(-) diff --git a/models/business-unit/src/associate/builder.spec.ts b/models/business-unit/src/associate/builder.spec.ts index 748ac5feb..7f25effe1 100644 --- a/models/business-unit/src/associate/builder.spec.ts +++ b/models/business-unit/src/associate/builder.spec.ts @@ -70,10 +70,10 @@ describe('builder', () => { ]), customer: expect.objectContaining({ id: expect.any(String), - typeId: 'customer', - __typename: 'Reference', + email: expect.any(String), }), customerRef: expect.objectContaining({ + id: expect.any(String), typeId: 'customer', __typename: 'Reference', }), diff --git a/models/business-unit/src/associate/transformers.ts b/models/business-unit/src/associate/transformers.ts index 778aa42a8..5fddf2f79 100644 --- a/models/business-unit/src/associate/transformers.ts +++ b/models/business-unit/src/associate/transformers.ts @@ -2,7 +2,8 @@ import { type TReferenceGraphql, Reference, } from '@commercetools-test-data/commons'; -import { Transformer } from '@commercetools-test-data/core'; +import { buildField, Transformer } from '@commercetools-test-data/core'; +import { Customer, TCustomerGraphql } from '@commercetools-test-data/customer'; import type { TAssociateDefault, TAssociateRest, @@ -17,14 +18,28 @@ const transformers = { buildFields: ['associateRoleAssignments', 'customer'], }), graphql: Transformer('graphql', { - buildFields: ['associateRoleAssignments', 'customer'], + buildFields: ['associateRoleAssignments'], replaceFields: ({ fields }) => { - const customerRef: TReferenceGraphql = Reference.presets + const restCustomerRef = buildField(fields.customer, 'rest'); + + const customerRef = Reference.presets .customerReference() - .id(fields.customer.id) - .buildGraphql(); + .id(restCustomerRef.id) + .buildGraphql(); + + const customer = Customer.random() + .id(restCustomerRef.id) + .firstName(restCustomerRef.obj?.firstName) + .lastName(restCustomerRef.obj?.lastName) + .key(restCustomerRef.obj?.key) + .customerNumber(restCustomerRef.obj?.customerNumber) + .externalId(restCustomerRef.obj?.externalId) + .email(restCustomerRef.obj?.email || '') + .buildGraphql(); + return { ...fields, + customer, customerRef, __typename: 'Associate', }; diff --git a/models/business-unit/src/associate/types.ts b/models/business-unit/src/associate/types.ts index 027c422ed..f212d84e7 100644 --- a/models/business-unit/src/associate/types.ts +++ b/models/business-unit/src/associate/types.ts @@ -1,26 +1,17 @@ -import type { - Associate, - AssociateDraft, - Customer, -} from '@commercetools/platform-sdk'; -import { - TReferenceGraphql, - TReferenceRest, -} from '@commercetools-test-data/commons'; +import type { Associate, AssociateDraft } from '@commercetools/platform-sdk'; +import { TReferenceGraphql } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; -import { TCustomer } from '@commercetools-test-data/customer'; +import { TCustomerGraphql } from '@commercetools-test-data/customer'; + +export type TAssociateDefault = Associate; export type TAssociateDraft = AssociateDraft; export type TAssociateDraftGraphql = TAssociateDraft; -export type TAssociateDefault = Omit & { - customer: Customer; -}; -export type TAssociateRest = Omit & { - customer: TReferenceRest; -}; +export type TAssociateRest = Associate; -export type TAssociateGraphql = TAssociateDefault & { +export type TAssociateGraphql = Omit & { + customer: TCustomerGraphql; customerRef: TReferenceGraphql | null; __typename: 'Associate'; }; diff --git a/models/channel/src/builder.spec.ts b/models/channel/src/builder.spec.ts index 24b917e87..f1081a199 100644 --- a/models/channel/src/builder.spec.ts +++ b/models/channel/src/builder.spec.ts @@ -83,6 +83,7 @@ describe('builder', () => { ), expect.objectContaining({ __typename: 'Channel', + name: 'Food Store', nameAllLocales: expect.arrayContaining([ expect.objectContaining({ __typename: 'LocalizedString', diff --git a/models/channel/src/transformers.ts b/models/channel/src/transformers.ts index 5039d121c..f2bb909b7 100644 --- a/models/channel/src/transformers.ts +++ b/models/channel/src/transformers.ts @@ -1,4 +1,7 @@ -import { LocalizedString } from '@commercetools-test-data/commons'; +import { + LocalizedString, + TClientLoggingGraphql, +} from '@commercetools-test-data/commons'; import { Transformer } from '@commercetools-test-data/core'; import type { TChannel, TChannelGraphql } from './types'; @@ -23,16 +26,25 @@ const transformers = { }), graphql: Transformer('graphql', { buildFields: ['address', 'createdBy', 'lastModifiedBy'], - addFields: ({ fields }) => { + replaceFields: ({ fields }) => { const nameAllLocales = LocalizedString.toLocalizedField(fields.name); const descriptionAllLocales = LocalizedString.toLocalizedField( fields.description ); return { + ...fields, __typename: 'Channel', + createdBy: fields.createdBy as TClientLoggingGraphql | undefined, + lastModifiedBy: fields.lastModifiedBy as + | TClientLoggingGraphql + | undefined, nameAllLocales, + name: LocalizedString.resolveGraphqlDefaultLocaleValue(nameAllLocales), descriptionAllLocales, + description: LocalizedString.resolveGraphqlDefaultLocaleValue( + descriptionAllLocales + ), }; }, }), diff --git a/models/channel/src/types.ts b/models/channel/src/types.ts index 1d15bafcb..63cbc4388 100644 --- a/models/channel/src/types.ts +++ b/models/channel/src/types.ts @@ -19,19 +19,15 @@ export type TChannelDraftGraphql = Omit< export type TChannelGraphql = Omit< TChannel, - // In GraphQL, we prefer to use `nameAllLocales` instead of `name`. - | 'name' - // In GraphQL, we prefer to use `descriptionAllLocales` instead of `description`. - | 'description' - // In GraphQL, the object shape is different. - | 'createdBy' - // In GraphQL, the object shape is different. - | 'lastModifiedBy' + // In GraphQL, these properties have different shapes. + 'name' | 'description' | 'createdBy' | 'lastModifiedBy' > & { __typename: 'Channel'; - createdBy: TClientLoggingGraphql; - lastModifiedBy: TClientLoggingGraphql; + createdBy?: TClientLoggingGraphql; + lastModifiedBy?: TClientLoggingGraphql; + name?: string; nameAllLocales?: TLocalizedStringGraphql | null; + description?: string; descriptionAllLocales?: TLocalizedStringGraphql | null; }; diff --git a/models/commons/src/localized-string/helpers.ts b/models/commons/src/localized-string/helpers.ts index 8b97ee0b9..4e1ae40df 100644 --- a/models/commons/src/localized-string/helpers.ts +++ b/models/commons/src/localized-string/helpers.ts @@ -24,7 +24,7 @@ const resolveGraphqlDefaultLocaleValue = ( const defaultLocaleName = allLocales.find( (name) => name.locale === DEFAULT_LOCALE ); - return defaultLocaleName ? defaultLocaleName.value : allLocales[0].value; + return defaultLocaleName ? defaultLocaleName.value : allLocales[0]?.value; }; export { resolveGraphqlDefaultLocaleValue, toLocalizedField }; diff --git a/models/inventory-entry/src/builder.spec.ts b/models/inventory-entry/src/builder.spec.ts index d3773680d..ad31319ae 100644 --- a/models/inventory-entry/src/builder.spec.ts +++ b/models/inventory-entry/src/builder.spec.ts @@ -1,5 +1,7 @@ /* eslint-disable jest/no-disabled-tests */ /* eslint-disable jest/valid-title */ +import { Channel } from '@commercetools-test-data/channel'; +import { Reference } from '@commercetools-test-data/commons'; import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; import { TInventoryEntry, @@ -94,4 +96,83 @@ describe('builder', () => { }) ) ); + + describe('when customizing the model', () => { + const inventoryEntryMock = InventoryEntry.random() + .id('entry-id') + .key('entry-key') + .quantityOnStock(11) + .availableQuantity(10) + .restockableInDays(5) + .expectedDelivery('2024-01-01') + .sku('entry-sku') + .supplyChannel( + Reference.presets + .channelReference() + .obj(Channel.presets.foodStore().id('food-store-id')) + ) + .version(123); + + it('should build the right rest model', () => { + const restInventoryEntry = + inventoryEntryMock.buildRest(); + + expect(restInventoryEntry).toEqual( + expect.objectContaining({ + id: 'entry-id', + key: 'entry-key', + quantityOnStock: 11, + availableQuantity: 10, + restockableInDays: 5, + expectedDelivery: '2024-01-01', + sku: 'entry-sku', + supplyChannel: expect.objectContaining({ + id: 'food-store-id', + typeId: 'channel', + obj: expect.objectContaining({ + key: 'food-store-key', + name: expect.objectContaining({ + en: 'Food Store', + }), + }), + }), + version: 123, + }) + ); + }); + + it('should build the right graphql model', () => { + const graphqlInventoryEntry = + inventoryEntryMock.buildGraphql(); + + expect(graphqlInventoryEntry).toEqual( + expect.objectContaining({ + id: 'entry-id', + key: 'entry-key', + quantityOnStock: 11, + availableQuantity: 10, + restockableInDays: 5, + expectedDelivery: '2024-01-01', + sku: 'entry-sku', + supplyChannel: expect.objectContaining({ + id: 'food-store-id', + key: 'food-store-key', + name: 'Food Store', + nameAllLocales: expect.arrayContaining([ + expect.objectContaining({ + locale: 'en', + value: 'Food Store', + }), + ]), + }), + supplyChannelRef: expect.objectContaining({ + id: 'food-store-id', + typeId: 'channel', + __typename: 'Reference', + }), + version: 123, + }) + ); + }); + }); }); diff --git a/models/inventory-entry/src/transformers.ts b/models/inventory-entry/src/transformers.ts index 3bb376bd0..475150734 100644 --- a/models/inventory-entry/src/transformers.ts +++ b/models/inventory-entry/src/transformers.ts @@ -1,5 +1,9 @@ import { Channel, TChannelGraphql } from '@commercetools-test-data/channel'; -import { Reference, TReferenceGraphql } from '@commercetools-test-data/commons'; +import { + LocalizedString, + Reference, + TReferenceGraphql, +} from '@commercetools-test-data/commons'; import { buildField, Transformer } from '@commercetools-test-data/core'; import type { TInventoryEntry, @@ -16,18 +20,29 @@ const transformers = { }), graphql: Transformer('graphql', { replaceFields: ({ fields }) => { - const restSupplyChannel = buildField(fields.supplyChannel, 'rest'); - const supplyChannelRef = Reference.presets - .channelReference() - .id(fields.supplyChannel.id) - .buildGraphql(); + let supplyChannel: TChannelGraphql | undefined = undefined; + let supplyChannelRef: TReferenceGraphql | undefined = undefined; - const supplyChannel = Channel.random() - .description(restSupplyChannel.description) - .id(restSupplyChannel.id) - .key(restSupplyChannel.key) - .name(restSupplyChannel.name) - .buildGraphql(); + if (fields.supplyChannel) { + const restSupplyChannelRef = buildField(fields.supplyChannel, 'rest'); + + supplyChannelRef = Reference.presets + .channelReference() + .id(restSupplyChannelRef.id) + .buildGraphql(); + + supplyChannel = Channel.random() + .description(restSupplyChannelRef.obj!.description) + .id(restSupplyChannelRef.id) + .key(restSupplyChannelRef.obj!.key) + .name( + LocalizedString.presets + .empty() + .en(restSupplyChannelRef.obj!.name?.en) + .de(restSupplyChannelRef.obj!.name?.de) + ) + .buildGraphql(); + } return { ...fields, diff --git a/models/inventory-entry/src/types.ts b/models/inventory-entry/src/types.ts index 2bb96f6d4..d1048537e 100644 --- a/models/inventory-entry/src/types.ts +++ b/models/inventory-entry/src/types.ts @@ -1,32 +1,24 @@ import { InventoryEntry, InventoryEntryDraft, - Channel, } from '@commercetools/platform-sdk'; -import { TChannel, TChannelGraphql } from '@commercetools-test-data/channel'; -import type { - TReferenceGraphql, - TReferenceRest, -} from '@commercetools-test-data/commons'; +import { TChannelGraphql } from '@commercetools-test-data/channel'; +import type { TReferenceGraphql } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; // Default -export type TInventoryEntry = Omit & { - supplyChannel: Channel; -}; +export type TInventoryEntry = InventoryEntry; export type TInventoryEntryDraft = InventoryEntryDraft; // REST -export type TInventoryEntryRest = Omit & { - supplyChannel: TReferenceRest; -}; +export type TInventoryEntryRest = TInventoryEntry; export type TInventoryEntryDraftRest = InventoryEntryDraft; // GraphQL export type TInventoryEntryGraphql = Omit & { __typename: 'InventoryEntry'; - supplyChannel: TChannelGraphql; - supplyChannelRef: TReferenceGraphql; + supplyChannel?: TChannelGraphql; + supplyChannelRef?: TReferenceGraphql; }; export type TInventoryEntryDraftGraphql = TInventoryEntryDraft; diff --git a/models/payment/src/payment/transformers.ts b/models/payment/src/payment/transformers.ts index a4fe869fa..1121ef9dc 100644 --- a/models/payment/src/payment/transformers.ts +++ b/models/payment/src/payment/transformers.ts @@ -1,4 +1,4 @@ -import { TReferenceGraphql } from '@commercetools-test-data/commons'; +import { Reference, TReferenceGraphql } from '@commercetools-test-data/commons'; import { Transformer, buildField, @@ -39,23 +39,29 @@ const transformers = { 'custom', ], replaceFields: ({ fields }) => { - const restCustomer = buildField(fields.customer, 'rest'); - const customerBuilder = restCustomer.email - ? Customer.random() - .id(restCustomer.id) - .firstName(restCustomer.firstName) - .lastName(restCustomer.lastName) - .key(restCustomer.key) - .customerNumber(restCustomer.customerNumber) - .externalId(restCustomer.externalId) - .email(restCustomer.email) - .title(restCustomer.title) - : Customer.random().id(restCustomer.id); - const customerRef: TReferenceGraphql = { - id: restCustomer.id, - typeId: 'customer', - __typename: 'Reference', - }; + let customer: TCustomerGraphql | undefined = undefined; + let customerRef: TReferenceGraphql | undefined = undefined; + + if (fields.customer) { + const restCustomerRef = buildField(fields.customer, 'rest'); + + customerRef = Reference.presets + .customerReference() + .id(restCustomerRef.id) + .buildGraphql(); + + customer = Customer.random() + .id(restCustomerRef.id) + .firstName(restCustomerRef.obj?.firstName) + .lastName(restCustomerRef.obj?.lastName) + .key(restCustomerRef.obj?.key) + .customerNumber(restCustomerRef.obj?.customerNumber) + .externalId(restCustomerRef.obj?.externalId) + .email(restCustomerRef.obj?.email || '') + .title(restCustomerRef.obj?.title) + .buildGraphql(); + } + // TODO: This exists in the Graphql API, but not in the REST API // We're stubbing it out for now because it's non-nullable const interfaceInteractionsRaw = toGraphqlPaginatedQueryResult([], { @@ -63,7 +69,7 @@ const transformers = { }); return { ...fields, - customer: customerBuilder.buildGraphql(), + customer, customerRef, interfaceInteractionsRaw, __typename: 'Payment', diff --git a/models/payment/src/payment/types.ts b/models/payment/src/payment/types.ts index 00c6ca90e..f77904a6c 100644 --- a/models/payment/src/payment/types.ts +++ b/models/payment/src/payment/types.ts @@ -1,31 +1,24 @@ -import { Customer, Payment, PaymentDraft } from '@commercetools/platform-sdk'; -import type { - TReferenceGraphql, - TReferenceRest, -} from '@commercetools-test-data/commons'; +import { Payment, PaymentDraft } from '@commercetools/platform-sdk'; +import type { TReferenceGraphql } from '@commercetools-test-data/commons'; import type { TBuilder, TPaginatedQueryResult, } from '@commercetools-test-data/core'; -import { TCustomer, TCustomerGraphql } from '@commercetools-test-data/customer'; +import { TCustomerGraphql } from '@commercetools-test-data/customer'; // Default -export type TPayment = Omit & { - customer: Customer; -}; +export type TPayment = Payment; export type TPaymentDraft = PaymentDraft; // Rest -export type TPaymentRest = Omit & { - customer?: TReferenceRest; -}; +export type TPaymentRest = Payment; export type TPaymentDraftRest = PaymentDraft; // Graphql -export type TPaymentGraphql = TPayment & { +export type TPaymentGraphql = Omit & { __typename: 'Payment'; - customer: TCustomerGraphql; - customerRef: TReferenceGraphql; + customer?: TCustomerGraphql; + customerRef?: TReferenceGraphql; interfaceInteractionsRaw: TPaginatedQueryResult; }; export type TPaymentDraftGraphql = TPaymentDraft; diff --git a/models/product-projection/src/types.ts b/models/product-projection/src/types.ts index 975a15dca..96ce2b186 100644 --- a/models/product-projection/src/types.ts +++ b/models/product-projection/src/types.ts @@ -3,34 +3,19 @@ import { ReviewRatingStatistics, SuggestTokenizer, } from '@commercetools/platform-sdk'; -import { TCategory, TCategoryGraphql } from '@commercetools-test-data/category'; +import { TCategoryGraphql } from '@commercetools-test-data/category'; import { TLocalizedStringGraphql, - TReferenceRest, TReferenceGraphql, } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; -import { - TProductType, - TProductTypeGraphql, -} from '@commercetools-test-data/product-type'; -import { TState, TStateGraphql } from '@commercetools-test-data/state'; -import { - TTaxCategory, - TTaxCategoryGraphql, -} from '@commercetools-test-data/tax-category'; +import { TProductTypeGraphql } from '@commercetools-test-data/product-type'; +import { TStateGraphql } from '@commercetools-test-data/state'; +import { TTaxCategoryGraphql } from '@commercetools-test-data/tax-category'; export type TProductProjection = ProductProjection; -export type TProductProjectionRest = Omit< - TProductProjection, - 'productType' | 'categories' | 'taxCategory' | 'state' -> & { - productType: TReferenceRest; - categories: TReferenceRest[]; - taxCategory?: TReferenceRest; - state?: TReferenceRest; -}; +export type TProductProjectionRest = TProductProjection; export type TCategoryOrderHintGraphql = { categoryId: string; diff --git a/models/quote/src/builder.spec.ts b/models/quote/src/builder.spec.ts index 463160a46..def3cf765 100644 --- a/models/quote/src/builder.spec.ts +++ b/models/quote/src/builder.spec.ts @@ -15,24 +15,40 @@ describe('builder', () => { version: expect.any(Number), key: expect.any(String), quoteRequest: expect.objectContaining({ - quoteRequestState: expect.any(String), + id: expect.any(String), + typeId: 'quote-request', + obj: expect.objectContaining({ + quoteRequestState: expect.any(String), + }), }), stagedQuote: expect.objectContaining({ - stagedQuoteState: expect.any(String), + id: expect.any(String), + typeId: 'staged-quote', + obj: expect.objectContaining({ + stagedQuoteState: expect.any(String), + }), }), customer: expect.objectContaining({ - email: expect.any(String), + id: expect.any(String), + typeId: 'customer', + obj: expect.objectContaining({ + email: expect.any(String), + }), }), customerGroup: expect.objectContaining({ - name: expect.any(String), - version: expect.any(Number), + id: expect.any(String), + typeId: 'customer-group', + obj: expect.objectContaining({ + name: expect.any(String), + version: expect.any(Number), + }), }), validTo: expect.any(String), sellerComment: expect.any(String), buyerComment: expect.any(String), store: expect.objectContaining({ - id: expect.any(String), key: expect.any(String), + typeId: 'store', }), lineItems: expect.arrayContaining([ expect.objectContaining({ @@ -76,9 +92,8 @@ describe('builder', () => { state: null, purchaseOrderNumber: null, businessUnit: expect.objectContaining({ - id: expect.any(String), key: expect.any(String), - associateMode: expect.any(String), + typeId: 'business-unit', }), custom: null, createdAt: expect.any(String), @@ -103,17 +118,31 @@ describe('builder', () => { quoteRequest: expect.objectContaining({ id: expect.any(String), typeId: 'quote-request', + obj: expect.objectContaining({ + quoteRequestState: expect.any(String), + }), }), stagedQuote: expect.objectContaining({ id: expect.any(String), typeId: 'staged-quote', + obj: expect.objectContaining({ + stagedQuoteState: expect.any(String), + }), }), customer: expect.objectContaining({ id: expect.any(String), typeId: 'customer', + obj: expect.objectContaining({ + email: expect.any(String), + }), }), customerGroup: expect.objectContaining({ + id: expect.any(String), typeId: 'customer-group', + obj: expect.objectContaining({ + name: expect.any(String), + version: expect.any(Number), + }), }), validTo: expect.any(String), sellerComment: expect.any(String), @@ -161,7 +190,7 @@ describe('builder', () => { ]), directDiscounts: expect.arrayContaining([]), quoteState: expect.any(String), - state: undefined, + state: null, businessUnit: expect.objectContaining({ key: expect.any(String), typeId: 'business-unit', @@ -267,7 +296,7 @@ describe('builder', () => { ]), directDiscounts: expect.arrayContaining([]), quoteState: expect.any(String), - state: null, + state: undefined, stateRef: undefined, businessUnit: expect.objectContaining({ id: expect.any(String), diff --git a/models/quote/src/generator.ts b/models/quote/src/generator.ts index 1cb1a21e1..12786892e 100644 --- a/models/quote/src/generator.ts +++ b/models/quote/src/generator.ts @@ -1,9 +1,10 @@ -import { Company } from '@commercetools-test-data/business-unit'; import { LineItem } from '@commercetools-test-data/cart'; import { CentPrecisionMoney, ClientLogging, Address, + Reference, + KeyReference, } from '@commercetools-test-data/commons'; import { sequence, @@ -15,7 +16,6 @@ import { Customer } from '@commercetools-test-data/customer'; import { CustomerGroup } from '@commercetools-test-data/customer-group'; import { QuoteRequest } from '@commercetools-test-data/quote-request'; import { StagedQuote } from '@commercetools-test-data/staged-quote'; -import { Store } from '@commercetools-test-data/store'; import { createRelatedDates } from '@commercetools-test-data/utils'; import { QUOTE_STATE, @@ -35,14 +35,22 @@ const generator = Generator({ id: fake((f) => f.string.uuid()), version: sequence(), key: fake((f) => f.lorem.slug(2)), - quoteRequest: fake(() => QuoteRequest.random()), - stagedQuote: fake(() => StagedQuote.random()), - customer: fake(() => Customer.random()), - customerGroup: fake(() => CustomerGroup.random()), + quoteRequest: fake(() => + Reference.presets.quoteRequestReference().obj(QuoteRequest.random()) + ), + stagedQuote: fake(() => + Reference.presets.stagedQuoteReference().obj(StagedQuote.random()) + ), + customer: fake(() => + Reference.presets.customerReference().obj(Customer.random()) + ), + customerGroup: fake(() => + Reference.presets.customerGroupReference().obj(CustomerGroup.random()) + ), validTo: fake(getFutureDate), sellerComment: fake((f) => f.lorem.words(5)), buyerComment: fake((f) => f.lorem.words(5)), - store: fake(() => Store.random()), + store: fake(() => KeyReference.presets.store()), lineItems: fake(() => [LineItem.random()]), customLineItems: [], totalPrice: fake(() => CentPrecisionMoney.random()), @@ -62,7 +70,10 @@ const generator = Generator({ quoteState: oneOf(...Object.values(QUOTE_STATE)), state: null, purchaseOrderNumber: null, - businessUnit: fake(() => Company.random()), + businessUnit: fake( + () => KeyReference.presets.businessUnit().key('company') + // Reference.random().typeId('company').obj(Company.random()) + ), custom: null, createdAt: fake(getOlderDate), createdBy: fake(() => ClientLogging.random()), diff --git a/models/quote/src/transformers.ts b/models/quote/src/transformers.ts index db46154aa..640e010bc 100644 --- a/models/quote/src/transformers.ts +++ b/models/quote/src/transformers.ts @@ -1,21 +1,32 @@ import { - BusinessUnitKeyReference, - StoreKeyReference, -} from '@commercetools/platform-sdk'; + Company, + TCompanyGraphql, + TDivisionGraphql, +} from '@commercetools-test-data/business-unit'; import { Reference, KeyReference, TReferenceGraphql, TKeyReferenceGraphql, - TReferenceRest, + LocalizedString, } from '@commercetools-test-data/commons'; -import { Transformer } from '@commercetools-test-data/core'; +import { buildField, Transformer } from '@commercetools-test-data/core'; -import { TCustomer } from '@commercetools-test-data/customer'; -import { TCustomerGroup } from '@commercetools-test-data/customer-group'; -import { TQuoteRequestRest } from '@commercetools-test-data/quote-request'; -import { TStagedQuoteRest } from '@commercetools-test-data/staged-quote'; -import { TState } from '@commercetools-test-data/state'; +import { Customer, TCustomerGraphql } from '@commercetools-test-data/customer'; +import { + CustomerGroup, + TCustomerGroupGraphql, +} from '@commercetools-test-data/customer-group'; +import { + QuoteRequest, + TQuoteRequestGraphql, +} from '@commercetools-test-data/quote-request'; +import { + StagedQuote, + TStagedQuoteGraphql, +} from '@commercetools-test-data/staged-quote'; +import { State, TStateGraphql } from '@commercetools-test-data/state'; +import { Store } from '@commercetools-test-data/store'; import type { TQuote, TQuoteRest, TQuoteGraphql } from './types'; const transformers = { @@ -60,61 +71,9 @@ const transformers = { 'createdBy', 'lastModifiedBy', ], - replaceFields: ({ fields }) => { - const quoteRequest = Reference.presets - .quoteRequestReference() - .id(fields.quoteRequest.id) - .build>(); - - const stagedQuote = Reference.presets - .stagedQuoteReference() - .id(fields.stagedQuote.id) - .build>(); - - const customer = Reference.presets - .customerReference() - .id(fields.customer.id) - .build>(); - - const customerGroup = Reference.presets - .customerGroupReference() - .id(fields.customerGroup?.id) - .build>(); - - const store = KeyReference.presets - .store() - .key(fields.store?.key) - .buildRest(); - - const state = Reference.presets - .stateReference() - .id(fields.state?.id) - .build>(); - - const businessUnit = KeyReference.presets - .businessUnit() - .key(fields.businessUnit?.key) - .buildRest(); - - return { - ...fields, - quoteRequest, - stagedQuote, - customer, - customerGroup: fields.customerGroup ? customerGroup : undefined, - store: fields.store ? store : undefined, - state: fields.state ? state : undefined, - businessUnit: fields.businessUnit ? businessUnit : undefined, - }; - }, }), graphql: Transformer('graphql', { buildFields: [ - 'quoteRequest', - 'stagedQuote', - 'customer', - 'customerGroup', - 'store', 'lineItems', 'customLineItems', 'totalPrice', @@ -122,59 +81,127 @@ const transformers = { 'billingAddress', 'itemShippingAddresses', 'directDiscounts', - 'state', - 'businessUnit', 'custom', 'createdBy', 'lastModifiedBy', ], - addFields: ({ fields }) => { + replaceFields: ({ fields }) => { + let businessUnit: TCompanyGraphql | TDivisionGraphql | undefined = + undefined; + let businessUnitRef: TKeyReferenceGraphql | undefined = undefined; + let customer: TCustomerGraphql | undefined = undefined; + let customerRef: TReferenceGraphql | undefined = undefined; + let customerGroup: TCustomerGroupGraphql | undefined = undefined; + let customerGroupRef: TReferenceGraphql | undefined = undefined; + let state: TStateGraphql | undefined = undefined; + let stateRef: TReferenceGraphql | undefined = undefined; + let store: TReferenceGraphql | undefined = undefined; + let storeRef: TKeyReferenceGraphql | undefined = undefined; + + const restQuoteRequestRef = buildField(fields.quoteRequest, 'rest'); const quoteRequestRef: TReferenceGraphql = Reference.presets .quoteRequestReference() - .id(fields.quoteRequest.id) + .id(restQuoteRequestRef.id) .buildGraphql(); + const quoteRequest = QuoteRequest.random() + .id(restQuoteRequestRef.id) + .key(restQuoteRequestRef.obj?.key) + .buildGraphql(); + const restStagedQuoteRef = buildField(fields.stagedQuote, 'rest'); const stagedQuoteRef: TReferenceGraphql = Reference.presets .stagedQuoteReference() - .id(fields.stagedQuote.id) - .buildGraphql(); - - const customerRef: TReferenceGraphql = Reference.presets - .customerReference() - .id(fields.customer.id) - .typeId('customer') - .buildGraphql(); - - const customerGroupRef: TReferenceGraphql = Reference.presets - .customerGroupReference() - .id(fields.customerGroup?.id) - .typeId('customer-group') - .buildGraphql(); - - const storeRef: TKeyReferenceGraphql = KeyReference.presets - .store() - .key(fields.store?.key) - .buildGraphql(); - - const stateRef: TReferenceGraphql = Reference.presets - .stateReference() - .id(fields.state?.id) - .typeId('state') - .buildGraphql(); - - const businessUnitRef: TKeyReferenceGraphql = KeyReference.presets - .businessUnit() - .key(fields.businessUnit?.key) + .id(restStagedQuoteRef.id) .buildGraphql(); + const stagedQuote = StagedQuote.random() + .id(restStagedQuoteRef.id) + .key(restStagedQuoteRef.obj?.key) + .buildGraphql(); + + if (fields.businessUnit) { + const restBusinessUnitRef = buildField(fields.businessUnit, 'rest'); + businessUnitRef = KeyReference.presets + .businessUnit() + .key(restBusinessUnitRef.key) + .buildGraphql(); + businessUnit = Company.random() + .key(restBusinessUnitRef.key) + .buildGraphql(); + } + + if (fields.customer) { + const restCustomerRef = buildField(fields.customer, 'rest'); + customerRef = Reference.presets + .customerReference() + .id(restCustomerRef.id) + .buildGraphql(); + customer = Customer.random() + .id(restCustomerRef.id) + .firstName(restCustomerRef.obj?.firstName) + .lastName(restCustomerRef.obj?.lastName) + .key(restCustomerRef.obj?.key) + .email(restCustomerRef.obj?.email || '') + .buildGraphql(); + } + + if (fields.customerGroup) { + const restCustomerGroupRef = buildField(fields.customerGroup, 'rest'); + customerGroupRef = Reference.presets + .customerGroupReference() + .id(restCustomerGroupRef.id) + .buildGraphql(); + customerGroup = CustomerGroup.random() + .id(restCustomerGroupRef.id) + .key(restCustomerGroupRef.obj?.key) + .buildGraphql(); + } + + if (fields.state) { + const restStateRef = buildField(fields.state, 'rest'); + stateRef = Reference.presets + .stateReference() + .id(restStateRef.id) + .buildGraphql(); + state = State.random() + .id(restStateRef.id) + .key(restStateRef.obj?.key || '') + .type(restStateRef.obj?.type || '') + .name( + LocalizedString.presets + .empty() + .en(restStateRef.obj?.name?.en) + .de(restStateRef.obj?.name?.de) + ) + .buildGraphql(); + } + + if (fields.store) { + const restStoreRef = buildField(fields.store, 'rest'); + storeRef = KeyReference.presets + .store() + .key(restStoreRef.key) + .buildGraphql(); + store = Store.random() + .key(restStoreRef.key) + .buildGraphql(); + } return { + ...fields, + quoteRequest, quoteRequestRef, + stagedQuote, stagedQuoteRef, + customer, customerRef, - customerGroupRef: fields.customerGroup ? customerGroupRef : undefined, - storeRef: fields.store ? storeRef : undefined, - stateRef: fields.state ? stateRef : undefined, - businessUnitRef: fields.businessUnit ? businessUnitRef : undefined, + customerGroup, + customerGroupRef, + state, + stateRef, + store, + storeRef, + businessUnit, + businessUnitRef, __typename: 'Quote', }; }, diff --git a/models/quote/src/types.ts b/models/quote/src/types.ts index ed9684dcf..b0995cbd8 100644 --- a/models/quote/src/types.ts +++ b/models/quote/src/types.ts @@ -1,29 +1,28 @@ -import type { - BusinessUnit, - Customer, - CustomerGroup, - Quote, - QuoteDraft, - QuoteRequest, - StagedQuote, - State, - Store, -} from '@commercetools/platform-sdk'; +import type { Quote, QuoteDraft } from '@commercetools/platform-sdk'; +import { + TCompanyGraphql, + TDivisionGraphql, +} from '@commercetools-test-data/business-unit'; import { TReferenceGraphql, TKeyReferenceGraphql, - TReferenceRest, } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; -import { TCustomer } from '@commercetools-test-data/customer'; -import { TCustomerGroup } from '@commercetools-test-data/customer-group'; -import { TQuoteRequestRest } from '@commercetools-test-data/quote-request'; -import { TStagedQuoteRest } from '@commercetools-test-data/staged-quote'; -import { TState } from '@commercetools-test-data/state'; +import { TCustomerGraphql } from '@commercetools-test-data/customer'; +import { TCustomerGroupGraphql } from '@commercetools-test-data/customer-group'; +import { TQuoteRequestGraphql } from '@commercetools-test-data/quote-request'; +import { TStagedQuoteGraphql } from '@commercetools-test-data/staged-quote'; +import { TStateGraphql } from '@commercetools-test-data/state'; // Default -export type TQuote = Omit< - Quote, +export type TQuote = Quote; + +// Rest +export type TQuoteRest = Quote; +export type TQuoteDraft = QuoteDraft; + +export type TQuoteGraphql = Omit< + TQuote, | 'businessUnit' | 'customer' | 'customerGroup' @@ -32,36 +31,20 @@ export type TQuote = Omit< | 'state' | 'store' > & { - businessUnit: BusinessUnit; - customer: Customer; - customerGroup: CustomerGroup; - quoteRequest: QuoteRequest; - stagedQuote: StagedQuote; - state: State; - store: Store; -}; - -// Rest -export type TQuoteRest = Omit< - Quote, - 'customer' | 'customerGroup' | 'quoteRequest' | 'stagedQuote' | 'state' -> & { - customer?: TReferenceRest; - customerGroup?: TReferenceRest; - quoteRequest: TReferenceRest; - stagedQuote: TReferenceRest; - state?: TReferenceRest; -}; -export type TQuoteDraft = QuoteDraft; - -export type TQuoteGraphql = TQuote & { - businessUnitRef: TKeyReferenceGraphql | null; - customerRef: TReferenceGraphql | null; - customerGroupRef: TReferenceGraphql | null; - quoteReqestRef: TReferenceGraphql; + businessUnit?: TCompanyGraphql | TDivisionGraphql; + businessUnitRef?: TKeyReferenceGraphql; + customer?: TCustomerGraphql; + customerRef?: TReferenceGraphql; + customerGroup?: TCustomerGroupGraphql; + customerGroupRef?: TReferenceGraphql; + quoteRequest: TQuoteRequestGraphql; + quoteRequestRef: TReferenceGraphql; + stagedQuote: TStagedQuoteGraphql; stagedQuoteRef: TReferenceGraphql; - stateRef: TReferenceGraphql | null; - storeRef: TKeyReferenceGraphql | null; + state?: TStateGraphql; + stateRef?: TReferenceGraphql; + store?: TReferenceGraphql; + storeRef?: TKeyReferenceGraphql; __typename: 'Quote'; }; export type TQuoteDraftGraphql = TQuoteDraft; diff --git a/models/standalone-price/src/builder.spec.ts b/models/standalone-price/src/builder.spec.ts index fb2398a3e..68c609b01 100644 --- a/models/standalone-price/src/builder.spec.ts +++ b/models/standalone-price/src/builder.spec.ts @@ -31,11 +31,11 @@ describe('builder', () => { country: expect.any(String), customerGroup: expect.objectContaining({ id: expect.any(String), - key: expect.any(String), + typeId: 'customer-group', }), channel: expect.objectContaining({ id: expect.any(String), - key: expect.any(String), + typeId: 'channel', }), validFrom: expect.any(String), validUntil: expect.any(String), @@ -53,7 +53,6 @@ describe('builder', () => { discounted: null, staged: null, active: expect.any(Boolean), - expiresAt: expect.any(String), }) ) ); @@ -141,12 +140,14 @@ describe('builder', () => { key: expect.any(String), }), customerGroupRef: expect.objectContaining({ + id: expect.any(String), typeId: 'customer-group', - key: expect.any(String), + __typename: 'Reference', }), channelRef: expect.objectContaining({ + id: expect.any(String), typeId: 'channel', - key: expect.any(String), + __typename: 'Reference', }), validFrom: expect.any(String), validUntil: expect.any(String), diff --git a/models/standalone-price/src/generator.ts b/models/standalone-price/src/generator.ts index f1bb5c551..6d3aeb9fd 100644 --- a/models/standalone-price/src/generator.ts +++ b/models/standalone-price/src/generator.ts @@ -3,6 +3,7 @@ import { ClientLogging, PriceTier, CentPrecisionMoney, + Reference, } from '@commercetools-test-data/commons'; import { Generator, fake, sequence } from '@commercetools-test-data/core'; import { CustomerGroup } from '@commercetools-test-data/customer-group'; @@ -25,15 +26,18 @@ const generator = Generator({ sku: fake((f) => `${f.lorem.word()}-${f.string.alphanumeric(3)}`), value: fake(() => CentPrecisionMoney.random()), country: fake((f) => f.location.countryCode()), - customerGroup: fake(() => CustomerGroup.random()), - channel: fake(() => Channel.random()), + customerGroup: fake(() => + Reference.presets.customerGroupReference().obj(CustomerGroup.random()) + ), + channel: fake(() => + Reference.presets.channelReference().obj(Channel.random()) + ), validFrom: fake(getCreatedAt), validUntil: fake(getExpiresAt), tiers: [fake(() => PriceTier.random())], discounted: null, staged: null, active: fake((f) => f.datatype.boolean()), - expiresAt: fake(getExpiresAt), }, }); diff --git a/models/standalone-price/src/transformers.ts b/models/standalone-price/src/transformers.ts index 0359c3844..a3fe958a8 100644 --- a/models/standalone-price/src/transformers.ts +++ b/models/standalone-price/src/transformers.ts @@ -1,54 +1,16 @@ -import { TChannel } from '@commercetools-test-data/channel'; +import { Channel, TChannelGraphql } from '@commercetools-test-data/channel'; +import { Reference, TReferenceGraphql } from '@commercetools-test-data/commons'; +import { buildField, Transformer } from '@commercetools-test-data/core'; import { - Reference, - KeyReference, - TReferenceGraphql, - TReferenceRest, -} from '@commercetools-test-data/commons'; -import { Transformer } from '@commercetools-test-data/core'; -import { type TCustomerGroup } from '@commercetools-test-data/customer-group'; + CustomerGroup, + TCustomerGroupGraphql, +} from '@commercetools-test-data/customer-group'; import type { TStandalonePrice, TStandalonePriceGraphql, TStandalonePriceRest, } from './types'; -// Overloads -function createCustomerGroupReference( - customerGroup: TCustomerGroup, - target: 'rest' -): TReferenceRest; -function createCustomerGroupReference( - customerGroup: TCustomerGroup, - target: 'graphql' -): TReferenceGraphql; - -// Create a customer group reference depending on `id` or `key` field availability -function createCustomerGroupReference( - customerGroup: TCustomerGroup, - target: 'graphql' | 'rest' -) { - let referenceBuilder; - - // `key` is optional in CustomerGroup, prioritize it over `id` - if (customerGroup.key) { - referenceBuilder = KeyReference.random() - .typeId('customer-group') - .key(customerGroup.key); - } else if (customerGroup.id) { - referenceBuilder = Reference.random() - .typeId('customer-group') - .id(customerGroup.id); - } - - // Dynamically call buildRest or buildGraphql based on target - if (referenceBuilder) { - return target === 'rest' - ? referenceBuilder.buildRest>() - : referenceBuilder.buildGraphql(); - } -} - const transformers = { default: Transformer('default', { buildFields: [ @@ -69,49 +31,53 @@ const transformers = { 'channel', 'tiers', ], + }), + graphql: Transformer('graphql', { + buildFields: ['lastModifiedBy', 'createdBy', 'value', 'tiers'], replaceFields: ({ fields }) => { - // Remove `expiresAt` from the fields - const { expiresAt, ...rest } = fields; + let channel: TChannelGraphql | undefined = undefined; + let channelRef: TReferenceGraphql | undefined = undefined; + let customerGroup: TCustomerGroupGraphql | undefined = undefined; + let customerGroupRef: TReferenceGraphql | undefined = undefined; - const channel = fields.channel - ? KeyReference.random() - .typeId('channel') - .key(fields.channel.key) - .buildRest>() - : undefined; + if (fields.customerGroup) { + const restCustomerGroupRef = buildField(fields.customerGroup, 'rest'); + customerGroupRef = Reference.presets + .customerGroupReference() + .id(restCustomerGroupRef.id) + .buildGraphql(); + + customerGroup = CustomerGroup.random() + .id(restCustomerGroupRef.id) + .key(restCustomerGroupRef.obj!.key) + .name(restCustomerGroupRef.obj!.name) + .buildGraphql(); + } + + if (fields.channel) { + const restChannelRef = buildField(fields.channel, 'rest'); + channelRef = Reference.presets + .channelReference() + .id(restChannelRef.id) + .buildGraphql(); + + channel = Channel.random() + .id(restChannelRef.id) + .key(restChannelRef.obj!.key) + .name(restChannelRef.obj!.name) + .buildGraphql(); + } return { - ...rest, - customerGroup: fields.customerGroup - ? createCustomerGroupReference(fields.customerGroup, 'rest') - : undefined, + ...fields, + __typename: 'StandalonePrice', channel, + channelRef, + customerGroup, + customerGroupRef, }; }, }), - graphql: Transformer('graphql', { - buildFields: [ - 'lastModifiedBy', - 'createdBy', - 'value', - 'customerGroup', - 'channel', - 'tiers', - ], - addFields: ({ fields }) => { - const customerGroupRef = fields.customerGroup - ? createCustomerGroupReference(fields.customerGroup, 'graphql') - : null; - const channelRef = fields.channel - ? KeyReference.random() - .typeId('channel') - .key(fields.channel.key) - .buildGraphql() - : null; - - return { __typename: 'StandalonePrice', customerGroupRef, channelRef }; - }, - }), }; export default transformers; diff --git a/models/standalone-price/src/types.ts b/models/standalone-price/src/types.ts index ef3f05cdf..3110954cd 100644 --- a/models/standalone-price/src/types.ts +++ b/models/standalone-price/src/types.ts @@ -1,44 +1,31 @@ import { StandalonePrice, StandalonePriceDraft, - CustomerGroup, - Channel, } from '@commercetools/platform-sdk'; -import { TChannel } from '@commercetools-test-data/channel'; +import { TChannelGraphql } from '@commercetools-test-data/channel'; import { TMoneyGraphql, TReferenceGraphql, - TReferenceRest, } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; -import { TCustomerGroup } from '@commercetools-test-data/customer-group'; +import { TCustomerGroupGraphql } from '@commercetools-test-data/customer-group'; // Base representation -// TODO: This doesn't seem to be right. I don't understand why the default type should have customized fields. -// It seems to me that's something only transformed versions of the model should have. -export type TStandalonePrice = Omit< - StandalonePrice, - 'customerGroup' | 'channel' -> & { - customerGroup: CustomerGroup | null; - channel: Channel | null; - expiresAt: string | null; -}; +export type TStandalonePrice = StandalonePrice; // REST representation -export type TStandalonePriceRest = Omit< - StandalonePrice, - 'channel' | 'customerGroup' -> & { - channel?: TReferenceRest; - customerGroup?: TReferenceRest; -}; +export type TStandalonePriceRest = StandalonePrice; export type TStandalonePriceDraft = StandalonePriceDraft; // Graphql representation -export type TStandalonePriceGraphql = TStandalonePrice & { - customerGroupRef: TReferenceGraphql | null; - channelRef: TReferenceGraphql | null; +export type TStandalonePriceGraphql = Omit< + TStandalonePrice, + 'channel' | 'customerGroup' +> & { + channel?: TChannelGraphql; + channelRef?: TReferenceGraphql; + customerGroup?: TCustomerGroupGraphql; + customerGroupRef?: TReferenceGraphql; __typename: 'StandalonePrice'; }; From 293ddaf4b3b27026a21b9d564576137ec01523c2 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Wed, 21 Aug 2024 21:10:04 +0200 Subject: [PATCH 09/17] fix: fix models properties definitions --- models/quote-request/src/builder.spec.ts | 49 +++++- models/quote-request/src/generator.ts | 22 ++- models/quote-request/src/transformers.ts | 204 +++++++++++++---------- models/quote-request/src/types.ts | 64 ++++--- models/staged-quote/src/builder.spec.ts | 37 +++- models/staged-quote/src/generator.ts | 21 ++- models/staged-quote/src/transformers.ts | 159 ++++++++++-------- models/staged-quote/src/types.ts | 55 +++--- 8 files changed, 346 insertions(+), 265 deletions(-) diff --git a/models/quote-request/src/builder.spec.ts b/models/quote-request/src/builder.spec.ts index c0889409f..eb291866a 100644 --- a/models/quote-request/src/builder.spec.ts +++ b/models/quote-request/src/builder.spec.ts @@ -21,15 +21,23 @@ describe('builder', () => { quoteRequestState: expect.any(String), comment: null, customer: expect.objectContaining({ - email: expect.any(String), + id: expect.any(String), + typeId: 'customer', + obj: expect.objectContaining({ + email: expect.any(String), + }), }), customerGroup: expect.objectContaining({ - name: expect.any(String), - version: expect.any(Number), + id: expect.any(String), + typeId: 'customer-group', + obj: expect.objectContaining({ + name: expect.any(String), + version: expect.any(Number), + }), }), store: expect.objectContaining({ - id: expect.any(String), key: expect.any(String), + typeId: 'store', }), lineItems: expect.arrayContaining([ expect.objectContaining({ @@ -71,12 +79,15 @@ describe('builder', () => { directDiscounts: expect.arrayContaining([]), state: null, cart: expect.objectContaining({ + id: expect.any(String), typeId: 'cart', + obj: expect.objectContaining({ + taxMode: expect.any(String), + }), }), businessUnit: expect.objectContaining({ - id: expect.any(String), key: expect.any(String), - associateMode: expect.any(String), + typeId: 'business-unit', }), custom: null, createdAt: expect.any(String), @@ -90,6 +101,7 @@ describe('builder', () => { }) ) ); + it( ...createBuilderSpec( 'rest', @@ -103,11 +115,20 @@ describe('builder', () => { customer: expect.objectContaining({ id: expect.any(String), typeId: 'customer', + obj: expect.objectContaining({ + email: expect.any(String), + }), }), customerGroup: expect.objectContaining({ + id: expect.any(String), typeId: 'customer-group', + obj: expect.objectContaining({ + name: expect.any(String), + version: expect.any(Number), + }), }), store: expect.objectContaining({ + key: expect.any(String), typeId: 'store', }), lineItems: expect.arrayContaining([ @@ -148,11 +169,16 @@ describe('builder', () => { }), ]), directDiscounts: expect.arrayContaining([]), - state: undefined, + state: null, cart: expect.objectContaining({ + id: expect.any(String), typeId: 'cart', + obj: expect.objectContaining({ + taxMode: expect.any(String), + }), }), businessUnit: expect.objectContaining({ + key: expect.any(String), typeId: 'business-unit', }), custom: null, @@ -238,8 +264,13 @@ describe('builder', () => { }), ]), directDiscounts: expect.arrayContaining([]), - state: null, + state: undefined, stateRef: undefined, + cart: expect.objectContaining({ + id: expect.any(String), + taxMode: expect.any(String), + __typename: 'Cart', + }), cartRef: expect.objectContaining({ typeId: 'cart', __typename: 'Reference', @@ -247,7 +278,7 @@ describe('builder', () => { businessUnit: expect.objectContaining({ id: expect.any(String), key: expect.any(String), - associateMode: expect.any(String), + name: expect.any(String), }), businessUnitRef: expect.objectContaining({ typeId: 'business-unit', diff --git a/models/quote-request/src/generator.ts b/models/quote-request/src/generator.ts index 8e1d14022..ed6012249 100644 --- a/models/quote-request/src/generator.ts +++ b/models/quote-request/src/generator.ts @@ -1,10 +1,10 @@ -import { Company } from '@commercetools-test-data/business-unit'; -import { LineItem } from '@commercetools-test-data/cart'; +import { Cart, LineItem } from '@commercetools-test-data/cart'; import { CentPrecisionMoney, ClientLogging, Address, Reference, + KeyReference, } from '@commercetools-test-data/commons'; import { sequence, @@ -14,7 +14,6 @@ import { } from '@commercetools-test-data/core'; import { Customer } from '@commercetools-test-data/customer'; import { CustomerGroup } from '@commercetools-test-data/customer-group'; -import { Store } from '@commercetools-test-data/store'; import { createRelatedDates } from '@commercetools-test-data/utils'; import { QUOTE_REQUEST_STATE, @@ -36,9 +35,13 @@ const generator = Generator({ key: fake((f) => f.lorem.slug(2)), quoteRequestState: oneOf(...Object.values(QUOTE_REQUEST_STATE)), comment: null, - customer: fake(() => Customer.random()), - customerGroup: fake(() => CustomerGroup.random()), - store: fake(() => Store.random()), + customer: fake(() => + Reference.presets.customerReference().obj(Customer.random()) + ), + customerGroup: fake(() => + Reference.presets.customerGroupReference().obj(CustomerGroup.random()) + ), + store: fake(() => KeyReference.presets.store()), lineItems: fake(() => [LineItem.random()]), customLineItems: [], totalPrice: fake(() => CentPrecisionMoney.random()), @@ -57,8 +60,11 @@ const generator = Generator({ directDiscounts: [], state: null, purchaseOrderNumber: null, - cart: fake(() => Reference.random().typeId('cart')), - businessUnit: fake(() => Company.random()), + cart: fake(() => Reference.presets.cartReference().obj(Cart.random())), + businessUnit: fake( + () => KeyReference.presets.businessUnit() + // Reference.presets.businessUnitReference().obj(Company.random()) + ), custom: null, createdAt: fake(getOlderDate), createdBy: fake(() => ClientLogging.random()), diff --git a/models/quote-request/src/transformers.ts b/models/quote-request/src/transformers.ts index 81bd3fd69..92dfdbece 100644 --- a/models/quote-request/src/transformers.ts +++ b/models/quote-request/src/transformers.ts @@ -1,20 +1,25 @@ import { - BusinessUnitKeyReference, - StoreKeyReference, -} from '@commercetools/platform-sdk'; -import { TCart } from '@commercetools-test-data/cart'; + Company, + TCompanyGraphql, + TDivisionGraphql, +} from '@commercetools-test-data/business-unit'; +import { Cart, TCartGraphql } from '@commercetools-test-data/cart'; import { Reference, KeyReference, TReferenceGraphql, TKeyReferenceGraphql, - TReferenceRest, + LocalizedString, } from '@commercetools-test-data/commons'; -import { Transformer } from '@commercetools-test-data/core'; +import { buildField, Transformer } from '@commercetools-test-data/core'; -import { TCustomer } from '@commercetools-test-data/customer'; -import { TCustomerGroup } from '@commercetools-test-data/customer-group'; -import { TState } from '@commercetools-test-data/state'; +import { Customer, TCustomerGraphql } from '@commercetools-test-data/customer'; +import { + CustomerGroup, + TCustomerGroupGraphql, +} from '@commercetools-test-data/customer-group'; +import { State, TStateGraphql } from '@commercetools-test-data/state'; +import { Store, TStoreGraphql } from '@commercetools-test-data/store'; import type { TQuoteRequest, TQuoteRequestRest, @@ -57,113 +62,128 @@ const transformers = { 'createdBy', 'lastModifiedBy', ], - replaceFields: ({ fields }) => { - const customer = Reference.presets - .customerReference() - .id(fields.customer.id) - .build>(); - - const customerGroup = Reference.presets - .customerGroupReference() - .id(fields.customerGroup?.id) - .build>(); - - const store = KeyReference.random() - .typeId('store') - .key(fields.store?.key) - .buildRest(); - - const state = Reference.presets - .stateReference() - .id(fields.state?.id) - .build>(); - - const businessUnit = KeyReference.random() - .typeId('business-unit') - .key(fields.businessUnit?.key) - .buildRest(); - - const cart = Reference.presets - .cartReference() - .id(fields.cart?.id || '') - .build>(); - - return { - ...fields, - cart, - customer, - customerGroup: fields.customerGroup ? customerGroup : undefined, - store: fields.store ? store : undefined, - state: fields.state ? state : undefined, - businessUnit: fields.businessUnit ? businessUnit : undefined, - }; - }, }), graphql: Transformer('graphql', { buildFields: [ - 'customer', - 'customerGroup', - 'store', 'lineItems', 'totalPrice', 'shippingAddress', 'billingAddress', 'itemShippingAddresses', - 'state', - 'cart', - 'businessUnit', 'custom', 'createdBy', 'lastModifiedBy', ], - addFields: ({ fields }) => { - const customerRef: TReferenceGraphql = Reference.presets + replaceFields: ({ fields }) => { + let businessUnit: TCompanyGraphql | TDivisionGraphql | undefined = + undefined; + let businessUnitRef: TKeyReferenceGraphql | undefined = undefined; + let cart: TCartGraphql | undefined = undefined; + let cartRef: TReferenceGraphql | undefined = undefined; + let customerGroup: TCustomerGroupGraphql | undefined = undefined; + let customerGroupRef: TReferenceGraphql | undefined = undefined; + let state: TStateGraphql | undefined = undefined; + let stateRef: TReferenceGraphql | undefined = undefined; + let store: TStoreGraphql | undefined = undefined; + let storeRef: TKeyReferenceGraphql | undefined = undefined; + + const restCustomerRef = buildField(fields.customer, 'rest'); + const customerRef = Reference.presets .customerReference() - .id(fields.customer.id) - .typeId('customer') - .buildGraphql(); + .id(restCustomerRef.id) + .buildGraphql(); + const customer = Customer.random() + .id(restCustomerRef.id) + .firstName(restCustomerRef.obj?.firstName) + .lastName(restCustomerRef.obj?.lastName) + .key(restCustomerRef.obj?.key) + .email(restCustomerRef.obj?.email || '') + .buildGraphql(); - const customerGroupRef: TReferenceGraphql = Reference.presets - .customerGroupReference() - .id(fields.customerGroup?.id) - .typeId('customer-group') - .buildGraphql(); + if (fields.businessUnit) { + const restBusinessUnitRef = buildField(fields.businessUnit, 'rest'); + businessUnitRef = KeyReference.presets + .businessUnit() + .key(restBusinessUnitRef.key) + .buildGraphql(); + businessUnit = Company.random() + .key(restBusinessUnitRef.key) + .buildGraphql(); + } - const storeRef: TKeyReferenceGraphql = KeyReference.presets - .store() - .key(fields.store?.key) - .buildGraphql(); + if (fields.cart) { + const restCartRef = buildField(fields.cart, 'rest'); + cartRef = Reference.presets + .cartReference() + .id(fields.cart.id) + .buildGraphql(); + cart = Cart.random() + .id(restCartRef.id) + .key(restCartRef.obj?.key) + .customerId(restCartRef.obj?.customerId) + .customerEmail(restCartRef.obj?.customerEmail) + .buildGraphql(); + } - const stateRef: TReferenceGraphql = Reference.presets - .stateReference() - .id(fields.state?.id) - .typeId('state') - .buildGraphql(); + if (fields.customerGroup) { + const restCustomerGroupRef = buildField(fields.customerGroup, 'rest'); + customerGroupRef = Reference.presets + .customerGroupReference() + .id(restCustomerGroupRef.id) + .buildGraphql(); + customerGroup = CustomerGroup.random() + .id(restCustomerGroupRef.id) + .key(restCustomerGroupRef.obj?.key) + .buildGraphql(); + } - const cartRef: TReferenceGraphql | null = fields.cart - ? Reference.presets - .cartReference() - .id(fields.cart.id) - .typeId('cart') - .buildGraphql() - : null; + if (fields.state) { + const restStateRef = buildField(fields.state, 'rest'); + stateRef = Reference.presets + .stateReference() + .id(restStateRef.id) + .buildGraphql(); + state = State.random() + .id(restStateRef.id) + .key(restStateRef.obj?.key || '') + .type(restStateRef.obj?.type || '') + .name( + LocalizedString.presets + .empty() + .en(restStateRef.obj?.name?.en) + .de(restStateRef.obj?.name?.de) + ) + .buildGraphql(); + } - const businessUnitRef: TKeyReferenceGraphql = KeyReference.presets - .businessUnit() - .key(fields.businessUnit?.key) - .buildGraphql(); + if (fields.store) { + const restStoreRef = buildField(fields.store, 'rest'); + storeRef = KeyReference.presets + .store() + .key(restStoreRef.key) + .buildGraphql(); + store = Store.random() + .key(restStoreRef.key) + .buildGraphql(); + } return { + ...fields, + customer, customerRef, - customerGroupRef: fields.customerGroup ? customerGroupRef : undefined, - storeRef: fields.store ? storeRef : undefined, - stateRef: fields.state ? stateRef : undefined, - cartRef: fields.cart ? cartRef : undefined, - businessUnitRef: fields.businessUnit ? businessUnitRef : undefined, + customerGroup, + customerGroupRef, + store, + storeRef, + state, + stateRef, + cart, + cartRef, + businessUnit, + businessUnitRef, __typename: 'QuoteRequest', }; }, - removeFields: ['cart'], }), }; diff --git a/models/quote-request/src/types.ts b/models/quote-request/src/types.ts index 6faa2778c..b6b67a3dc 100644 --- a/models/quote-request/src/types.ts +++ b/models/quote-request/src/types.ts @@ -1,56 +1,48 @@ import type { - BusinessUnit, - Customer, - CustomerGroup, - State, - Store, QuoteRequest, QuoteRequestDraft, } from '@commercetools/platform-sdk'; -import { TCart } from '@commercetools-test-data/cart'; +import { + TCompanyGraphql, + TDivisionGraphql, +} from '@commercetools-test-data/business-unit'; +import { TCartGraphql } from '@commercetools-test-data/cart'; import { TReferenceGraphql, TKeyReferenceGraphql, - TReferenceRest, } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; -import { TCustomer } from '@commercetools-test-data/customer'; -import { TCustomerGroup } from '@commercetools-test-data/customer-group'; -import { TState } from '@commercetools-test-data/state'; +import { TCustomerGraphql } from '@commercetools-test-data/customer'; +import { TCustomerGroupGraphql } from '@commercetools-test-data/customer-group'; +import { TStateGraphql } from '@commercetools-test-data/state'; +import { TStoreGraphql } from '@commercetools-test-data/store'; // Default -export type TQuoteRequest = Omit< - QuoteRequest, - 'customer' | 'customerGroup' | 'store' | 'state' | 'businessUnit' -> & { - customer: Customer; - customerGroup: CustomerGroup; - store: Store; - state: State; - businessUnit: BusinessUnit; -}; +export type TQuoteRequest = QuoteRequest; // Rest -export type TQuoteRequestRest = Omit< - QuoteRequest, - 'cart' | 'customer' | 'customerGroup' | 'state' -> & { - cart?: TReferenceRest; - customer: TReferenceRest; - customerGroup?: TReferenceRest; - state?: TReferenceRest; -}; +export type TQuoteRequestRest = QuoteRequest; export type TQuoteRequestDraft = QuoteRequestDraft; -export type TQuoteRequestGraphql = TQuoteRequest & { - customerRef: TReferenceGraphql | null; - customerGroupRef: TReferenceGraphql | null; - storeRef: TKeyReferenceGraphql | null; - stateRef: TReferenceGraphql | null; - cartRef: TReferenceGraphql | null; - businessUnitRef: TKeyReferenceGraphql | null; +export type TQuoteRequestGraphql = Omit< + TQuoteRequest, + 'cart' | 'businessUnit' | 'customer' | 'customerGroup' | 'state' | 'store' +> & { + businessUnit?: TCompanyGraphql | TDivisionGraphql; + businessUnitRef?: TKeyReferenceGraphql | null; + cart?: TCartGraphql; + cartRef?: TReferenceGraphql; + customer: TCustomerGraphql; + customerRef: TReferenceGraphql; + customerGroup?: TCustomerGroupGraphql; + customerGroupRef?: TReferenceGraphql; + state?: TStateGraphql; + stateRef?: TReferenceGraphql; + store?: TStoreGraphql; + storeRef?: TKeyReferenceGraphql; __typename: 'QuoteRequest'; }; + export type TQuoteRequestDraftGraphql = TQuoteRequestDraft; export type TQuoteRequestBuilder = TBuilder; diff --git a/models/staged-quote/src/builder.spec.ts b/models/staged-quote/src/builder.spec.ts index 22df52bca..2863a8d15 100644 --- a/models/staged-quote/src/builder.spec.ts +++ b/models/staged-quote/src/builder.spec.ts @@ -20,22 +20,33 @@ describe('builder', () => { key: expect.any(String), stagedQuoteState: expect.any(String), customer: expect.objectContaining({ - email: expect.any(String), + id: expect.any(String), + typeId: 'customer', + obj: expect.objectContaining({ + email: expect.any(String), + }), }), quoteRequest: expect.objectContaining({ - quoteRequestState: expect.any(String), + id: expect.any(String), + typeId: 'quote-request', + obj: expect.objectContaining({ + quoteRequestState: expect.any(String), + }), }), quotationCart: expect.objectContaining({ - cartState: expect.any(String), + id: expect.any(String), + typeId: 'cart', + obj: expect.objectContaining({ + cartState: expect.any(String), + }), }), validTo: expect.any(String), sellerComment: expect.any(String), state: null, purchaseOrderNumber: null, businessUnit: expect.objectContaining({ - id: expect.any(String), key: expect.any(String), - associateMode: expect.any(String), + typeId: 'business-unit', }), custom: null, createdAt: expect.any(String), @@ -61,18 +72,30 @@ describe('builder', () => { customer: expect.objectContaining({ id: expect.any(String), typeId: 'customer', + obj: expect.objectContaining({ + email: expect.any(String), + }), }), quoteRequest: expect.objectContaining({ + id: expect.any(String), typeId: 'quote-request', + obj: expect.objectContaining({ + quoteRequestState: expect.any(String), + }), }), quotationCart: expect.objectContaining({ + id: expect.any(String), typeId: 'cart', + obj: expect.objectContaining({ + cartState: expect.any(String), + }), }), validTo: expect.any(String), sellerComment: expect.any(String), - state: undefined, + state: null, purchaseOrderNumber: null, businessUnit: expect.objectContaining({ + key: expect.any(String), typeId: 'business-unit', }), custom: null, @@ -119,7 +142,7 @@ describe('builder', () => { }), validTo: expect.any(String), sellerComment: expect.any(String), - state: null, + state: undefined, stateRef: undefined, purchaseOrderNumber: null, businessUnit: expect.objectContaining({ diff --git a/models/staged-quote/src/generator.ts b/models/staged-quote/src/generator.ts index ba446c965..eba14c8e1 100644 --- a/models/staged-quote/src/generator.ts +++ b/models/staged-quote/src/generator.ts @@ -1,6 +1,9 @@ -import { Company } from '@commercetools-test-data/business-unit'; import { Cart } from '@commercetools-test-data/cart'; -import { ClientLogging } from '@commercetools-test-data/commons'; +import { + ClientLogging, + KeyReference, + Reference, +} from '@commercetools-test-data/commons'; import { sequence, fake, @@ -23,14 +26,20 @@ const generator = Generator({ version: sequence(), key: fake((f) => f.lorem.slug(2)), stagedQuoteState: oneOf(...Object.values(STAGED_QUOTE_STATE)), - customer: fake(() => Customer.random()), - quoteRequest: fake(() => QuoteRequest.random()), - quotationCart: fake(() => Cart.random()), + customer: fake(() => + Reference.presets.customerReference().obj(Customer.random()) + ), + quoteRequest: fake(() => + Reference.presets.quoteRequestReference().obj(QuoteRequest.random()) + ), + quotationCart: fake(() => + Reference.presets.cartReference().obj(Cart.random()) + ), validTo: fake(getFutureDate), sellerComment: fake((f) => f.lorem.words(5)), state: null, purchaseOrderNumber: null, - businessUnit: fake(() => Company.random()), + businessUnit: fake(() => KeyReference.presets.businessUnit()), custom: null, createdAt: fake(getOlderDate), createdBy: fake(() => ClientLogging.random()), diff --git a/models/staged-quote/src/transformers.ts b/models/staged-quote/src/transformers.ts index 2950ec3d8..3c998407c 100644 --- a/models/staged-quote/src/transformers.ts +++ b/models/staged-quote/src/transformers.ts @@ -1,17 +1,23 @@ -import { BusinessUnitKeyReference } from '@commercetools/platform-sdk'; -import { TCart } from '@commercetools-test-data/cart'; +import { + Company, + TCompanyGraphql, +} from '@commercetools-test-data/business-unit'; +import { Cart, TCartGraphql } from '@commercetools-test-data/cart'; import { Reference, KeyReference, TReferenceGraphql, TKeyReferenceGraphql, - TReferenceRest, + LocalizedString, } from '@commercetools-test-data/commons'; -import { Transformer } from '@commercetools-test-data/core'; +import { buildField, Transformer } from '@commercetools-test-data/core'; -import { TCustomer } from '@commercetools-test-data/customer'; -import { TQuoteRequestRest } from '@commercetools-test-data/quote-request'; -import { TState } from '@commercetools-test-data/state'; +import { Customer, TCustomerGraphql } from '@commercetools-test-data/customer'; +import { + QuoteRequest, + TQuoteRequestGraphql, +} from '@commercetools-test-data/quote-request'; +import { State, TStateGraphql } from '@commercetools-test-data/state'; import type { TStagedQuote, TStagedQuoteRest, @@ -42,89 +48,94 @@ const transformers = { 'createdBy', 'lastModifiedBy', ], - replaceFields: ({ fields }) => { - const customer = Reference.presets - .customerReference() - .id(fields.customer.id) - .build>(); - - const quoteRequest = Reference.presets - .quoteRequestReference() - .id(fields.quoteRequest.id) - .build>(); - - const quotationCart = Reference.presets - .cartReference() - .id(fields.quotationCart.id) - .build>(); - - const state = Reference.presets - .stateReference() - .id(fields.state?.id) - .build>(); - - const businessUnit = KeyReference.presets - .businessUnit() - .key(fields.businessUnit?.key) - .buildRest(); - - return { - ...fields, - customer, - quoteRequest, - quotationCart, - state: fields.state ? state : undefined, - businessUnit: fields.businessUnit ? businessUnit : undefined, - }; - }, }), graphql: Transformer('graphql', { - buildFields: [ - 'customer', - 'quoteRequest', - 'quotationCart', - 'state', - 'businessUnit', - 'custom', - 'createdBy', - 'lastModifiedBy', - ], - addFields: ({ fields }) => { - const customerRef: TReferenceGraphql = Reference.presets - .customerReference() - .id(fields.customer.id) - .typeId('customer') - .buildGraphql(); + buildFields: ['custom', 'createdBy', 'lastModifiedBy'], + replaceFields: ({ fields }) => { + let businessUnit: TCompanyGraphql | undefined = undefined; + let businessUnitRef: TKeyReferenceGraphql | undefined = undefined; + let customer: TCustomerGraphql | undefined = undefined; + let customerRef: TReferenceGraphql | undefined = undefined; + let state: TStateGraphql | undefined = undefined; + let stateRef: TReferenceGraphql | undefined = undefined; + const restQuoteRequestRef = buildField(fields.quoteRequest, 'rest'); const quoteRequestRef: TReferenceGraphql = Reference.presets .quoteRequestReference() - .id(fields.quoteRequest.id) - .typeId('quote-request') + .id(restQuoteRequestRef.id) .buildGraphql(); + const quoteRequest = QuoteRequest.random() + .id(restQuoteRequestRef.id) + .key(restQuoteRequestRef.obj?.key) + .buildGraphql(); + const restQuotationCartRef = buildField(fields.quotationCart, 'rest'); const quotationCartRef: TReferenceGraphql = Reference.presets .cartReference() - .id(fields.quotationCart.id) - .typeId('cart') + .id(restQuotationCartRef.id) .buildGraphql(); + const quotationCart = Cart.random() + .id(restQuotationCartRef.id) + .key(restQuotationCartRef.obj?.key) + .buildGraphql(); - const stateRef: TReferenceGraphql = Reference.presets - .stateReference() - .id(fields.state?.id) - .typeId('state') - .buildGraphql(); + if (fields.customer) { + const restCustomerRef = buildField(fields.customer, 'rest'); + customerRef = Reference.presets + .customerReference() + .id(restCustomerRef.id) + .buildGraphql(); + customer = Customer.random() + .id(restCustomerRef.id) + .firstName(restCustomerRef.obj?.firstName) + .lastName(restCustomerRef.obj?.lastName) + .key(restCustomerRef.obj?.key) + .email(restCustomerRef.obj?.email || '') + .buildGraphql(); + } - const businessUnitRef: TKeyReferenceGraphql = KeyReference.presets - .businessUnit() - .key(fields.businessUnit?.key) - .buildGraphql(); + if (fields.businessUnit) { + const restBusinessUnitRef = buildField(fields.businessUnit, 'rest'); + businessUnitRef = KeyReference.presets + .businessUnit() + .key(restBusinessUnitRef.key) + .buildGraphql(); + businessUnit = Company.random() + .key(restBusinessUnitRef.key) + .buildGraphql(); + } + + if (fields.state) { + const restStateRef = buildField(fields.state, 'rest'); + stateRef = Reference.presets + .stateReference() + .id(restStateRef.id) + .buildGraphql(); + state = State.random() + .id(restStateRef.id) + .key(restStateRef.obj?.key || '') + .type(restStateRef.obj?.type || '') + .name( + LocalizedString.presets + .empty() + .en(restStateRef.obj?.name?.en) + .de(restStateRef.obj?.name?.de) + ) + .buildGraphql(); + } return { + ...fields, + businessUnit, + businessUnitRef, + customer, customerRef, - quoteRequestRef, + quotationCart, quotationCartRef, - stateRef: fields.state ? stateRef : undefined, - businessUnitRef: fields.businessUnit ? businessUnitRef : undefined, + quoteRequest, + quoteRequestRef, + state, + stateRef, __typename: 'StagedQuote', }; }, diff --git a/models/staged-quote/src/types.ts b/models/staged-quote/src/types.ts index 97c5ddaef..a9bf6dbe2 100644 --- a/models/staged-quote/src/types.ts +++ b/models/staged-quote/src/types.ts @@ -1,53 +1,42 @@ import type { - BusinessUnit, - Cart, - Customer, StagedQuote, StagedQuoteDraft, - State, - QuoteRequest, } from '@commercetools/platform-sdk'; -import { TCart } from '@commercetools-test-data/cart'; +import { + TCompanyGraphql, + TDivisionGraphql, +} from '@commercetools-test-data/business-unit'; +import { TCartGraphql } from '@commercetools-test-data/cart'; import { TReferenceGraphql, TKeyReferenceGraphql, - TReferenceRest, } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; -import { TCustomer } from '@commercetools-test-data/customer'; -import { TQuoteRequestRest } from '@commercetools-test-data/quote-request'; -import { TState } from '@commercetools-test-data/state'; +import { TCustomerGraphql } from '@commercetools-test-data/customer'; +import { TQuoteRequestGraphql } from '@commercetools-test-data/quote-request'; +import { TStateGraphql } from '@commercetools-test-data/state'; // Default -export type TStagedQuote = Omit< - StagedQuote, - 'businessUnit' | 'customer' | 'quotationCart' | 'quoteRequest' | 'state' -> & { - businessUnit: BusinessUnit; - customer: Customer; - quotationCart: Cart; - quoteRequest: QuoteRequest; - state: State; -}; +export type TStagedQuote = StagedQuote; // Rest -export type TStagedQuoteRest = Omit< - StagedQuote, - 'customer' | 'quoteRequest' | 'quoteRequest' | 'quotationCart' | 'state' -> & { - customer?: TReferenceRest; - quotationCart: TReferenceRest; - quoteRequest: TReferenceRest; - state?: TReferenceRest; -}; +export type TStagedQuoteRest = StagedQuote; export type TStagedQuoteDraft = StagedQuoteDraft; -export type TStagedQuoteGraphql = TStagedQuote & { - businessUnitRef: TKeyReferenceGraphql | null; - customerRef: TReferenceGraphql | null; +export type TStagedQuoteGraphql = Omit< + TStagedQuote, + 'businessUnit' | 'customer' | 'quotationCart' | 'quoteRequest' | 'state' +> & { + businessUnit?: TCompanyGraphql | TDivisionGraphql; + businessUnitRef?: TKeyReferenceGraphql; + customer?: TCustomerGraphql; + customerRef?: TReferenceGraphql; + quotationCart: TCartGraphql; quotationCartRef: TReferenceGraphql; + quoteRequest: TQuoteRequestGraphql; quoteRequestRef: TReferenceGraphql; - stateRef: TReferenceGraphql | null; + state?: TStateGraphql; + stateRef?: TReferenceGraphql | null; __typename: 'StagedQuote'; }; export type TStagedQuoteDraftGraphql = TStagedQuoteDraft; From a3fdb798162a28cb538e69859d9711fca26bcd9e Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Tue, 27 Aug 2024 10:04:59 +0200 Subject: [PATCH 10/17] chore: refresh lock file --- pnpm-lock.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 11f554220..c91b84fd8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -956,10 +956,10 @@ importers: specifier: 10.1.4 version: link:../quote-request '@commercetools-test-data/staged-quote': - specifier: ^10.1.4 + specifier: 10.1.4 version: link:../staged-quote '@commercetools-test-data/state': - specifier: 10.1.3 + specifier: 10.1.4 version: link:../state '@commercetools-test-data/store': specifier: 10.1.4 @@ -1001,7 +1001,7 @@ importers: specifier: 10.1.4 version: link:../customer-group '@commercetools-test-data/state': - specifier: 10.1.3 + specifier: 10.1.4 version: link:../state '@commercetools-test-data/store': specifier: 10.1.4 @@ -1124,7 +1124,7 @@ importers: specifier: 10.1.4 version: link:../quote-request '@commercetools-test-data/state': - specifier: 10.1.3 + specifier: 10.1.4 version: link:../state '@commercetools-test-data/store': specifier: 10.1.4 From bce128c2c7937387a52f0427417962b1265ce8f1 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Tue, 27 Aug 2024 19:09:59 +0200 Subject: [PATCH 11/17] fix(product): adjust models properties --- models/product/package.json | 1 + .../product/src/product-data/transformers.ts | 4 +- models/product/src/product/builder.spec.ts | 118 +++++++++++------- models/product/src/product/generator.ts | 10 +- models/product/src/product/transformers.ts | 84 +++++++++---- models/product/src/product/types.ts | 15 ++- pnpm-lock.yaml | 3 + 7 files changed, 153 insertions(+), 82 deletions(-) diff --git a/models/product/package.json b/models/product/package.json index 2d2fd5e5f..21225de0f 100644 --- a/models/product/package.json +++ b/models/product/package.json @@ -24,6 +24,7 @@ "@commercetools-test-data/commons": "10.2.0", "@commercetools-test-data/core": "10.2.0", "@commercetools-test-data/product-type": "10.2.0", + "@commercetools-test-data/state": "10.2.0", "@commercetools-test-data/tax-category": "10.2.0", "@commercetools-test-data/utils": "10.2.0", "@commercetools/platform-sdk": "^7.0.0", diff --git a/models/product/src/product-data/transformers.ts b/models/product/src/product-data/transformers.ts index 99478dc83..26056136a 100644 --- a/models/product/src/product-data/transformers.ts +++ b/models/product/src/product-data/transformers.ts @@ -39,7 +39,7 @@ const transformers = { 'variants', ], replaceFields: ({ fields }) => { - const { categories } = fields; + const { allVariants, variant, skus, categories, ...rest } = fields; const categoryReferences: Array = categories.map( (category) => ({ @@ -49,7 +49,7 @@ const transformers = { ); return { - ...fields, + ...rest, categories: categoryReferences, }; }, diff --git a/models/product/src/product/builder.spec.ts b/models/product/src/product/builder.spec.ts index 6fede1ea8..4ba5ba421 100644 --- a/models/product/src/product/builder.spec.ts +++ b/models/product/src/product/builder.spec.ts @@ -26,54 +26,62 @@ describe('builder', () => { state: null, taxCategory: expect.objectContaining({ id: expect.any(String), - version: expect.any(Number), - key: expect.any(String), - name: expect.any(String), - description: expect.any(String), - rates: expect.any(Array), - createdAt: expect.any(String), - createdBy: expect.objectContaining({ - customer: expect.objectContaining({ typeId: 'customer' }), - }), - lastModifiedAt: expect.any(String), - lastModifiedBy: expect.objectContaining({ - customer: expect.objectContaining({ typeId: 'customer' }), + typeId: 'tax-category', + obj: expect.objectContaining({ + id: expect.any(String), + version: expect.any(Number), + key: expect.any(String), + name: expect.any(String), + description: expect.any(String), + rates: expect.any(Array), + createdAt: expect.any(String), + createdBy: expect.objectContaining({ + customer: expect.objectContaining({ typeId: 'customer' }), + }), + lastModifiedAt: expect.any(String), + lastModifiedBy: expect.objectContaining({ + customer: expect.objectContaining({ typeId: 'customer' }), + }), }), }), productType: expect.objectContaining({ id: expect.any(String), - key: expect.any(String), - version: expect.any(Number), - createdAt: expect.any(String), - createdBy: expect.objectContaining({ - customer: expect.objectContaining({ typeId: 'customer' }), - }), - lastModifiedAt: expect.any(String), - lastModifiedBy: expect.objectContaining({ - customer: expect.objectContaining({ typeId: 'customer' }), - }), - name: expect.any(String), - description: expect.any(String), - attributes: expect.arrayContaining([ - expect.objectContaining({ - type: expect.objectContaining({ name: expect.any(String) }), - name: expect.any(String), - label: expect.objectContaining({ - de: expect.any(String), - en: expect.any(String), - fr: expect.any(String), - }), - isRequired: expect.any(Boolean), - attributeConstraint: expect.any(String), - inputTip: expect.objectContaining({ - de: expect.any(String), - en: expect.any(String), - fr: expect.any(String), - }), - inputHint: expect.any(String), - isSearchable: expect.any(Boolean), + typeId: 'product-type', + obj: expect.objectContaining({ + id: expect.any(String), + key: expect.any(String), + version: expect.any(Number), + createdAt: expect.any(String), + createdBy: expect.objectContaining({ + customer: expect.objectContaining({ typeId: 'customer' }), + }), + lastModifiedAt: expect.any(String), + lastModifiedBy: expect.objectContaining({ + customer: expect.objectContaining({ typeId: 'customer' }), }), - ]), + name: expect.any(String), + description: expect.any(String), + attributes: expect.arrayContaining([ + expect.objectContaining({ + type: expect.objectContaining({ name: expect.any(String) }), + name: expect.any(String), + label: expect.objectContaining({ + de: expect.any(String), + en: expect.any(String), + fr: expect.any(String), + }), + isRequired: expect.any(Boolean), + attributeConstraint: expect.any(String), + inputTip: expect.objectContaining({ + de: expect.any(String), + en: expect.any(String), + fr: expect.any(String), + }), + inputHint: expect.any(String), + isSearchable: expect.any(Boolean), + }), + ]), + }), }), createdBy: expect.objectContaining({ customer: expect.objectContaining({ typeId: 'customer' }), @@ -102,12 +110,26 @@ describe('builder', () => { }), }), priceMode: expect.any(String), - state: undefined, + state: null, taxCategory: expect.objectContaining({ + id: expect.any(String), typeId: 'tax-category', + obj: expect.objectContaining({ + id: expect.any(String), + key: expect.any(String), + name: expect.any(String), + rates: expect.any(Array), + }), }), productType: expect.objectContaining({ + id: expect.any(String), typeId: 'product-type', + obj: expect.objectContaining({ + id: expect.any(String), + key: expect.any(String), + name: expect.any(String), + description: expect.any(String), + }), }), createdBy: expect.objectContaining({ customer: expect.objectContaining({ typeId: 'customer' }), @@ -136,10 +158,8 @@ describe('builder', () => { }), }), priceMode: expect.any(String), - state: null, - stateRef: expect.objectContaining({ - typeId: 'state', - }), + state: undefined, + stateRef: undefined, taxCategory: expect.objectContaining({ __typename: 'TaxCategory', id: expect.any(String), @@ -160,6 +180,7 @@ describe('builder', () => { }), }), taxCategoryRef: expect.objectContaining({ + id: expect.any(String), typeId: 'tax-category', }), productType: expect.objectContaining({ @@ -184,6 +205,7 @@ describe('builder', () => { }), }), productTypeRef: expect.objectContaining({ + id: expect.any(String), typeId: 'product-type', }), skus: expect.arrayContaining([]), diff --git a/models/product/src/product/generator.ts b/models/product/src/product/generator.ts index 185256270..82debc404 100644 --- a/models/product/src/product/generator.ts +++ b/models/product/src/product/generator.ts @@ -1,4 +1,4 @@ -import { ClientLogging } from '@commercetools-test-data/commons'; +import { ClientLogging, Reference } from '@commercetools-test-data/commons'; import { fake, Generator, oneOf } from '@commercetools-test-data/core'; import { ProductType } from '@commercetools-test-data/product-type'; import { TaxCategory } from '@commercetools-test-data/tax-category'; @@ -16,9 +16,13 @@ const generator = Generator({ id: fake((f) => f.string.uuid()), version: fake((f) => f.number.int()), key: fake((f) => f.lorem.slug()), - productType: fake(() => ProductType.random()), + productType: fake(() => + Reference.presets.productTypeReference().obj(ProductType.random()) + ), masterData: fake(() => ProductCatalogData.random()), - taxCategory: fake(() => TaxCategory.random()), + taxCategory: fake(() => + Reference.presets.taxCategoryReference().obj(TaxCategory.random()) + ), state: null, reviewRatingStatistics: null, priceMode: oneOf(...Object.values(productPriceMode)), diff --git a/models/product/src/product/transformers.ts b/models/product/src/product/transformers.ts index dfa84cae8..98b8cfdd3 100644 --- a/models/product/src/product/transformers.ts +++ b/models/product/src/product/transformers.ts @@ -1,5 +1,14 @@ import { Reference, TReferenceGraphql } from '@commercetools-test-data/commons'; -import { Transformer } from '@commercetools-test-data/core'; +import { buildField, Transformer } from '@commercetools-test-data/core'; +import { + ProductType, + TProductTypeGraphql, +} from '@commercetools-test-data/product-type'; +import { TStateGraphql, State } from '@commercetools-test-data/state'; +import { + TaxCategory, + TTaxCategoryGraphql, +} from '@commercetools-test-data/tax-category'; import type { TProduct, TProductRest, TProductGraphql } from './types'; const transformers = { @@ -14,19 +23,6 @@ const transformers = { ], }), rest: Transformer('rest', { - buildFields: ['masterData', 'createdBy', 'lastModifiedBy'], - replaceFields: ({ fields }) => { - return { - ...fields, - productType: Reference.random().typeId('product-type').buildRest(), - taxCategory: Reference.random().typeId('tax-category').buildRest(), - state: fields.state - ? Reference.random().id(fields.state.id).typeId('state').buildRest() - : undefined, - }; - }, - }), - graphql: Transformer('graphql', { buildFields: [ 'productType', 'masterData', @@ -35,25 +31,61 @@ const transformers = { 'createdBy', 'lastModifiedBy', ], - addFields: ({ fields }) => { - const productTypeRef: TReferenceGraphql = Reference.random() - .id(fields.productType.id) + }), + graphql: Transformer('graphql', { + buildFields: ['masterData', 'state', 'createdBy', 'lastModifiedBy'], + replaceFields: ({ fields }) => { + const restProductType = buildField(fields.productType, 'rest'); + const productType = ProductType.random() + .id(restProductType.id) + .key(restProductType.obj!.key) + .name(restProductType.obj!.name) + .description(restProductType.obj!.description) + .buildGraphql(); + const productTypeRef = Reference.random() + .id(restProductType.id) .typeId('product-type') - .buildGraphql(); + .buildGraphql(); + + let state: TStateGraphql | undefined; + let stateRef: TReferenceGraphql | undefined; + let taxCategory: TTaxCategoryGraphql | undefined; + let taxCategoryRef: TReferenceGraphql | undefined; - const stateRef: TReferenceGraphql = Reference.random() - .id(fields.productType.id) - .typeId('state') - .buildGraphql(); + if (fields.state) { + const restStateRef = buildField(fields.state, 'rest'); + stateRef = Reference.presets + .stateReference() + .id(restStateRef.id) + .buildGraphql(); + state = State.random() + .id(restStateRef.id) + .key(restStateRef.obj!.key) + .name(restStateRef.obj!.name) + .buildGraphql(); + } - const taxCategoryRef: TReferenceGraphql = Reference.random() - .id(fields.productType.id) - .typeId('tax-category') - .buildGraphql(); + if (fields.taxCategory) { + const restTaxCategoryRef = buildField(fields.taxCategory, 'rest'); + taxCategoryRef = Reference.presets + .taxCategoryReference() + .id(restTaxCategoryRef.id) + .buildGraphql(); + taxCategory = TaxCategory.random() + .id(restTaxCategoryRef.id) + .key(restTaxCategoryRef.obj!.key) + .name(restTaxCategoryRef.obj!.name) + .description(restTaxCategoryRef.obj!.description) + .buildGraphql(); + } return { + ...fields, + productType, productTypeRef, + state, stateRef, + taxCategory, taxCategoryRef, __typename: 'Product', }; diff --git a/models/product/src/product/types.ts b/models/product/src/product/types.ts index 33e1514dd..877f31b95 100644 --- a/models/product/src/product/types.ts +++ b/models/product/src/product/types.ts @@ -4,6 +4,9 @@ import { TReferenceGraphql, } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; +import { TProductTypeGraphql } from '@commercetools-test-data/product-type'; +import { TTaxCategoryGraphql } from '@commercetools-test-data/tax-category'; +import { TStateGraphql } from '../../../state/src'; export type TProduct = Product & { skus: Array; @@ -11,10 +14,16 @@ export type TProduct = Product & { export type TProductRest = Omit; -export type TProductGraphql = TProduct & { +export type TProductGraphql = Omit< + TProduct, + 'productType' | 'state' | 'taxCategory' +> & { + productType: TProductTypeGraphql; productTypeRef: TReferenceGraphql; - stateRef: TReferenceGraphql; - taxCategoryRef: TReferenceGraphql; + state?: TStateGraphql; + stateRef?: TReferenceGraphql; + taxCategory?: TTaxCategoryGraphql; + taxCategoryRef?: TReferenceGraphql; // TODO: add productSelectionRefs __typename: 'Product'; }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 017663354..a69745de0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -754,6 +754,9 @@ importers: '@commercetools-test-data/product-type': specifier: 10.2.0 version: link:../product-type + '@commercetools-test-data/state': + specifier: 10.2.0 + version: link:../state '@commercetools-test-data/tax-category': specifier: 10.2.0 version: link:../tax-category From 9b87be56fb5e98a0a54c1ef49631f16b5795ba08 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Wed, 28 Aug 2024 11:16:45 +0200 Subject: [PATCH 12/17] fix(product): fix presets --- models/product-projection/src/index.ts | 1 + ...ppy-cow-milk-product-projection.ts => happy-cow-milk.ts} | 6 ++++-- models/product-projection/src/presets/index.ts | 4 ++-- models/product/src/product/presets/boring-generic-milk.ts | 5 ++++- models/product/src/product/presets/happy-cow-milk.ts | 5 ++++- 5 files changed, 15 insertions(+), 6 deletions(-) rename models/product-projection/src/presets/{happy-cow-milk-product-projection.ts => happy-cow-milk.ts} (83%) diff --git a/models/product-projection/src/index.ts b/models/product-projection/src/index.ts index b19319eb5..5089f19da 100644 --- a/models/product-projection/src/index.ts +++ b/models/product-projection/src/index.ts @@ -1,4 +1,5 @@ export { default as random } from './builder'; export { default as presets } from './presets'; +export * as ProductProjection from '.'; export * from './types'; diff --git a/models/product-projection/src/presets/happy-cow-milk-product-projection.ts b/models/product-projection/src/presets/happy-cow-milk.ts similarity index 83% rename from models/product-projection/src/presets/happy-cow-milk-product-projection.ts rename to models/product-projection/src/presets/happy-cow-milk.ts index c95d79b3a..79fba2994 100644 --- a/models/product-projection/src/presets/happy-cow-milk-product-projection.ts +++ b/models/product-projection/src/presets/happy-cow-milk.ts @@ -1,4 +1,4 @@ -import { LocalizedString } from '@commercetools-test-data/commons'; +import { LocalizedString, Reference } from '@commercetools-test-data/commons'; import { ProductVariant } from '@commercetools-test-data/product'; import { ProductType } from '@commercetools-test-data/product-type'; import ProductProjection from '../builder'; @@ -17,7 +17,9 @@ const happyCowMilk = () => { const slug = LocalizedString.presets.empty().en('happy-cow-milk-slug'); return ProductProjection() - .productType(ProductType.presets.milk()) + .productType( + Reference.presets.productTypeReference().obj(ProductType.presets.milk()) + ) .slug(slug) .key('happy-cow-milk-key') .name(productName) diff --git a/models/product-projection/src/presets/index.ts b/models/product-projection/src/presets/index.ts index aa495b374..db6e8a994 100644 --- a/models/product-projection/src/presets/index.ts +++ b/models/product-projection/src/presets/index.ts @@ -1,5 +1,5 @@ -import happyCowMilkProductProjection from './happy-cow-milk-product-projection'; +import happyCowMilk from './happy-cow-milk'; -const presets = { happyCowMilkProductProjection }; +const presets = { happyCowMilk }; export default presets; diff --git a/models/product/src/product/presets/boring-generic-milk.ts b/models/product/src/product/presets/boring-generic-milk.ts index 9f39fc5ae..2d06fd572 100644 --- a/models/product/src/product/presets/boring-generic-milk.ts +++ b/models/product/src/product/presets/boring-generic-milk.ts @@ -1,3 +1,4 @@ +import { Reference } from '@commercetools-test-data/commons'; import { ProductType } from '@commercetools-test-data/product-type'; import * as ProductCatalogData from '../../product-catalog-data'; import Product from '../builder'; @@ -5,7 +6,9 @@ import { TProductBuilder } from '../types'; const boringGenericMilk = (): TProductBuilder => Product() - .productType(ProductType.presets.milk()) + .productType( + Reference.presets.productTypeReference().obj(ProductType.presets.milk()) + ) .key('boring-generic-milk-key') .masterData( ProductCatalogData.presets.boringGenericMilkProductCatalogData() diff --git a/models/product/src/product/presets/happy-cow-milk.ts b/models/product/src/product/presets/happy-cow-milk.ts index ba8252d77..7269d0b7b 100644 --- a/models/product/src/product/presets/happy-cow-milk.ts +++ b/models/product/src/product/presets/happy-cow-milk.ts @@ -1,3 +1,4 @@ +import { Reference } from '@commercetools-test-data/commons'; import { ProductType } from '@commercetools-test-data/product-type'; import * as ProductCatalogData from '../../product-catalog-data'; import Product from '../builder'; @@ -5,7 +6,9 @@ import { TProductBuilder } from '../types'; const happyCowMilk = (): TProductBuilder => Product() - .productType(ProductType.presets.milk()) + .productType( + Reference.presets.productTypeReference().obj(ProductType.presets.milk()) + ) .key('happy-cow-milk-key') .masterData(ProductCatalogData.presets.happyCowMilkProductCatalogData()); From 996f336a9a5e9f9772d35d17e456769d272ffd2c Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Wed, 28 Aug 2024 11:41:05 +0200 Subject: [PATCH 13/17] fix(product): fix product-data transformer --- models/product/src/product-data/transformers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/models/product/src/product-data/transformers.ts b/models/product/src/product-data/transformers.ts index 26056136a..649d7ff42 100644 --- a/models/product/src/product-data/transformers.ts +++ b/models/product/src/product-data/transformers.ts @@ -45,6 +45,7 @@ const transformers = { (category) => ({ id: category.id, typeId: 'category', + obj: category, }) ); From ebd6718ac51c78a45632bd3b867246f4fbe3b8d8 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Wed, 28 Aug 2024 12:24:49 +0200 Subject: [PATCH 14/17] fix(product-projection): fix test --- models/product-projection/src/builder.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/product-projection/src/builder.spec.ts b/models/product-projection/src/builder.spec.ts index 453a4204b..8f077c8a6 100644 --- a/models/product-projection/src/builder.spec.ts +++ b/models/product-projection/src/builder.spec.ts @@ -250,7 +250,7 @@ describe('builder', () => { describe('when customizing the model', () => { const productProjectionMock = ProductProjection.presets - .happyCowMilkProductProjection() + .happyCowMilk() .categories([ Reference.presets .categoryReference() From 32b8b40a2e0f0f69efd9db6f8297f740ca76f863 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Thu, 29 Aug 2024 12:22:13 +0200 Subject: [PATCH 15/17] fix(prouct): fix import --- models/product/src/product/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/product/src/product/types.ts b/models/product/src/product/types.ts index 877f31b95..a9baa4cc1 100644 --- a/models/product/src/product/types.ts +++ b/models/product/src/product/types.ts @@ -5,8 +5,8 @@ import { } from '@commercetools-test-data/commons'; import type { TBuilder } from '@commercetools-test-data/core'; import { TProductTypeGraphql } from '@commercetools-test-data/product-type'; +import { TStateGraphql } from '@commercetools-test-data/state'; import { TTaxCategoryGraphql } from '@commercetools-test-data/tax-category'; -import { TStateGraphql } from '../../../state/src'; export type TProduct = Product & { skus: Array; From 374d67bc023a71c4577b9a61132c1af52ebd6ff0 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Thu, 5 Sep 2024 17:03:00 +0200 Subject: [PATCH 16/17] chore: typescript config update --- tsconfig.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 476725c56..4fe4d5df6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,7 @@ "forceConsistentCasingInFileNames": true, "isolatedModules": true, "resolveJsonModule": true, - "allowJs": false + "allowJs": false, + "preserveSymlinks": true, } -} \ No newline at end of file +} From defe86cc3be88da21f6eadc986b2e0296739050f Mon Sep 17 00:00:00 2001 From: Carlos Cortizas Date: Mon, 23 Sep 2024 18:43:53 +0200 Subject: [PATCH 17/17] refactor(product-discount): add missing model --- .../discounted-product-price/builder.spec.ts | 62 +++++++++++++++++++ .../src/discounted-product-price/builder.ts | 15 +++++ .../builder.spec.ts | 57 +++++++++++++++++ .../discounted-product-price-draft/builder.ts | 15 +++++ .../generator.ts | 11 ++++ .../discounted-product-price-draft/index.ts | 2 + .../presets/index.ts | 3 + .../transformers.ts | 54 ++++++++++++++++ .../src/discounted-product-price/generator.ts | 12 ++++ .../src/discounted-product-price/index.ts | 6 ++ .../discounted-product-price/presets/index.ts | 3 + .../discounted-product-price/transformers.ts | 62 +++++++++++++++++++ .../src/discounted-product-price/types.ts | 40 ++++++++++++ models/product-discount/src/index.ts | 4 ++ models/standalone-price/src/builder.spec.ts | 2 +- models/standalone-price/src/transformers.ts | 52 +++++++++++++++- pnpm-lock.yaml | 8 +-- 17 files changed, 402 insertions(+), 6 deletions(-) create mode 100644 models/product-discount/src/discounted-product-price/builder.spec.ts create mode 100644 models/product-discount/src/discounted-product-price/builder.ts create mode 100644 models/product-discount/src/discounted-product-price/discounted-product-price-draft/builder.spec.ts create mode 100644 models/product-discount/src/discounted-product-price/discounted-product-price-draft/builder.ts create mode 100644 models/product-discount/src/discounted-product-price/discounted-product-price-draft/generator.ts create mode 100644 models/product-discount/src/discounted-product-price/discounted-product-price-draft/index.ts create mode 100644 models/product-discount/src/discounted-product-price/discounted-product-price-draft/presets/index.ts create mode 100644 models/product-discount/src/discounted-product-price/discounted-product-price-draft/transformers.ts create mode 100644 models/product-discount/src/discounted-product-price/generator.ts create mode 100644 models/product-discount/src/discounted-product-price/index.ts create mode 100644 models/product-discount/src/discounted-product-price/presets/index.ts create mode 100644 models/product-discount/src/discounted-product-price/transformers.ts create mode 100644 models/product-discount/src/discounted-product-price/types.ts diff --git a/models/product-discount/src/discounted-product-price/builder.spec.ts b/models/product-discount/src/discounted-product-price/builder.spec.ts new file mode 100644 index 000000000..d1924422a --- /dev/null +++ b/models/product-discount/src/discounted-product-price/builder.spec.ts @@ -0,0 +1,62 @@ +/* eslint-disable jest/no-disabled-tests */ +/* eslint-disable jest/valid-title */ +import { + HighPrecisionMoney, + Reference, +} from '@commercetools-test-data/commons'; +import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; +import { + DiscountedProductPrice, + type TDiscountedProductPriceRest, + type TDiscountedProductPriceGraphql, +} from './'; + +describe('builder', () => { + it( + ...createBuilderSpec< + TDiscountedProductPriceRest, + TDiscountedProductPriceRest + >( + 'rest', + DiscountedProductPrice.random() + .value(HighPrecisionMoney.random().currencyCode('USD')) + .discount(Reference.presets.productDiscountReference().id('pd-123')), + expect.objectContaining({ + value: expect.objectContaining({ + currencyCode: 'USD', + }), + discount: expect.objectContaining({ + id: 'pd-123', + typeId: 'product-discount', + }), + }) + ) + ); + + it( + ...createBuilderSpec< + TDiscountedProductPriceRest, + TDiscountedProductPriceGraphql + >( + 'graphql', + DiscountedProductPrice.random() + .value(HighPrecisionMoney.random().currencyCode('USD')) + .discount(Reference.presets.productDiscountReference().id('pd-123')), + expect.objectContaining({ + value: expect.objectContaining({ + currencyCode: 'USD', + __typename: 'HighPrecisionMoney', + }), + discount: expect.objectContaining({ + id: 'pd-123', + __typename: 'ProductDiscount', + }), + discountRef: expect.objectContaining({ + id: 'pd-123', + __typename: 'Reference', + }), + __typename: 'DiscountedProductPrice', + }) + ) + ); +}); diff --git a/models/product-discount/src/discounted-product-price/builder.ts b/models/product-discount/src/discounted-product-price/builder.ts new file mode 100644 index 000000000..137d60de8 --- /dev/null +++ b/models/product-discount/src/discounted-product-price/builder.ts @@ -0,0 +1,15 @@ +import { Builder } from '@commercetools-test-data/core'; +import generator from './generator'; +import transformers from './transformers'; +import type { + TCreateDiscountedPriceBuilder, + TDiscountedProductPriceRest, +} from './types'; + +const Model: TCreateDiscountedPriceBuilder = () => + Builder({ + generator, + transformers, + }); + +export default Model; diff --git a/models/product-discount/src/discounted-product-price/discounted-product-price-draft/builder.spec.ts b/models/product-discount/src/discounted-product-price/discounted-product-price-draft/builder.spec.ts new file mode 100644 index 000000000..ff45adfee --- /dev/null +++ b/models/product-discount/src/discounted-product-price/discounted-product-price-draft/builder.spec.ts @@ -0,0 +1,57 @@ +/* eslint-disable jest/no-disabled-tests */ +/* eslint-disable jest/valid-title */ +import { + HighPrecisionMoney, + Reference, +} from '@commercetools-test-data/commons'; +import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; +import { DiscountedProductPriceDraft } from '..'; +import { + TDiscountedProductPriceDraft, + TDiscountedProductPriceDraftGraphql, +} from '../types'; + +describe('builder', () => { + it( + ...createBuilderSpec< + TDiscountedProductPriceDraft, + TDiscountedProductPriceDraft + >( + 'rest', + DiscountedProductPriceDraft.random() + .value(HighPrecisionMoney.random().currencyCode('USD')) + .discount(Reference.presets.productDiscountReference().id('pd-123')), + expect.objectContaining({ + value: expect.objectContaining({ + currencyCode: 'USD', + }), + discount: expect.objectContaining({ + id: 'pd-123', + typeId: 'product-discount', + }), + }) + ) + ); + + it( + ...createBuilderSpec< + TDiscountedProductPriceDraft, + TDiscountedProductPriceDraftGraphql + >( + 'graphql', + DiscountedProductPriceDraft.random() + .value(HighPrecisionMoney.random().currencyCode('USD')) + .discount(Reference.presets.productDiscountReference().id('pd-123')), + expect.objectContaining({ + value: expect.objectContaining({ + currencyCode: 'USD', + }), + discount: expect.objectContaining({ + id: 'pd-123', + __typename: 'ProductDiscount', + }), + __typename: 'DiscountedProductPriceDraft', + }) + ) + ); +}); diff --git a/models/product-discount/src/discounted-product-price/discounted-product-price-draft/builder.ts b/models/product-discount/src/discounted-product-price/discounted-product-price-draft/builder.ts new file mode 100644 index 000000000..e2f287b32 --- /dev/null +++ b/models/product-discount/src/discounted-product-price/discounted-product-price-draft/builder.ts @@ -0,0 +1,15 @@ +import { Builder } from '@commercetools-test-data/core'; +import type { + TCreateDiscountedPriceDraftBuilder, + TDiscountedProductPriceDraft, +} from '../types'; +import generator from './generator'; +import transformers from './transformers'; + +const AddressDraft: TCreateDiscountedPriceDraftBuilder = () => + Builder({ + generator, + transformers, + }); + +export default AddressDraft; diff --git a/models/product-discount/src/discounted-product-price/discounted-product-price-draft/generator.ts b/models/product-discount/src/discounted-product-price/discounted-product-price-draft/generator.ts new file mode 100644 index 000000000..6fa5c63de --- /dev/null +++ b/models/product-discount/src/discounted-product-price/discounted-product-price-draft/generator.ts @@ -0,0 +1,11 @@ +import { Generator } from '@commercetools-test-data/core'; +import { TDiscountedProductPriceDraft } from '../types'; + +const generator = Generator({ + fields: { + value: null, + discount: null, + }, +}); + +export default generator; diff --git a/models/product-discount/src/discounted-product-price/discounted-product-price-draft/index.ts b/models/product-discount/src/discounted-product-price/discounted-product-price-draft/index.ts new file mode 100644 index 000000000..96e2519e1 --- /dev/null +++ b/models/product-discount/src/discounted-product-price/discounted-product-price-draft/index.ts @@ -0,0 +1,2 @@ +export { default as random } from './builder'; +export { default as presets } from './presets'; diff --git a/models/product-discount/src/discounted-product-price/discounted-product-price-draft/presets/index.ts b/models/product-discount/src/discounted-product-price/discounted-product-price-draft/presets/index.ts new file mode 100644 index 000000000..763e57fe0 --- /dev/null +++ b/models/product-discount/src/discounted-product-price/discounted-product-price-draft/presets/index.ts @@ -0,0 +1,3 @@ +const presets = {}; + +export default presets; diff --git a/models/product-discount/src/discounted-product-price/discounted-product-price-draft/transformers.ts b/models/product-discount/src/discounted-product-price/discounted-product-price-draft/transformers.ts new file mode 100644 index 000000000..e66b5d1aa --- /dev/null +++ b/models/product-discount/src/discounted-product-price/discounted-product-price-draft/transformers.ts @@ -0,0 +1,54 @@ +import { + HighPrecisionMoneyDraft, + type THighPrecisionMoneyDraft, + type THighPrecisionMoneyDraftGraphql, +} from '@commercetools-test-data/commons'; +import { buildField, Transformer } from '@commercetools-test-data/core'; +import { ProductDiscount, type TProductDiscountDraftGraphql } from '../..'; +import type { + TDiscountedProductPriceDraft, + TDiscountedProductPriceDraftGraphql, +} from '../types'; + +const transformers = { + default: Transformer< + TDiscountedProductPriceDraft, + TDiscountedProductPriceDraft + >('default', { + buildFields: ['value', 'discount'], + }), + rest: Transformer( + 'rest', + { + buildFields: ['value', 'discount'], + } + ), + graphql: Transformer< + TDiscountedProductPriceDraft, + TDiscountedProductPriceDraftGraphql + >('graphql', { + buildFields: ['value'], + replaceFields: ({ fields }) => { + const restValue = fields.value as THighPrecisionMoneyDraft; + const value = HighPrecisionMoneyDraft.random() + .centAmount(restValue.centAmount) + .currencyCode(restValue.currencyCode) + .fractionDigits(restValue.fractionDigits) + .preciseAmount(restValue.preciseAmount) + .type(restValue.type) + .buildGraphql(); + const restProductDiscount = buildField(fields.discount, 'rest'); + const graphqlProductDiscount = ProductDiscount.random() + .id(restProductDiscount.id) + .buildGraphql(); + return { + ...fields, + value, + discount: graphqlProductDiscount, + __typename: 'DiscountedProductPriceDraft', + }; + }, + }), +}; + +export default transformers; diff --git a/models/product-discount/src/discounted-product-price/generator.ts b/models/product-discount/src/discounted-product-price/generator.ts new file mode 100644 index 000000000..5c4b8008b --- /dev/null +++ b/models/product-discount/src/discounted-product-price/generator.ts @@ -0,0 +1,12 @@ +import { HighPrecisionMoney } from '@commercetools-test-data/commons'; +import { fake, Generator } from '@commercetools-test-data/core'; +import type { TDiscountedProductPriceRest } from './types'; + +const generator = Generator({ + fields: { + value: fake(() => HighPrecisionMoney.random()), + discount: null, + }, +}); + +export default generator; diff --git a/models/product-discount/src/discounted-product-price/index.ts b/models/product-discount/src/discounted-product-price/index.ts new file mode 100644 index 000000000..716f83c2b --- /dev/null +++ b/models/product-discount/src/discounted-product-price/index.ts @@ -0,0 +1,6 @@ +export * as DiscountedProductPriceDraft from './discounted-product-price-draft'; +export * as DiscountedProductPrice from '.'; + +export { default as random } from './builder'; +export { default as presets } from './presets'; +export * from './types'; diff --git a/models/product-discount/src/discounted-product-price/presets/index.ts b/models/product-discount/src/discounted-product-price/presets/index.ts new file mode 100644 index 000000000..763e57fe0 --- /dev/null +++ b/models/product-discount/src/discounted-product-price/presets/index.ts @@ -0,0 +1,3 @@ +const presets = {}; + +export default presets; diff --git a/models/product-discount/src/discounted-product-price/transformers.ts b/models/product-discount/src/discounted-product-price/transformers.ts new file mode 100644 index 000000000..b2bcfed97 --- /dev/null +++ b/models/product-discount/src/discounted-product-price/transformers.ts @@ -0,0 +1,62 @@ +import { + HighPrecisionMoney, + Reference, + THighPrecisionMoney, + THighPrecisionMoneyGraphql, + TReferenceGraphql, +} from '@commercetools-test-data/commons'; +import { buildField, Transformer } from '@commercetools-test-data/core'; +import { ProductDiscount, TProductDiscountGraphql } from '..'; +import type { + TDiscountedProductPriceRest, + TDiscountedProductPriceGraphql, +} from './types'; + +const transformers = { + default: Transformer< + TDiscountedProductPriceRest, + TDiscountedProductPriceRest + >('default', { + buildFields: ['value', 'discount'], + }), + rest: Transformer( + 'rest', + { + buildFields: ['value', 'discount'], + } + ), + graphql: Transformer< + TDiscountedProductPriceRest, + TDiscountedProductPriceGraphql + >('graphql', { + buildFields: ['value'], + replaceFields: ({ fields }) => { + const restValue = fields.value as THighPrecisionMoney; + const value = HighPrecisionMoney.random() + .centAmount(restValue.centAmount) + .currencyCode(restValue.currencyCode) + .fractionDigits(restValue.fractionDigits) + .preciseAmount(restValue.preciseAmount) + .type(restValue.type) + .buildGraphql(); + const restProductDiscount = buildField(fields.discount, 'rest'); + const graphqlProductDiscount = ProductDiscount.random() + .id(restProductDiscount.id) + .buildGraphql(); + const productDiscountRef = Reference.presets + .productDiscountReference() + .id(restProductDiscount.id) + .buildGraphql(); + + return { + ...fields, + value, + discount: graphqlProductDiscount, + discountRef: productDiscountRef, + __typename: 'DiscountedProductPrice', + }; + }, + }), +}; + +export default transformers; diff --git a/models/product-discount/src/discounted-product-price/types.ts b/models/product-discount/src/discounted-product-price/types.ts new file mode 100644 index 000000000..0c9b62a5d --- /dev/null +++ b/models/product-discount/src/discounted-product-price/types.ts @@ -0,0 +1,40 @@ +import { + DiscountedPrice, + DiscountedPriceDraft, +} from '@commercetools/platform-sdk'; +import { + THighPrecisionMoneyDraftGraphql, + THighPrecisionMoneyGraphql, + TReferenceGraphql, +} from '@commercetools-test-data/commons'; +import { TBuilder } from '@commercetools-test-data/core'; +import { + TProductDiscountDraftGraphql, + TProductDiscountGraphql, +} from '../product-discount'; + +export type TDiscountedProductPriceRest = DiscountedPrice; + +export type TDiscountedProductPriceGraphql = { + value: THighPrecisionMoneyGraphql; + discount: TProductDiscountGraphql; + discountRef: TReferenceGraphql; + __typename: 'DiscountedProductPrice'; +}; + +export type TDiscountedProductPriceDraft = DiscountedPriceDraft; + +export type TDiscountedProductPriceDraftGraphql = { + value: THighPrecisionMoneyDraftGraphql; + discount: TProductDiscountDraftGraphql; + __typename: 'DiscountedProductPriceDraft'; +}; + +export type TDiscountedProductPriceBuilder = + TBuilder; +export type TCreateDiscountedPriceBuilder = + () => TDiscountedProductPriceBuilder; +export type TDiscountedProductPriceDraftBuilder = + TBuilder; +export type TCreateDiscountedPriceDraftBuilder = + () => TDiscountedProductPriceDraftBuilder; diff --git a/models/product-discount/src/index.ts b/models/product-discount/src/index.ts index 5ac603e12..ee1a1e676 100644 --- a/models/product-discount/src/index.ts +++ b/models/product-discount/src/index.ts @@ -3,6 +3,7 @@ export * from './product-discount/types'; export * from './product-discount-value-absolute/types'; export * from './product-discount-value-external/types'; export * from './product-discount-value-relative/types'; +export * from './discounted-product-price/types'; // Export models export * as ProductDiscount from './product-discount'; @@ -16,3 +17,6 @@ export * as ProductDiscountValueExternalDraft from './product-discount-value-ext export * as ProductDiscountValueRelative from './product-discount-value-relative'; export * as ProductDiscountValueRelativeDraft from './product-discount-value-relative/product-discount-value-relative-draft'; + +export * as DiscountedProductPrice from './discounted-product-price'; +export * as DiscountedProductPriceDraft from './discounted-product-price/discounted-product-price-draft'; diff --git a/models/standalone-price/src/builder.spec.ts b/models/standalone-price/src/builder.spec.ts index dd68c5837..afc4c306c 100644 --- a/models/standalone-price/src/builder.spec.ts +++ b/models/standalone-price/src/builder.spec.ts @@ -102,7 +102,7 @@ describe('builder', () => { }), }), ]), - discounted: undefined, + discounted: null, staged: undefined, active: expect.any(Boolean), }) diff --git a/models/standalone-price/src/transformers.ts b/models/standalone-price/src/transformers.ts index 2a26f06d9..d19bc0e3b 100644 --- a/models/standalone-price/src/transformers.ts +++ b/models/standalone-price/src/transformers.ts @@ -1,5 +1,9 @@ import { Channel, TChannelGraphql } from '@commercetools-test-data/channel'; -import { Reference, TReferenceGraphql } from '@commercetools-test-data/commons'; +import { + Reference, + TReference, + TReferenceGraphql, +} from '@commercetools-test-data/commons'; import { buildField, Transformer } from '@commercetools-test-data/core'; import { CustomerGroup, @@ -37,6 +41,31 @@ const transformers = { 'discounted', 'staged', ], + replaceFields: ({ fields }) => { + const mainCurrency = fields.value.currencyCode; + + return { + ...fields, + tiers: fields.tiers + ? fields.tiers.map((tier) => ({ + ...tier, + value: { + ...tier.value, + currencyCode: mainCurrency, + }, + })) + : [], + staged: fields.staged + ? { + ...fields.staged, + value: { + ...fields.staged.value, + currencyCode: mainCurrency, + }, + } + : undefined, + }; + }, }), graphql: Transformer('graphql', { buildFields: ['lastModifiedBy', 'createdBy', 'value', 'tiers'], @@ -83,6 +112,27 @@ const transformers = { channelRef, customerGroup, customerGroupRef, + custom: fields.custom || null, + // Currency sync + tiers: fields.tiers + ? fields.tiers.map((tier) => ({ + ...tier, + value: { + ...tier.value, + currencyCode: mainCurrency, + }, + })) + : null, + staged: fields.staged + ? { + ...fields.staged, + value: { + ...fields.staged.value, + currencyCode: mainCurrency, + }, + } + : null, + discounted: fields.discounted || null, }; return adjustedFields; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e9467a740..b5c0fa49f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -840,7 +840,7 @@ importers: specifier: 10.7.0 version: link:../product-type '@commercetools-test-data/state': - specifier: 10.5.2 + specifier: 10.7.0 version: link:../state '@commercetools-test-data/tax-category': specifier: 10.7.0 @@ -1050,7 +1050,7 @@ importers: specifier: ^10.7.0 version: link:../staged-quote '@commercetools-test-data/state': - specifier: 10.5.2 + specifier: 10.7.0 version: link:../state '@commercetools-test-data/store': specifier: 10.7.0 @@ -1092,7 +1092,7 @@ importers: specifier: 10.7.0 version: link:../customer-group '@commercetools-test-data/state': - specifier: 10.5.2 + specifier: 10.7.0 version: link:../state '@commercetools-test-data/store': specifier: 10.7.0 @@ -1215,7 +1215,7 @@ importers: specifier: 10.7.0 version: link:../quote-request '@commercetools-test-data/state': - specifier: 10.5.2 + specifier: 10.7.0 version: link:../state '@commercetools-test-data/store': specifier: 10.7.0