Skip to content

Commit

Permalink
feat(customer-store-credit): support in-memory backend delegate (#3186)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 authored Oct 10, 2024
1 parent bc80e7e commit 2a49d59
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ 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.
*/
@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(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DAFF_CUSTOMER_STORE_CREDIT_IN_MEMORY_COLLECTION_NAME = 'customer-store-credit';
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -25,6 +27,7 @@ export class DaffCustomerStoreCreditInMemoryDriverModule {
provide: DaffCustomerStoreCreditDriver,
useExisting: DaffCustomerStoreCreditInMemoryDriver,
},
provideDaffInMemoryBackends(DaffCustomerStoreCreditInMemoryBackendService),
],
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -25,6 +26,12 @@ describe('@daffodil/customer-store-credit/driver/in-memory | DaffCustomerStoreCr
imports: [],
providers: [
DaffCustomerStoreCreditInMemoryDriver,
{
provide: InMemoryBackendConfig,
useValue: {
apiBase: 'api',
},
},
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
],
Expand All @@ -50,7 +57,7 @@ describe('@daffodil/customer-store-credit/driver/in-memory | DaffCustomerStoreCr
let result: Observable<DaffCustomerStoreCredit>;

beforeEach(() => {
url = service.url;
url = service['url'];
result = service.get();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<DaffCustomerStoreCredit> {
return this.http.get<DaffCustomerStoreCredit>(this.url);
Expand Down

0 comments on commit 2a49d59

Please sign in to comment.