diff --git a/.changeset/seven-tools-brake.md b/.changeset/seven-tools-brake.md new file mode 100644 index 000000000..9c668fc95 --- /dev/null +++ b/.changeset/seven-tools-brake.md @@ -0,0 +1,5 @@ +--- +'@commercetools/sync-actions': minor +--- + +Fix action keys for changeMyBusinessUnitStatusOnCreation, setMyBusinessUnitAssociateRoleOnCreation and changeCustomerSearchStatus diff --git a/packages/sync-actions/src/projects-actions.js b/packages/sync-actions/src/projects-actions.js index 9fe974563..ebd9e9e93 100644 --- a/packages/sync-actions/src/projects-actions.js +++ b/packages/sync-actions/src/projects-actions.js @@ -7,15 +7,26 @@ export const baseActionsList = [ { action: 'changeLanguages', key: 'languages' }, { action: 'changeMessagesConfiguration', key: 'messagesConfiguration' }, { action: 'setShippingRateInputType', key: 'shippingRateInputType' }, +] + +export const myBusinessUnitActionsList = [ { action: 'changeMyBusinessUnitStatusOnCreation', key: 'myBusinessUnitStatusOnCreation', + actionKey: 'status', }, { action: 'setMyBusinessUnitAssociateRoleOnCreation', key: 'myBusinessUnitAssociateRoleOnCreation', + actionKey: 'associateRole', + }, +] + +export const customerSearchActionsList = [ + { + action: 'changeCustomerSearchStatus', + key: 'status', }, - { action: 'changeCustomerSearchStatus', key: 'customerSearchStatus' }, ] export function actionsMapBase(diff, oldObj, newObj, config = {}) { @@ -27,3 +38,37 @@ export function actionsMapBase(diff, oldObj, newObj, config = {}) { shouldOmitEmptyString: config.shouldOmitEmptyString, }) } + +export const actionsMapBusinessUnit = (diff, oldObj, newObj) => { + const { businessUnits } = diff + if (!businessUnits) { + return [] + } + + return buildBaseAttributesActions({ + actions: myBusinessUnitActionsList, + diff: businessUnits, + oldObj: oldObj.businessUnits, + newObj: newObj.businessUnits, + }) +} + +export function actionsMapSearchIndexingConfiguration(diff, oldObj, newObj) { + const { searchIndexing } = diff + + if (!searchIndexing) { + return [] + } + + const { customers } = searchIndexing + if (!customers) { + return [] + } + + return buildBaseAttributesActions({ + actions: customerSearchActionsList, + diff: diff.searchIndexing.customers, + oldObj: oldObj.searchIndexing.customers, + newObj: newObj.searchIndexing.customers, + }) +} diff --git a/packages/sync-actions/src/projects.js b/packages/sync-actions/src/projects.js index 1e593efeb..130b65548 100644 --- a/packages/sync-actions/src/projects.js +++ b/packages/sync-actions/src/projects.js @@ -1,10 +1,18 @@ import flatten from 'lodash.flatten' import createBuildActions from './utils/create-build-actions' import createMapActionGroup from './utils/create-map-action-group' -import { actionsMapBase } from './projects-actions' +import { + actionsMapBase, + actionsMapBusinessUnit, + actionsMapSearchIndexingConfiguration, +} from './projects-actions' import * as diffpatcher from './utils/diffpatcher' -export const actionGroups = ['base'] +export const actionGroups = [ + 'base', + 'businessUnit', + 'searchIndexingConfiguration', +] function createChannelsMapActions(mapActionGroup, syncActionConfig) { return function doMapActions(diff, newObj, oldObj) { @@ -16,6 +24,18 @@ function createChannelsMapActions(mapActionGroup, syncActionConfig) { ) ) + allActions.push( + mapActionGroup('businessUnit', () => + actionsMapBusinessUnit(diff, oldObj, newObj) + ) + ) + + allActions.push( + mapActionGroup('searchIndexingConfiguration', () => + actionsMapSearchIndexingConfiguration(diff, oldObj, newObj) + ) + ) + return flatten(allActions) } } diff --git a/packages/sync-actions/test/projects-sync.spec.js b/packages/sync-actions/test/projects-sync.spec.js index cdd427eab..d58846917 100644 --- a/packages/sync-actions/test/projects-sync.spec.js +++ b/packages/sync-actions/test/projects-sync.spec.js @@ -1,9 +1,17 @@ import createProjectsSync, { actionGroups } from '../src/projects' -import { baseActionsList } from '../src/projects-actions' +import { + baseActionsList, + myBusinessUnitActionsList, + customerSearchActionsList, +} from '../src/projects-actions' describe('Exports', () => { test('action group list', () => { - expect(actionGroups).toEqual(['base']) + expect(actionGroups).toEqual([ + 'base', + 'businessUnit', + 'searchIndexingConfiguration', + ]) }) describe('action list', () => { @@ -66,33 +74,35 @@ describe('Exports', () => { }) test('should contain `changeMyBusinessUnitStatusOnCreation` action', () => { - expect(baseActionsList).toEqual( + expect(myBusinessUnitActionsList).toEqual( expect.arrayContaining([ { action: 'changeMyBusinessUnitStatusOnCreation', key: 'myBusinessUnitStatusOnCreation', + actionKey: 'status', }, ]) ) }) test('should contain `setMyBusinessUnitAssociateRoleOnCreation` action', () => { - expect(baseActionsList).toEqual( + expect(myBusinessUnitActionsList).toEqual( expect.arrayContaining([ { action: 'setMyBusinessUnitAssociateRoleOnCreation', key: 'myBusinessUnitAssociateRoleOnCreation', + actionKey: 'associateRole', }, ]) ) }) test('should contain `changeCustomerSearchStatus` action', () => { - expect(baseActionsList).toEqual( + expect(customerSearchActionsList).toEqual( expect.arrayContaining([ { action: 'changeCustomerSearchStatus', - key: 'customerSearchStatus', + key: 'status', }, ]) ) @@ -247,13 +257,17 @@ describe('Actions', () => { }) test('should build `changeMyBusinessUnitStatusOnCreation` action', () => { - const before = { myBusinessUnitStatusOnCreation: 'Active' } - const now = { myBusinessUnitStatusOnCreation: 'Deactive' } + const before = { + businessUnits: { myBusinessUnitStatusOnCreation: 'Active' }, + } + const now = { + businessUnits: { myBusinessUnitStatusOnCreation: 'Inactive' }, + } const actual = projectsSync.buildActions(now, before) const expected = [ { action: 'changeMyBusinessUnitStatusOnCreation', - ...now, + status: 'Inactive', }, ] expect(actual).toEqual(expected) @@ -261,35 +275,63 @@ describe('Actions', () => { test('should build `setMyBusinessUnitAssociateRoleOnCreation` action', () => { const before = { - myBusinessUnitAssociateRoleOnCreation: { - typeId: 'associate-role', - key: 'old-role', + businessUnits: { + myBusinessUnitAssociateRoleOnCreation: { + typeId: 'associate-role', + key: 'old-role', + }, }, } const now = { - myBusinessUnitAssociateRoleOnCreation: { - typeId: 'associate-role', - key: 'new-role', + businessUnits: { + myBusinessUnitAssociateRoleOnCreation: { + typeId: 'associate-role', + key: 'new-role', + }, }, } const actual = projectsSync.buildActions(now, before) const expected = [ { action: 'setMyBusinessUnitAssociateRoleOnCreation', - ...now, + associateRole: { + typeId: 'associate-role', + key: 'new-role', + }, }, ] expect(actual).toEqual(expected) }) test('should build `changeCustomerSearchStatus` action', () => { - const before = { customerSearchStatus: 'Activated' } - const now = { customerSearchStatus: 'Deactivated' } + const before = { + searchIndexing: { + customers: { + status: 'Activated', + lastModifiedAt: '2024-05-31T08:20:26.187Z', + lastModifiedBy: { + isPlatformClient: true, + }, + }, + }, + } + + const now = { + searchIndexing: { + customers: { + status: 'Deactivated', + lastModifiedAt: '2024-05-31T08:20:26.187Z', + lastModifiedBy: { + isPlatformClient: true, + }, + }, + }, + } const actual = projectsSync.buildActions(now, before) const expected = [ { action: 'changeCustomerSearchStatus', - ...now, + status: 'Deactivated', }, ] expect(actual).toEqual(expected)