@labdigital/commercetools-mock 3.0.0-beta.1 → 3.0.0-beta.3

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.
@@ -131,7 +131,9 @@ declare class OrderRepository extends AbstractResourceRepository<"order"> {
131
131
  private lineItemFromImportDraft;
132
132
  private customLineItemFromImportDraft;
133
133
  getWithOrderNumber(context: RepositoryContext, orderNumber: string, params?: QueryParams$1): Promise<Order | undefined>;
134
- createShippingInfo(context: RepositoryContext, resource: Writable<Order>, shippingMethodRef: ShippingMethodReference): Promise<ShippingInfo>;
134
+ createShippingInfo(context: RepositoryContext, resource: Writable<Order>, shippingMethodRef: ShippingMethodReference): Promise<Writable<ShippingInfo>>;
135
+ private shippingInfoFromImportDraft;
136
+ private deliveriesFromImportDraft;
135
137
  search(context: RepositoryContext, searchRequest: OrderSearchRequest): Promise<OrderPagedSearchResponse>;
136
138
  }
137
139
  //#endregion
@@ -1715,4 +1717,4 @@ type Config = {
1715
1717
  };
1716
1718
  //#endregion
1717
1719
  export { QueryParams as a, ResourceType as c, ProjectStorage as i, RepositoryMap as l, AbstractStorage as n, PagedQueryResponseMap as o, GetParams as r, ResourceMap as s, Config as t, GetParams$1 as u };
1718
- //# sourceMappingURL=config-BcNSzPZz.d.mts.map
1720
+ //# sourceMappingURL=config-BGZiZhn4.d.mts.map
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as QueryParams, c as ResourceType, i as ProjectStorage, l as RepositoryMap, n as AbstractStorage, o as PagedQueryResponseMap, r as GetParams, s as ResourceMap, t as Config, u as GetParams$1 } from "./config-BcNSzPZz.mjs";
1
+ import { a as QueryParams, c as ResourceType, i as ProjectStorage, l as RepositoryMap, n as AbstractStorage, o as PagedQueryResponseMap, r as GetParams, s as ResourceMap, t as Config, u as GetParams$1 } from "./config-BGZiZhn4.mjs";
2
2
  import * as fastify from "fastify";
3
3
  import { FastifyBaseLogger, FastifyBaseLogger as FastifyBaseLogger$1, FastifyInstance } from "fastify";
4
4
  import * as msw from "msw";
package/dist/index.mjs CHANGED
@@ -3120,21 +3120,7 @@ var OrderRepository = class extends AbstractResourceRepository {
3120
3120
  customLineItems,
3121
3121
  totalPrice: createCentPrecisionMoney(draft.totalPrice)
3122
3122
  };
3123
- if (draft.shippingInfo?.shippingMethod) {
3124
- const { ...shippingMethodRef } = draft.shippingInfo.shippingMethod;
3125
- if (shippingMethodRef.key && !shippingMethodRef.id) {
3126
- const shippingMethod = await this._storage.getByResourceIdentifier(context.projectKey, shippingMethodRef);
3127
- if (!shippingMethod) throw new CommercetoolsError({
3128
- code: "General",
3129
- message: `A shipping method with key '${shippingMethodRef.key}' does not exist.`
3130
- });
3131
- shippingMethodRef.id = shippingMethod.id;
3132
- }
3133
- resource.shippingInfo = await this.createShippingInfo(context, resource, {
3134
- typeId: "shipping-method",
3135
- id: shippingMethodRef.id
3136
- });
3137
- }
3123
+ if (draft.shippingInfo) resource.shippingInfo = await this.shippingInfoFromImportDraft(context, resource, draft.shippingInfo);
3138
3124
  const { taxedPrice, taxedShippingPrice } = calculateTaxTotals({
3139
3125
  lineItems: resource.lineItems,
3140
3126
  customLineItems: resource.customLineItems,
@@ -3256,6 +3242,39 @@ var OrderRepository = class extends AbstractResourceRepository {
3256
3242
  deliveries: []
3257
3243
  };
3258
3244
  }
3245
+ async shippingInfoFromImportDraft(context, resource, draft) {
3246
+ if (!draft.shippingMethod) return;
3247
+ const { ...shippingMethodRef } = draft.shippingMethod;
3248
+ if (shippingMethodRef.key && !shippingMethodRef.id) {
3249
+ const shippingMethod = await this._storage.getByResourceIdentifier(context.projectKey, shippingMethodRef);
3250
+ if (!shippingMethod) throw new CommercetoolsError({
3251
+ code: "General",
3252
+ message: `A shipping method with key '${shippingMethodRef.key}' does not exist.`
3253
+ });
3254
+ shippingMethodRef.id = shippingMethod.id;
3255
+ }
3256
+ const shippingInfo = await this.createShippingInfo(context, resource, {
3257
+ typeId: "shipping-method",
3258
+ id: shippingMethodRef.id
3259
+ });
3260
+ shippingInfo.deliveries = await this.deliveriesFromImportDraft(context, draft);
3261
+ return shippingInfo;
3262
+ }
3263
+ async deliveriesFromImportDraft(context, draft) {
3264
+ if (!draft.deliveries) return [];
3265
+ return Promise.all(draft.deliveries.map(async (deliveryDraft) => ({
3266
+ ...getBaseResourceProperties(),
3267
+ key: deliveryDraft.key,
3268
+ items: deliveryDraft.items ?? [],
3269
+ parcels: await Promise.all(deliveryDraft.parcels?.map(async (parcel) => ({
3270
+ ...getBaseResourceProperties(),
3271
+ ...parcel,
3272
+ custom: await createCustomFields(parcel.custom, context.projectKey, this._storage)
3273
+ })) ?? []),
3274
+ address: createAddress(deliveryDraft.address, context.projectKey, this._storage),
3275
+ custom: await createCustomFields(deliveryDraft.custom, context.projectKey, this._storage)
3276
+ })));
3277
+ }
3259
3278
  async search(context, searchRequest) {
3260
3279
  return await this._searchService.search(context.projectKey, searchRequest);
3261
3280
  }