Skip to content

Commit 8bebbbd

Browse files
committed
feat(migrate): adding types to create-map-action-group.ts
1 parent 6020384 commit 8bebbbd

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

packages/sync-actions/src/utils/create-map-action-group.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
// { type: 'prices', group: 'allow' },
66
// { type: 'variants', group: 'ignore' },
77
// ]
8-
export default function createMapActionGroup(actionGroups = []) {
9-
return function mapActionGroup(type, fn) {
8+
import { ActionGroup } from '@commercetools/sdk-client-v2'
9+
10+
export default function createMapActionGroup(
11+
actionGroups: Array<ActionGroup> = []
12+
) {
13+
return function mapActionGroup(type: string, fn: () => any) {
1014
if (!Object.keys(actionGroups).length) return fn()
1115

1216
const found = actionGroups.find((c) => c.type === type)
1317
if (!found) return []
1418

1519
// Keep `black` for backwards compatibility.
16-
if (found.group === 'ignore' || found.group === 'black') return []
20+
if (found.group === 'ignore' || (found as any).group === 'black') return []
1721
// Keep `white` for backwards compatibility.
18-
if (found.group === 'allow' || found.group === 'white') return fn()
22+
if (found.group === 'allow' || (found as any).group === 'white') return fn()
1923

2024
throw new Error(
2125
`Action group '${found.group}' not supported. Use either "allow" or "ignore".`

packages/sync-actions/test/utils/create-map-action-group.spec.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import createMapActionGroup from '../../src/utils/create-map-action-group'
2+
import { ActionGroup } from '@commercetools/sdk-client-v2'
23

34
describe('createMapActionGroup', () => {
45
describe('without actionGroups', () => {
@@ -18,7 +19,9 @@ describe('createMapActionGroup', () => {
1819
describe('with found `actionGroup` (type)', () => {
1920
describe('with `group` being `allow`', () => {
2021
const fn = jest.fn()
21-
const actionGroups = [{ type: 'base', group: 'allow' }]
22+
const actionGroups: Array<ActionGroup> = [
23+
{ type: 'base', group: 'allow' },
24+
]
2225
let mapActionGroup
2326

2427
beforeEach(() => {
@@ -33,7 +36,9 @@ describe('createMapActionGroup', () => {
3336

3437
describe('with `group` being `ignore`', () => {
3538
const fn = jest.fn()
36-
const actionGroups = [{ type: 'base', group: 'ignore' }]
39+
const actionGroups: Array<ActionGroup> = [
40+
{ type: 'base', group: 'ignore' },
41+
]
3742
let mapActionGroup
3843

3944
beforeEach(() => {
@@ -52,7 +57,9 @@ describe('createMapActionGroup', () => {
5257
let mapActionGroup
5358

5459
beforeEach(() => {
55-
mapActionGroup = createMapActionGroup(actionGroups)
60+
mapActionGroup = createMapActionGroup(
61+
actionGroups as Array<ActionGroup>
62+
)
5663
})
5764

5865
test('should throw an error', () => {
@@ -74,7 +81,7 @@ describe('createMapActionGroup', () => {
7481

7582
describe('with non found `actionGroup` (type)', () => {
7683
const fn = jest.fn()
77-
const actionGroups = [{ type: 'base', group: 'allow' }]
84+
const actionGroups: Array<ActionGroup> = [{ type: 'base', group: 'allow' }]
7885
let mapActionGroup
7986

8087
beforeEach(() => {

0 commit comments

Comments
 (0)