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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
import PerformanceBarService from '~/performance_bar/services/performance_bar_service';
describe('PerformanceBarService', () => {
describe('callbackParams', () => {
describe('fireCallback', () => {
function fireCallback(response, peekUrl) {
return PerformanceBarService.callbackParams(response, peekUrl)[0];
}
it('returns false when the request URL is the peek URL', () => {
expect(
fireCallback({ headers: { 'x-request-id': '123' }, config: { url: '/peek' } }, '/peek'),
).toBe(false);
});
it('returns false when there is no request ID', () => {
expect(fireCallback({ headers: {}, config: { url: '/request' } }, '/peek')).toBe(false);
});
it('returns false when the response is from the cache', () => {
expect(
fireCallback(
{ headers: { 'x-request-id': '123', 'x-gitlab-from-cache': 'true' }, url: '/request' },
'/peek',
),
).toBe(false);
});
it('returns true when the request is an API request', () => {
expect(
fireCallback({ headers: { 'x-request-id': '123' }, config: { url: '/api/' } }, '/peek'),
).toBe(true);
});
it('returns true for all other requests', () => {
expect(
fireCallback(
{ headers: { 'x-request-id': '123' }, config: { url: '/request' } },
'/peek',
),
).toBe(true);
});
});
describe('requestId', () => {
function requestId(response, peekUrl) {
return PerformanceBarService.callbackParams(response, peekUrl)[1];
}
it('gets the request ID from the headers', () => {
expect(requestId({ headers: { 'x-request-id': '123' } }, '/peek')).toBe('123');
});
});
describe('requestUrl', () => {
function requestUrl(response, peekUrl) {
return PerformanceBarService.callbackParams(response, peekUrl)[2];
}
it('gets the request URL from response.config', () => {
expect(requestUrl({ headers: {}, config: { url: '/config-url' } }, '/peek')).toBe(
'/config-url',
);
});
});
});
});
|