diff --git a/libs/cart-store-credit/driver/in-memory/src/backend/store-credit.service.ts b/libs/cart-store-credit/driver/in-memory/src/backend/store-credit.service.ts index 664d86bd67..0f8e12a2c4 100644 --- a/libs/cart-store-credit/driver/in-memory/src/backend/store-credit.service.ts +++ b/libs/cart-store-credit/driver/in-memory/src/backend/store-credit.service.ts @@ -10,8 +10,10 @@ import { import { DaffCartTotalTypeEnum } from '@daffodil/cart'; import { DaffInMemoryBackendCartRootService } from '@daffodil/cart/driver/in-memory'; import { DaffCartWithStoreCredit } from '@daffodil/cart-store-credit'; -import { DaffCartWithStoreCreditFactory } from '@daffodil/cart-store-credit/testing'; import { DaffCustomerStoreCreditInMemoryBackendService } from '@daffodil/customer-store-credit/driver/in-memory'; +import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory'; + +import { DAFF_CART_STORE_CREDIT_IN_MEMORY_COLLECTION_NAME } from '../collection-name.const'; /** @@ -20,7 +22,9 @@ import { DaffCustomerStoreCreditInMemoryBackendService } from '@daffodil/custome @Injectable({ providedIn: 'root', }) -export class DaffCartStoreCreditInMemoryBackendService implements InMemoryDbService { +export class DaffCartStoreCreditInMemoryBackendService implements InMemoryDbService, DaffInMemorySingleRouteableBackend { + readonly collectionName = DAFF_CART_STORE_CREDIT_IN_MEMORY_COLLECTION_NAME; + constructor( private customerStoreCredit: DaffCustomerStoreCreditInMemoryBackendService, private cart: DaffInMemoryBackendCartRootService, diff --git a/libs/cart-store-credit/driver/in-memory/src/collection-name.const.ts b/libs/cart-store-credit/driver/in-memory/src/collection-name.const.ts new file mode 100644 index 0000000000..00f2000045 --- /dev/null +++ b/libs/cart-store-credit/driver/in-memory/src/collection-name.const.ts @@ -0,0 +1 @@ +export const DAFF_CART_STORE_CREDIT_IN_MEMORY_COLLECTION_NAME = 'cart-store-credit'; diff --git a/libs/cart-store-credit/driver/in-memory/src/driver/driver.module.ts b/libs/cart-store-credit/driver/in-memory/src/driver/driver.module.ts index d818c1ce13..245d2a6b0f 100644 --- a/libs/cart-store-credit/driver/in-memory/src/driver/driver.module.ts +++ b/libs/cart-store-credit/driver/in-memory/src/driver/driver.module.ts @@ -5,8 +5,10 @@ import { } from '@angular/core'; import { DaffCartStoreCreditDriver } from '@daffodil/cart-store-credit/driver'; +import { provideDaffInMemoryBackends } from '@daffodil/driver/in-memory'; import { DaffCartStoreCreditInMemoryDriver } from './store-credit.service'; +import { DaffCartStoreCreditInMemoryBackendService } from '../backend/store-credit.service'; /** * Provides the {@link DaffCartStoreCreditInMemoryDriver} as the {@link DaffCartStoreCreditDriver}. @@ -25,6 +27,7 @@ export class DaffCartStoreCreditInMemoryDriverModule { provide: DaffCartStoreCreditDriver, useExisting: DaffCartStoreCreditInMemoryDriver, }, + provideDaffInMemoryBackends(DaffCartStoreCreditInMemoryBackendService), ], }; } diff --git a/libs/cart-store-credit/driver/in-memory/src/driver/store-credit.service.spec.ts b/libs/cart-store-credit/driver/in-memory/src/driver/store-credit.service.spec.ts index 98ff71cbda..94d8849bf9 100644 --- a/libs/cart-store-credit/driver/in-memory/src/driver/store-credit.service.spec.ts +++ b/libs/cart-store-credit/driver/in-memory/src/driver/store-credit.service.spec.ts @@ -7,6 +7,7 @@ import { provideHttpClientTesting, } from '@angular/common/http/testing'; import { TestBed } from '@angular/core/testing'; +import { InMemoryBackendConfig } from 'angular-in-memory-web-api'; import { Observable } from 'rxjs'; import { DaffCartWithStoreCredit } from '@daffodil/cart-store-credit'; @@ -25,6 +26,12 @@ describe('@daffodil/cart-store-credit/driver/in-memory | DaffCartStoreCreditInMe imports: [], providers: [ DaffCartStoreCreditInMemoryDriver, + { + provide: InMemoryBackendConfig, + useValue: { + apiBase: 'api', + }, + }, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), ], @@ -50,7 +57,7 @@ describe('@daffodil/cart-store-credit/driver/in-memory | DaffCartStoreCreditInMe let result: Observable; beforeEach(() => { - url = service.url; + url = service['url']; result = service.apply(mockCartWithStoreCredit.id); }); @@ -72,7 +79,7 @@ describe('@daffodil/cart-store-credit/driver/in-memory | DaffCartStoreCreditInMe let result: Observable; beforeEach(() => { - url = service.url; + url = service['url']; result = service.remove(mockCartWithStoreCredit.id); }); diff --git a/libs/cart-store-credit/driver/in-memory/src/driver/store-credit.service.ts b/libs/cart-store-credit/driver/in-memory/src/driver/store-credit.service.ts index 566713c8ff..0389b4ab3f 100644 --- a/libs/cart-store-credit/driver/in-memory/src/driver/store-credit.service.ts +++ b/libs/cart-store-credit/driver/in-memory/src/driver/store-credit.service.ts @@ -1,9 +1,13 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; +import { InMemoryBackendConfig } from 'angular-in-memory-web-api'; import { Observable } from 'rxjs'; import { DaffCartWithStoreCredit } from '@daffodil/cart-store-credit'; import { DaffCartStoreCreditDriverInterface } from '@daffodil/cart-store-credit/driver'; +import { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory'; + +import { DAFF_CART_STORE_CREDIT_IN_MEMORY_COLLECTION_NAME } from '../collection-name.const'; /** * The cart store credit in-memory driver to mock the cart store credit backend service. @@ -13,15 +17,13 @@ import { DaffCartStoreCreditDriverInterface } from '@daffodil/cart-store-credit/ @Injectable({ providedIn: 'root', }) -export class DaffCartStoreCreditInMemoryDriver implements DaffCartStoreCreditDriverInterface { - /** - * @docs-private - */ - url = '/api/cart-store-credit'; - +export class DaffCartStoreCreditInMemoryDriver extends DaffInMemoryDriverBase implements DaffCartStoreCreditDriverInterface { constructor( private http: HttpClient, - ) {} + config: InMemoryBackendConfig, + ) { + super(config, DAFF_CART_STORE_CREDIT_IN_MEMORY_COLLECTION_NAME); + } apply(cartId: DaffCartWithStoreCredit['id']): Observable { return this.http.post(`${this.url}/${cartId}`, {});