Skip to content

Commit

Permalink
fix serialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Sep 15, 2022
1 parent dd9947a commit c3c3c09
Showing 1 changed file with 56 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ describe('<EditPolicy /> serialization', () => {
await actions.hot.setShrinkCount('2');
await actions.hot.toggleReadonly();
await actions.hot.setIndexPriority('123');
await actions.hot.downsample.toggle();
await actions.hot.downsample.setDownsampleInterval('2', 'h');

await actions.savePolicy();

Expand Down Expand Up @@ -233,7 +231,6 @@ describe('<EditPolicy /> serialization', () => {
priority: 123,
},
readonly: {},
downsample: { fixed_interval: '2h' },
},
},
},
Expand All @@ -257,6 +254,24 @@ describe('<EditPolicy /> serialization', () => {
expect(parsedReqBody.phases.hot.actions.searchable_snapshot.snapshot_repository).toBe('abc');
});

// Setting downsample disables setting readonly so we test this separately
test('setting downsample', async () => {
const { actions } = testBed;

await actions.rollover.toggleDefault();
await actions.hot.downsample.toggle();
await actions.hot.downsample.setDownsampleInterval('2', 'h');

await actions.savePolicy();

const lastReq: HttpFetchOptionsWithPath[] = httpSetup.post.mock.calls.pop() || [];
const [requestUrl, requestBody] = lastReq;
const parsedReqBody = JSON.parse((requestBody as Record<string, any>).body);

expect(requestUrl).toBe(`${API_BASE_PATH}/policies`);
expect(parsedReqBody.phases.hot.actions.downsample).toEqual({ fixed_interval: '2h' });
});

test('disabling rollover', async () => {
const { actions } = testBed;

Expand Down Expand Up @@ -326,8 +341,6 @@ describe('<EditPolicy /> serialization', () => {
await actions.warm.setBestCompression(true);
await actions.warm.toggleReadonly();
await actions.warm.setIndexPriority('123');
await actions.warm.downsample.toggle();
await actions.warm.downsample.setDownsampleInterval('20', 'm');
await actions.savePolicy();

expect(httpSetup.post).toHaveBeenLastCalledWith(
Expand Down Expand Up @@ -365,7 +378,6 @@ describe('<EditPolicy /> serialization', () => {
number_of_replicas: 123,
},
readonly: {},
downsample: { fixed_interval: '20m' },
},
},
},
Expand All @@ -374,6 +386,25 @@ describe('<EditPolicy /> serialization', () => {
);
});

// Setting downsample disables setting readonly so we test this separately
test('setting downsample', async () => {
const { actions } = testBed;

await actions.togglePhase('warm');
await actions.warm.setMinAgeValue('11');
await actions.warm.downsample.toggle();
await actions.warm.downsample.setDownsampleInterval('20', 'm');

await actions.savePolicy();

const lastReq: HttpFetchOptionsWithPath[] = httpSetup.post.mock.calls.pop() || [];
const [requestUrl, requestBody] = lastReq;
const parsedReqBody = JSON.parse((requestBody as Record<string, any>).body);

expect(requestUrl).toBe(`${API_BASE_PATH}/policies`);
expect(parsedReqBody.phases.warm.actions.downsample).toEqual({ fixed_interval: '20m' });
});

describe('policy with include and exclude', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([POLICY_WITH_INCLUDE_EXCLUDE]);
Expand Down Expand Up @@ -469,8 +500,6 @@ describe('<EditPolicy /> serialization', () => {
await actions.cold.setReplicas('123');
await actions.cold.toggleReadonly();
await actions.cold.setIndexPriority('123');
await actions.cold.downsample.toggle();
await actions.cold.downsample.setDownsampleInterval('5');

await actions.savePolicy();

Expand Down Expand Up @@ -502,7 +531,6 @@ describe('<EditPolicy /> serialization', () => {
number_of_replicas: 123,
},
readonly: {},
downsample: { fixed_interval: '5d' },
},
},
},
Expand All @@ -511,6 +539,25 @@ describe('<EditPolicy /> serialization', () => {
);
});

// Setting downsample disables setting readonly so we test this separately
test('setting downsample', async () => {
const { actions } = testBed;

await actions.togglePhase('cold');
await actions.cold.setMinAgeValue('11');
await actions.cold.downsample.toggle();
await actions.cold.downsample.setDownsampleInterval('2');

await actions.savePolicy();

const lastReq: HttpFetchOptionsWithPath[] = httpSetup.post.mock.calls.pop() || [];
const [requestUrl, requestBody] = lastReq;
const parsedReqBody = JSON.parse((requestBody as Record<string, any>).body);

expect(requestUrl).toBe(`${API_BASE_PATH}/policies`);
expect(parsedReqBody.phases.cold.actions.downsample).toEqual({ fixed_interval: '2d' });
});

// Setting searchable snapshot field disables setting replicas so we test this separately
test('setting searchable snapshot', async () => {
const { actions } = testBed;
Expand Down

0 comments on commit c3c3c09

Please sign in to comment.