/
index.spec.ts
102 lines (98 loc) · 2.73 KB
/
index.spec.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
import { getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
import { datasource } from './common';
describe('datasource/gitlab-packages/index', () => {
describe('getReleases', () => {
it('returns package from custom registry', async () => {
const body = [
{
version: '1.0.0',
created_at: '2020-03-04T12:01:37.000-06:00',
name: 'mypkg',
},
{
version: 'v1.1.0',
created_at: '2020-04-04T12:01:37.000-06:00',
name: 'mypkg',
},
{
version: 'v1.1.1',
created_at: '2020-05-04T12:01:37.000-06:00',
name: 'mypkg',
},
{
version: 'v2.0.0',
created_at: '2020-05-04T12:01:37.000-06:00',
name: 'otherpkg',
},
];
httpMock
.scope('https://gitlab.com')
.get('/api/v4/projects/user%2Fproject1/packages')
.query({
package_name: 'mypkg',
per_page: '100',
})
.reply(200, body);
const res = await getPkgReleases({
datasource,
registryUrls: ['https://gitlab.com'],
depName: 'user/project1:mypkg',
});
expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(3);
});
it('returns null for 404', async () => {
httpMock
.scope('https://gitlab.com')
.get('/api/v4/projects/user%2Fproject1/packages')
.query({
package_name: 'mypkg',
per_page: '100',
})
.reply(404);
expect(
await getPkgReleases({
datasource,
registryUrls: ['https://gitlab.com'],
depName: 'user/project1:mypkg',
})
).toBeNull();
});
it('returns null for empty 200 OK', async () => {
httpMock
.scope('https://gitlab.com')
.get('/api/v4/projects/user%2Fproject1/packages')
.query({
package_name: 'mypkg',
per_page: '100',
})
.reply(200, []);
expect(
await getPkgReleases({
datasource,
registryUrls: ['https://gitlab.com'],
depName: 'user/project1:mypkg',
})
).toBeNull();
});
it('throws for 5xx', async () => {
httpMock
.scope('https://gitlab.com')
.get('/api/v4/projects/user%2Fproject1/packages')
.query({
package_name: 'mypkg',
per_page: '100',
})
.reply(502);
await expect(
getPkgReleases({
datasource,
registryUrls: ['https://gitlab.com'],
depName: 'user/project1:mypkg',
})
).rejects.toThrow(EXTERNAL_HOST_ERROR);
});
});
});