Skip to content

Commit

Permalink
[Upgrade Assistant] Tests for updating step state accordingly if API …
Browse files Browse the repository at this point in the history
…poll receives count followed by error (#111701)

* Add test for logs count polling

* Test when count api fails
  • Loading branch information
sabarasaba authored Sep 9, 2021
1 parent d91e865 commit 5250db8
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ jest.mock('../../../../public/application/lib/logs_checkpoint', () => {

import { DeprecationLoggingStatus } from '../../../../common/types';
import { DEPRECATION_LOGS_SOURCE_ID } from '../../../../common/constants';
import { setupEnvironment } from '../../helpers';
import { OverviewTestBed, setupOverviewPage } from '../overview.helpers';
import { setupEnvironment, advanceTime } from '../../helpers';
import { DEPRECATION_LOGS_COUNT_POLL_INTERVAL_MS } from '../../../../common/constants';

const getLoggingResponse = (toggle: boolean): DeprecationLoggingStatus => ({
isDeprecationLogIndexingEnabled: toggle,
Expand Down Expand Up @@ -308,5 +309,42 @@ describe('Overview - Fix deprecation logs step', () => {

expect(exists('noWarningsCallout')).toBe(true);
});

describe('Poll for logs count', () => {
beforeEach(async () => {
jest.useFakeTimers();

// First request should make the step be complete
httpRequestsMockHelpers.setLoadDeprecationLogsCountResponse({
count: 0,
});

testBed = await setupOverviewPage();
});

afterEach(() => {
jest.useRealTimers();
});

test('renders step as incomplete when a success state is followed by an error state', async () => {
const { exists } = testBed;

expect(exists('fixLogsStep-complete')).toBe(true);

// second request will error
const error = {
statusCode: 500,
error: 'Internal server error',
message: 'Internal server error',
};
httpRequestsMockHelpers.setLoadDeprecationLogsCountResponse(undefined, error);

// Resolve the polling timeout.
await advanceTime(DEPRECATION_LOGS_COUNT_POLL_INTERVAL_MS);
testBed.component.update();

expect(exists('fixLogsStep-incomplete')).toBe(true);
});
});
});
});

0 comments on commit 5250db8

Please sign in to comment.