diff --git a/.changeset/tender-wasps-judge.md b/.changeset/tender-wasps-judge.md new file mode 100644 index 000000000..0675bd782 --- /dev/null +++ b/.changeset/tender-wasps-judge.md @@ -0,0 +1,5 @@ +--- +'@commercetools/sync-actions': minor +--- + +Add support for 'changeAssetOrder' in (ProductVariants)[https://docs.commercetools.com/api/projects/products#change-asset-order]. diff --git a/README.md b/README.md index b0e9e71bc..ce8d424b6 100644 --- a/README.md +++ b/README.md @@ -188,4 +188,3 @@ We'd love to have your helping hand on this ecosystem! Please see [CONTRIBUTING. [personal-data-erasure-icon]: https://img.shields.io/npm/v/@commercetools/personal-data-erasure.svg?style=flat-square [personal-data-erasure-dependencies]: https://david-dm.org/commercetools/nodejs?path=packages/personal-data-erasure [personal-data-erasure-dependencies-icon]: https://img.shields.io/david/commercetools/nodejs.svg?path=packages/personal-data-erasure&style=flat-square - diff --git a/docs/sdk/api/sdkMiddlewareHttp.md b/docs/sdk/api/sdkMiddlewareHttp.md index 3e323b61e..acf73d5a3 100644 --- a/docs/sdk/api/sdkMiddlewareHttp.md +++ b/docs/sdk/api/sdkMiddlewareHttp.md @@ -42,7 +42,7 @@ The HTTP middleware can run in either a browser or Node.js environment. For Node 13. `fetch` _(Function)_: A `fetch` implementation which can be e.g. `node-fetch` or `unfetch` but also the native browser `fetch` function 14. `timeout` _(Number)_: Request/response timeout in ms. Must be globally available or passed in `AbortController` 15. `abortController` or `getAbortController` depending on what you chose to handle the timeout (_abortController_): This property accepts the `AbortController` instance. Could be [abort-controller](https://www.npmjs.com/package/abort-controller) or a globally available one. -16. `retryConfig` _(Object)_: Field required in the object listed below +16. `retryConfig` _(Object)_: Field required in the object listed below #### Retrying requests @@ -73,12 +73,7 @@ const client = createClient({ retryDelay: 300, //milliseconds maxDelay: 5000, //milliseconds retryOnAbort: false, - retryCodes: [ - 504, - 'ETIMEDOUT', - 'ECONNREFUSED', - 503 - ] + retryCodes: [504, 'ETIMEDOUT', 'ECONNREFUSED', 503], }, // Optional if not globally available diff --git a/packages/sync-actions/package.json b/packages/sync-actions/package.json index 082ee19b6..2eba69bf8 100644 --- a/packages/sync-actions/package.json +++ b/packages/sync-actions/package.json @@ -43,6 +43,8 @@ "lodash.isnil": "^4.0.0", "lodash.shuffle": "^4.2.0", "lodash.sortby": "^4.7.0", - "lodash.uniqwith": "^4.5.0" + "lodash.uniqwith": "^4.5.0", + "lodash.intersection": "^4.4.0", + "lodash.without": "^4.4.0" } } diff --git a/packages/sync-actions/src/product-actions.js b/packages/sync-actions/src/product-actions.js index c67c75d35..9189908eb 100644 --- a/packages/sync-actions/src/product-actions.js +++ b/packages/sync-actions/src/product-actions.js @@ -1,6 +1,8 @@ /* eslint-disable max-len */ import forEach from 'lodash.foreach' import uniqWith from 'lodash.uniqwith' +import intersection from 'lodash.intersection' +import without from 'lodash.without' import * as diffpatcher from './utils/diffpatcher' import extractMatchingPairs from './utils/extract-matching-pairs' import actionsMapCustom from './utils/action-map-custom' @@ -58,6 +60,9 @@ const getIsUpdateAction = (key, resource) => const getIsRemoveAction = (key, resource) => REGEX_UNDERSCORE_NUMBER.test(key) && Number(resource[2]) === 0 +const getIsItemMovedAction = (key, resource) => + REGEX_UNDERSCORE_NUMBER.test(key) && Number(resource[2]) === 3 + function _buildSkuActions(variantDiff, oldVariant) { if ({}.hasOwnProperty.call(variantDiff, 'sku')) { const newValue = diffpatcher.getDeltaValue(variantDiff.sku) @@ -401,6 +406,30 @@ function toVariantIdentifier(variant) { return id ? { variantId: id } : { sku } } +function _buildVariantChangeAssetOrderAction( + diffAssets, + oldVariant, + newVariant +) { + const isAssetOrderChanged = Object.entries(diffAssets).find((entry) => + getIsItemMovedAction(entry[0], entry[1]) + ) + if (!isAssetOrderChanged) { + return [] + } + const assetIdsBefore = oldVariant.assets.map((_) => _.id) + const assetIdsCurrent = newVariant.assets + .map((_) => _.id) + .filter((_) => _ !== undefined) + const assetIdsToKeep = intersection(assetIdsCurrent, assetIdsBefore) + const assetIdsToRemove = without(assetIdsBefore, ...assetIdsToKeep) + const changeAssetOrderAction = { + action: 'changeAssetOrder', + assetOrder: assetIdsToKeep.concat(assetIdsToRemove), + ...toVariantIdentifier(oldVariant), + } + return [changeAssetOrderAction] +} function _buildVariantAssetsActions(diffAssets, oldVariant, newVariant) { const assetActions = [] @@ -478,7 +507,12 @@ function _buildVariantAssetsActions(diffAssets, oldVariant, newVariant) { } }) - return assetActions + const changedAssetOrderAction = _buildVariantChangeAssetOrderAction( + diffAssets, + oldVariant, + newVariant + ) + return [...changedAssetOrderAction, ...assetActions] } /** diff --git a/packages/sync-actions/src/product-types-actions.js b/packages/sync-actions/src/product-types-actions.js index 7f0e57606..5d1031280 100644 --- a/packages/sync-actions/src/product-types-actions.js +++ b/packages/sync-actions/src/product-types-actions.js @@ -186,13 +186,14 @@ const generateUpdateActionsForAttributeEnumValues = ( ...Object.values( removedAttributeEnumValues.reduce( (nextEnumUpdateActions, removedAttributeEnumValue) => { - const removedAttributeEnumValueOfSameAttributeName = nextEnumUpdateActions[ - removedAttributeEnumValue.hint.attributeName - ] || { - keys: [], - attributeName: removedAttributeEnumValue.hint.attributeName, - action: 'removeEnumValues', - } + const removedAttributeEnumValueOfSameAttributeName = + nextEnumUpdateActions[ + removedAttributeEnumValue.hint.attributeName + ] || { + keys: [], + attributeName: removedAttributeEnumValue.hint.attributeName, + action: 'removeEnumValues', + } return { ...nextEnumUpdateActions, [removedAttributeEnumValue.hint.attributeName]: { diff --git a/packages/sync-actions/src/quote-requests-actions.js b/packages/sync-actions/src/quote-requests-actions.js index c723cf695..da3ec5c7f 100644 --- a/packages/sync-actions/src/quote-requests-actions.js +++ b/packages/sync-actions/src/quote-requests-actions.js @@ -2,7 +2,7 @@ import { buildBaseAttributesActions } from './utils/common-actions' export const baseActionsList = [ { action: 'changeQuoteRequestState', key: 'quoteRequestState' }, - { action: 'transitionState', key: 'state'}, + { action: 'transitionState', key: 'state' }, ] export function actionsMapBase(diff, oldObj, newObj, config = {}) { diff --git a/packages/sync-actions/src/quote-requests.js b/packages/sync-actions/src/quote-requests.js index 728724c3f..4a1d22d70 100644 --- a/packages/sync-actions/src/quote-requests.js +++ b/packages/sync-actions/src/quote-requests.js @@ -12,10 +12,7 @@ import actionsMapCustom from './utils/action-map-custom' import * as QuoteRequestsActions from './quote-requests-actions' import * as diffpatcher from './utils/diffpatcher' -const actionGroups = [ - 'base', - 'custom', -] +const actionGroups = ['base', 'custom'] function createQuoteRequestsMapActions( mapActionGroup: Function, @@ -29,7 +26,7 @@ function createQuoteRequestsMapActions( return function doMapActions( diff: Object, newObj: Object, - oldObj: Object, + oldObj: Object ): Array { const allActions = [] @@ -59,13 +56,13 @@ export default ( syncActionConfig: SyncActionConfig ): SyncAction => { const mapActionGroup = createMapActionGroup(actionGroupList) - const doMapActions = createQuoteRequestsMapActions(mapActionGroup, syncActionConfig) - - const buildActions = createBuildActions( - diffpatcher.diff, - doMapActions, + const doMapActions = createQuoteRequestsMapActions( + mapActionGroup, + syncActionConfig ) + const buildActions = createBuildActions(diffpatcher.diff, doMapActions) + return { buildActions } } diff --git a/packages/sync-actions/src/quotes-actions.js b/packages/sync-actions/src/quotes-actions.js index 454571552..2a6edb506 100644 --- a/packages/sync-actions/src/quotes-actions.js +++ b/packages/sync-actions/src/quotes-actions.js @@ -3,7 +3,7 @@ import { buildBaseAttributesActions } from './utils/common-actions' export const baseActionsList = [ { action: 'changeQuoteState', key: 'quoteState' }, { action: 'requestQuoteRenegotiation', key: 'buyerComment' }, - { action: 'transitionState', key: 'state'}, + { action: 'transitionState', key: 'state' }, ] export function actionsMapBase(diff, oldObj, newObj, config = {}) { diff --git a/packages/sync-actions/src/quotes.js b/packages/sync-actions/src/quotes.js index 627541511..4105853b7 100644 --- a/packages/sync-actions/src/quotes.js +++ b/packages/sync-actions/src/quotes.js @@ -12,10 +12,7 @@ import actionsMapCustom from './utils/action-map-custom' import * as QuotesActions from './quotes-actions' import * as diffpatcher from './utils/diffpatcher' -const actionGroups = [ - 'base', - 'custom', -] +const actionGroups = ['base', 'custom'] function createQuotesMapActions( mapActionGroup: Function, @@ -29,18 +26,13 @@ function createQuotesMapActions( return function doMapActions( diff: Object, newObj: Object, - oldObj: Object, + oldObj: Object ): Array { const allActions = [] allActions.push( mapActionGroup('base', (): Array => - QuotesActions.actionsMapBase( - diff, - oldObj, - newObj, - syncActionConfig - ) + QuotesActions.actionsMapBase(diff, oldObj, newObj, syncActionConfig) ) ) @@ -61,10 +53,7 @@ export default ( const mapActionGroup = createMapActionGroup(actionGroupList) const doMapActions = createQuotesMapActions(mapActionGroup, syncActionConfig) - const buildActions = createBuildActions( - diffpatcher.diff, - doMapActions, - ) + const buildActions = createBuildActions(diffpatcher.diff, doMapActions) return { buildActions } } diff --git a/packages/sync-actions/src/staged-quotes-actions.js b/packages/sync-actions/src/staged-quotes-actions.js index 14f7e36e6..04b036ca2 100644 --- a/packages/sync-actions/src/staged-quotes-actions.js +++ b/packages/sync-actions/src/staged-quotes-actions.js @@ -3,8 +3,8 @@ import { buildBaseAttributesActions } from './utils/common-actions' export const baseActionsList = [ { action: 'changeStagedQuoteState', key: 'stagedQuoteState' }, { action: 'setSellerComment', key: 'sellerComment' }, - { action: 'setValidTo', key: 'validTo'}, - { action: 'transitionState', key: 'state'}, + { action: 'setValidTo', key: 'validTo' }, + { action: 'transitionState', key: 'state' }, ] export function actionsMapBase(diff, oldObj, newObj, config = {}) { diff --git a/packages/sync-actions/src/staged-quotes.js b/packages/sync-actions/src/staged-quotes.js index fa29e1274..9e751b040 100644 --- a/packages/sync-actions/src/staged-quotes.js +++ b/packages/sync-actions/src/staged-quotes.js @@ -12,10 +12,7 @@ import actionsMapCustom from './utils/action-map-custom' import * as StagedQuotesActions from './staged-quotes-actions' import * as diffpatcher from './utils/diffpatcher' -const actionGroups = [ - 'base', - 'custom', -] +const actionGroups = ['base', 'custom'] function createStagedQuotesMapActions( mapActionGroup: Function, @@ -29,7 +26,7 @@ function createStagedQuotesMapActions( return function doMapActions( diff: Object, newObj: Object, - oldObj: Object, + oldObj: Object ): Array { const allActions = [] @@ -59,13 +56,13 @@ export default ( syncActionConfig: SyncActionConfig ): SyncAction => { const mapActionGroup = createMapActionGroup(actionGroupList) - const doMapActions = createStagedQuotesMapActions(mapActionGroup, syncActionConfig) - - const buildActions = createBuildActions( - diffpatcher.diff, - doMapActions, + const doMapActions = createStagedQuotesMapActions( + mapActionGroup, + syncActionConfig ) + const buildActions = createBuildActions(diffpatcher.diff, doMapActions) + return { buildActions } } diff --git a/packages/sync-actions/test/product-sync-images.spec.js b/packages/sync-actions/test/product-sync-images.spec.js index 9f34db597..727e6acd6 100644 --- a/packages/sync-actions/test/product-sync-images.spec.js +++ b/packages/sync-actions/test/product-sync-images.spec.js @@ -198,16 +198,14 @@ describe('Actions', () => { assets: [], images: [ { - url: - 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/Screen+Shot+2017-04--LOx1OrZZ.png', + url: 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/Screen+Shot+2017-04--LOx1OrZZ.png', dimensions: { w: 1456, h: 1078, }, }, { - url: - 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/cactus-with-surfboar-BmOeVZEZ.jpg', + url: 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/cactus-with-surfboar-BmOeVZEZ.jpg', label: 'cactus', dimensions: { w: 602, @@ -245,8 +243,7 @@ describe('Actions', () => { sku: '89978FRU', images: [ { - url: - 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/cactus-with-surfboar-BmOeVZEZ.jpg', + url: 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/cactus-with-surfboar-BmOeVZEZ.jpg', label: 'cactus', dimensions: { w: 602, @@ -254,8 +251,7 @@ describe('Actions', () => { }, }, { - url: - 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/Screen+Shot+2017-04--LOx1OrZZ.png', + url: 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/Screen+Shot+2017-04--LOx1OrZZ.png', dimensions: { w: 1456, h: 1078, @@ -353,16 +349,14 @@ describe('Actions', () => { prices: [], images: [ { - url: - 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/Screen+Shot+2017-04--LOx1OrZZ.png', + url: 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/Screen+Shot+2017-04--LOx1OrZZ.png', dimensions: { w: 1456, h: 1078, }, }, { - url: - 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/cactus-with-surfboar-BmOeVZEZ.jpg', + url: 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/cactus-with-surfboar-BmOeVZEZ.jpg', label: 'cactus', dimensions: { w: 602, @@ -402,8 +396,7 @@ describe('Actions', () => { prices: [], images: [ { - url: - 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/cactus-with-surfboar-BmOeVZEZ.jpg', + url: 'https://95bc80c3c245100a18cc-04fc5bec7ec901344d7cbd57f9a2fab3.ssl.cf3.rackcdn.com/cactus-with-surfboar-BmOeVZEZ.jpg', label: 'cactus', dimensions: { w: 602, diff --git a/packages/sync-actions/test/product-sync-variants.spec.js b/packages/sync-actions/test/product-sync-variants.spec.js index 06bd67141..750a94f44 100644 --- a/packages/sync-actions/test/product-sync-variants.spec.js +++ b/packages/sync-actions/test/product-sync-variants.spec.js @@ -1731,5 +1731,89 @@ describe('Actions', () => { ] expect(actual).toEqual(expected) }) + + describe('changeAssetOrder', () => { + const makeAsset = (asset) => { + const base = { + sources: [ + { + uri: 'http://example.org/content/product-manual.xml', + contentType: 'application/xml', + }, + ], + } + return { + ...base, + ...asset, + } + } + + const makeVariant = (assets) => ({ + variants: [ + { + id: 1, + assets, + }, + ], + }) + + test('should build "changeAssetOrder" if assets are simply re-ordered', () => { + const assetOne = makeAsset({ id: 'asset-one' }) + const assetTwo = makeAsset({ id: 'asset-two' }) + const assetThree = makeAsset({ id: 'asset-three' }) + + const before = makeVariant([assetOne, assetTwo, assetThree]) + const now = makeVariant([assetTwo, assetThree, assetOne]) + const actual = productsSync.buildActions(now, before) + const expected = [ + { + action: 'changeAssetOrder', + assetOrder: [assetTwo.id, assetThree.id, assetOne.id], + variantId: 1, + }, + ] + expect(actual).toEqual(expected) + }) + + test('moves to be deleted assets to the end of the ordering', () => { + const assetOne = makeAsset({ id: 'asset-one' }) + const assetTwo = makeAsset({ id: 'asset-two' }) + const assetThree = makeAsset({ id: 'asset-three' }) + + const before = makeVariant([assetOne, assetTwo, assetThree]) + const now = makeVariant([assetTwo, assetOne]) + const actual = productsSync.buildActions(now, before)[0] + const expected = { + action: 'changeAssetOrder', + assetOrder: [assetTwo.id, assetOne.id, assetThree.id], + variantId: 1, + } + + expect(actual).toEqual(expected) + }) + + test('`changeAssetOrder` ignores newly added assets', () => { + const assetOne = makeAsset({ id: 'asset-one' }) + const assetTwo = makeAsset({ id: 'asset-two' }) + const assetThree = makeAsset({ id: 'asset-three' }) + + const before = makeVariant([assetOne, assetTwo]) + const now = makeVariant([assetThree, assetTwo, assetOne]) + const actual = productsSync.buildActions(now, before) + const expected = { + action: 'changeAssetOrder', + assetOrder: [assetTwo.id, assetOne.id], + variantId: 1, + } + + expect(actual[0]).toEqual(expected) + expect(actual[1]).toEqual({ + action: 'addAsset', + asset: assetThree, + variantId: 1, + position: 0, + }) + }) + }) }) }) diff --git a/packages/sync-actions/test/quote-requests-sync.spec.js b/packages/sync-actions/test/quote-requests-sync.spec.js index 1ce072d7f..1375db167 100644 --- a/packages/sync-actions/test/quote-requests-sync.spec.js +++ b/packages/sync-actions/test/quote-requests-sync.spec.js @@ -9,7 +9,9 @@ describe('Exports', () => { describe('action list', () => { test('should contain `changeQuoteRequestState` action', () => { expect(baseActionsList).toEqual( - expect.arrayContaining([{ action: 'changeQuoteRequestState', key: 'quoteRequestState' }]) + expect.arrayContaining([ + { action: 'changeQuoteRequestState', key: 'quoteRequestState' }, + ]) ) }) @@ -34,31 +36,31 @@ describe('Actions', () => { const expected = [ { action: 'changeQuoteRequestState', - ...now - } + ...now, + }, ] expect(actual).toEqual(expected) }) test('should build `transitionState` action', () => { const before = { - state : { - typeId : 'state', - id : 'sid1' - } + state: { + typeId: 'state', + id: 'sid1', + }, } const now = { - state : { - typeId : 'state', - id : 'sid2' - } + state: { + typeId: 'state', + id: 'sid2', + }, } const actual = quoteRequestsSync.buildActions(now, before) const expected = [ { action: 'transitionState', - ...now - } + ...now, + }, ] expect(actual).toEqual(expected) }) diff --git a/packages/sync-actions/test/quotes-sync.spec.js b/packages/sync-actions/test/quotes-sync.spec.js index b0e1d5e14..6862269ff 100644 --- a/packages/sync-actions/test/quotes-sync.spec.js +++ b/packages/sync-actions/test/quotes-sync.spec.js @@ -9,13 +9,17 @@ describe('Exports', () => { describe('action list', () => { test('should contain `changeQuoteState` action', () => { expect(baseActionsList).toEqual( - expect.arrayContaining([{ action: 'changeQuoteState', key: 'quoteState' }]) + expect.arrayContaining([ + { action: 'changeQuoteState', key: 'quoteState' }, + ]) ) }) test('should contain `requestQuoteRenegotiation` action', () => { expect(baseActionsList).toEqual( - expect.arrayContaining([{ action: 'requestQuoteRenegotiation', key: 'buyerComment' }]) + expect.arrayContaining([ + { action: 'requestQuoteRenegotiation', key: 'buyerComment' }, + ]) ) }) @@ -40,8 +44,8 @@ describe('Actions', () => { const expected = [ { action: 'changeQuoteState', - ...now - } + ...now, + }, ] expect(actual).toEqual(expected) }) @@ -53,31 +57,31 @@ describe('Actions', () => { const expected = [ { action: 'requestQuoteRenegotiation', - ...now - } + ...now, + }, ] expect(actual).toEqual(expected) }) test('should build `transitionState` action', () => { const before = { - state : { - typeId : 'state', - id : 'sid1' - } + state: { + typeId: 'state', + id: 'sid1', + }, } const now = { - state : { - typeId : 'state', - id : 'sid2' - } + state: { + typeId: 'state', + id: 'sid2', + }, } const actual = quotesSync.buildActions(now, before) const expected = [ { action: 'transitionState', - ...now - } + ...now, + }, ] expect(actual).toEqual(expected) }) @@ -143,4 +147,4 @@ describe('Actions', () => { ] expect(actual).toEqual(expected) }) -}) \ No newline at end of file +}) diff --git a/packages/sync-actions/test/staged-quotes-sync.spec.js b/packages/sync-actions/test/staged-quotes-sync.spec.js index 57df17a68..503890044 100644 --- a/packages/sync-actions/test/staged-quotes-sync.spec.js +++ b/packages/sync-actions/test/staged-quotes-sync.spec.js @@ -9,13 +9,17 @@ describe('Exports', () => { describe('action list', () => { test('should contain `changeStagedQuoteState` action', () => { expect(baseActionsList).toEqual( - expect.arrayContaining([{ action: 'changeStagedQuoteState', key: 'stagedQuoteState' }]) + expect.arrayContaining([ + { action: 'changeStagedQuoteState', key: 'stagedQuoteState' }, + ]) ) }) test('should contain `setSellerComment` action', () => { expect(baseActionsList).toEqual( - expect.arrayContaining([{ action: 'setSellerComment', key: 'sellerComment' }]) + expect.arrayContaining([ + { action: 'setSellerComment', key: 'sellerComment' }, + ]) ) }) @@ -46,21 +50,23 @@ describe('Actions', () => { const expected = [ { action: 'changeStagedQuoteState', - ...now - } + ...now, + }, ] expect(actual).toEqual(expected) }) test('should build `setSellerComment` action', () => { const before = { sellerComment: '' } - const now = { sellerComment: 'let me know if this matches your expectations' } + const now = { + sellerComment: 'let me know if this matches your expectations', + } const actual = stagedQuotesSync.buildActions(now, before) const expected = [ { action: 'setSellerComment', - ...now - } + ...now, + }, ] expect(actual).toEqual(expected) }) @@ -72,31 +78,31 @@ describe('Actions', () => { const expected = [ { action: 'setValidTo', - ...now - } + ...now, + }, ] expect(actual).toEqual(expected) }) test('should build `transitionState` action', () => { const before = { - state : { - typeId : 'state', - id : 'sid1' - } + state: { + typeId: 'state', + id: 'sid1', + }, } const now = { - state : { - typeId : 'state', - id : 'sid2' - } + state: { + typeId: 'state', + id: 'sid2', + }, } const actual = stagedQuotesSync.buildActions(now, before) const expected = [ { action: 'transitionState', - ...now - } + ...now, + }, ] expect(actual).toEqual(expected) }) diff --git a/packages/sync-actions/test/utils/action-map-custom.spec.js b/packages/sync-actions/test/utils/action-map-custom.spec.js index 82c20612d..194070140 100644 --- a/packages/sync-actions/test/utils/action-map-custom.spec.js +++ b/packages/sync-actions/test/utils/action-map-custom.spec.js @@ -240,7 +240,7 @@ describe('buildActions', () => { expect(actual).toEqual(expected) }) test('throw error if either argument function arguments are not provided', () => { - expect(() => buildActions(null, null)).toThrow(); + expect(() => buildActions(null, null)).toThrow() }) }) }) diff --git a/packages/sync-actions/test/utils/create-build-array-actions.spec.js b/packages/sync-actions/test/utils/create-build-array-actions.spec.js index bce126185..2804a51ce 100644 --- a/packages/sync-actions/test/utils/create-build-array-actions.spec.js +++ b/packages/sync-actions/test/utils/create-build-array-actions.spec.js @@ -76,8 +76,10 @@ describe('createBuildArrayActions', () => { }) test('should throw an error for non array parameter', () => { - expect(() => getDeltaValue('non-array-imput', { sample: 'object' })).toThrow() - }); + expect(() => + getDeltaValue('non-array-imput', { sample: 'object' }) + ).toThrow() + }) test('throw an error if `originalObject` is not provided', () => { const sampleArray = [ { @@ -85,23 +87,23 @@ describe('createBuildArrayActions', () => { heightInMillimeter: 10, lengthInMillimeter: 20, widthInMillimeter: 2, - weightInGram: 5 + weightInGram: 5, }, - trackingData: { trackingId: 'tracking-id-1' } + trackingData: { trackingId: 'tracking-id-1' }, }, { measurements: { heightInMillimeter: 10, lengthInMillimeter: 20, widthInMillimeter: 2, - weightInGram: 5 + weightInGram: 5, }, - trackingData: { trackingId: 'tracking-id-2' } + trackingData: { trackingId: 'tracking-id-2' }, }, - 2 + 2, ] expect(() => getDeltaValue(sampleArray, null)).toThrow() - }); + }) test('throw an error if array is length 3 and second item is 3', () => { const sampleArray = [ { @@ -109,23 +111,23 @@ describe('createBuildArrayActions', () => { heightInMillimeter: 10, lengthInMillimeter: 20, widthInMillimeter: 2, - weightInGram: 5 + weightInGram: 5, }, - trackingData: { trackingId: 'tracking-id-1' } + trackingData: { trackingId: 'tracking-id-1' }, }, { measurements: { heightInMillimeter: 10, lengthInMillimeter: 20, widthInMillimeter: 2, - weightInGram: 5 + weightInGram: 5, }, - trackingData: { trackingId: 'tracking-id-2' } + trackingData: { trackingId: 'tracking-id-2' }, }, - 3 + 3, ] expect(() => getDeltaValue(sampleArray, null)).toThrow() - }); + }) test('throw an error if array is length 3 and second item is 4', () => { const sampleArray = [ { @@ -133,21 +135,21 @@ describe('createBuildArrayActions', () => { heightInMillimeter: 10, lengthInMillimeter: 20, widthInMillimeter: 2, - weightInGram: 5 + weightInGram: 5, }, - trackingData: { trackingId: 'tracking-id-1' } + trackingData: { trackingId: 'tracking-id-1' }, }, { measurements: { heightInMillimeter: 10, lengthInMillimeter: 20, widthInMillimeter: 2, - weightInGram: 5 + weightInGram: 5, }, - trackingData: { trackingId: 'tracking-id-2' } + trackingData: { trackingId: 'tracking-id-2' }, }, - 4 + 4, ] expect(() => getDeltaValue(sampleArray, null)).toThrow() - }); + }) }) diff --git a/yarn.lock b/yarn.lock index 3cb557de8..3e2065b8e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9753,6 +9753,11 @@ lodash.groupby@^4.6.0: resolved "https://registry.yarnpkg.com/lodash.groupby/-/lodash.groupby-4.6.0.tgz#0b08a1dcf68397c397855c3239783832df7403d1" integrity sha512-5dcWxm23+VAoz+awKmBaiBvzox8+RqMgFhi7UvX9DHZr2HdxHXM/Wrf8cfKpsW37RNrvtPn6hSwNqurSILbmJw== +lodash.intersection@^4.4.0: + version "4.4.0" + resolved "https://registry.yarnpkg.com/lodash.intersection/-/lodash.intersection-4.4.0.tgz#0a11ba631d0e95c23c7f2f4cbb9a692ed178e705" + integrity sha512-N+L0cCfnqMv6mxXtSPeKt+IavbOBBSiAEkKyLasZ8BVcP9YXQgxLO12oPR8OyURwKV8l5vJKiE1M8aS70heuMg== + lodash.isarguments@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" @@ -9902,7 +9907,7 @@ lodash.uniqwith@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniqwith/-/lodash.uniqwith-4.5.0.tgz#7a0cbf65f43b5928625a9d4d0dc54b18cadc7ef3" integrity sha512-7lYL8bLopMoy4CTICbxygAUq6CdRJ36vFc80DucPueUee+d5NBRxz3FdT9Pes/HEx5mPoT9jwnsEJWz1N7uq7Q== -lodash.without@~4.4.0: +lodash.without@^4.4.0, lodash.without@~4.4.0: version "4.4.0" resolved "https://registry.yarnpkg.com/lodash.without/-/lodash.without-4.4.0.tgz#3cd4574a00b67bae373a94b748772640507b7aac" integrity sha512-M3MefBwfDhgKgINVuBJCO1YR3+gf6s9HNJsIiZ/Ru77Ws6uTb9eBuvrkpzO+9iLoAaRodGuq7tyrPCx+74QYGQ==