-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy pathutils.test.ts
More file actions
89 lines (75 loc) · 2.9 KB
/
Copy pathutils.test.ts
File metadata and controls
89 lines (75 loc) · 2.9 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import type { AxiosResponse } from 'axios';
import type { Hostname } from '../../types';
import {
getGitHubAPIBaseUrl,
getGitHubAuthBaseUrl,
getGitHubGraphQLUrl,
getNextURLFromLinkHeader,
} from './utils';
describe('renderer/utils/api/utils.ts', () => {
describe('getGitHubAuthBaseUrl', () => {
it('should generate a GitHub Auth url - non enterprise', () => {
const result = getGitHubAuthBaseUrl('github.com' as Hostname);
expect(result.toString()).toBe('https://github.com/');
});
it('should generate a GitHub Auth url - enterprise', () => {
const result = getGitHubAuthBaseUrl('github.gitify.io' as Hostname);
expect(result.toString()).toBe('https://github.gitify.io/api/v3/');
});
});
describe('getGitHubAPIBaseUrl', () => {
it('should generate a GitHub API url - non enterprise', () => {
const result = getGitHubAPIBaseUrl('github.com' as Hostname);
expect(result.toString()).toBe('https://api.github.com/');
});
it('should generate a GitHub API url - enterprise', () => {
const result = getGitHubAPIBaseUrl('github.gitify.io' as Hostname);
expect(result.toString()).toBe('https://github.gitify.io/api/v3/');
});
});
describe('getGitHubGraphQLUrl', () => {
it('should generate a GitHub GraphQL url - non enterprise', () => {
const result = getGitHubGraphQLUrl('github.com' as Hostname);
expect(result.toString()).toBe('https://api.github.com/graphql');
});
it('should generate a GitHub GraphQL url - enterprise', () => {
const result = getGitHubGraphQLUrl('github.gitify.io' as Hostname);
expect(result.toString()).toBe('https://github.gitify.io/api/graphql');
});
});
describe('getNextURLFromLinkHeader', () => {
it('should parse next url from link header', () => {
const mockResponse = {
headers: {
link: '<https://api.github.com/notifications?participating=false&page=2>; rel="next", <https://api.github.com/notifications?participating=false&page=2>; rel="last"',
},
};
const result = getNextURLFromLinkHeader(
mockResponse as unknown as AxiosResponse,
);
expect(result.toString()).toBe(
'https://api.github.com/notifications?participating=false&page=2',
);
});
it('should return null if no next url in link header', () => {
const mockResponse = {
headers: {
link: '<https://api.github.com/notifications?participating=false&page=2>; rel="last"',
},
};
const result = getNextURLFromLinkHeader(
mockResponse as unknown as AxiosResponse,
);
expect(result).toBeNull();
});
it('should return null if no link header exists', () => {
const mockResponse = {
headers: {},
};
const result = getNextURLFromLinkHeader(
mockResponse as unknown as AxiosResponse,
);
expect(result).toBeNull();
});
});
});