-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate ProductProjection model #738
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a486874
refactor(product-projection): migrate to new implementation patterns
CarlosCortizasCT df0937c
refactor(common): temporary reference adjustment
CarlosCortizasCT bbd53c7
fix(product-projection): adjust preset
CarlosCortizasCT d4ce5d2
refactor(common): temporary reference adjustment
CarlosCortizasCT 865ba65
refactor(product-data): add missing nested model prop
CarlosCortizasCT bfa97b0
chore: add changesets
CarlosCortizasCT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@commercetools-test-data/product': patch | ||
--- | ||
|
||
Added missing `obj` property to category references in the `ProductData` REST model. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@commercetools-test-data/commons': patch | ||
--- | ||
|
||
When providing a model to the `obj` property of the `Reference` model, that one was not used at build time in the REST representation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@commercetools-test-data/product-projection': patch | ||
--- | ||
|
||
Migrated the `ProductProjection` model to the new implementation patterns. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
/* eslint-disable jest/no-disabled-tests */ | ||
/* eslint-disable jest/valid-title */ | ||
import { Category } from '@commercetools-test-data/category'; | ||
import { LocalizedString, Reference } from '@commercetools-test-data/commons'; | ||
import { LocalizedString } 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 { | ||
TProductProjection, | ||
TProductProjectionGraphql, | ||
TProductProjectionRest, | ||
} from './types'; | ||
import { State } from '@commercetools-test-data/state'; | ||
import { TaxCategory } from '@commercetools-test-data/tax-category'; | ||
import { TProductProjectionGraphql, TProductProjectionRest } from './types'; | ||
import * as ProductProjection from './index'; | ||
|
||
describe('builder', () => { | ||
|
@@ -27,99 +25,9 @@ describe('builder', () => { | |
]); | ||
|
||
it( | ||
...createBuilderSpec<TProductProjection, TProductProjection>( | ||
'default', | ||
ProductProjection.random(), | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
version: expect.any(Number), | ||
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), | ||
}), | ||
]), | ||
}), | ||
name: expectedGeneralLocalizedString, | ||
description: expectedGeneralLocalizedString, | ||
slug: expectedGeneralLocalizedString, | ||
categories: [], | ||
categoryOrderHints: null, | ||
metaTitle: null, | ||
metaDescription: null, | ||
metaKeywords: null, | ||
searchKeywords: [], | ||
hasStagedChanges: expect.any(Boolean), | ||
published: expect.any(Boolean), | ||
masterVariant: expect.objectContaining({ | ||
key: expect.any(String), | ||
sku: expect.any(String), | ||
prices: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
value: expect.any(Object), | ||
}), | ||
]), | ||
price: null, | ||
images: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
url: expect.any(String), | ||
}), | ||
]), | ||
attributes: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
name: expect.any(String), | ||
}), | ||
]), | ||
assets: expect.arrayContaining([]), | ||
availability: null, | ||
isMatchingVariant: expect.any(Boolean), | ||
scopedPrice: null, | ||
scopedPriceDiscounted: null, | ||
}), | ||
variants: [], | ||
taxCategory: null, | ||
state: null, | ||
createdAt: expect.any(String), | ||
lastModifiedAt: expect.any(String), | ||
reviewRatingStatistics: null, | ||
priceMode: null, | ||
}) | ||
) | ||
); | ||
|
||
it( | ||
...createBuilderSpec<TProductProjection, TProductProjectionRest>( | ||
...createBuilderSpec<TProductProjectionRest, TProductProjectionRest>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the default type test as we don't have it anymore. |
||
'rest', | ||
ProductProjection.random(), | ||
ProductProjection.ProductProjectionRest.random(), | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
version: expect.any(Number), | ||
|
@@ -199,9 +107,9 @@ describe('builder', () => { | |
); | ||
|
||
it( | ||
...createBuilderSpec<TProductProjection, TProductProjectionGraphql>( | ||
...createBuilderSpec<TProductProjectionGraphql, TProductProjectionGraphql>( | ||
'graphql', | ||
ProductProjection.random(), | ||
ProductProjection.ProductProjectionGraphql.random(), | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
version: expect.any(Number), | ||
|
@@ -225,8 +133,11 @@ describe('builder', () => { | |
categories: [], | ||
categoryOrderHints: [], | ||
metaTitle: null, | ||
metaTitleAllLocales: null, | ||
metaDescription: null, | ||
metaDescriptionAllLocales: null, | ||
metaKeywords: null, | ||
metaKeywordsAllLocales: null, | ||
searchKeywords: [], | ||
hasStagedChanges: expect.any(Boolean), | ||
published: expect.any(Boolean), | ||
|
@@ -236,47 +147,55 @@ 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, | ||
priceMode: null, | ||
reviewRatingStatistics: null, | ||
}) | ||
) | ||
); | ||
|
||
it('should allow customization', () => { | ||
const productProjectionMock = ProductProjection.presets | ||
.happyCowMilkProductProjection() | ||
.categories([ | ||
Category.random() | ||
.id('category-id') | ||
.name(LocalizedString.presets.empty().en('category-name')), | ||
]) | ||
.categoryOrderHints({ | ||
'category-1': '0.4', | ||
}) | ||
.id('happy-cow-milk-id') | ||
.key('happy-cow-milk-key') | ||
.metaKeywords(LocalizedString.presets.empty().en('happy')) | ||
.priceMode('Embedded') | ||
.productType(ProductType.presets.milk().id('product-type-id')) | ||
.reviewRatingStatistics({ | ||
averageRating: 3.12345, | ||
highestRating: 4.9, | ||
lowestRating: 2.1, | ||
count: 25, | ||
ratingsDistribution: {}, | ||
}) | ||
.searchKeywords({ | ||
en: [{ text: 'product search keyword' }], | ||
}) | ||
.state(Reference.presets.stateReference()) | ||
.taxCategory(Reference.presets.taxCategoryReference()) | ||
.variants([ProductVariant.random().key('alternative-variant-key')]) | ||
.version(222) | ||
.buildGraphql<TProductProjectionGraphql>(); | ||
const productProjectionMock = | ||
ProductProjection.ProductProjectionGraphql.presets | ||
.happyCowMilk() | ||
.categories([ | ||
Category.random() | ||
.id('category-id') | ||
.name(LocalizedString.presets.empty().en('category-name')), | ||
]) | ||
.categoryOrderHints([ | ||
{ | ||
__typename: 'CategoryOrderHintProductSearch', | ||
categoryId: 'category-1', | ||
orderHint: '0.4', | ||
}, | ||
]) | ||
.id('happy-cow-milk-id') | ||
.key('happy-cow-milk-key') | ||
.metaKeywordsAllLocales(LocalizedString.presets.empty().en('happy')) | ||
.productType(ProductType.presets.milk().id('product-type-id')) | ||
.reviewRatingStatistics({ | ||
averageRating: 3.12345, | ||
highestRating: 4.9, | ||
lowestRating: 2.1, | ||
count: 25, | ||
ratingsDistribution: {}, | ||
__typename: 'ReviewRatingStatistics', | ||
}) | ||
.searchKeywords([ | ||
{ | ||
__typename: 'SearchKeywordsProductSearch', | ||
locale: 'en', | ||
searchKeywords: [{ text: 'product search keyword' }], | ||
}, | ||
]) | ||
.state(State.random().id('state-id')) | ||
.taxCategory(TaxCategory.random().id('tax-category-id')) | ||
.variants([ProductVariant.random().key('alternative-variant-key')]) | ||
.version(222) | ||
.buildGraphql<TProductProjectionGraphql>(); | ||
|
||
const expectedLocalizedName = expect.arrayContaining([ | ||
expect.objectContaining({ | ||
|
@@ -312,7 +231,7 @@ describe('builder', () => { | |
{ | ||
categoryId: 'category-1', | ||
orderHint: '0.4', | ||
__typename: 'CategoryOrderHint', | ||
__typename: 'CategoryOrderHintProductSearch', | ||
}, | ||
]), | ||
categoriesRef: expect.arrayContaining([ | ||
|
@@ -339,13 +258,13 @@ describe('builder', () => { | |
expect.objectContaining({ | ||
locale: 'en', | ||
value: 'happy', | ||
__typename: 'LocalizedString', | ||
}), | ||
]), | ||
metaTitle: 'Happy Cow Milk', | ||
metaTitleAllLocales: expectedLocalizedName, | ||
name: 'Happy Cow Milk', | ||
nameAllLocales: expectedLocalizedName, | ||
priceMode: 'Embedded', | ||
productType: expect.objectContaining({ | ||
__typename: 'ProductTypeDefinition', | ||
name: 'Milk Product Type', | ||
|
@@ -384,18 +303,20 @@ describe('builder', () => { | |
}), | ||
]), | ||
state: expect.objectContaining({ | ||
id: 'product-type-id', | ||
id: 'state-id', | ||
__typename: 'State', | ||
}), | ||
stateRef: expect.objectContaining({ | ||
id: 'state-id', | ||
typeId: 'state', | ||
__typename: 'Reference', | ||
}), | ||
taxCategory: expect.objectContaining({ | ||
id: 'product-type-id', | ||
id: 'tax-category-id', | ||
__typename: 'TaxCategory', | ||
}), | ||
taxCategoryRef: expect.objectContaining({ | ||
id: 'tax-category-id', | ||
typeId: 'tax-category', | ||
__typename: 'Reference', | ||
}), | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so we can forward to the
obj
object all the properties we potentially have received so, in case the model was populated with a reference object, the model instance has its properties.