Skip to content

Commit

Permalink
fix(projects): fix myBusinessUnits and customerSearchStatus action ke…
Browse files Browse the repository at this point in the history
…ys (#1908)

* fix(projects): fix myBusinessUnits and customerSearchStatus action keys

* chore(projects): add changeset

* fix(projects): remove groups and map created actions to project object structure

* chore(project): add groups and rename customer mapping function
  • Loading branch information
ChristianMoll authored Sep 12, 2024
1 parent 3f14b4e commit df373a1
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-tools-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools/sync-actions': minor
---

Fix action keys for changeMyBusinessUnitStatusOnCreation, setMyBusinessUnitAssociateRoleOnCreation and changeCustomerSearchStatus
47 changes: 46 additions & 1 deletion packages/sync-actions/src/projects-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand All @@ -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,
})
}
24 changes: 22 additions & 2 deletions packages/sync-actions/src/projects.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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)
}
}
Expand Down
80 changes: 61 additions & 19 deletions packages/sync-actions/test/projects-sync.spec.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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',
},
])
)
Expand Down Expand Up @@ -247,49 +257,81 @@ 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)
})

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)
Expand Down

0 comments on commit df373a1

Please sign in to comment.