@labdigital/commercetools-mock 1.10.0 → 2.0.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 +171 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +171 -79
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/constants.ts +2 -4
- package/src/ctMock.ts +81 -50
- package/src/index.test.ts +54 -20
- package/src/lib/proxy.ts +4 -4
- package/src/repositories/cart.ts +48 -0
- package/src/repositories/product-selection.ts +14 -5
- package/src/services/cart.test.ts +87 -0
- package/src/services/index.ts +9 -4
- package/src/services/product-selection.test.ts +36 -0
- package/src/services/product-selection.ts +16 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import * as ctp from '@commercetools/platform-sdk';
|
|
3
|
-
import { Project, ResourceIdentifier, QueryParam, AssociateRoleDraft, AssociateRole, AssociateRoleSetNameAction, AssociateRoleSetPermissionsAction, AssociateRoleChangeBuyerAssignableAction, AssociateRoleSetCustomFieldAction, AssociateRoleAddPermissionAction, AssociateRoleRemovePermissionAction, AttributeGroupDraft, AttributeGroup, AttributeGroupSetAttributesAction, AttributeGroupChangeNameAction, AttributeGroupSetDescriptionAction, AttributeGroupSetKeyAction, BusinessUnitDraft, BusinessUnit, BusinessUnitAddAddressAction, BusinessUnitAddAssociateAction, BusinessUnitSetAssociatesAction, BusinessUnitSetContactEmailAction, BusinessUnitSetStoreModeAction, BusinessUnitChangeNameAction, BusinessUnitChangeAddressAction, BusinessUnitAddStoreAction, BusinessUnitChangeParentUnitAction, BusinessUnitChangeStatusAction, CartDraft, Cart, CartAddLineItemAction, CartChangeLineItemQuantityAction, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetShippingMethodAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetShippingAddressAction, CartRemoveDiscountCodeAction, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CartDiscountUpdateAction, AssetDraft, Asset, CategoryDraft, Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategorySetKeyAction, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, CategorySetCustomTypeAction, CategorySetCustomFieldAction, CategoryRemoveAssetAction, CategoryAddAssetAction, ChannelDraft, Channel, ChannelUpdateAction, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerChangeEmailAction, CustomerSetAuthenticationModeAction, CustomerSetCustomFieldAction, CustomerGroupDraft, CustomerGroup, CustomerGroupSetKeyAction, CustomerGroupChangeNameAction, CustomerGroupSetCustomTypeAction, CustomerGroupSetCustomFieldAction, DiscountCodeDraft, DiscountCode, DiscountCodeUpdateAction, Extension, ExtensionDraft, ExtensionUpdateAction, InventoryEntryDraft, InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetRestockableInDaysAction, OrderFromCartDraft, Order, CartReference, OrderImportDraft, OrderAddPaymentAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderTransitionStateAction, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentTransitionStateAction, ProductDraft, Product, ProductUpdateAction, ProductDiscountDraft, ProductDiscount, ProductDiscountUpdateAction, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection,
|
|
3
|
+
import { Project, ResourceIdentifier, QueryParam, AssociateRoleDraft, AssociateRole, AssociateRoleSetNameAction, AssociateRoleSetPermissionsAction, AssociateRoleChangeBuyerAssignableAction, AssociateRoleSetCustomFieldAction, AssociateRoleAddPermissionAction, AssociateRoleRemovePermissionAction, AttributeGroupDraft, AttributeGroup, AttributeGroupSetAttributesAction, AttributeGroupChangeNameAction, AttributeGroupSetDescriptionAction, AttributeGroupSetKeyAction, BusinessUnitDraft, BusinessUnit, BusinessUnitAddAddressAction, BusinessUnitAddAssociateAction, BusinessUnitSetAssociatesAction, BusinessUnitSetContactEmailAction, BusinessUnitSetStoreModeAction, BusinessUnitChangeNameAction, BusinessUnitChangeAddressAction, BusinessUnitAddStoreAction, BusinessUnitChangeParentUnitAction, BusinessUnitChangeStatusAction, CartDraft, Cart, CartAddLineItemAction, CartAddItemShippingAddressAction, CartChangeLineItemQuantityAction, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetShippingMethodAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetLineItemShippingDetailsAction, CartSetShippingAddressAction, CartRemoveDiscountCodeAction, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CartDiscountUpdateAction, AssetDraft, Asset, CategoryDraft, Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategorySetKeyAction, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, CategorySetCustomTypeAction, CategorySetCustomFieldAction, CategoryRemoveAssetAction, CategoryAddAssetAction, ChannelDraft, Channel, ChannelUpdateAction, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerChangeEmailAction, CustomerSetAuthenticationModeAction, CustomerSetCustomFieldAction, CustomerGroupDraft, CustomerGroup, CustomerGroupSetKeyAction, CustomerGroupChangeNameAction, CustomerGroupSetCustomTypeAction, CustomerGroupSetCustomFieldAction, DiscountCodeDraft, DiscountCode, DiscountCodeUpdateAction, Extension, ExtensionDraft, ExtensionUpdateAction, InventoryEntryDraft, InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetRestockableInDaysAction, OrderFromCartDraft, Order, CartReference, OrderImportDraft, OrderAddPaymentAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderTransitionStateAction, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentTransitionStateAction, ProductDraft, Product, ProductUpdateAction, ProductDiscountDraft, ProductDiscount, ProductDiscountUpdateAction, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ProductSelectionUpdateAction, ProductTypeDraft, ProductType, AttributeDefinitionDraft, AttributeDefinition, ProductTypeUpdateAction, ProjectUpdateAction, QuoteDraft, Quote, QuoteUpdateAction, QuoteRequestDraft, QuoteRequest, QuoteRequestUpdateAction, ReviewDraft, Review, ReviewUpdateAction, ShippingMethodDraft, ShippingMethod, ShippingMethodUpdateAction, ShoppingListDraft, ShoppingList, StagedQuoteDraft, StagedQuote, StagedQuoteUpdateAction, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, DiscountedPriceDraft, StandalonePriceChangeActiveAction, StandalonePriceChangeValueAction, StandalonePriceSetDiscountedPriceAction, StateDraft, State, StateUpdateAction, StoreDraft, Store, StoreUpdateAction, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TaxCategoryUpdateAction, TypeDraft, Type, TypeUpdateAction, ZoneDraft, Zone, ZoneUpdateAction, BaseResource, UpdateAction } from '@commercetools/platform-sdk';
|
|
4
4
|
|
|
5
5
|
type GetParams$1 = {
|
|
6
6
|
expand?: string[];
|
|
@@ -80,6 +80,7 @@ declare class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
80
80
|
getActiveCart(projectKey: string): Cart | undefined;
|
|
81
81
|
actions: {
|
|
82
82
|
addLineItem: (context: RepositoryContext, resource: Writable<Cart>, { productId, variantId, sku, quantity }: CartAddLineItemAction) => void;
|
|
83
|
+
addItemShippingAddress: (context: RepositoryContext, resource: Writable<Cart>, { action, address }: CartAddItemShippingAddressAction) => void;
|
|
83
84
|
changeLineItemQuantity: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, lineItemKey, quantity }: CartChangeLineItemQuantityAction) => void;
|
|
84
85
|
removeLineItem: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, quantity }: CartRemoveLineItemAction) => void;
|
|
85
86
|
setBillingAddress: (context: RepositoryContext, resource: Writable<Cart>, { address }: CartSetBillingAddressAction) => void;
|
|
@@ -89,6 +90,7 @@ declare class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
89
90
|
setCustomField: (context: RepositoryContext, resource: Cart, { name, value }: CartSetCustomFieldAction) => void;
|
|
90
91
|
setCustomType: (context: RepositoryContext, resource: Writable<Cart>, { type, fields }: CartSetCustomTypeAction) => void;
|
|
91
92
|
setLocale: (context: RepositoryContext, resource: Writable<Cart>, { locale }: CartSetLocaleAction) => void;
|
|
93
|
+
setLineItemShippingDetails: (context: RepositoryContext, resource: Writable<Cart>, { action, shippingDetails, lineItemId, lineItemKey, }: CartSetLineItemShippingDetailsAction) => void;
|
|
92
94
|
setShippingAddress: (context: RepositoryContext, resource: Writable<Cart>, { address }: CartSetShippingAddressAction) => void;
|
|
93
95
|
removeDiscountCode: (context: RepositoryContext, resource: Writable<Cart>, { discountCode }: CartRemoveDiscountCodeAction) => void;
|
|
94
96
|
};
|
|
@@ -331,7 +333,7 @@ declare class ProductProjectionRepository extends AbstractResourceRepository<'pr
|
|
|
331
333
|
declare class ProductSelectionRepository extends AbstractResourceRepository<'product-selection'> {
|
|
332
334
|
getTypeId(): "product-selection";
|
|
333
335
|
create(context: RepositoryContext, draft: ProductSelectionDraft): ProductSelection;
|
|
334
|
-
actions: Partial<Record<
|
|
336
|
+
actions: Partial<Record<ProductSelectionUpdateAction['action'], (context: RepositoryContext, resource: Writable<ProductSelection>, action: any) => void>>;
|
|
335
337
|
}
|
|
336
338
|
|
|
337
339
|
declare class ProductTypeRepository extends AbstractResourceRepository<'product-type'> {
|
|
@@ -628,7 +630,7 @@ declare class CommercetoolsMock {
|
|
|
628
630
|
options: CommercetoolsMockOptions;
|
|
629
631
|
private _storage;
|
|
630
632
|
private _oauth2;
|
|
631
|
-
private
|
|
633
|
+
private _mswServer;
|
|
632
634
|
private _services;
|
|
633
635
|
private _repositories;
|
|
634
636
|
private _projectService?;
|
|
@@ -639,8 +641,7 @@ declare class CommercetoolsMock {
|
|
|
639
641
|
project(projectKey?: string): ProjectAPI;
|
|
640
642
|
runServer(port?: number, options?: AppOptions): void;
|
|
641
643
|
private createApp;
|
|
642
|
-
private
|
|
643
|
-
private mockAuthHost;
|
|
644
|
+
private startServer;
|
|
644
645
|
}
|
|
645
646
|
|
|
646
647
|
declare const getBaseResourceProperties: () => {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import * as ctp from '@commercetools/platform-sdk';
|
|
3
|
-
import { Project, ResourceIdentifier, QueryParam, AssociateRoleDraft, AssociateRole, AssociateRoleSetNameAction, AssociateRoleSetPermissionsAction, AssociateRoleChangeBuyerAssignableAction, AssociateRoleSetCustomFieldAction, AssociateRoleAddPermissionAction, AssociateRoleRemovePermissionAction, AttributeGroupDraft, AttributeGroup, AttributeGroupSetAttributesAction, AttributeGroupChangeNameAction, AttributeGroupSetDescriptionAction, AttributeGroupSetKeyAction, BusinessUnitDraft, BusinessUnit, BusinessUnitAddAddressAction, BusinessUnitAddAssociateAction, BusinessUnitSetAssociatesAction, BusinessUnitSetContactEmailAction, BusinessUnitSetStoreModeAction, BusinessUnitChangeNameAction, BusinessUnitChangeAddressAction, BusinessUnitAddStoreAction, BusinessUnitChangeParentUnitAction, BusinessUnitChangeStatusAction, CartDraft, Cart, CartAddLineItemAction, CartChangeLineItemQuantityAction, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetShippingMethodAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetShippingAddressAction, CartRemoveDiscountCodeAction, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CartDiscountUpdateAction, AssetDraft, Asset, CategoryDraft, Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategorySetKeyAction, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, CategorySetCustomTypeAction, CategorySetCustomFieldAction, CategoryRemoveAssetAction, CategoryAddAssetAction, ChannelDraft, Channel, ChannelUpdateAction, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerChangeEmailAction, CustomerSetAuthenticationModeAction, CustomerSetCustomFieldAction, CustomerGroupDraft, CustomerGroup, CustomerGroupSetKeyAction, CustomerGroupChangeNameAction, CustomerGroupSetCustomTypeAction, CustomerGroupSetCustomFieldAction, DiscountCodeDraft, DiscountCode, DiscountCodeUpdateAction, Extension, ExtensionDraft, ExtensionUpdateAction, InventoryEntryDraft, InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetRestockableInDaysAction, OrderFromCartDraft, Order, CartReference, OrderImportDraft, OrderAddPaymentAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderTransitionStateAction, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentTransitionStateAction, ProductDraft, Product, ProductUpdateAction, ProductDiscountDraft, ProductDiscount, ProductDiscountUpdateAction, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection,
|
|
3
|
+
import { Project, ResourceIdentifier, QueryParam, AssociateRoleDraft, AssociateRole, AssociateRoleSetNameAction, AssociateRoleSetPermissionsAction, AssociateRoleChangeBuyerAssignableAction, AssociateRoleSetCustomFieldAction, AssociateRoleAddPermissionAction, AssociateRoleRemovePermissionAction, AttributeGroupDraft, AttributeGroup, AttributeGroupSetAttributesAction, AttributeGroupChangeNameAction, AttributeGroupSetDescriptionAction, AttributeGroupSetKeyAction, BusinessUnitDraft, BusinessUnit, BusinessUnitAddAddressAction, BusinessUnitAddAssociateAction, BusinessUnitSetAssociatesAction, BusinessUnitSetContactEmailAction, BusinessUnitSetStoreModeAction, BusinessUnitChangeNameAction, BusinessUnitChangeAddressAction, BusinessUnitAddStoreAction, BusinessUnitChangeParentUnitAction, BusinessUnitChangeStatusAction, CartDraft, Cart, CartAddLineItemAction, CartAddItemShippingAddressAction, CartChangeLineItemQuantityAction, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetShippingMethodAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetLineItemShippingDetailsAction, CartSetShippingAddressAction, CartRemoveDiscountCodeAction, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CartDiscountUpdateAction, AssetDraft, Asset, CategoryDraft, Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategorySetKeyAction, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, CategorySetCustomTypeAction, CategorySetCustomFieldAction, CategoryRemoveAssetAction, CategoryAddAssetAction, ChannelDraft, Channel, ChannelUpdateAction, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerChangeEmailAction, CustomerSetAuthenticationModeAction, CustomerSetCustomFieldAction, CustomerGroupDraft, CustomerGroup, CustomerGroupSetKeyAction, CustomerGroupChangeNameAction, CustomerGroupSetCustomTypeAction, CustomerGroupSetCustomFieldAction, DiscountCodeDraft, DiscountCode, DiscountCodeUpdateAction, Extension, ExtensionDraft, ExtensionUpdateAction, InventoryEntryDraft, InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetRestockableInDaysAction, OrderFromCartDraft, Order, CartReference, OrderImportDraft, OrderAddPaymentAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderTransitionStateAction, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentTransitionStateAction, ProductDraft, Product, ProductUpdateAction, ProductDiscountDraft, ProductDiscount, ProductDiscountUpdateAction, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ProductSelectionUpdateAction, ProductTypeDraft, ProductType, AttributeDefinitionDraft, AttributeDefinition, ProductTypeUpdateAction, ProjectUpdateAction, QuoteDraft, Quote, QuoteUpdateAction, QuoteRequestDraft, QuoteRequest, QuoteRequestUpdateAction, ReviewDraft, Review, ReviewUpdateAction, ShippingMethodDraft, ShippingMethod, ShippingMethodUpdateAction, ShoppingListDraft, ShoppingList, StagedQuoteDraft, StagedQuote, StagedQuoteUpdateAction, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, DiscountedPriceDraft, StandalonePriceChangeActiveAction, StandalonePriceChangeValueAction, StandalonePriceSetDiscountedPriceAction, StateDraft, State, StateUpdateAction, StoreDraft, Store, StoreUpdateAction, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TaxCategoryUpdateAction, TypeDraft, Type, TypeUpdateAction, ZoneDraft, Zone, ZoneUpdateAction, BaseResource, UpdateAction } from '@commercetools/platform-sdk';
|
|
4
4
|
|
|
5
5
|
type GetParams$1 = {
|
|
6
6
|
expand?: string[];
|
|
@@ -80,6 +80,7 @@ declare class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
80
80
|
getActiveCart(projectKey: string): Cart | undefined;
|
|
81
81
|
actions: {
|
|
82
82
|
addLineItem: (context: RepositoryContext, resource: Writable<Cart>, { productId, variantId, sku, quantity }: CartAddLineItemAction) => void;
|
|
83
|
+
addItemShippingAddress: (context: RepositoryContext, resource: Writable<Cart>, { action, address }: CartAddItemShippingAddressAction) => void;
|
|
83
84
|
changeLineItemQuantity: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, lineItemKey, quantity }: CartChangeLineItemQuantityAction) => void;
|
|
84
85
|
removeLineItem: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, quantity }: CartRemoveLineItemAction) => void;
|
|
85
86
|
setBillingAddress: (context: RepositoryContext, resource: Writable<Cart>, { address }: CartSetBillingAddressAction) => void;
|
|
@@ -89,6 +90,7 @@ declare class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
89
90
|
setCustomField: (context: RepositoryContext, resource: Cart, { name, value }: CartSetCustomFieldAction) => void;
|
|
90
91
|
setCustomType: (context: RepositoryContext, resource: Writable<Cart>, { type, fields }: CartSetCustomTypeAction) => void;
|
|
91
92
|
setLocale: (context: RepositoryContext, resource: Writable<Cart>, { locale }: CartSetLocaleAction) => void;
|
|
93
|
+
setLineItemShippingDetails: (context: RepositoryContext, resource: Writable<Cart>, { action, shippingDetails, lineItemId, lineItemKey, }: CartSetLineItemShippingDetailsAction) => void;
|
|
92
94
|
setShippingAddress: (context: RepositoryContext, resource: Writable<Cart>, { address }: CartSetShippingAddressAction) => void;
|
|
93
95
|
removeDiscountCode: (context: RepositoryContext, resource: Writable<Cart>, { discountCode }: CartRemoveDiscountCodeAction) => void;
|
|
94
96
|
};
|
|
@@ -331,7 +333,7 @@ declare class ProductProjectionRepository extends AbstractResourceRepository<'pr
|
|
|
331
333
|
declare class ProductSelectionRepository extends AbstractResourceRepository<'product-selection'> {
|
|
332
334
|
getTypeId(): "product-selection";
|
|
333
335
|
create(context: RepositoryContext, draft: ProductSelectionDraft): ProductSelection;
|
|
334
|
-
actions: Partial<Record<
|
|
336
|
+
actions: Partial<Record<ProductSelectionUpdateAction['action'], (context: RepositoryContext, resource: Writable<ProductSelection>, action: any) => void>>;
|
|
335
337
|
}
|
|
336
338
|
|
|
337
339
|
declare class ProductTypeRepository extends AbstractResourceRepository<'product-type'> {
|
|
@@ -628,7 +630,7 @@ declare class CommercetoolsMock {
|
|
|
628
630
|
options: CommercetoolsMockOptions;
|
|
629
631
|
private _storage;
|
|
630
632
|
private _oauth2;
|
|
631
|
-
private
|
|
633
|
+
private _mswServer;
|
|
632
634
|
private _services;
|
|
633
635
|
private _repositories;
|
|
634
636
|
private _projectService?;
|
|
@@ -639,8 +641,7 @@ declare class CommercetoolsMock {
|
|
|
639
641
|
project(projectKey?: string): ProjectAPI;
|
|
640
642
|
runServer(port?: number, options?: AppOptions): void;
|
|
641
643
|
private createApp;
|
|
642
|
-
private
|
|
643
|
-
private mockAuthHost;
|
|
644
|
+
private startServer;
|
|
644
645
|
}
|
|
645
646
|
|
|
646
647
|
declare const getBaseResourceProperties: () => {
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// src/ctMock.ts
|
|
2
|
-
import nock from "nock";
|
|
3
2
|
import express2 from "express";
|
|
4
3
|
import supertest from "supertest";
|
|
5
4
|
import morgan from "morgan";
|
|
5
|
+
import { setupServer } from "msw/node";
|
|
6
|
+
import { http, HttpResponse } from "msw";
|
|
6
7
|
|
|
7
8
|
// src/storage/abstract.ts
|
|
8
9
|
var AbstractStorage = class {
|
|
@@ -1378,19 +1379,19 @@ var ProjectAPI = class {
|
|
|
1378
1379
|
|
|
1379
1380
|
// src/lib/proxy.ts
|
|
1380
1381
|
var copyHeaders = (headers) => {
|
|
1381
|
-
const validHeaders = ["accept", "host", "authorization"];
|
|
1382
|
+
const validHeaders = ["accept", "host", "authorization", "content-type"];
|
|
1382
1383
|
const result = {};
|
|
1383
|
-
|
|
1384
|
+
for (const [key, value] of headers.entries()) {
|
|
1384
1385
|
if (validHeaders.includes(key.toLowerCase())) {
|
|
1385
1386
|
result[key] = value;
|
|
1386
1387
|
}
|
|
1387
|
-
}
|
|
1388
|
+
}
|
|
1388
1389
|
return result;
|
|
1389
1390
|
};
|
|
1390
1391
|
|
|
1391
1392
|
// src/constants.ts
|
|
1392
|
-
var DEFAULT_API_HOSTNAME =
|
|
1393
|
-
var DEFAULT_AUTH_HOSTNAME =
|
|
1393
|
+
var DEFAULT_API_HOSTNAME = "https://api.*.commercetools.com";
|
|
1394
|
+
var DEFAULT_AUTH_HOSTNAME = "https://auth.*.commercetools.com";
|
|
1394
1395
|
|
|
1395
1396
|
// src/repositories/helpers.ts
|
|
1396
1397
|
import { v4 as uuidv42 } from "uuid";
|
|
@@ -2152,6 +2153,16 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
2152
2153
|
}
|
|
2153
2154
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
2154
2155
|
},
|
|
2156
|
+
addItemShippingAddress: (context, resource, { action, address }) => {
|
|
2157
|
+
const newAddress = createAddress(
|
|
2158
|
+
address,
|
|
2159
|
+
context.projectKey,
|
|
2160
|
+
this._storage
|
|
2161
|
+
);
|
|
2162
|
+
if (newAddress) {
|
|
2163
|
+
resource.itemShippingAddresses.push(newAddress);
|
|
2164
|
+
}
|
|
2165
|
+
},
|
|
2155
2166
|
changeLineItemQuantity: (context, resource, { lineItemId, lineItemKey, quantity }) => {
|
|
2156
2167
|
let lineItem;
|
|
2157
2168
|
if (lineItemId) {
|
|
@@ -2275,6 +2286,26 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
2275
2286
|
setLocale: (context, resource, { locale }) => {
|
|
2276
2287
|
resource.locale = locale;
|
|
2277
2288
|
},
|
|
2289
|
+
setLineItemShippingDetails: (context, resource, {
|
|
2290
|
+
action,
|
|
2291
|
+
shippingDetails,
|
|
2292
|
+
lineItemId,
|
|
2293
|
+
lineItemKey
|
|
2294
|
+
}) => {
|
|
2295
|
+
const lineItem = resource.lineItems.find(
|
|
2296
|
+
(x) => lineItemId && x.id === lineItemId || lineItemKey && x.key === lineItemKey
|
|
2297
|
+
);
|
|
2298
|
+
if (!lineItem) {
|
|
2299
|
+
throw new CommercetoolsError({
|
|
2300
|
+
code: "General",
|
|
2301
|
+
message: lineItemKey ? `A line item with key '${lineItemKey}' not found.` : `A line item with ID '${lineItemId}' not found.`
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
lineItem.shippingDetails = {
|
|
2305
|
+
...shippingDetails,
|
|
2306
|
+
valid: true
|
|
2307
|
+
};
|
|
2308
|
+
},
|
|
2278
2309
|
setShippingAddress: (context, resource, { address }) => {
|
|
2279
2310
|
if (!address) {
|
|
2280
2311
|
resource.shippingAddress = void 0;
|
|
@@ -4642,6 +4673,7 @@ var ProductSelectionRepository = class extends AbstractResourceRepository {
|
|
|
4642
4673
|
const resource = {
|
|
4643
4674
|
...getBaseResourceProperties(),
|
|
4644
4675
|
productCount: 0,
|
|
4676
|
+
key: draft.key,
|
|
4645
4677
|
name: draft.name,
|
|
4646
4678
|
type: "individual",
|
|
4647
4679
|
mode: "Individual"
|
|
@@ -4649,7 +4681,11 @@ var ProductSelectionRepository = class extends AbstractResourceRepository {
|
|
|
4649
4681
|
this.saveNew(context, resource);
|
|
4650
4682
|
return resource;
|
|
4651
4683
|
}
|
|
4652
|
-
actions = {
|
|
4684
|
+
actions = {
|
|
4685
|
+
changeName: (context, resource, { name }) => {
|
|
4686
|
+
resource.name = name;
|
|
4687
|
+
}
|
|
4688
|
+
};
|
|
4653
4689
|
};
|
|
4654
4690
|
|
|
4655
4691
|
// src/repositories/product-type.ts
|
|
@@ -5649,6 +5685,18 @@ var AssociateRoleServices = class extends AbstractService {
|
|
|
5649
5685
|
}
|
|
5650
5686
|
};
|
|
5651
5687
|
|
|
5688
|
+
// src/services/attribute-group.ts
|
|
5689
|
+
var AttributeGroupService = class extends AbstractService {
|
|
5690
|
+
repository;
|
|
5691
|
+
constructor(parent, repository) {
|
|
5692
|
+
super(parent);
|
|
5693
|
+
this.repository = repository;
|
|
5694
|
+
}
|
|
5695
|
+
getBasePath() {
|
|
5696
|
+
return "attribute-groups";
|
|
5697
|
+
}
|
|
5698
|
+
};
|
|
5699
|
+
|
|
5652
5700
|
// src/services/business-units.ts
|
|
5653
5701
|
var BusinessUnitServices = class extends AbstractService {
|
|
5654
5702
|
repository;
|
|
@@ -5661,6 +5709,18 @@ var BusinessUnitServices = class extends AbstractService {
|
|
|
5661
5709
|
}
|
|
5662
5710
|
};
|
|
5663
5711
|
|
|
5712
|
+
// src/services/cart-discount.ts
|
|
5713
|
+
var CartDiscountService = class extends AbstractService {
|
|
5714
|
+
repository;
|
|
5715
|
+
constructor(parent, repository) {
|
|
5716
|
+
super(parent);
|
|
5717
|
+
this.repository = repository;
|
|
5718
|
+
}
|
|
5719
|
+
getBasePath() {
|
|
5720
|
+
return "cart-discounts";
|
|
5721
|
+
}
|
|
5722
|
+
};
|
|
5723
|
+
|
|
5664
5724
|
// src/services/cart.ts
|
|
5665
5725
|
var CartService = class extends AbstractService {
|
|
5666
5726
|
repository;
|
|
@@ -5699,18 +5759,6 @@ var CartService = class extends AbstractService {
|
|
|
5699
5759
|
}
|
|
5700
5760
|
};
|
|
5701
5761
|
|
|
5702
|
-
// src/services/cart-discount.ts
|
|
5703
|
-
var CartDiscountService = class extends AbstractService {
|
|
5704
|
-
repository;
|
|
5705
|
-
constructor(parent, repository) {
|
|
5706
|
-
super(parent);
|
|
5707
|
-
this.repository = repository;
|
|
5708
|
-
}
|
|
5709
|
-
getBasePath() {
|
|
5710
|
-
return "cart-discounts";
|
|
5711
|
-
}
|
|
5712
|
-
};
|
|
5713
|
-
|
|
5714
5762
|
// src/services/category.ts
|
|
5715
5763
|
var CategoryServices = class extends AbstractService {
|
|
5716
5764
|
repository;
|
|
@@ -5787,6 +5835,18 @@ var CustomObjectService = class extends AbstractService {
|
|
|
5787
5835
|
}
|
|
5788
5836
|
};
|
|
5789
5837
|
|
|
5838
|
+
// src/services/customer-group.ts
|
|
5839
|
+
var CustomerGroupService = class extends AbstractService {
|
|
5840
|
+
repository;
|
|
5841
|
+
constructor(parent, repository) {
|
|
5842
|
+
super(parent);
|
|
5843
|
+
this.repository = repository;
|
|
5844
|
+
}
|
|
5845
|
+
getBasePath() {
|
|
5846
|
+
return "customer-groups";
|
|
5847
|
+
}
|
|
5848
|
+
};
|
|
5849
|
+
|
|
5790
5850
|
// src/services/customer.ts
|
|
5791
5851
|
import { v4 as uuidv48 } from "uuid";
|
|
5792
5852
|
var CustomerService = class extends AbstractService {
|
|
@@ -5818,18 +5878,6 @@ var CustomerService = class extends AbstractService {
|
|
|
5818
5878
|
}
|
|
5819
5879
|
};
|
|
5820
5880
|
|
|
5821
|
-
// src/services/customer-group.ts
|
|
5822
|
-
var CustomerGroupService = class extends AbstractService {
|
|
5823
|
-
repository;
|
|
5824
|
-
constructor(parent, repository) {
|
|
5825
|
-
super(parent);
|
|
5826
|
-
this.repository = repository;
|
|
5827
|
-
}
|
|
5828
|
-
getBasePath() {
|
|
5829
|
-
return "customer-groups";
|
|
5830
|
-
}
|
|
5831
|
-
};
|
|
5832
|
-
|
|
5833
5881
|
// src/services/discount-code.ts
|
|
5834
5882
|
var DiscountCodeService = class extends AbstractService {
|
|
5835
5883
|
repository;
|
|
@@ -6038,18 +6086,6 @@ var PaymentService = class extends AbstractService {
|
|
|
6038
6086
|
}
|
|
6039
6087
|
};
|
|
6040
6088
|
|
|
6041
|
-
// src/services/product.ts
|
|
6042
|
-
var ProductService = class extends AbstractService {
|
|
6043
|
-
repository;
|
|
6044
|
-
constructor(parent, repository) {
|
|
6045
|
-
super(parent);
|
|
6046
|
-
this.repository = repository;
|
|
6047
|
-
}
|
|
6048
|
-
getBasePath() {
|
|
6049
|
-
return "products";
|
|
6050
|
-
}
|
|
6051
|
-
};
|
|
6052
|
-
|
|
6053
6089
|
// src/services/product-discount.ts
|
|
6054
6090
|
var ProductDiscountService = class extends AbstractService {
|
|
6055
6091
|
repository;
|
|
@@ -6112,6 +6148,18 @@ var ProductProjectionService = class extends AbstractService {
|
|
|
6112
6148
|
}
|
|
6113
6149
|
};
|
|
6114
6150
|
|
|
6151
|
+
// src/services/product-selection.ts
|
|
6152
|
+
var ProductSelectionService = class extends AbstractService {
|
|
6153
|
+
repository;
|
|
6154
|
+
constructor(parent, repository) {
|
|
6155
|
+
super(parent);
|
|
6156
|
+
this.repository = repository;
|
|
6157
|
+
}
|
|
6158
|
+
getBasePath() {
|
|
6159
|
+
return "product-selections";
|
|
6160
|
+
}
|
|
6161
|
+
};
|
|
6162
|
+
|
|
6115
6163
|
// src/services/product-type.ts
|
|
6116
6164
|
var ProductTypeService = class extends AbstractService {
|
|
6117
6165
|
repository;
|
|
@@ -6124,6 +6172,18 @@ var ProductTypeService = class extends AbstractService {
|
|
|
6124
6172
|
}
|
|
6125
6173
|
};
|
|
6126
6174
|
|
|
6175
|
+
// src/services/product.ts
|
|
6176
|
+
var ProductService = class extends AbstractService {
|
|
6177
|
+
repository;
|
|
6178
|
+
constructor(parent, repository) {
|
|
6179
|
+
super(parent);
|
|
6180
|
+
this.repository = repository;
|
|
6181
|
+
}
|
|
6182
|
+
getBasePath() {
|
|
6183
|
+
return "products";
|
|
6184
|
+
}
|
|
6185
|
+
};
|
|
6186
|
+
|
|
6127
6187
|
// src/services/shipping-method.ts
|
|
6128
6188
|
var ShippingMethodService = class extends AbstractService {
|
|
6129
6189
|
repository;
|
|
@@ -6236,18 +6296,6 @@ var ZoneService = class extends AbstractService {
|
|
|
6236
6296
|
}
|
|
6237
6297
|
};
|
|
6238
6298
|
|
|
6239
|
-
// src/services/attribute-group.ts
|
|
6240
|
-
var AttributeGroupService = class extends AbstractService {
|
|
6241
|
-
repository;
|
|
6242
|
-
constructor(parent, repository) {
|
|
6243
|
-
super(parent);
|
|
6244
|
-
this.repository = repository;
|
|
6245
|
-
}
|
|
6246
|
-
getBasePath() {
|
|
6247
|
-
return "attribute-groups";
|
|
6248
|
-
}
|
|
6249
|
-
};
|
|
6250
|
-
|
|
6251
6299
|
// src/services/index.ts
|
|
6252
6300
|
var createServices = (router, repos) => ({
|
|
6253
6301
|
"associate-role": new AssociateRoleServices(router, repos["associate-role"]),
|
|
@@ -6292,6 +6340,10 @@ var createServices = (router, repos) => ({
|
|
|
6292
6340
|
router,
|
|
6293
6341
|
repos["product-projection"]
|
|
6294
6342
|
),
|
|
6343
|
+
"product-selection": new ProductSelectionService(
|
|
6344
|
+
router,
|
|
6345
|
+
repos["product-selection"]
|
|
6346
|
+
),
|
|
6295
6347
|
"shopping-list": new ShoppingListService(router, repos["shopping-list"]),
|
|
6296
6348
|
state: new StateService(router, repos["state"]),
|
|
6297
6349
|
store: new StoreService(router, repos["store"]),
|
|
@@ -6314,12 +6366,13 @@ var DEFAULT_OPTIONS = {
|
|
|
6314
6366
|
authHost: DEFAULT_AUTH_HOSTNAME,
|
|
6315
6367
|
silent: false
|
|
6316
6368
|
};
|
|
6369
|
+
var _globalListeners = [];
|
|
6317
6370
|
var CommercetoolsMock = class {
|
|
6318
6371
|
app;
|
|
6319
6372
|
options;
|
|
6320
6373
|
_storage;
|
|
6321
6374
|
_oauth2;
|
|
6322
|
-
|
|
6375
|
+
_mswServer = void 0;
|
|
6323
6376
|
_services;
|
|
6324
6377
|
_repositories;
|
|
6325
6378
|
_projectService;
|
|
@@ -6336,16 +6389,15 @@ var CommercetoolsMock = class {
|
|
|
6336
6389
|
this.app = this.createApp({ silent: this.options.silent });
|
|
6337
6390
|
}
|
|
6338
6391
|
start() {
|
|
6339
|
-
this.
|
|
6340
|
-
this.
|
|
6392
|
+
this.clear();
|
|
6393
|
+
this.startServer();
|
|
6341
6394
|
}
|
|
6342
6395
|
stop() {
|
|
6343
|
-
this.
|
|
6344
|
-
this.
|
|
6345
|
-
this._nockScopes.api?.persist(false);
|
|
6346
|
-
this._nockScopes.api = void 0;
|
|
6396
|
+
this._mswServer?.close();
|
|
6397
|
+
this._mswServer = void 0;
|
|
6347
6398
|
}
|
|
6348
6399
|
clear() {
|
|
6400
|
+
this._mswServer?.resetHandlers();
|
|
6349
6401
|
this._storage.clear();
|
|
6350
6402
|
}
|
|
6351
6403
|
project(projectKey) {
|
|
@@ -6408,25 +6460,65 @@ var CommercetoolsMock = class {
|
|
|
6408
6460
|
});
|
|
6409
6461
|
return app;
|
|
6410
6462
|
}
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
}
|
|
6420
|
-
const response = await supertest(app).delete(uri).set(copyHeaders(this.req.headers)).send(body);
|
|
6421
|
-
return [response.status, response.body];
|
|
6422
|
-
});
|
|
6423
|
-
}
|
|
6424
|
-
mockAuthHost() {
|
|
6463
|
+
startServer() {
|
|
6464
|
+
if (_globalListeners.length > 0) {
|
|
6465
|
+
if (this._mswServer !== void 0) {
|
|
6466
|
+
throw new Error("Server already started");
|
|
6467
|
+
} else {
|
|
6468
|
+
console.warn("Server wasn't stopped properly, clearing");
|
|
6469
|
+
_globalListeners.forEach((listener) => listener.close());
|
|
6470
|
+
}
|
|
6471
|
+
}
|
|
6425
6472
|
const app = this.app;
|
|
6426
|
-
this.
|
|
6427
|
-
|
|
6428
|
-
|
|
6473
|
+
this._mswServer = setupServer(
|
|
6474
|
+
http.post(`${this.options.authHost}/oauth/*`, async ({ request }) => {
|
|
6475
|
+
const text = await request.text();
|
|
6476
|
+
const url = new URL(request.url);
|
|
6477
|
+
const res = await supertest(app).post(url.pathname + "?" + url.searchParams.toString()).set(copyHeaders(request.headers)).send(text);
|
|
6478
|
+
return new HttpResponse(res.text, {
|
|
6479
|
+
status: res.status,
|
|
6480
|
+
headers: res.headers
|
|
6481
|
+
});
|
|
6482
|
+
}),
|
|
6483
|
+
http.get(`${this.options.apiHost}/*`, async ({ request }) => {
|
|
6484
|
+
const body = await request.text();
|
|
6485
|
+
const url = new URL(request.url);
|
|
6486
|
+
const res = await supertest(app).get(url.pathname + "?" + url.searchParams.toString()).set(copyHeaders(request.headers)).send(body);
|
|
6487
|
+
return new HttpResponse(res.text, {
|
|
6488
|
+
status: res.status,
|
|
6489
|
+
headers: res.headers
|
|
6490
|
+
});
|
|
6491
|
+
}),
|
|
6492
|
+
http.post(`${this.options.apiHost}/*`, async ({ request }) => {
|
|
6493
|
+
const body = await request.text();
|
|
6494
|
+
const url = new URL(request.url);
|
|
6495
|
+
const res = await supertest(app).post(url.pathname + "?" + url.searchParams.toString()).set(copyHeaders(request.headers)).send(body);
|
|
6496
|
+
return new HttpResponse(res.text, {
|
|
6497
|
+
status: res.status,
|
|
6498
|
+
headers: res.headers
|
|
6499
|
+
});
|
|
6500
|
+
}),
|
|
6501
|
+
http.delete(`${this.options.apiHost}/*`, async ({ request }) => {
|
|
6502
|
+
const body = await request.text();
|
|
6503
|
+
const url = new URL(request.url);
|
|
6504
|
+
const res = await supertest(app).delete(url.pathname + "?" + url.searchParams.toString()).set(copyHeaders(request.headers)).send(body);
|
|
6505
|
+
return new HttpResponse(res.text, {
|
|
6506
|
+
status: res.status,
|
|
6507
|
+
headers: res.headers
|
|
6508
|
+
});
|
|
6509
|
+
})
|
|
6510
|
+
);
|
|
6511
|
+
this._mswServer.listen({
|
|
6512
|
+
// We need to allow requests done by supertest
|
|
6513
|
+
onUnhandledRequest: (request, print) => {
|
|
6514
|
+
const url = new URL(request.url);
|
|
6515
|
+
if (url.hostname === "127.0.0.1") {
|
|
6516
|
+
return;
|
|
6517
|
+
}
|
|
6518
|
+
print.error();
|
|
6519
|
+
}
|
|
6429
6520
|
});
|
|
6521
|
+
_globalListeners.push(this._mswServer);
|
|
6430
6522
|
}
|
|
6431
6523
|
};
|
|
6432
6524
|
export {
|