Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Ensure rule message do not span multiple lines (#62391) #62480

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,23 @@ describe('buildRuleMessageFactory', () => {
expect(message).toEqual(expect.stringContaining('signals index: "index"'));
});

it('joins message parts with newlines', () => {
it('joins message parts with spaces', () => {
const buildMessage = buildRuleMessageFactory(factoryParams);

const message = buildMessage('my message');
const messageParts = message.split('\n');
expect(messageParts).toContain('my message');
expect(messageParts).toContain('name: "name"');
expect(messageParts).toContain('id: "id"');
expect(messageParts).toContain('rule id: "ruleId"');
expect(messageParts).toContain('signals index: "index"');
expect(message).toEqual(expect.stringContaining('my message '));
expect(message).toEqual(expect.stringContaining(' name: "name" '));
expect(message).toEqual(expect.stringContaining(' id: "id" '));
expect(message).toEqual(expect.stringContaining(' rule id: "ruleId" '));
expect(message).toEqual(expect.stringContaining(' signals index: "index"'));
});

it('joins multiple arguments with newlines', () => {
it('joins multiple arguments with spaces', () => {
const buildMessage = buildRuleMessageFactory(factoryParams);

const message = buildMessage('my message', 'here is more');
const messageParts = message.split('\n');
expect(messageParts).toContain('my message');
expect(messageParts).toContain('here is more');
expect(message).toEqual(expect.stringContaining('my message '));
expect(message).toEqual(expect.stringContaining(' here is more'));
});

it('defaults the rule ID if not provided ', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ export const buildRuleMessageFactory = ({
`id: "${id}"`,
`rule id: "${ruleId ?? '(unknown rule id)'}"`,
`signals index: "${index}"`,
].join('\n');
].join(' ');
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const signalRulesAlertType = ({
'Machine learning rule is missing job id and/or anomaly threshold:',
`job id: "${machineLearningJobId}"`,
`anomaly threshold: "${anomalyThreshold}"`,
].join('\n')
].join(' ')
);
}

Expand Down