import './helpers/mockRequestAtlassian'; import api from '../../index'; import { MOCK_APPLICATION_MANAGED_COMPONENTS_PAGEINFO, MOCK_BASE_COMPONENT_WITH_ID, MOCK_CLOUD_ID, MOCK_ERROR_MESSAGE, MOCK_ERROR_TYPE, MOCK_QUERY_ERROR, } from '../fixtures/mocks'; import { mockRequestGraph } from './helpers/requestMocks'; import { GRAPHQL_GATEWAY_SOURCE } from '../../helpers/constants'; const compassApp = api.compass.asApp(); // @ts-ignore const requestGraphSpy = jest.spyOn(compassApp.api, 'requestGraph'); describe('getApplicationManagedComponents', () => { beforeEach(() => { jest.clearAllMocks(); }); test('transforms GqlErrors', async () => { mockRequestGraph(requestGraphSpy, [ { message: MOCK_ERROR_MESSAGE, extensions: { errorSource: GRAPHQL_GATEWAY_SOURCE, classification: MOCK_ERROR_TYPE, }, }, ]); const resp = await compassApp.getApplicationManagedComponents({ query: { cloudId: MOCK_CLOUD_ID, first: 10, after: '', }, }); expect(resp).toMatchSnapshot(); }); test('transform applicationManagedComponents QueryErrors', async () => { mockRequestGraph(requestGraphSpy, [], { compass: { applicationManagedComponents: MOCK_QUERY_ERROR, }, } as any); const resp = await compassApp.getApplicationManagedComponents({ query: { cloudId: MOCK_CLOUD_ID, first: 10, after: '', }, }); expect(resp).toMatchSnapshot(); }); test('transform successful applicationManagedComponents result', async () => { mockRequestGraph(requestGraphSpy, [], { compass: { applicationManagedComponents: { nodes: [{ component: MOCK_BASE_COMPONENT_WITH_ID }], pageInfo: MOCK_APPLICATION_MANAGED_COMPONENTS_PAGEINFO, }, }, } as any); const resp = await compassApp.getApplicationManagedComponents({ query: { cloudId: MOCK_CLOUD_ID, first: 10, after: '', }, }); expect(resp.data.components).toHaveLength(1); expect(resp).toMatchSnapshot(); }); test('errors if component cannot be transformed', async () => { mockRequestGraph(requestGraphSpy, [], { invalid_response: 'hello world', } as any); const resp = await compassApp.getApplicationManagedComponents({ query: { cloudId: MOCK_CLOUD_ID, first: 10, after: '', }, }); expect(resp).toMatchSnapshot(); }); });