diff --git a/libs/customer-store-credit/driver/in-memory/src/backend/store-credit.service.ts b/libs/customer-store-credit/driver/in-memory/src/backend/store-credit.service.ts index 7c78869e09..2af6dd26fa 100644 --- a/libs/customer-store-credit/driver/in-memory/src/backend/store-credit.service.ts +++ b/libs/customer-store-credit/driver/in-memory/src/backend/store-credit.service.ts @@ -9,6 +9,9 @@ import { import { DaffCustomerStoreCredit } from '@daffodil/customer-store-credit'; import { DaffCustomerStoreCreditFactory } from '@daffodil/customer-store-credit/testing'; +import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory'; + +import { DAFF_CUSTOMER_STORE_CREDIT_IN_MEMORY_COLLECTION_NAME } from '../collection-name.const'; /** * An in-memory service that handles customer store credit HTTP requests. @@ -16,7 +19,9 @@ import { DaffCustomerStoreCreditFactory } from '@daffodil/customer-store-credit/ @Injectable({ providedIn: 'root', }) -export class DaffCustomerStoreCreditInMemoryBackendService implements InMemoryDbService { +export class DaffCustomerStoreCreditInMemoryBackendService implements InMemoryDbService, DaffInMemorySingleRouteableBackend { + readonly collectionName = DAFF_CUSTOMER_STORE_CREDIT_IN_MEMORY_COLLECTION_NAME; + storeCredit: DaffCustomerStoreCredit; constructor( diff --git a/libs/customer-store-credit/driver/in-memory/src/collection-name.const.ts b/libs/customer-store-credit/driver/in-memory/src/collection-name.const.ts new file mode 100644 index 0000000000..5ad3d79ae0 --- /dev/null +++ b/libs/customer-store-credit/driver/in-memory/src/collection-name.const.ts @@ -0,0 +1 @@ +export const DAFF_CUSTOMER_STORE_CREDIT_IN_MEMORY_COLLECTION_NAME = 'customer-store-credit'; diff --git a/libs/customer-store-credit/driver/in-memory/src/driver/driver.module.ts b/libs/customer-store-credit/driver/in-memory/src/driver/driver.module.ts index d31276e54f..ea4bda0fca 100644 --- a/libs/customer-store-credit/driver/in-memory/src/driver/driver.module.ts +++ b/libs/customer-store-credit/driver/in-memory/src/driver/driver.module.ts @@ -5,8 +5,10 @@ import { } from '@angular/core'; import { DaffCustomerStoreCreditDriver } from '@daffodil/customer-store-credit/driver'; +import { provideDaffInMemoryBackends } from '@daffodil/driver/in-memory'; import { DaffCustomerStoreCreditInMemoryDriver } from './store-credit.service'; +import { DaffCustomerStoreCreditInMemoryBackendService } from '../backend/store-credit.service'; /** * Provides the {@link DaffCustomerStoreCreditInMemoryDriver} as the {@link DaffCustomerStoreCreditDriver}. @@ -25,6 +27,7 @@ export class DaffCustomerStoreCreditInMemoryDriverModule { provide: DaffCustomerStoreCreditDriver, useExisting: DaffCustomerStoreCreditInMemoryDriver, }, + provideDaffInMemoryBackends(DaffCustomerStoreCreditInMemoryBackendService), ], }; } diff --git a/libs/customer-store-credit/driver/in-memory/src/driver/store-credit.service.spec.ts b/libs/customer-store-credit/driver/in-memory/src/driver/store-credit.service.spec.ts index 1f6709c2ce..f71da79b67 100644 --- a/libs/customer-store-credit/driver/in-memory/src/driver/store-credit.service.spec.ts +++ b/libs/customer-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 { DaffCustomerStoreCredit } from '@daffodil/customer-store-credit'; @@ -25,6 +26,12 @@ describe('@daffodil/customer-store-credit/driver/in-memory | DaffCustomerStoreCr imports: [], providers: [ DaffCustomerStoreCreditInMemoryDriver, + { + provide: InMemoryBackendConfig, + useValue: { + apiBase: 'api', + }, + }, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), ], @@ -50,7 +57,7 @@ describe('@daffodil/customer-store-credit/driver/in-memory | DaffCustomerStoreCr let result: Observable; beforeEach(() => { - url = service.url; + url = service['url']; result = service.get(); }); diff --git a/libs/customer-store-credit/driver/in-memory/src/driver/store-credit.service.ts b/libs/customer-store-credit/driver/in-memory/src/driver/store-credit.service.ts index 79e9f0b6cf..22b3ef0baa 100644 --- a/libs/customer-store-credit/driver/in-memory/src/driver/store-credit.service.ts +++ b/libs/customer-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 { DaffCustomerStoreCredit } from '@daffodil/customer-store-credit'; import { DaffCustomerStoreCreditDriverInterface } from '@daffodil/customer-store-credit/driver'; +import { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory'; + +import { DAFF_CUSTOMER_STORE_CREDIT_IN_MEMORY_COLLECTION_NAME } from '../collection-name.const'; /** * The customer store credit in-memory driver to mock the customer store credit backend service. @@ -13,15 +17,13 @@ import { DaffCustomerStoreCreditDriverInterface } from '@daffodil/customer-store @Injectable({ providedIn: 'root', }) -export class DaffCustomerStoreCreditInMemoryDriver implements DaffCustomerStoreCreditDriverInterface { - /** - * @docs-private - */ - url = '/api/customer-store-credit'; - +export class DaffCustomerStoreCreditInMemoryDriver extends DaffInMemoryDriverBase implements DaffCustomerStoreCreditDriverInterface { constructor( private http: HttpClient, - ) {} + config: InMemoryBackendConfig, + ) { + super(config, DAFF_CUSTOMER_STORE_CREDIT_IN_MEMORY_COLLECTION_NAME); + } get(): Observable { return this.http.get(this.url);