Skip to content

Commit 80dc9ec

Browse files
committed
Avoid exporting roundToNearestMinute
1 parent 0685a0a commit 80dc9ec

2 files changed

Lines changed: 25 additions & 34 deletions

File tree

x-pack/plugins/apm/public/components/app/TraceLink/get_redirect_to_transaction_detail_page_url.test.ts

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,35 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

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';
89

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 });
1824

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');
2627
});
2728

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');
3631
});
3732

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+
);
4637
});
4738
});

x-pack/plugins/apm/public/components/app/TraceLink/get_redirect_to_transaction_detail_page_url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const getRedirectToTransactionDetailPageUrl = ({
3939
});
4040
};
4141

42-
export function roundToNearestMinute({
42+
function roundToNearestMinute({
4343
timestamp,
4444
diff = 0,
4545
direction = 'up',

0 commit comments

Comments
 (0)