Skip to content

Commit

Permalink
fix(presets/fashion): attribute enum type for product types
Browse files Browse the repository at this point in the history
  • Loading branch information
stephsprinkle committed Feb 23, 2024
1 parent 08e8f23 commit 8973632
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,28 @@ describe('builder', () => {
AttributeEnumTypeDraft.random(),
expect.objectContaining({
name: 'enum',
values: [],
values: expect.arrayContaining([
expect.objectContaining({
key: expect.any(String),
label: expect.any(String),
}),
]),
})
)
);

it(
...createBuilderSpec<TAttributeEnumType, TAttributeEnumTypeDraft>(
'rest',
AttributeEnumTypeDraft.random(),
expect.objectContaining({
name: 'enum',
values: expect.arrayContaining([
expect.objectContaining({
key: expect.any(String),
label: expect.any(String),
}),
]),
})
)
);
Expand All @@ -25,7 +46,14 @@ describe('builder', () => {
'graphql',
AttributeEnumTypeDraft.random(),
expect.objectContaining({
enum: { values: [] },
enum: {
values: expect.arrayContaining([
expect.objectContaining({
key: expect.any(String),
label: expect.any(String),
}),
]),
},
})
)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Generator } from '@commercetools-test-data/core';
import { fake, Generator } from '@commercetools-test-data/core';
import * as AttributePlainEnumValueDraft from '../../attribute-plain-enum-value/attribute-plain-enum-value-draft';
import { TAttributeEnumTypeDraft } from '../types';

// https://docs.commercetools.com/api/projects/productTypes#attributeenumtype

export const generator = Generator<TAttributeEnumTypeDraft>({
fields: {
name: 'enum',
values: [],
values: fake((f) => [AttributePlainEnumValueDraft.random()]),
},
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Transformer } from '@commercetools-test-data/core';
import { buildField, Transformer } from '@commercetools-test-data/core';
import {
TAttributeEnumTypeDraftGraphql,
TAttributeEnumTypeDraft,
Expand All @@ -11,6 +11,9 @@ const transformers = {
buildFields: ['values'],
}
),
rest: Transformer<TAttributeEnumTypeDraft, TAttributeEnumTypeDraft>('rest', {
buildFields: ['values'],
}),
graphql: Transformer<TAttributeEnumTypeDraft, TAttributeEnumTypeDraftGraphql>(
'graphql',
{
Expand Down
21 changes: 18 additions & 3 deletions models/product-type/src/attribute-enum-type/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ describe('builder', () => {
AttributeEnumType.random(),
expect.objectContaining({
name: 'enum',
values: [],
values: expect.arrayContaining([
expect.objectContaining({
key: expect.any(String),
label: expect.any(String),
}),
]),
})
)
);
Expand All @@ -22,7 +27,12 @@ describe('builder', () => {
AttributeEnumType.random(),
expect.objectContaining({
name: 'enum',
values: [],
values: expect.arrayContaining([
expect.objectContaining({
key: expect.any(String),
label: expect.any(String),
}),
]),
})
)
);
Expand All @@ -33,7 +43,12 @@ describe('builder', () => {
AttributeEnumType.random(),
expect.objectContaining({
name: 'enum',
values: [],
values: expect.arrayContaining([
expect.objectContaining({
key: expect.any(String),
label: expect.any(String),
}),
]),
__typename: 'EnumAttributionDefinitionType',
})
)
Expand Down
5 changes: 3 additions & 2 deletions models/product-type/src/attribute-enum-type/generator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Generator } from '@commercetools-test-data/core';
import { fake, Generator } from '@commercetools-test-data/core';
import * as AttributePlainEnumValue from '../attribute-plain-enum-value';
import { TAttributeEnumType } from './types';

// https://docs.commercetools.com/api/projects/productTypes#attributeenumtype

export const generator = Generator<TAttributeEnumType>({
fields: {
name: 'enum',
values: [],
values: fake((f) => [AttributePlainEnumValue.random()]),
},
});
6 changes: 3 additions & 3 deletions models/product-type/src/attribute-enum-type/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { TAttributeEnumTypeGraphql, TAttributeEnumType } from './types';

const transformers = {
default: Transformer<TAttributeEnumType, TAttributeEnumType>('default', {
buildFields: [],
buildFields: ['values'],
}),
rest: Transformer<TAttributeEnumType, TAttributeEnumType>('rest', {
buildFields: [],
buildFields: ['values'],
}),
graphql: Transformer<TAttributeEnumType, TAttributeEnumTypeGraphql>(
'graphql',
{
buildFields: [],
buildFields: ['values'],
addFields: ({ fields }) => ({
__typename: 'EnumAttributionDefinitionType',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LocalizedStringDraft } from '@commercetools-test-data/commons';
import {
AttributeDefinitionDraft,
AttributeEnumTypeDraft,
AttributePlainEnumValueDraft,
AttributeTextTypeDraft,
} from '../../../../index';
import type { TProductTypeDraftBuilder } from '../../../types';
Expand All @@ -22,18 +23,11 @@ const accessories = (): TProductTypeDraftBuilder =>
.isRequired(true)
.type(
AttributeEnumTypeDraft.random().values([
{
key: 'Jewelry',
label: 'Jewelry',
},
{
key: 'Bag',
label: 'Bag',
},
{
key: 'Shoes',
label: 'Shoes',
},
AttributePlainEnumValueDraft.random()
.key('Jewelry')
.label('Jewelry'),
AttributePlainEnumValueDraft.random().key('Bag').label('Bag'),
AttributePlainEnumValueDraft.random().key('Shoes').label('Shoes'),
])
)
.attributeConstraint('None')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LocalizedStringDraft } from '@commercetools-test-data/commons';
import {
AttributeDefinitionDraft,
AttributeEnumTypeDraft,
AttributePlainEnumValueDraft,
} from '../../../../index';
import type { TProductTypeDraftBuilder } from '../../../types';
import * as ProductTypeDraft from '../../index';
Expand All @@ -21,18 +22,11 @@ const dresses = (): TProductTypeDraftBuilder =>
.isRequired(false)
.type(
AttributeEnumTypeDraft.random().values([
{
key: 'Maxi',
label: 'Maxi',
},
{
key: 'Knee Length',
label: 'Knee Length',
},
{
key: 'Mini',
label: 'Mini',
},
AttributePlainEnumValueDraft.random().key('Maxi').label('Maxi'),
AttributePlainEnumValueDraft.random()
.key('Knee Length')
.label('Knee Length'),
AttributePlainEnumValueDraft.random().key('Mini').label('Mini'),
])
)
.attributeConstraint('CombinationUnique')
Expand All @@ -46,18 +40,9 @@ const dresses = (): TProductTypeDraftBuilder =>
.isRequired(false)
.type(
AttributeEnumTypeDraft.random().values([
{
key: 'White',
label: 'White',
},
{
key: 'Pink',
label: 'Pink',
},
{
key: 'Floral',
label: 'Floral',
},
AttributePlainEnumValueDraft.random().key('White').label('White'),
AttributePlainEnumValueDraft.random().key('Pink').label('Pink'),
AttributePlainEnumValueDraft.random().key('Floral').label('Floral'),
])
)
.attributeConstraint('CombinationUnique')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AttributeBooleanTypeDraft,
AttributeDefinitionDraft,
AttributeEnumTypeDraft,
AttributePlainEnumValueDraft,
} from '../../../../index';
import type { TProductTypeDraftBuilder } from '../../../types';
import * as ProductTypeDraft from '../../index';
Expand All @@ -24,18 +25,11 @@ const jackets = (): TProductTypeDraftBuilder =>
.isRequired(false)
.type(
AttributeEnumTypeDraft.random().values([
{
key: 'Crop',
label: 'Crop',
},
{
key: 'Normal',
label: 'Normal',
},
{
key: 'Extra Long',
label: 'Extra Long',
},
AttributePlainEnumValueDraft.random().key('Crop').label('Crop'),
AttributePlainEnumValueDraft.random().key('Normal').label('Normal'),
AttributePlainEnumValueDraft.random()
.key('Extra Long')
.label('Extra Long'),
])
)
.attributeConstraint('None')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LocalizedStringDraft } from '@commercetools-test-data/commons';
import {
AttributeDefinitionDraft,
AttributeEnumTypeDraft,
AttributePlainEnumValueDraft,
} from '../../../../index';
import type { TProductTypeDraftBuilder } from '../../../types';
import * as ProductTypeDraft from '../../index';
Expand All @@ -21,18 +22,9 @@ const pants = (): TProductTypeDraftBuilder =>
.isRequired(true)
.type(
AttributeEnumTypeDraft.random().values([
{
key: 'Small',
label: 'Small',
},
{
key: 'Medium',
label: 'Medium',
},
{
key: 'Large',
label: 'Large',
},
AttributePlainEnumValueDraft.random().key('Small').label('Small'),
AttributePlainEnumValueDraft.random().key('Medium').label('Medium'),
AttributePlainEnumValueDraft.random().key('Large').label('Large'),
])
)
.attributeConstraint('None')
Expand All @@ -46,18 +38,11 @@ const pants = (): TProductTypeDraftBuilder =>
.isRequired(false)
.type(
AttributeEnumTypeDraft.random().values([
{
key: 'Slim',
label: 'Slim',
},
{
key: 'Straight',
label: 'Straight',
},
{
key: 'Flair',
label: 'Flair',
},
AttributePlainEnumValueDraft.random().key('Slim').label('Slim'),
AttributePlainEnumValueDraft.random()
.key('Straight')
.label('Straight'),
AttributePlainEnumValueDraft.random().key('Flair').label('Flair'),
])
)
.attributeConstraint('None')
Expand All @@ -71,18 +56,9 @@ const pants = (): TProductTypeDraftBuilder =>
.isRequired(false)
.type(
AttributeEnumTypeDraft.random().values([
{
key: 'Blue',
label: 'Blue',
},
{
key: 'Black',
label: 'Black',
},
{
key: 'White',
label: 'White',
},
AttributePlainEnumValueDraft.random().key('Blue').label('Blue'),
AttributePlainEnumValueDraft.random().key('Black').label('Black'),
AttributePlainEnumValueDraft.random().key('White').label('White'),
])
)
.attributeConstraint('None')
Expand All @@ -96,18 +72,11 @@ const pants = (): TProductTypeDraftBuilder =>
.isRequired(false)
.type(
AttributeEnumTypeDraft.random().values([
{
key: 'Ankle',
label: 'Ankle',
},
{
key: 'Crop',
label: 'Crop',
},
{
key: 'Extra Long',
label: 'Extra Long',
},
AttributePlainEnumValueDraft.random().key('Ankle').label('Ankle'),
AttributePlainEnumValueDraft.random().key('Crop').label('Crop'),
AttributePlainEnumValueDraft.random()
.key('Extra Long')
.label('Extra Long'),
])
)
.attributeConstraint('None')
Expand Down
Loading

0 comments on commit 8973632

Please sign in to comment.