diff --git a/apps/demo/src/app/drivers/in-memory/backend/backend.service.spec.ts b/apps/demo/src/app/drivers/in-memory/backend/backend.service.spec.ts index 142fb6cfcb..41c4aeb306 100644 --- a/apps/demo/src/app/drivers/in-memory/backend/backend.service.spec.ts +++ b/apps/demo/src/app/drivers/in-memory/backend/backend.service.spec.ts @@ -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({ @@ -23,6 +24,7 @@ describe('Driver | In Memory | InMemoryService', () => { DaffInMemoryBackendProductService, DaffInMemoryBackendCheckoutService, DaffInMemoryBackendNavigationService, + DaffInMemoryBackendGeographyService, DemoInMemoryBackendService, ], }); @@ -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 = { @@ -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', () => { @@ -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', }; @@ -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', () => { @@ -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', }; @@ -114,7 +116,7 @@ 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', () => { @@ -122,6 +124,31 @@ describe('Driver | In Memory | InMemoryService', () => { }); }); + describe('when collectionName is country', () => { + + let reqInfo; + let result; + let returnedValue; + + beforeEach(() => { + returnedValue = 'returnedValue'; + spyOn(service['geographyTestingService'], 'get').and.returnValue(returnedValue); + reqInfo = { + collectionName: 'country', + }; + + result = service.get(reqInfo); + }); + + it('should call countryTestingService.get', () => { + expect(service['geographyTestingService'].get).toHaveBeenCalledWith(reqInfo); + }); + + it('should return the returned value of countryTestingService.get', () => { + expect(result).toEqual(returnedValue); + }); + }); + describe('when collectionName is a DaffInMemoryBackendCartRootService collection name', () => { let reqInfo; @@ -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], }; @@ -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', () => { @@ -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 = { @@ -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', () => { @@ -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 = { @@ -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', () => { @@ -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', () => { diff --git a/apps/demo/src/app/drivers/in-memory/backend/backend.service.ts b/apps/demo/src/app/drivers/in-memory/backend/backend.service.ts index dfafb6132c..c081539326 100644 --- a/apps/demo/src/app/drivers/in-memory/backend/backend.service.ts +++ b/apps/demo/src/app/drivers/in-memory/backend/backend.service.ts @@ -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'; @@ -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 { @@ -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); } } diff --git a/apps/demo/src/app/drivers/in-memory/in-memory.module.ts b/apps/demo/src/app/drivers/in-memory/in-memory.module.ts index 26b4d44351..9a6d6ffe60 100644 --- a/apps/demo/src/app/drivers/in-memory/in-memory.module.ts +++ b/apps/demo/src/app/drivers/in-memory/in-memory.module.ts @@ -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'; @@ -20,6 +21,7 @@ import { DemoInMemoryBackendService } from './backend/backend.service'; DaffCheckoutInMemoryDriverModule.forRoot(), DaffNavigationInMemoryDriverModule.forRoot(), DaffNewsletterInMemoryDriverModule.forRoot(), + DaffGeographyInMemoryDriverModule.forRoot(), ], }) export class DemoInMemoryDriverModule { } diff --git a/apps/demo/src/app/drivers/magento/magento.module.ts b/apps/demo/src/app/drivers/magento/magento.module.ts index 36db416187..0d11306295 100644 --- a/apps/demo/src/app/drivers/magento/magento.module.ts +++ b/apps/demo/src/app/drivers/magento/magento.module.ts @@ -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'; @@ -35,6 +36,7 @@ const cache = new InMemoryCache({ possibleTypes: possibleTypes.possibleTypes }); DaffCheckoutInMemoryDriverModule.forRoot(), DaffNavigationMagentoDriverModule.forRoot(), DaffNewsletterInMemoryDriverModule.forRoot(), + DaffGeographyMagentoDriverModule.forRoot(), ApolloModule, ], })