import '../compass-requests/helpers/mockRequestAtlassian'; import ForgeWrapper from '../../forge_wrapper'; import { CompassRequests } from '../../compass-requests'; import { MOCK_CLOUD_ID } from '../fixtures/mocks'; const apiSpy = jest.fn(); const compassApp = new CompassRequests( ForgeWrapper.wrap({ requestGraph: apiSpy, }), ); describe('attachDataManager', () => { beforeEach(() => { jest.clearAllMocks(); }); test('adds headers properly when there is an analytic to send ', async () => { compassApp.createBaseComponent(MOCK_CLOUD_ID, { name: 'test', options: { createdFromFile: true }, }); expect(apiSpy.mock.calls[0][2]).toEqual( expect.objectContaining({ 'Content-Type': 'application/json', 'X-ExperimentalApi': 'compass-beta, compass-prototype', 'X-SDK-Analytics': '{"createdFromFile":"true"}', 'X-SDK-Method': 'createBaseComponent', // Not including the version as it keeps changing }), ); }); test('adds headers properly when there is an analytic to send but no option is chosen', async () => { compassApp.createBaseComponent(MOCK_CLOUD_ID, { name: 'test', }); expect(apiSpy.mock.calls[0][2]).toEqual( expect.objectContaining({ 'Content-Type': 'application/json', 'X-ExperimentalApi': 'compass-beta, compass-prototype', 'X-SDK-Analytics': '{"createdFromFile":"false"}', 'X-SDK-Method': 'createBaseComponent', // Not including the version as it keeps changing }), ); }); test('does not add analytics headers for a call that doesnt include them', async () => { compassApp.getComponent({ componentId: 'test', }); expect(apiSpy.mock.calls[0][2]).toEqual( expect.objectContaining({ 'Content-Type': 'application/json', 'X-ExperimentalApi': 'compass-beta, compass-prototype', 'X-SDK-Method': 'getComponent', // Not including the version as it keeps changing }), ); expect(apiSpy.mock.calls[0][2]).not.toContain('X-SDK-Analytics'); }); });