Skip to content

Commit

Permalink
Improve mocking of customer updates.
Browse files Browse the repository at this point in the history
This includes adding support for:
 - `removeAddress`,
 - `removeBillingAddressId`
 - `removeShippingAddressId`
 - `setCustomerGroup`
 - `setDateOfBirth`
 - `setDefaultShippingAddress`
 - `setDefaultBillingAddress`
 - `setMiddleName`
 - `setTitle`

This change also improves the testing of some actions and introduces
`fishery` as dependency to ease the test creation
  • Loading branch information
mvantellingen committed Oct 22, 2024
1 parent 3a148e0 commit ac90ac3
Show file tree
Hide file tree
Showing 6 changed files with 713 additions and 209 deletions.
8 changes: 8 additions & 0 deletions .changeset/gorgeous-turtles-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@labdigital/commercetools-mock": minor
---

Improve mocking of customer updates. This includes adding support for
`removeAddress`, `removeBillingAddressId`, `removeShippingAddressId`,
`setCustomerGroup`, `setDateOfBirth`, `setDefaultShippingAddress`,
`setDefaultBillingAddress`, `setMiddleName`, `setTitle`.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"eslint": "^8.57.0",
"eslint-plugin-sort-class-members": "^1.20.0",
"eslint-plugin-unused-imports": "^3.1.0",
"fishery": "^2.2.2",
"got": "^14.2.0",
"husky": "^9.0.11",
"prettier": "^3.2.5",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/repositories/abstract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
BaseResource,
InvalidInputError,
Project,
QueryParam,
ResourceNotFoundError,
Expand Down Expand Up @@ -253,6 +254,22 @@ export class AbstractUpdateHandler {
: (resource as Project).key;

for (const action of actions) {
// Validate if this action exists
// @ts-ignore
if (this[action.action] === undefined) {
console.info(`No handler for action ${action.action}`);
throw new CommercetoolsError<InvalidInputError>({
code: "InvalidInput",
message: `Invalid action ${action.action}`,
errors: [
{
code: "InvalidInput",
message: `Invalid action ${action.action}`,
},
],
});
}

// @ts-ignore
const updateFunc = this[action.action].bind(this);

Expand Down
Loading

0 comments on commit ac90ac3

Please sign in to comment.