Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cart): support in-memory backend delegate #3180

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('@daffodil/demo | DemoInMemoryBackendService', () => {
returnedValue,
);
reqInfo = {
collectionName: DaffInMemoryBackendCartRootService.COLLECTION_NAMES[0],
collectionName: 'cart',
};

result = service.post(reqInfo);
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('@daffodil/demo | DemoInMemoryBackendService', () => {
returnedValue = 'returnedValue';
spyOn(service['cartTestingService'], 'get').and.returnValue(returnedValue);
reqInfo = {
collectionName: DaffInMemoryBackendCartRootService.COLLECTION_NAMES[0],
collectionName: 'cart',
};

result = service.get(reqInfo);
Expand Down Expand Up @@ -195,7 +195,7 @@ describe('@daffodil/demo | DemoInMemoryBackendService', () => {
returnedValue,
);
reqInfo = {
collectionName: DaffInMemoryBackendCartRootService.COLLECTION_NAMES[0],
collectionName: 'cart',
};

result = service.put(reqInfo);
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('@daffodil/demo | DemoInMemoryBackendService', () => {
returnedValue,
);
reqInfo = {
collectionName: DaffInMemoryBackendCartRootService.COLLECTION_NAMES[0],
collectionName: 'cart',
};

result = service.delete(reqInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class DemoInMemoryBackendService implements InMemoryDbService {

post(reqInfo: any) {
const collectionName = reqInfo.collectionName;
if (DaffInMemoryBackendCartRootService.COLLECTION_NAMES.indexOf(collectionName) > -1) {
if (this.cartTestingService.canHandle(collectionName)) {
return this.cartTestingService.post(reqInfo);
} else if (collectionName === 'auth') {
return this.authTestingService.post(reqInfo);
Expand All @@ -51,7 +51,7 @@ export class DemoInMemoryBackendService implements InMemoryDbService {
return this.productTestingService.get(reqInfo);
} else if (collectionName === 'navigation') {
return this.navigationTestingService.get(reqInfo);
} else if (DaffInMemoryBackendCartRootService.COLLECTION_NAMES.indexOf(collectionName) > -1) {
} else if (this.cartTestingService.canHandle(collectionName)) {
return this.cartTestingService.get(reqInfo);
} else if (collectionName === 'countries') {
return this.geographyTestingService.get(reqInfo);
Expand All @@ -62,14 +62,14 @@ export class DemoInMemoryBackendService implements InMemoryDbService {

put(reqInfo: any) {
const collectionName = reqInfo.collectionName;
if(DaffInMemoryBackendCartRootService.COLLECTION_NAMES.indexOf(collectionName) > -1) {
if(this.cartTestingService.canHandle(collectionName)) {
return this.cartTestingService.put(reqInfo);
}
}

delete(reqInfo: any) {
const collectionName = reqInfo.collectionName;
if(DaffInMemoryBackendCartRootService.COLLECTION_NAMES.indexOf(collectionName) > -1) {
if(this.cartTestingService.canHandle(collectionName)) {
return this.cartTestingService.delete(reqInfo);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
} from 'angular-in-memory-web-api';

import { DaffCart } from '@daffodil/cart';
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';

import { DAFF_CART_IN_MEMORY_CART_ADDRESS_COLLECTION_NAME } from '../../collection-names';
import {
DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK,
DaffCartInMemoryExtraAttributesHook,
Expand All @@ -21,7 +22,9 @@ import {
@Injectable({
providedIn: 'root',
})
export class DaffInMemoryBackendCartAddressService implements DaffInMemoryDataServiceInterface {
export class DaffInMemoryBackendCartAddressService implements DaffInMemorySingleRouteableBackend {
readonly collectionName = DAFF_CART_IN_MEMORY_CART_ADDRESS_COLLECTION_NAME;

constructor(
@Inject(DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK) private extraFieldsHook: DaffCartInMemoryExtraAttributesHook,
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
DaffCart,
DaffCartAddress,
} from '@daffodil/cart';
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';

import { DAFF_CART_IN_MEMORY_CART_BILLING_ADDRESS_COLLECTION_NAME } from '../../collection-names';
import {
DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK,
DaffCartInMemoryExtraAttributesHook,
Expand All @@ -24,7 +25,9 @@ import {
@Injectable({
providedIn: 'root',
})
export class DaffInMemoryBackendCartBillingAddressService implements DaffInMemoryDataServiceInterface {
export class DaffInMemoryBackendCartBillingAddressService implements DaffInMemorySingleRouteableBackend {
readonly collectionName = DAFF_CART_IN_MEMORY_CART_BILLING_ADDRESS_COLLECTION_NAME;

constructor(
@Inject(DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK) private extraFieldsHook: DaffCartInMemoryExtraAttributesHook,
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
DaffCart,
DaffCartCoupon,
} from '@daffodil/cart';
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';

import { DAFF_CART_IN_MEMORY_CART_COUPON_COLLECTION_NAME } from '../../collection-names';
import {
DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK,
DaffCartInMemoryExtraAttributesHook,
Expand All @@ -24,7 +25,9 @@ import {
@Injectable({
providedIn: 'root',
})
export class DaffInMemoryBackendCartCouponService implements DaffInMemoryDataServiceInterface {
export class DaffInMemoryBackendCartCouponService implements DaffInMemorySingleRouteableBackend {
readonly collectionName = DAFF_CART_IN_MEMORY_CART_COUPON_COLLECTION_NAME;

constructor(
@Inject(DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK) private extraFieldsHook: DaffCartInMemoryExtraAttributesHook,
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import {
DaffCartItemInput,
} from '@daffodil/cart';
import { DaffCartItemFactory } from '@daffodil/cart/testing';
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';
import { DaffInMemoryBackendProductService } from '@daffodil/product/driver/in-memory';

import { DAFF_CART_IN_MEMORY_CART_ITEMS_COLLECTION_NAME } from '../../collection-names';
import { daffCartInMemoryComputeCartItemPrices } from '../../helpers/compute-cart-item-prices';
import { daffCartInMemoryComputeCartTotals } from '../../helpers/compute-cart-totals';
import {
Expand All @@ -29,7 +30,9 @@ import {
@Injectable({
providedIn: 'root',
})
export class DaffInMemoryBackendCartItemsService implements DaffInMemoryDataServiceInterface {
export class DaffInMemoryBackendCartItemsService implements DaffInMemorySingleRouteableBackend {
readonly collectionName = DAFF_CART_IN_MEMORY_CART_ITEMS_COLLECTION_NAME;

constructor(
private cartItemFactory: DaffCartItemFactory,
@Inject(DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK) private extraFieldsHook: DaffCartInMemoryExtraAttributesHook,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import {
} from 'angular-in-memory-web-api';

import { DaffCartOrderResult } from '@daffodil/cart';
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';

import { DAFF_CART_IN_MEMORY_CART_ORDER_COLLECTION_NAME } from '../../collection-names';

/**
* @inheritdoc
*/
@Injectable({
providedIn: 'root',
})
export class DaffInMemoryBackendCartOrderService implements DaffInMemoryDataServiceInterface {
export class DaffInMemoryBackendCartOrderService implements DaffInMemorySingleRouteableBackend {
readonly collectionName = DAFF_CART_IN_MEMORY_CART_ORDER_COLLECTION_NAME;

post(reqInfo: RequestInfo) {
return reqInfo.utils.createResponse$(() => ({
body: this.placeOrder(reqInfo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ import {
DaffCart,
DaffCartPaymentMethod,
} from '@daffodil/cart';
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';

import { DAFF_CART_IN_MEMORY_CART_PAYMENT_METHODS_COLLECTION_NAME } from '../../collection-names';

/**
* @inheritdoc
*/
@Injectable({
providedIn: 'root',
})
export class DaffInMemoryBackendCartPaymentMethodsService implements DaffInMemoryDataServiceInterface {
export class DaffInMemoryBackendCartPaymentMethodsService implements DaffInMemorySingleRouteableBackend {
readonly collectionName = DAFF_CART_IN_MEMORY_CART_PAYMENT_METHODS_COLLECTION_NAME;

get(reqInfo: RequestInfo) {
return reqInfo.utils.createResponse$(() => ({
body: this.listPaymentMethods(reqInfo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
DaffCart,
DaffCartPaymentMethod,
} from '@daffodil/cart';
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';

import { DAFF_CART_IN_MEMORY_CART_PAYMENT_COLLECTION_NAME } from '../../collection-names';
import {
DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK,
DaffCartInMemoryExtraAttributesHook,
Expand All @@ -24,7 +25,9 @@ import {
@Injectable({
providedIn: 'root',
})
export class DaffInMemoryBackendCartPaymentService implements DaffInMemoryDataServiceInterface {
export class DaffInMemoryBackendCartPaymentService implements DaffInMemorySingleRouteableBackend {
readonly collectionName = DAFF_CART_IN_MEMORY_CART_PAYMENT_COLLECTION_NAME;

constructor(
@Inject(DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK) private extraFieldsHook: DaffCartInMemoryExtraAttributesHook,
) {}
Expand Down
Loading
Loading