commercetools / commercetools/nodejs

Sync actions fail with error on an undefined field

Open
#1,545 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
77
Forks
70
PR merge metrics
No merged PRs in 30d

Description

### Description

I was wondering what is expected behaviour from commercetools nodejs sdk perspective in the following scenario:

1. Create a customer:
```json
{
"key": "abc",
"email": "abc@test.com",
"password": "password"
}
```

2. Use sync actions using the same payload:
```json
{
"key": "abc",
"email": "abc@test.com",
"password": "password"
}
```

It fails with an error:

```shell
TypeError: Cannot read property '0' of undefined
at /node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:496:73
at Array.forEach ()
at buildArrayActions (/node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:484:31)
at actionsMapAddresses (/node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:906:10)
at /node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:951:14
at mapActionGroup (/node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:264:51)
at doMapActions (/node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:950:21)
at Object.buildActions (/node_modules/@commercetools/sync-actions/dist/sync-actions.cjs.js:250:12)
at /packages/data-import/dist/lib/sync.js:37:33
at processTicksAndRejections (internal/process/task_queues.js:97:5)
```

It looks like sync actions fail to merge arrays when the new resource does not have a property defined. In the case of the customer type when a customer is created following properties are defined with empty array `addresses`, `shippingAddressIds`, `billingAddressIds` and `stores`.

### Expected Behavior

Sync actions to skip a property for new resource when old resource has empty array and the property is not defined.

Alternatively, add the property with empty array which enables sync actions to resolve actions accordingly. (probably easier)

### Current Behavior

Throws an error.

### Possible Solution

I'm happy to create PR if that is expected behaviour.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.