Skip to content

Commit

Permalink
fix(customer): customer repository allow no stores (#251)
Browse files Browse the repository at this point in the history
Empty arrays for the stores of a customer were wrongfully check for
empty arrays. Fixes issue introduced in #249.
  • Loading branch information
jsm1t authored Nov 21, 2024
1 parent f602b99 commit f61e38d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-bugs-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/commercetools-mock": patch
---

Fix customer not being allowed to have no stores
15 changes: 14 additions & 1 deletion src/repositories/customer/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, test } from "vitest";
import { InMemoryStorage } from "~src/storage";
import { CustomerRepository } from "./index";

describe("Order repository", () => {
describe("Customer repository", () => {
const storage = new InMemoryStorage();
const repository = new CustomerRepository(storage);

Expand Down Expand Up @@ -111,4 +111,17 @@ describe("Order repository", () => {
},
]);
});

test("adding customer without linked stores", async () => {
const result = repository.create(
{ projectKey: "dummy" },
{
email: "my-customer-without-stores@email.com",
stores: [],
},
);

expect(result.email).toEqual("my-customer-without-stores@email.com");
expect(result?.stores).toHaveLength(0);
});
});
2 changes: 1 addition & 1 deletion src/repositories/customer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class CustomerRepository extends AbstractResourceRepository<"customer"> {

let storesForCustomer: StoreKeyReference[] = [];

if (draft.stores) {
if (draft.stores && draft.stores.length > 0) {
const storeIds = draft.stores
.map((storeReference) => storeReference.id)
.filter(Boolean);
Expand Down

0 comments on commit f61e38d

Please sign in to comment.