import 'reflect-metadata'; import { HttpClient, } from '@angular/common/http'; import { of, } from 'rxjs'; import { requiredMocks, } from './../../../../test-mocks'; requiredMocks(jest); import { KiteCatalogService, } from './kite-catalog.service'; const initKiteCatalogService = ( httpClient?: HttpClient, ) => new KiteCatalogService( httpClient, ); describe('getSlugForTemplate$', () => { const initGetSlugForTemplate$Data = () => { const mockGetResponse = of({}); const httpClient = {} as HttpClient; httpClient.get = jest.fn() .mockReturnValue(mockGetResponse); const kiteCatalogService = initKiteCatalogService( httpClient, ); return { httpClient, kiteCatalogService, mockGetResponse, }; }; // tslint:disable-next-line test('Calls HttpClient.get with url to retrieve the slug for particular template id', () => { const { httpClient, kiteCatalogService, } = initGetSlugForTemplate$Data(); const templateId = 'foo'; kiteCatalogService.getSlugForTemplate$(templateId); expect(httpClient.get).toHaveBeenCalledWith( `https://catalog.kite.ly/api/slug-for-template-id/${templateId}`, ); }); test('Returns the response from the get call', () => { const { kiteCatalogService, mockGetResponse, } = initGetSlugForTemplate$Data(); const response = kiteCatalogService.getSlugForTemplate$('foo'); expect(response).toBe(mockGetResponse); }); }); describe('getContentForSlug$', () => { const initGetContentForSlug$Data = () => { const mockGetResponse = of({}); const httpClient = {} as HttpClient; httpClient.get = jest.fn() .mockReturnValue(mockGetResponse); const kiteCatalogService = initKiteCatalogService( httpClient, ); return { httpClient, kiteCatalogService, mockGetResponse, }; }; // tslint:disable-next-line test('Calls HttpClient.get with url to retrieve the content for particular slug', () => { const { httpClient, kiteCatalogService, } = initGetContentForSlug$Data(); const mockSlug = 'bar'; kiteCatalogService.getContentForSlug$(mockSlug); expect(httpClient.get).toHaveBeenCalledWith( `https://catalog.kite.ly/api/catalog/${mockSlug}`, ); }); // tslint:disable-next-line test('Returns the response from the get call', () => { const { kiteCatalogService, mockGetResponse, } = initGetContentForSlug$Data(); const mockSlug = 'bar'; const response = kiteCatalogService.getContentForSlug$(mockSlug); expect(response).toBe(mockGetResponse); }); });