Skip to content

Commit

Permalink
[CCR] Remove axios dependency in tests (elastic#128148)
Browse files Browse the repository at this point in the history
* Start refactoring test

* Finish refactoring rest of tests

(cherry picked from commit 7b545b0)
  • Loading branch information
sabarasaba committed Mar 22, 2022
1 parent 006c563 commit c1b0af8
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ import { setupEnvironment, pageHelpers, nextTick, getRandomString } from './help
const { setup } = pageHelpers.autoFollowPatternAdd;

describe('Create Auto-follow pattern', () => {
let server;
let httpRequestsMockHelpers;

beforeAll(() => {
({ server, httpRequestsMockHelpers } = setupEnvironment());
});

afterAll(() => {
server.restore();
({ httpRequestsMockHelpers } = setupEnvironment());
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@
import { AutoFollowPatternForm } from '../../app/components/auto_follow_pattern_form';
import './mocks';
import { setupEnvironment, pageHelpers, nextTick } from './helpers';
import { AUTO_FOLLOW_PATTERN_EDIT } from './helpers/constants';
import { AUTO_FOLLOW_PATTERN_EDIT, AUTO_FOLLOW_PATTERN_EDIT_NAME } from './helpers/constants';

const { setup } = pageHelpers.autoFollowPatternEdit;
const { setup: setupAutoFollowPatternAdd } = pageHelpers.autoFollowPatternAdd;

describe('Edit Auto-follow pattern', () => {
let server;
let httpRequestsMockHelpers;

beforeAll(() => {
({ server, httpRequestsMockHelpers } = setupEnvironment());
});

afterAll(() => {
server.restore();
({ httpRequestsMockHelpers } = setupEnvironment());
});

describe('on component mount', () => {
Expand All @@ -36,7 +31,10 @@ describe('Edit Auto-follow pattern', () => {

beforeEach(async () => {
httpRequestsMockHelpers.setLoadRemoteClustersResponse(remoteClusters);
httpRequestsMockHelpers.setGetAutoFollowPatternResponse(AUTO_FOLLOW_PATTERN_EDIT);
httpRequestsMockHelpers.setGetAutoFollowPatternResponse(
AUTO_FOLLOW_PATTERN_EDIT_NAME,
AUTO_FOLLOW_PATTERN_EDIT
);
({ component, find } = setup());

await nextTick();
Expand Down Expand Up @@ -83,7 +81,10 @@ describe('Edit Auto-follow pattern', () => {
httpRequestsMockHelpers.setLoadRemoteClustersResponse([
{ name: 'cluster-2', seeds: ['localhost:123'], isConnected: false },
]);
httpRequestsMockHelpers.setGetAutoFollowPatternResponse(AUTO_FOLLOW_PATTERN_EDIT);
httpRequestsMockHelpers.setGetAutoFollowPatternResponse(
AUTO_FOLLOW_PATTERN_EDIT_NAME,
AUTO_FOLLOW_PATTERN_EDIT
);
({ component, find, exists, actions, form } = setup());

await nextTick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ import { setupEnvironment, pageHelpers, nextTick, delay, getRandomString } from
const { setup } = pageHelpers.autoFollowPatternList;

describe('<AutoFollowPatternList />', () => {
let server;
let httpRequestsMockHelpers;

beforeAll(() => {
({ server, httpRequestsMockHelpers } = setupEnvironment());
});

afterAll(() => {
server.restore();
({ httpRequestsMockHelpers } = setupEnvironment());
});

beforeEach(() => {
Expand Down Expand Up @@ -213,7 +208,7 @@ describe('<AutoFollowPatternList />', () => {
expect(rows.length).toBe(2);

// We wil delete the *first* auto-follow pattern in the table
httpRequestsMockHelpers.setDeleteAutoFollowPatternResponse({
httpRequestsMockHelpers.setDeleteAutoFollowPatternResponse(autoFollowPattern1.name, {
itemsDeleted: [autoFollowPattern1.name],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ const { setup } = pageHelpers.followerIndexAdd;
const { setup: setupAutoFollowPatternAdd } = pageHelpers.autoFollowPatternAdd;

describe('Create Follower index', () => {
let server;
let httpSetup;
let httpRequestsMockHelpers;

beforeAll(() => {
({ server, httpRequestsMockHelpers } = setupEnvironment());
});

afterAll(() => {
server.restore();
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
});

beforeEach(() => {
Expand Down Expand Up @@ -165,15 +163,12 @@ describe('Create Follower index', () => {
test('should make a request to check if the index name is available in ES', async () => {
httpRequestsMockHelpers.setGetClusterIndicesResponse([]);

// Keep track of the request count made until this point
const totalRequests = server.requests.length;

form.setInputValue('followerIndexInput', 'index-name');
await delay(550); // we need to wait as there is a debounce of 500ms on the http validation

expect(server.requests.length).toBe(totalRequests + 1);
expect(server.requests[server.requests.length - 1].url).toBe(
'/api/index_management/indices'
expect(httpSetup.get).toHaveBeenLastCalledWith(
`/api/index_management/indices`,
expect.anything()
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@ import { act } from 'react-dom/test-utils';
import { API_BASE_PATH } from '../../../common/constants';
import { FollowerIndexForm } from '../../app/components/follower_index_form/follower_index_form';
import './mocks';
import { FOLLOWER_INDEX_EDIT } from './helpers/constants';
import { FOLLOWER_INDEX_EDIT, FOLLOWER_INDEX_EDIT_NAME } from './helpers/constants';
import { setupEnvironment, pageHelpers, nextTick } from './helpers';

const { setup } = pageHelpers.followerIndexEdit;
const { setup: setupFollowerIndexAdd } = pageHelpers.followerIndexAdd;

describe('Edit follower index', () => {
let server;
let httpSetup;
let httpRequestsMockHelpers;

beforeAll(() => {
({ server, httpRequestsMockHelpers } = setupEnvironment());
});

afterAll(() => {
server.restore();
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
});

describe('on component mount', () => {
Expand All @@ -35,7 +33,10 @@ describe('Edit follower index', () => {

beforeEach(async () => {
httpRequestsMockHelpers.setLoadRemoteClustersResponse(remoteClusters);
httpRequestsMockHelpers.setGetFollowerIndexResponse(FOLLOWER_INDEX_EDIT);
httpRequestsMockHelpers.setGetFollowerIndexResponse(
FOLLOWER_INDEX_EDIT_NAME,
FOLLOWER_INDEX_EDIT
);
({ component, find } = setup());

await nextTick();
Expand Down Expand Up @@ -97,7 +98,10 @@ describe('Edit follower index', () => {

beforeEach(async () => {
httpRequestsMockHelpers.setLoadRemoteClustersResponse(remoteClusters);
httpRequestsMockHelpers.setGetFollowerIndexResponse(FOLLOWER_INDEX_EDIT);
httpRequestsMockHelpers.setGetFollowerIndexResponse(
FOLLOWER_INDEX_EDIT_NAME,
FOLLOWER_INDEX_EDIT
);

await act(async () => {
testBed = await setup();
Expand All @@ -117,26 +121,23 @@ describe('Edit follower index', () => {

await nextTick(); // Make sure the Request went through

const latestRequest = server.requests[server.requests.length - 1];
const requestBody = JSON.parse(JSON.parse(latestRequest.requestBody).body);

// Verify the API endpoint called: method, path and payload
expect(latestRequest.method).toBe('PUT');
expect(latestRequest.url).toBe(
`${API_BASE_PATH}/follower_indices/${FOLLOWER_INDEX_EDIT.name}`
expect(httpSetup.put).toHaveBeenLastCalledWith(
`${API_BASE_PATH}/follower_indices/${FOLLOWER_INDEX_EDIT_NAME}`,
expect.objectContaining({
body: JSON.stringify({
maxReadRequestOperationCount: 7845,
maxOutstandingReadRequests: 16,
maxReadRequestSize: '64mb',
maxWriteRequestOperationCount: 2456,
maxWriteRequestSize: '1048b',
maxOutstandingWriteRequests: 69,
maxWriteBufferCount: 123456,
maxWriteBufferSize: '256mb',
maxRetryDelay: '10s',
readPollTimeout: '2m',
}),
})
);
expect(requestBody).toEqual({
maxReadRequestOperationCount: 7845,
maxOutstandingReadRequests: 16,
maxReadRequestSize: '64mb',
maxWriteRequestOperationCount: 2456,
maxWriteRequestSize: '1048b',
maxOutstandingWriteRequests: 69,
maxWriteBufferCount: 123456,
maxWriteBufferSize: '256mb',
maxRetryDelay: '10s',
readPollTimeout: '2m',
});
});
});

Expand All @@ -151,7 +152,10 @@ describe('Edit follower index', () => {
httpRequestsMockHelpers.setLoadRemoteClustersResponse([
{ name: 'new-york', seeds: ['localhost:123'], isConnected: false },
]);
httpRequestsMockHelpers.setGetFollowerIndexResponse(FOLLOWER_INDEX_EDIT);
httpRequestsMockHelpers.setGetFollowerIndexResponse(
FOLLOWER_INDEX_EDIT_NAME,
FOLLOWER_INDEX_EDIT
);
({ component, find, exists, actions, form } = setup());

await nextTick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ import { setupEnvironment, pageHelpers, getRandomString } from './helpers';
const { setup } = pageHelpers.followerIndexList;

describe('<FollowerIndicesList />', () => {
let server;
let httpRequestsMockHelpers;

beforeAll(() => {
jest.useFakeTimers();
({ server, httpRequestsMockHelpers } = setupEnvironment());
({ httpRequestsMockHelpers } = setupEnvironment());
});

afterAll(() => {
jest.useRealTimers();
server.restore();
});

beforeEach(() => {
Expand Down
Loading

0 comments on commit c1b0af8

Please sign in to comment.