Skip to content

Commit

Permalink
Update remaining patch tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spong committed Mar 23, 2023
1 parent d48bec2 commit a38bc4b
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { convertPatchAPIToInternalSchema, patchTypeSpecificSnakeToCamel } from './rule_converters';
import { patchTypeSpecificSnakeToCamel } from './rule_converters';
import {
getEqlRuleParams,
getMlRuleParams,
Expand All @@ -15,7 +15,6 @@ import {
getThreatRuleParams,
getThresholdRuleParams,
} from '../../rule_schema/mocks';
import { getRuleMock } from '../../routes/__mocks__/request_responses';

describe('rule_converters', () => {
describe('patchTypeSpecificSnakeToCamel', () => {
Expand Down Expand Up @@ -204,79 +203,4 @@ describe('rule_converters', () => {
);
});
});

describe('convertPatchAPIToInternalSchema', () => {
test('should set version to one specified in next params for custom rules', () => {
const nextParams = {
index: ['new-test-index'],
language: 'lucene',
version: 3,
};
const existingRule = getRuleMock({ ...getQueryRuleParams(), version: 1 });
const patchedParams = convertPatchAPIToInternalSchema(nextParams, existingRule);
expect(patchedParams).toEqual(
expect.objectContaining({
params: expect.objectContaining({ version: 3 }),
})
);
});

test('should set version to one specified in next params for immutable rules', () => {
const nextParams = {
index: ['new-test-index'],
language: 'lucene',
version: 3,
};
const existingRule = getRuleMock({ ...getQueryRuleParams(), version: 1, immutable: true });
const patchedParams = convertPatchAPIToInternalSchema(nextParams, existingRule);
expect(patchedParams).toEqual(
expect.objectContaining({
params: expect.objectContaining({ version: 3 }),
})
);
});

test('should not increment version for immutable rules if it is not specified in next params', () => {
const nextParams = {
index: ['new-test-index'],
language: 'lucene',
};
const existingRule = getRuleMock({ ...getQueryRuleParams(), version: 1, immutable: true });
const patchedParams = convertPatchAPIToInternalSchema(nextParams, existingRule);
expect(patchedParams).toEqual(
expect.objectContaining({
params: expect.objectContaining({ version: 1 }),
})
);
});

test('should increment version for custom rules if it is not specified in next params', () => {
const nextParams = {
index: ['new-test-index'],
language: 'lucene',
};
const existingRule = getRuleMock({ ...getQueryRuleParams(), version: 1 });
const patchedParams = convertPatchAPIToInternalSchema(nextParams, existingRule);
expect(patchedParams).toEqual(
expect.objectContaining({
params: expect.objectContaining({ version: 2 }),
})
);
});

test('should not increment version due to enabled, id, or rule_id, ', () => {
const nextParams = {
enabled: false,
id: 'some-id',
rule_id: 'some-rule-id',
};
const existingRule = getRuleMock({ ...getQueryRuleParams(), version: 1 });
const patchedParams = convertPatchAPIToInternalSchema(nextParams, existingRule);
expect(patchedParams).toEqual(
expect.objectContaining({
params: expect.objectContaining({ version: 1 }),
})
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ export default ({ getService }: FtrProviderContext): void => {
output_index: '',
};
ruleOutput.name = 'some other name';
ruleOutput.version = 2;
ruleOutput.revision = 0;
expect(bodyToCompare).to.eql(ruleOutput);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutput();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;
const bodyToCompare = removeServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(outputRule);
Expand Down Expand Up @@ -86,7 +85,6 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutputWithoutRuleId();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;
const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body);
expect(bodyToCompare).to.eql(outputRule);
Expand All @@ -104,13 +102,12 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutput();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;
const bodyToCompare = removeServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(outputRule);
});

it('should not change the version of a rule when it patches only enabled', async () => {
it('should not change the revision of a rule when it patches only enabled', async () => {
await createRule(supertest, log, getSimpleRule('rule-1'));

// patch a simple rule's enabled to false
Expand All @@ -127,7 +124,7 @@ export default ({ getService }: FtrProviderContext) => {
expect(bodyToCompare).to.eql(outputRule);
});

it('should change the version of a rule when it patches enabled and another property', async () => {
it('should change the revision of a rule when it patches enabled and another property', async () => {
await createRule(supertest, log, getSimpleRule('rule-1'));

// patch a simple rule's enabled to false and another property
Expand All @@ -140,7 +137,6 @@ export default ({ getService }: FtrProviderContext) => {
const outputRule = getSimpleRuleOutput();
outputRule.enabled = false;
outputRule.severity = 'low';
outputRule.version = 2;
outputRule.revision = 1;

const bodyToCompare = removeServerGeneratedProperties(body);
Expand Down Expand Up @@ -168,7 +164,6 @@ export default ({ getService }: FtrProviderContext) => {
outputRule.name = 'some other name';
outputRule.timeline_title = 'some title';
outputRule.timeline_id = 'some id';
outputRule.version = 3;
outputRule.revision = 2;

const bodyToCompare = removeServerGeneratedProperties(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutput();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;
const bodyToCompare = removeServerGeneratedProperties(body[0]);
expect(bodyToCompare).to.eql(outputRule);
Expand All @@ -71,12 +70,10 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule1 = getSimpleRuleOutput();
outputRule1.name = 'some other name';
outputRule1.version = 2;
outputRule1.revision = 1;

const outputRule2 = getSimpleRuleOutput('rule-2');
outputRule2.name = 'some other name';
outputRule2.version = 2;
outputRule2.revision = 1;

const bodyToCompare1 = removeServerGeneratedProperties(body[0]);
Expand All @@ -97,7 +94,6 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutput();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;
const bodyToCompare = removeServerGeneratedProperties(body[0]);
expect(bodyToCompare).to.eql(outputRule);
Expand All @@ -119,12 +115,10 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule1 = getSimpleRuleOutputWithoutRuleId('rule-1');
outputRule1.name = 'some other name';
outputRule1.version = 2;
outputRule1.revision = 1;

const outputRule2 = getSimpleRuleOutputWithoutRuleId('rule-2');
outputRule2.name = 'some other name';
outputRule2.version = 2;
outputRule2.revision = 1;

const bodyToCompare1 = removeServerGeneratedPropertiesIncludingRuleId(body[0]);
Expand All @@ -145,13 +139,12 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutput();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;
const bodyToCompare = removeServerGeneratedProperties(body[0]);
expect(bodyToCompare).to.eql(outputRule);
});

it('should not change the version of a rule when it patches only enabled', async () => {
it('should not change the revision of a rule when it patches only enabled', async () => {
await createRule(supertest, log, getSimpleRule('rule-1'));

// patch a simple rule's enabled to false
Expand All @@ -168,7 +161,7 @@ export default ({ getService }: FtrProviderContext) => {
expect(bodyToCompare).to.eql(outputRule);
});

it('should change the version of a rule when it patches enabled and another property', async () => {
it('should change the revision of a rule when it patches enabled and another property', async () => {
await createRule(supertest, log, getSimpleRule('rule-1'));

// patch a simple rule's enabled to false and another property
Expand All @@ -181,7 +174,6 @@ export default ({ getService }: FtrProviderContext) => {
const outputRule = getSimpleRuleOutput();
outputRule.enabled = false;
outputRule.severity = 'low';
outputRule.version = 2;
outputRule.revision = 1;

const bodyToCompare = removeServerGeneratedProperties(body[0]);
Expand Down Expand Up @@ -209,7 +201,6 @@ export default ({ getService }: FtrProviderContext) => {
outputRule.name = 'some other name';
outputRule.timeline_title = 'some title';
outputRule.timeline_id = 'some id';
outputRule.version = 3;
outputRule.revision = 2;

const bodyToCompare = removeServerGeneratedProperties(body[0]);
Expand Down Expand Up @@ -264,7 +255,6 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutput();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;

const bodyToCompare = removeServerGeneratedProperties(body[0]);
Expand Down Expand Up @@ -295,7 +285,6 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutput();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;

const bodyToCompare = removeServerGeneratedProperties(body[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,6 @@ export default ({ getService }: FtrProviderContext): void => {
output_index: '',
};
ruleOutput.name = 'some other name';
ruleOutput.version = 2;
ruleOutput.revision = 0;
expect(bodyToCompare).to.eql(ruleOutput);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutput();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;
const bodyToCompare = removeServerGeneratedProperties(body[0]);
expect(bodyToCompare).to.eql(outputRule);
Expand All @@ -94,12 +93,10 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule1 = getSimpleRuleOutput();
outputRule1.name = 'some other name';
outputRule1.version = 2;
outputRule1.revision = 1;

const outputRule2 = getSimpleRuleOutput('rule-2');
outputRule2.name = 'some other name';
outputRule2.version = 2;
outputRule2.revision = 1;

const bodyToCompare1 = removeServerGeneratedProperties(body[0]);
Expand All @@ -120,7 +117,6 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutput();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;
const bodyToCompare = removeServerGeneratedProperties(body[0]);
expect(bodyToCompare).to.eql(outputRule);
Expand All @@ -142,12 +138,10 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule1 = getSimpleRuleOutputWithoutRuleId('rule-1');
outputRule1.name = 'some other name';
outputRule1.version = 2;
outputRule1.revision = 1;

const outputRule2 = getSimpleRuleOutputWithoutRuleId('rule-2');
outputRule2.name = 'some other name';
outputRule2.version = 2;
outputRule2.revision = 1;

const bodyToCompare1 = removeServerGeneratedPropertiesIncludingRuleId(body[0]);
Expand Down Expand Up @@ -219,13 +213,12 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutput();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;
const bodyToCompare = removeServerGeneratedProperties(body[0]);
expect(bodyToCompare).to.eql(outputRule);
});

it('should not change the version of a rule when it patches only enabled', async () => {
it('should not change the revision of a rule when it patches only enabled', async () => {
await createRule(supertest, log, getSimpleRule('rule-1'));

// patch a simple rule's enabled to false
Expand All @@ -242,7 +235,7 @@ export default ({ getService }: FtrProviderContext) => {
expect(bodyToCompare).to.eql(outputRule);
});

it('should change the version of a rule when it patches enabled and another property', async () => {
it('should change the revision of a rule when it patches enabled and another property', async () => {
await createRule(supertest, log, getSimpleRule('rule-1'));

// patch a simple rule's enabled to false and another property
Expand All @@ -255,7 +248,6 @@ export default ({ getService }: FtrProviderContext) => {
const outputRule = getSimpleRuleOutput();
outputRule.enabled = false;
outputRule.severity = 'low';
outputRule.version = 2;
outputRule.revision = 1;

const bodyToCompare = removeServerGeneratedProperties(body[0]);
Expand Down Expand Up @@ -283,7 +275,6 @@ export default ({ getService }: FtrProviderContext) => {
outputRule.name = 'some other name';
outputRule.timeline_title = 'some title';
outputRule.timeline_id = 'some id';
outputRule.version = 3;
outputRule.revision = 2;

const bodyToCompare = removeServerGeneratedProperties(body[0]);
Expand Down Expand Up @@ -338,7 +329,6 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutput();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;

const bodyToCompare = removeServerGeneratedProperties(body[0]);
Expand Down Expand Up @@ -369,7 +359,6 @@ export default ({ getService }: FtrProviderContext) => {

const outputRule = getSimpleRuleOutput();
outputRule.name = 'some other name';
outputRule.version = 2;
outputRule.revision = 1;

const bodyToCompare = removeServerGeneratedProperties(body[0]);
Expand Down

0 comments on commit a38bc4b

Please sign in to comment.