import { GRAPHQL_GATEWAY_SOURCE } from '../../helpers'; import api from '../../index'; import { MOCK_COMPONENT_ID_2, MOCK_COMPONENT_REFERENCE_ARI_INPUT_1, MOCK_COMPONENT_REFERENCE_SLUG_INPUT_1, MOCK_ERROR_MESSAGE, MOCK_ERROR_TYPE, getMockedComponent, } from '../fixtures/mocks'; import { mockRequestGraph } from './helpers/requestMocks'; const compassApp = api.compass.asApp(); // @ts-ignore const requestGraphSpy = jest.spyOn(compassApp.api, 'requestGraph'); describe('getComponentsByReferences', () => { beforeEach(() => { jest.clearAllMocks(); }); it('transforms successful components fetch result', async () => { mockRequestGraph(requestGraphSpy, [], { compass: { componentsByReferences: [ getMockedComponent({ slug: 'slug-1' }), getMockedComponent({ id: MOCK_COMPONENT_ID_2, slug: 'slug-2' }), ], }, } as any); const resp = await compassApp.getComponentsByReferences([ MOCK_COMPONENT_REFERENCE_ARI_INPUT_1, MOCK_COMPONENT_REFERENCE_SLUG_INPUT_1, ]); expect(resp).toMatchSnapshot(); }); it('transforms GqlErrors', async () => { mockRequestGraph(requestGraphSpy, [ { message: MOCK_ERROR_MESSAGE, extensions: { errorSource: GRAPHQL_GATEWAY_SOURCE, classification: MOCK_ERROR_TYPE, }, }, ]); const resp = await compassApp.getComponentsByReferences([ MOCK_COMPONENT_REFERENCE_ARI_INPUT_1, ]); expect(resp).toMatchSnapshot(); }); it('transforms empty components fetch result', async () => { mockRequestGraph(requestGraphSpy, [], { compass: { componentsByReferences: [], }, } as any); const resp = await compassApp.getComponentsByReferences([ MOCK_COMPONENT_REFERENCE_ARI_INPUT_1, ]); expect(resp).toMatchSnapshot(); }); });