-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlogs.test.ts
51 lines (43 loc) · 1.68 KB
/
logs.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {getLogsLink} from '../logs';
describe('getLogsLink', () => {
test('should insert dbName into logs URL query', () => {
const loggingData = {
url: 'https://logging.url/projects/kikimr/logs?from=now-1h&to=now&query=%7Bproject+%3D+%22kikimr%22%2C+service+%3D+%22ydb%22%2C+cluster+%3D+%22ydb-ru-prestable%22%7D',
};
const result = getLogsLink({
logging: JSON.stringify(loggingData),
dbName: 'testdb',
});
// The URL should contain the dbName in the query parameter
expect(result).toBe(
'https://logging.url/projects/kikimr/logs?from=now-1h&to=now&query=%7Bproject+%3D+%22kikimr%22%2C+service+%3D+%22ydb%22%2C+cluster+%3D+%22ydb-ru-prestable%22%2C+database+%3D+%22testdb%22%7D',
);
});
test('should handle empty query parameters', () => {
const loggingData = {
url: 'https://logging.url/projects/kikimr/logs?from=now-1h&to=now&query=%7B%7D',
};
const result = getLogsLink({
logging: JSON.stringify(loggingData),
dbName: 'testdb',
});
// Should add dbName to empty query
expect(result).toBe(
'https://logging.url/projects/kikimr/logs?from=now-1h&to=now&query=%7Bdatabase+%3D+%22testdb%22%7D',
);
});
test('should return empty string for invalid data', () => {
expect(
getLogsLink({
logging: 'invalid json',
dbName: 'testdb',
}),
).toBe('');
expect(
getLogsLink({
logging: JSON.stringify({}),
dbName: 'testdb',
}),
).toBe('');
});
});