kibana/x-pack/solutions/observability/plugins/synthetics/server/routes/common.test.ts
Shahzad f317cec25b
[Synthetics] Multi space monitors !! (#221568)
## Summary

Multi space monitors !!

Fixes https://github.com/elastic/kibana/issues/164294

User will be able to choose in which space monitors will be available !!

<img width="1728" alt="image"
src="https://github.com/user-attachments/assets/f01ac226-ed54-4e96-b6f4-27f0134a9be5"
/>


### Technical 
This is being done by registering another saved object type and for
existing monitors it will continue to work as right now but for newly
created monitors user will have ability to specify spaces or choose
multiple spaces or all.

### Testing

1. Create few monitors before this PR in multiple spaces
2. Create multiple monitors in multiple spaces after this PR
3. Make sure filtering, editing and deleting, creating works as expected
on both set of monitors

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-06-25 10:47:47 +02:00

73 lines
3.1 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { parseArrayFilters } from './common';
import { getSavedObjectKqlFilter } from './common';
describe('common utils', () => {
it('tests parseArrayFilters', () => {
const filters = parseArrayFilters({
configIds: ['1 4', '2 6', '5'],
});
expect(filters.filtersStr).toMatchInlineSnapshot(
`"synthetics-monitor-multi-space.attributes.config_id:(\\"1 4\\" OR \\"2 6\\" OR \\"5\\")"`
);
});
it('tests parseArrayFilters with tags and configIds', () => {
const filters = parseArrayFilters({
configIds: ['1', '2'],
tags: ['tag1', 'tag2'],
});
expect(filters.filtersStr).toMatchInlineSnapshot(
`"synthetics-monitor-multi-space.attributes.tags:(\\"tag1\\" OR \\"tag2\\") AND synthetics-monitor-multi-space.attributes.config_id:(\\"1\\" OR \\"2\\")"`
);
});
it('tests parseArrayFilters with all options', () => {
const filters = parseArrayFilters({
configIds: ['1', '2'],
tags: ['tag1', 'tag2'],
locations: ['loc1', 'loc2'],
monitorTypes: ['type1', 'type2'],
projects: ['project1', 'project2'],
monitorQueryIds: ['query1', 'query2'],
schedules: ['schedule1', 'schedule2'],
});
expect(filters.filtersStr).toMatchInlineSnapshot(
`"synthetics-monitor-multi-space.attributes.tags:(\\"tag1\\" OR \\"tag2\\") AND synthetics-monitor-multi-space.attributes.project_id:(\\"project1\\" OR \\"project2\\") AND synthetics-monitor-multi-space.attributes.type:(\\"type1\\" OR \\"type2\\") AND synthetics-monitor-multi-space.attributes.locations.id:(\\"loc1\\" OR \\"loc2\\") AND synthetics-monitor-multi-space.attributes.schedule.number:(\\"schedule1\\" OR \\"schedule2\\") AND synthetics-monitor-multi-space.attributes.id:(\\"query1\\" OR \\"query2\\") AND synthetics-monitor-multi-space.attributes.config_id:(\\"1\\" OR \\"2\\")"`
);
});
});
describe('getSavedObjectKqlFilter', () => {
it('returns empty string if no values are provided', () => {
expect(getSavedObjectKqlFilter({ field: 'tags' })).toBe('');
});
it('returns KQL string if values are provided', () => {
expect(getSavedObjectKqlFilter({ field: 'tags', values: 'apm' })).toBe(
'synthetics-monitor-multi-space.attributes.tags:"apm"'
);
});
it('searches at root when specified', () => {
expect(getSavedObjectKqlFilter({ field: 'tags', values: 'apm', searchAtRoot: true })).toBe(
'tags:"apm"'
);
});
it('handles array values', () => {
expect(getSavedObjectKqlFilter({ field: 'tags', values: ['apm', 'synthetics'] })).toBe(
'synthetics-monitor-multi-space.attributes.tags:("apm" OR "synthetics")'
);
});
it('escapes quotes', () => {
expect(getSavedObjectKqlFilter({ field: 'tags', values: ['"apm', 'synthetics'] })).toBe(
'synthetics-monitor-multi-space.attributes.tags:("\\"apm" OR "synthetics")'
);
});
});