/
index.spec.ts
101 lines (87 loc) · 2.84 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
import { GetPkgReleasesConfig, GetReleasesConfig, getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { getName, loadJsonFixture, partial } from '../../../test/util';
import { ExternalHostError } from '../../types/errors/external-host-error';
import { id as versioning } from '../../versioning/gradle';
import { id as datasource, getReleases } from '.';
const allResponse: any = loadJsonFixture(__filename, 'all.json');
let config: GetPkgReleasesConfig;
describe(getName(__filename), () => {
describe('getReleases', () => {
beforeEach(() => {
config = {
datasource,
versioning,
depName: 'abc',
};
jest.clearAllMocks();
httpMock.setup();
});
afterEach(() => {
httpMock.reset();
});
it('processes real data', async () => {
httpMock
.scope('https://services.gradle.org/')
.get('/versions/all')
.reply(200, allResponse);
const res = await getPkgReleases(config);
expect(res).toMatchSnapshot();
expect(res).not.toBeNull();
expect(res.releases).toHaveLength(300);
expect(
res.releases.filter(({ isDeprecated }) => isDeprecated)
).toHaveLength(1);
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('calls configured registryUrls', async () => {
httpMock.scope('https://foo.bar').get('/').reply(200, allResponse);
httpMock
.scope('http://baz.qux')
.get('/')
.reply(200, [
{ version: '1.0.1' },
{ version: '1.0.2', buildTime: 'abc' },
]);
const res = await getPkgReleases({
...config,
registryUrls: ['https://foo.bar', 'http://baz.qux'],
});
expect(res).toMatchSnapshot();
expect(res).not.toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('handles empty releases', async () => {
httpMock
.scope('https://services.gradle.org/')
.get('/versions/all')
.reply(200, []);
const res = await getPkgReleases(config);
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('handles errors', async () => {
expect.assertions(3);
httpMock
.scope('https://services.gradle.org/')
.get('/versions/all')
.reply(404);
httpMock.scope('http://baz.qux').get('/').reply(404);
await expect(
getReleases(
partial<GetReleasesConfig>({
registryUrl: 'https://services.gradle.org/versions/all',
})
)
).rejects.toThrow(ExternalHostError);
await expect(
getReleases(
partial<GetReleasesConfig>({
registryUrl: 'http://baz.qux',
})
)
).rejects.toThrow('Response code 404 (Not Found)');
expect(httpMock.getTrace()).toMatchSnapshot();
});
});
});