|
4 | 4 | * you may not use this file except in compliance with the Elastic License. |
5 | 5 | */ |
6 | 6 |
|
7 | | -import { roundToNearestMinute } from './get_redirect_to_transaction_detail_page_url'; |
| 7 | +import { getRedirectToTransactionDetailPageUrl } from './get_redirect_to_transaction_detail_page_url'; |
| 8 | +import { parse } from 'url'; |
8 | 9 |
|
9 | | -describe('roundToNearestMinute', () => { |
10 | | - it('should round up to nearest 5 minute', () => { |
11 | | - expect( |
12 | | - roundToNearestMinute({ |
13 | | - timestamp: '2020-01-01T00:00:40.000Z', |
14 | | - direction: 'up', |
15 | | - }) |
16 | | - ).toBe('2020-01-01T00:05:00.000Z'); |
17 | | - }); |
| 10 | +describe('getRedirectToTransactionDetailPageUrl', () => { |
| 11 | + const transaction = ({ |
| 12 | + '@timestamp': '2020-01-01T00:01:00.000Z', |
| 13 | + service: { name: 'opbeans-node' }, |
| 14 | + trace: { id: 'trace_id' }, |
| 15 | + transaction: { |
| 16 | + id: 'transaction_id', |
| 17 | + name: 'transaction_name', |
| 18 | + type: 'request', |
| 19 | + duration: { us: 5000 }, |
| 20 | + }, |
| 21 | + } as unknown) as any; |
| 22 | + |
| 23 | + const url = getRedirectToTransactionDetailPageUrl({ transaction }); |
18 | 24 |
|
19 | | - it('should round down to nearest 5 minute', () => { |
20 | | - expect( |
21 | | - roundToNearestMinute({ |
22 | | - timestamp: '2020-01-01T00:00:40.000Z', |
23 | | - direction: 'down', |
24 | | - }) |
25 | | - ).toBe('2020-01-01T00:00:00.000Z'); |
| 25 | + it('rounds the start time down', () => { |
| 26 | + expect(parse(url, true).query.rangeFrom).toBe('2020-01-01T00:00:00.000Z'); |
26 | 27 | }); |
27 | 28 |
|
28 | | - it('should add diff and round up', () => { |
29 | | - expect( |
30 | | - roundToNearestMinute({ |
31 | | - timestamp: '2020-01-01T00:00:40.000Z', |
32 | | - diff: 1000 * 60 * 7, // 7 minutes |
33 | | - direction: 'up', |
34 | | - }) |
35 | | - ).toBe('2020-01-01T00:10:00.000Z'); |
| 29 | + it('rounds the end time up', () => { |
| 30 | + expect(parse(url, true).query.rangeTo).toBe('2020-01-01T00:05:00.000Z'); |
36 | 31 | }); |
37 | 32 |
|
38 | | - it('should add diff and round down', () => { |
39 | | - expect( |
40 | | - roundToNearestMinute({ |
41 | | - timestamp: '2020-01-01T00:00:40.000Z', |
42 | | - diff: 1000 * 60 * 7, // 7 minutes |
43 | | - direction: 'down', |
44 | | - }) |
45 | | - ).toBe('2020-01-01T00:05:00.000Z'); |
| 33 | + it('formats url correctly', () => { |
| 34 | + expect(url).toBe( |
| 35 | + '/services/opbeans-node/transactions/view?traceId=trace_id&transactionId=transaction_id&transactionName=transaction_name&transactionType=request&rangeFrom=2020-01-01T00%3A00%3A00.000Z&rangeTo=2020-01-01T00%3A05%3A00.000Z' |
| 36 | + ); |
46 | 37 | }); |
47 | 38 | }); |
0 commit comments