@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.js CHANGED
@@ -3171,6 +3171,11 @@ var CartDiscountUpdateHandler = class extends AbstractUpdateHandler {
3171
3171
  setKey(context, resource, { key }) {
3172
3172
  resource.key = key;
3173
3173
  }
3174
+ setStores(context, resource, { stores }) {
3175
+ resource.stores = stores?.map(
3176
+ (s) => getStoreKeyReference(s, context.projectKey, this._storage)
3177
+ );
3178
+ }
3174
3179
  setValidFrom(context, resource, { validFrom }) {
3175
3180
  resource.validFrom = validFrom;
3176
3181
  }
@@ -3905,6 +3910,23 @@ var CustomerRepository = class extends AbstractResourceRepository {
3905
3910
  const billingAddressIds = draft.billingAddresses?.map(
3906
3911
  (addressId) => lookupAdressId(addresses, addressId)
3907
3912
  ) ?? [];
3913
+ let storesForCustomer = [];
3914
+ if (draft.stores) {
3915
+ const storeIds = draft.stores.map((storeReference) => storeReference.id).filter(Boolean);
3916
+ const stores = this._storage.query(context.projectKey, "store", {
3917
+ where: storeIds.map((id) => `id="${id}"`)
3918
+ }).results;
3919
+ if (storeIds.length !== stores.length) {
3920
+ throw new CommercetoolsError({
3921
+ code: "ResourceNotFound",
3922
+ message: `Store with ID '${storeIds.find((id) => !stores.some((store) => store.id === id))}' was not found.`
3923
+ });
3924
+ }
3925
+ storesForCustomer = draft.stores.map((storeReference) => ({
3926
+ typeId: "store",
3927
+ key: storeReference.key ?? stores.find((store) => store.id === storeReference.id)?.key
3928
+ }));
3929
+ }
3908
3930
  const resource = {
3909
3931
  ...getBaseResourceProperties(),
3910
3932
  key: draft.key,
@@ -3930,7 +3952,7 @@ var CustomerRepository = class extends AbstractResourceRepository {
3930
3952
  context.projectKey,
3931
3953
  this._storage
3932
3954
  ),
3933
- stores: []
3955
+ stores: storesForCustomer
3934
3956
  };
3935
3957
  return this.saveNew(context, resource);
3936
3958
  }