Skip to content

Commit

Permalink
FEC-39: Fix models related to Batch 2 (Part 1) (#650)
Browse files Browse the repository at this point in the history
* feat: add discounted price type in commons model

* fix: make supply channel optional in inventory-entry

* chore: add enum lenum presets and total in transformer

* chore: changeset

* fix: lint issue

* refactor(discounted-price): adjust graphql types

* refactor(inventory-entry): adjust graphql types

* refactor(reference): adjust graphql types

* refactor(inventory-entry): supply channel is optional

* fix(inventory-entry): adjust tests

---------

Co-authored-by: Carlos Cortizas <[email protected]>
  • Loading branch information
jaikumar-tj and CarlosCortizasCT authored Dec 5, 2024
1 parent 33a191d commit 8038c61
Show file tree
Hide file tree
Showing 23 changed files with 200 additions and 71 deletions.
17 changes: 17 additions & 0 deletions .changeset/thick-experts-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@commercetools-test-data/product-type': minor
'@commercetools-test-data/commons': minor
'@commercetools-test-data/inventory-entry': patch
---

### Common Model (`common`)

- Introduced a new model called `discounted-price`.

### Inventory Entry Model (`inventory-entry`)

- Updated the transformer file to conditionally send the supply channel, making it optional.

### Product Type (`product-type`)

- Added new presets for enum and localized enum types.
7 changes: 3 additions & 4 deletions graphql-types/src/generated/core.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions graphql-types/src/generated/ctp.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions graphql-types/src/generated/mc.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions graphql-types/src/generated/settings.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion models/commons/src/discounted-price/builders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('DiscountedPrice Builder', () => {
__typename: 'ProductDiscount',
}),
discountRef: expect.objectContaining({
id: expect.any(String),
id: graphqlModel.discount?.id,
typeId: 'product-discount',
__typename: 'Reference',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('DiscountedPriceDraft Builder', () => {

expect(graphqlDraftModel).toEqual(
expect.objectContaining({
__typename: 'DiscountedProductPriceValue',
value: expect.objectContaining({
centAmount: expect.any(Number),
currencyCode: expect.any(String),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ export const graphqlFieldsConfig: TModelFieldsConfig<TDiscountedPriceDraftGraphq
{
fields: {
...commonFieldsConfig,
__typename: 'DiscountedProductPriceValue',
},
};
10 changes: 10 additions & 0 deletions models/commons/src/discounted-price/fields-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ export const graphqlFieldsConfig: TModelFieldsConfig<TDiscountedPriceGraphql> =
discount: fake(() => ProductDiscount.random()),
discountRef: fake(() => Reference.presets.productDiscountReference()),
},
postBuild: (model) => {
if (model.discount) {
model.discountRef = Reference.presets
.productDiscountReference()
.id(model.discount.id)
.buildGraphql();
}

return model;
},
};
20 changes: 6 additions & 14 deletions models/commons/src/discounted-price/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@ import {
DiscountedPriceDraft,
} from '@commercetools/platform-sdk';
import type { TBuilder } from '@commercetools-test-data/core';
import { TProductDiscountGraphql } from '@commercetools-test-data/product-discount';
import { TReferenceGraphql, TReferenceDraftGraphql } from '../reference/types';
import type {
TCtpDiscountedProductPriceValue,
TCtpDiscountedProductPriceValueInput,
} from '@commercetools-test-data/graphql-types';

export type TDiscountedPriceRest = DiscountedPrice;

export type TDiscountedPriceGraphql = Omit<TDiscountedPriceRest, 'discount'> & {
__typename: 'DiscountedProductPriceValue';
discount: TProductDiscountGraphql;
discountRef: TReferenceGraphql<'product-discount'>;
};
export type TDiscountedPriceGraphql = TCtpDiscountedProductPriceValue;

export type TDiscountedPriceDraftRest = DiscountedPriceDraft;
export type TDiscountedPriceDraftGraphql = Omit<
DiscountedPriceDraft,
'discount'
> & {
__typename: 'DiscountedProductPriceValue';
discount: TReferenceDraftGraphql<'product-discount'>;
};
export type TDiscountedPriceDraftGraphql = TCtpDiscountedProductPriceValueInput;

export type TCreateDiscountedPriceBuilder<
TModel extends
Expand Down
14 changes: 9 additions & 5 deletions models/commons/src/reference/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { TBuilder } from '@commercetools-test-data/core';
import { TCtpReference } from '@commercetools-test-data/graphql-types';

export type TReferenceBuilder<TypeId = string> = TBuilder<TReference<TypeId>>;

Expand All @@ -17,15 +18,18 @@ export type TCreateReferenceBuilder<TypeId = string> =

export type TReferenceRest<
TypeId = string,
ExpandedObject extends TExpandedReferenceObject<TypeId> = TExpandedReferenceObject<TypeId>
ExpandedObject extends
TExpandedReferenceObject<TypeId> = TExpandedReferenceObject<TypeId>,
> = TReference<TypeId> & {
obj: ExpandedObject;
};

export type TReferenceGraphql<TypeId = string> =
TExpandedReferenceObject<TypeId> & {
__typename: 'Reference';
};
export type TReferenceGraphql<TypeId = string> = Omit<
TCtpReference,
'typeId'
> & {
typeId: TypeId;
};

// Draft representation
export interface TReferenceDraft<TypeId = string> {
Expand Down
1 change: 1 addition & 0 deletions models/inventory-entry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@commercetools-test-data/channel": "10.10.1",
"@commercetools-test-data/commons": "10.10.1",
"@commercetools-test-data/core": "10.10.1",
"@commercetools-test-data/graphql-types": "10.10.1",
"@commercetools-test-data/product": "10.10.1",
"@commercetools-test-data/utils": "10.10.1",
"@commercetools/platform-sdk": "7.14.0",
Expand Down
22 changes: 6 additions & 16 deletions models/inventory-entry/src/builders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('InventoryEntry model builders', () => {
restockableInDays: expect.any(Number),
availableQuantity: expect.any(Number),
expectedDelivery: expect.any(String),
supplyChannel: expect.any(Object),
supplyChannel: null,
custom: null,
})
);
Expand All @@ -45,17 +45,8 @@ describe('InventoryEntry model builders', () => {
restockableInDays: expect.any(Number),
availableQuantity: expect.any(Number),
expectedDelivery: expect.any(String),
supplyChannel: expect.objectContaining({
__typename: 'Channel',
address: expect.objectContaining({
country: expect.any(String),
}),
}),
supplyChannelRef: expect.objectContaining({
__typename: 'Reference',
id: expect.any(String),
typeId: 'channel',
}),
supplyChannel: null,
supplyChannelRef: null,
custom: null,
__typename: 'InventoryEntry',
})
Expand All @@ -81,7 +72,7 @@ describe('InventoryEntry model compatibility builders', () => {
restockableInDays: expect.any(Number),
availableQuantity: expect.any(Number),
expectedDelivery: expect.any(String),
supplyChannel: expect.any(Object),
supplyChannel: null,
custom: null,
})
);
Expand All @@ -104,9 +95,8 @@ describe('InventoryEntry model compatibility builders', () => {
quantityOnStock: expect.any(Number),
restockableInDays: expect.any(Number),
expectedDelivery: expect.any(String),
supplyChannel: expect.objectContaining({
__typename: 'Channel',
}),
supplyChannel: null,
supplyChannelRef: null,
custom: null,
})
);
Expand Down
6 changes: 2 additions & 4 deletions models/inventory-entry/src/fields-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ChannelGraphql } from '@commercetools-test-data/channel';
import {
ClientLogging,
Reference,
Expand Down Expand Up @@ -27,20 +26,19 @@ const commonFieldsConfig = {
availableQuantity: fake((f) => f.number.int()),
restockableInDays: fake((f) => f.number.int()),
expectedDelivery: fake(getFutureDate),
supplyChannel: null,
custom: null,
};
export const restFieldsConfig: TModelFieldsConfig<TInventoryEntryRest> = {
fields: {
...commonFieldsConfig,
supplyChannel: fake(() => Reference.presets.channelReference()),
},
};
export const graphqlFieldsConfig: TModelFieldsConfig<TInventoryEntryGraphql> = {
fields: {
...commonFieldsConfig,
__typename: 'InventoryEntry',
supplyChannel: fake(() => ChannelGraphql.random()),
supplyChannelRef: fake((f) => Reference.presets.channelReference()),
supplyChannelRef: null,
},
postBuild: (model) => {
const supplyChannelRef = model.supplyChannel
Expand Down
17 changes: 9 additions & 8 deletions models/inventory-entry/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@ import {
InventoryEntry,
InventoryEntryDraft,
} from '@commercetools/platform-sdk';
import { TChannelGraphql } from '@commercetools-test-data/channel';
import type { TReferenceGraphql } from '@commercetools-test-data/commons';
import type { TBuilder } from '@commercetools-test-data/core';
import type {
TCtpInventoryEntry,
TCtpInventoryEntryDraft,
} from '@commercetools-test-data/graphql-types';

// Default
/**
* @deprecated use `TInventoryEntryRest` instead
*/
export type TInventoryEntry = InventoryEntry;
/**
* @deprecated use `TInventoryEntryDraftRest` instead
*/
export type TInventoryEntryDraft = InventoryEntryDraft;

// REST
export type TInventoryEntryRest = InventoryEntry;
export type TInventoryEntryDraftRest = InventoryEntryDraft;

// GraphQL
export type TInventoryEntryGraphql = Omit<InventoryEntry, 'supplyChannel'> & {
__typename: 'InventoryEntry';
supplyChannel?: TChannelGraphql | null;
supplyChannelRef?: TReferenceGraphql<'channel'> | null;
};
export type TInventoryEntryDraftGraphql = TInventoryEntryDraft;
export type TInventoryEntryGraphql = TCtpInventoryEntry;
export type TInventoryEntryDraftGraphql = TCtpInventoryEntryDraft;

export type TInventoryEntryBuilder = TBuilder<TInventoryEntry>;
export type TInventoryEntryDraftBuilder = TBuilder<TInventoryEntryDraft>;
Expand Down
44 changes: 43 additions & 1 deletion models/product-type/src/attribute-definition/presets/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
const presets = {};
import { LocalizedString } from '@commercetools-test-data/commons';
import {
AttributeEnumType,
AttributeNumberType,
AttributeTextType,
} from '../..';
import AttributeDefinition from '../builder';

const presets = {
number: () =>
AttributeDefinition()
.type(AttributeNumberType.random())
.name('Number Attribute Definition')
.label(
LocalizedString.presets
.empty()
.en(`Number Attribute Definition's Label`)
)
.inputTip(
LocalizedString.presets
.empty()
.en(`Number Attribute Definition's Input Tip`)
),

countryOfOrigin: () =>
AttributeDefinition()
.attributeConstraint('None')
.name('country-of-origin')
.label(LocalizedString.presets.empty().en('Country of Origin'))
.isRequired(true)
.type(AttributeTextType.random()),

size: () =>
AttributeDefinition()
.attributeConstraint('None')
.name('size')
.label(LocalizedString.presets.empty().en('Size'))
.inputTip(LocalizedString.presets.empty().en('Size of a product'))
.inputHint('SingleLine')
.isRequired(true)
.isSearchable(true)
.type(AttributeEnumType.presets.allSizesEnum()),
};

export default presets;
24 changes: 23 additions & 1 deletion models/product-type/src/attribute-enum-type/presets/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
const presets = {};
import { AttributePlainEnumValue } from '../..';
import AttributeEnumType from '../builder';

const presets = {
allSizesEnum: () =>
AttributeEnumType().values([
AttributePlainEnumValue.presets.s(),
AttributePlainEnumValue.presets.m(),
AttributePlainEnumValue.presets.l(),
AttributePlainEnumValue.presets.xl(),
]),
smallSizesEnum: () =>
AttributeEnumType().values([
AttributePlainEnumValue.presets.s(),
AttributePlainEnumValue.presets.m(),
]),

bigSizesEnum: () =>
AttributeEnumType().values([
AttributePlainEnumValue.presets.l(),
AttributePlainEnumValue.presets.xl(),
]),
};

export default presets;
Loading

0 comments on commit 8038c61

Please sign in to comment.