@labdigital/commercetools-mock 2.38.0 → 2.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3208,6 +3208,11 @@ var CartDiscountUpdateHandler = class extends AbstractUpdateHandler {
3208
3208
  setKey(context, resource, { key }) {
3209
3209
  resource.key = key;
3210
3210
  }
3211
+ setStores(context, resource, { stores }) {
3212
+ resource.stores = stores?.map(
3213
+ (s) => getStoreKeyReference(s, context.projectKey, this._storage)
3214
+ );
3215
+ }
3211
3216
  setValidFrom(context, resource, { validFrom }) {
3212
3217
  resource.validFrom = validFrom;
3213
3218
  }
@@ -3942,6 +3947,23 @@ var CustomerRepository = class extends AbstractResourceRepository {
3942
3947
  const billingAddressIds = draft.billingAddresses?.map(
3943
3948
  (addressId) => lookupAdressId(addresses, addressId)
3944
3949
  ) ?? [];
3950
+ let storesForCustomer = [];
3951
+ if (draft.stores) {
3952
+ const storeIds = draft.stores.map((storeReference) => storeReference.id).filter(Boolean);
3953
+ const stores = this._storage.query(context.projectKey, "store", {
3954
+ where: storeIds.map((id) => `id="${id}"`)
3955
+ }).results;
3956
+ if (storeIds.length !== stores.length) {
3957
+ throw new CommercetoolsError({
3958
+ code: "ResourceNotFound",
3959
+ message: `Store with ID '${storeIds.find((id) => !stores.some((store) => store.id === id))}' was not found.`
3960
+ });
3961
+ }
3962
+ storesForCustomer = draft.stores.map((storeReference) => ({
3963
+ typeId: "store",
3964
+ key: storeReference.key ?? stores.find((store) => store.id === storeReference.id)?.key
3965
+ }));
3966
+ }
3945
3967
  const resource = {
3946
3968
  ...getBaseResourceProperties(),
3947
3969
  key: draft.key,
@@ -3967,7 +3989,7 @@ var CustomerRepository = class extends AbstractResourceRepository {
3967
3989
  context.projectKey,
3968
3990
  this._storage
3969
3991
  ),
3970
- stores: []
3992
+ stores: storesForCustomer
3971
3993
  };
3972
3994
  return this.saveNew(context, resource);
3973
3995
  }