|
| 1 | +import { TestBed } from '@angular/core/testing'; |
| 2 | + |
| 3 | +import { DaffCheckoutInMemoryBackendOrderService } from '@daffodil/checkout/driver/in-memory'; |
| 4 | +import { DaffProductTestingModule } from '@daffodil/product/testing'; |
| 5 | + |
| 6 | +import { DaffCheckoutInMemoryBackendRootService } from './root.service'; |
| 7 | +import { DAFF_CHECKOUT_IN_MEMORY_CHECKOUT_ORDER_COLLECTION_NAME } from '../collection-names.const'; |
| 8 | + |
| 9 | +describe('DaffCheckoutInMemoryBackendRootService | Unit', () => { |
| 10 | + let service: DaffCheckoutInMemoryBackendRootService; |
| 11 | + |
| 12 | + let orderBackendService: DaffCheckoutInMemoryBackendOrderService; |
| 13 | + |
| 14 | + let reqInfoStub; |
| 15 | + let baseUrl; |
| 16 | + |
| 17 | + let orderPostSpy: jasmine.Spy; |
| 18 | + |
| 19 | + beforeEach(() => { |
| 20 | + TestBed.configureTestingModule({ |
| 21 | + imports: [ |
| 22 | + DaffProductTestingModule, |
| 23 | + ], |
| 24 | + providers: [ |
| 25 | + DaffCheckoutInMemoryBackendRootService, |
| 26 | + ], |
| 27 | + }); |
| 28 | + service = TestBed.inject(DaffCheckoutInMemoryBackendRootService); |
| 29 | + |
| 30 | + orderBackendService = TestBed.inject(DaffCheckoutInMemoryBackendOrderService); |
| 31 | + |
| 32 | + baseUrl = 'api/checkout'; |
| 33 | + reqInfoStub = { |
| 34 | + id: '', |
| 35 | + resourceUrl: baseUrl, |
| 36 | + collection: [], |
| 37 | + collectionName: '', |
| 38 | + method: '', |
| 39 | + req: { |
| 40 | + body: {}, |
| 41 | + }, |
| 42 | + utils: { |
| 43 | + createResponse$: func => func(), |
| 44 | + getJsonBody: req => req.body, |
| 45 | + findById: (ary, id) => ary.find(e => e.id === id), |
| 46 | + }, |
| 47 | + }; |
| 48 | + |
| 49 | + orderPostSpy = spyOn(orderBackendService, 'post'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should be created', () => { |
| 53 | + expect(service).toBeTruthy(); |
| 54 | + }); |
| 55 | + |
| 56 | + describe('processing a post request', () => { |
| 57 | + beforeEach(() => { |
| 58 | + reqInfoStub.method = 'post'; |
| 59 | + }); |
| 60 | + |
| 61 | + describe(`when the collectionName is ${DAFF_CHECKOUT_IN_MEMORY_CHECKOUT_ORDER_COLLECTION_NAME}`, () => { |
| 62 | + let result; |
| 63 | + |
| 64 | + beforeEach(() => { |
| 65 | + reqInfoStub.collectionName = DAFF_CHECKOUT_IN_MEMORY_CHECKOUT_ORDER_COLLECTION_NAME; |
| 66 | + |
| 67 | + result = service.post(reqInfoStub); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should delegate the request to the order service', () => { |
| 71 | + expect(orderPostSpy).toHaveBeenCalledWith(reqInfoStub); |
| 72 | + }); |
| 73 | + }); |
| 74 | + }); |
| 75 | +}); |
0 commit comments