Skip to content

Commit

Permalink
feat(demo): add geography driver modules (#2616)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Nov 22, 2023
1 parent 7a60ddb commit 2539cf6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 23 deletions.
73 changes: 50 additions & 23 deletions apps/demo/src/app/drivers/in-memory/backend/backend.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { TestBed } from '@angular/core/testing';

import { DaffInMemoryBackendCartRootService } from '@daffodil/cart/driver/in-memory';
import { DaffInMemoryBackendCheckoutService } from '@daffodil/checkout/testing';
import { DaffInMemoryBackendGeographyService } from '@daffodil/geography/driver/in-memory';
import { DaffInMemoryBackendNavigationService } from '@daffodil/navigation/driver/in-memory';
import { DaffInMemoryBackendProductService } from '@daffodil/product/driver/in-memory';
import { DaffProductTestingModule } from '@daffodil/product/testing';

import { DemoInMemoryBackendService } from './backend.service';

describe('Driver | In Memory | InMemoryService', () => {
let service;
describe('@daffodil/demo | DemoInMemoryBackendService', () => {
let service: DemoInMemoryBackendService;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -23,6 +24,7 @@ describe('Driver | In Memory | InMemoryService', () => {
DaffInMemoryBackendProductService,
DaffInMemoryBackendCheckoutService,
DaffInMemoryBackendNavigationService,
DaffInMemoryBackendGeographyService,
DemoInMemoryBackendService,
],
});
Expand All @@ -42,7 +44,7 @@ describe('Driver | In Memory | InMemoryService', () => {

beforeEach(() => {
returnedValue = 'returnedValue';
spyOn(service.cartTestingService, 'post').and.returnValue(
spyOn(service['cartTestingService'], 'post').and.returnValue(
returnedValue,
);
reqInfo = {
Expand All @@ -53,7 +55,7 @@ describe('Driver | In Memory | InMemoryService', () => {
});

it('should call cartTestingService.post', () => {
expect(service.cartTestingService.post).toHaveBeenCalledWith(reqInfo);
expect(service['cartTestingService'].post).toHaveBeenCalledWith(reqInfo);
});

it('should return the returned value of cartTestingService.post', () => {
Expand All @@ -80,7 +82,7 @@ describe('Driver | In Memory | InMemoryService', () => {

beforeEach(() => {
returnedValue = 'returnedValue';
spyOn(service.productTestingService, 'get').and.returnValue(returnedValue);
spyOn(service['productTestingService'], 'get').and.returnValue(returnedValue);
reqInfo = {
collectionName: 'products',
};
Expand All @@ -89,7 +91,7 @@ describe('Driver | In Memory | InMemoryService', () => {
});

it('should call productTestingService.get', () => {
expect(service.productTestingService.get).toHaveBeenCalledWith(reqInfo);
expect(service['productTestingService'].get).toHaveBeenCalledWith(reqInfo);
});

it('should return the returned value of productTestingService.get', () => {
Expand All @@ -105,7 +107,7 @@ describe('Driver | In Memory | InMemoryService', () => {

beforeEach(() => {
returnedValue = 'returnedValue';
spyOn(service.navigationTestingService, 'get').and.returnValue(returnedValue);
spyOn(service['navigationTestingService'], 'get').and.returnValue(returnedValue);
reqInfo = {
collectionName: 'navigation',
};
Expand All @@ -114,14 +116,39 @@ describe('Driver | In Memory | InMemoryService', () => {
});

it('should call navigationTestingService.get', () => {
expect(service.navigationTestingService.get).toHaveBeenCalledWith(reqInfo);
expect(service['navigationTestingService'].get).toHaveBeenCalledWith(reqInfo);
});

it('should return the returned value of navigationTestingService.get', () => {
expect(result).toEqual(returnedValue);
});
});

describe('when collectionName is countries', () => {

let reqInfo;
let result;
let returnedValue;

beforeEach(() => {
returnedValue = 'returnedValue';
spyOn(service['geographyTestingService'], 'get').and.returnValue(returnedValue);
reqInfo = {
collectionName: 'countries',
};

result = service.get(reqInfo);
});

it('should call geographyTestingService.get', () => {
expect(service['geographyTestingService'].get).toHaveBeenCalledWith(reqInfo);
});

it('should return the returned value of geographyTestingService.get', () => {
expect(result).toEqual(returnedValue);
});
});

describe('when collectionName is a DaffInMemoryBackendCartRootService collection name', () => {

let reqInfo;
Expand All @@ -130,7 +157,7 @@ describe('Driver | In Memory | InMemoryService', () => {

beforeEach(() => {
returnedValue = 'returnedValue';
spyOn(service.cartTestingService, 'get').and.returnValue(returnedValue);
spyOn(service['cartTestingService'], 'get').and.returnValue(returnedValue);
reqInfo = {
collectionName: DaffInMemoryBackendCartRootService.COLLECTION_NAMES[0],
};
Expand All @@ -139,7 +166,7 @@ describe('Driver | In Memory | InMemoryService', () => {
});

it('should call cartTestingService.get', () => {
expect(service.cartTestingService.get).toHaveBeenCalledWith(reqInfo);
expect(service['cartTestingService'].get).toHaveBeenCalledWith(reqInfo);
});

it('should return the returned value of cartTestingService.get', () => {
Expand All @@ -163,7 +190,7 @@ describe('Driver | In Memory | InMemoryService', () => {

beforeEach(() => {
returnedValue = 'returnedValue';
spyOn(service.cartTestingService, 'put').and.returnValue(
spyOn(service['cartTestingService'], 'put').and.returnValue(
returnedValue,
);
reqInfo = {
Expand All @@ -174,7 +201,7 @@ describe('Driver | In Memory | InMemoryService', () => {
});

it('should call cartTestingService.put', () => {
expect(service.cartTestingService.put).toHaveBeenCalledWith(reqInfo);
expect(service['cartTestingService'].put).toHaveBeenCalledWith(reqInfo);
});

it('should return the returned value of cartTestingService.put', () => {
Expand All @@ -199,7 +226,7 @@ describe('Driver | In Memory | InMemoryService', () => {

beforeEach(() => {
returnedValue = 'returnedValue';
spyOn(service.cartTestingService, 'delete').and.returnValue(
spyOn(service['cartTestingService'], 'delete').and.returnValue(
returnedValue,
);
reqInfo = {
Expand All @@ -210,7 +237,7 @@ describe('Driver | In Memory | InMemoryService', () => {
});

it('should call cartTestingService.delete', () => {
expect(service.cartTestingService.delete).toHaveBeenCalledWith(reqInfo);
expect(service['cartTestingService'].delete).toHaveBeenCalledWith(reqInfo);
});

it('should return the returned value of cartTestingService.delete', () => {
Expand Down Expand Up @@ -239,30 +266,30 @@ describe('Driver | In Memory | InMemoryService', () => {
cartReturn = 'cartReturn';
orderReturn = 'orderReturn';
navigationReturn = 'navigationReturn';
spyOn(service.productTestingService, 'createDb').and.returnValue(
spyOn(service['productTestingService'], 'createDb').and.returnValue(
productReturn,
);
spyOn(service.cartTestingService, 'createDb').and.returnValue(cartReturn);
spyOn(service.checkoutTestingService, 'createDb').and.returnValue(orderReturn);
spyOn(service.navigationTestingService, 'createDb').and.returnValue(navigationReturn);
spyOn(service['cartTestingService'], 'createDb').and.returnValue(cartReturn);
spyOn(service['checkoutTestingService'], 'createDb').and.returnValue(orderReturn);
spyOn(service['navigationTestingService'], 'createDb').and.returnValue(navigationReturn);

result = service.createDb();
result = service.createDb(null);
});

it('should call productTestingService.createDb', () => {
expect(service.productTestingService.createDb).toHaveBeenCalled();
expect(service['productTestingService'].createDb).toHaveBeenCalled();
});

it('should call cartTestingService.createDb', () => {
expect(service.cartTestingService.createDb).toHaveBeenCalled();
expect(service['cartTestingService'].createDb).toHaveBeenCalled();
});

it('should call checkoutTestingService.createDb', () => {
expect(service.checkoutTestingService.createDb).toHaveBeenCalled();
expect(service['checkoutTestingService'].createDb).toHaveBeenCalled();
});

it('should call navigationTestingService.createDb', () => {
expect(service.navigationTestingService.createDb).toHaveBeenCalled();
expect(service['navigationTestingService'].createDb).toHaveBeenCalled();
});

it('should return expected object', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DaffCart } from '@daffodil/cart';
import { DaffInMemoryBackendCartRootService } from '@daffodil/cart/driver/in-memory';
import { DaffOrder } from '@daffodil/checkout';
import { DaffInMemoryBackendCheckoutService } from '@daffodil/checkout/testing';
import { DaffInMemoryBackendGeographyService } from '@daffodil/geography/driver/in-memory';
import { DaffNavigationTree } from '@daffodil/navigation';
import { DaffInMemoryBackendNavigationService } from '@daffodil/navigation/driver/in-memory';
import { DaffProduct } from '@daffodil/product';
Expand All @@ -26,6 +27,7 @@ export class DemoInMemoryBackendService implements InMemoryDbService {
private checkoutTestingService: DaffInMemoryBackendCheckoutService,
private navigationTestingService: DaffInMemoryBackendNavigationService,
private authTestingService: DaffInMemoryBackendAuthService,
private geographyTestingService: DaffInMemoryBackendGeographyService,
) {}

parseRequestUrl(url: string, utils: RequestInfoUtilities): ParsedRequestUrl {
Expand Down Expand Up @@ -53,6 +55,8 @@ export class DemoInMemoryBackendService implements InMemoryDbService {
return this.navigationTestingService.get(reqInfo);
} else if (DaffInMemoryBackendCartRootService.COLLECTION_NAMES.indexOf(collectionName) > -1) {
return this.cartTestingService.get(reqInfo);
} else if (collectionName === 'countries') {
return this.geographyTestingService.get(reqInfo);
}
}

Expand Down
2 changes: 2 additions & 0 deletions apps/demo/src/app/drivers/in-memory/in-memory.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
import { DaffAuthInMemoryDriverModule } from '@daffodil/auth/driver/in-memory';
import { DaffCartInMemoryDriverModule } from '@daffodil/cart/driver/in-memory';
import { DaffCheckoutInMemoryDriverModule } from '@daffodil/checkout/testing';
import { DaffGeographyInMemoryDriverModule } from '@daffodil/geography/driver/in-memory';
import { DaffNavigationInMemoryDriverModule } from '@daffodil/navigation/driver/in-memory';
import { DaffNewsletterInMemoryDriverModule } from '@daffodil/newsletter/driver/in-memory';
import { DaffProductInMemoryDriverModule } from '@daffodil/product/driver/in-memory';
Expand All @@ -20,6 +21,7 @@ import { DemoInMemoryBackendService } from './backend/backend.service';
DaffCheckoutInMemoryDriverModule.forRoot(),
DaffNavigationInMemoryDriverModule.forRoot(),
DaffNewsletterInMemoryDriverModule.forRoot(),
DaffGeographyInMemoryDriverModule.forRoot(),
],
})
export class DemoInMemoryDriverModule { }
2 changes: 2 additions & 0 deletions apps/demo/src/app/drivers/magento/magento.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DaffAuthMagentoDriverModule } from '@daffodil/auth/driver/magento';
import { DaffCartMagentoDriverModule } from '@daffodil/cart/driver/magento';
import { DaffCheckoutInMemoryDriverModule } from '@daffodil/checkout/testing';
import { DaffMagentoApolloCacheableOperationsLinkGenerator } from '@daffodil/driver/magento';
import { DaffGeographyMagentoDriverModule } from '@daffodil/geography/driver/magento';
import { DaffNavigationMagentoDriverModule } from '@daffodil/navigation/driver/magento';
import { DaffNewsletterInMemoryDriverModule } from '@daffodil/newsletter/driver/in-memory';
import { DaffProductMagentoDriverModule } from '@daffodil/product/driver/magento';
Expand All @@ -35,6 +36,7 @@ const cache = new InMemoryCache({ possibleTypes: possibleTypes.possibleTypes });
DaffCheckoutInMemoryDriverModule.forRoot(),
DaffNavigationMagentoDriverModule.forRoot(),
DaffNewsletterInMemoryDriverModule.forRoot(),
DaffGeographyMagentoDriverModule.forRoot(),
ApolloModule,
],
})
Expand Down

0 comments on commit 2539cf6

Please sign in to comment.