forked from renovatebot/renovate
/
index.spec.ts
125 lines (103 loc) · 3.59 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { getName, loadJsonFixture } from '../../../test/util';
import * as versioning from '../../versioning/docker';
import { resetCache } from './get';
import * as jenkins from '.';
const jenkinsPluginsVersions = loadJsonFixture(
__filename,
'plugin-versions.json'
);
const jenkinsPluginsInfo = loadJsonFixture(
__filename,
'update-center.actual.json'
);
describe(getName(__filename), () => {
describe('getReleases', () => {
const SKIP_CACHE = process.env.RENOVATE_SKIP_CACHE;
const params = {
versioning: versioning.id,
datasource: jenkins.id,
depName: 'email-ext',
registryUrls: ['https://updates.jenkins.io/'],
};
beforeEach(() => {
resetCache();
httpMock.setup();
process.env.RENOVATE_SKIP_CACHE = 'true';
jest.resetAllMocks();
});
afterEach(() => {
if (!httpMock.allUsed()) {
throw new Error('Not all http mocks have been used!');
}
httpMock.reset();
process.env.RENOVATE_SKIP_CACHE = SKIP_CACHE;
});
it('returns null for a package miss', async () => {
const newparams = { ...params };
newparams.depName = 'non-existing';
httpMock
.scope('https://updates.jenkins.io')
.get('/current/update-center.actual.json')
.reply(200, jenkinsPluginsInfo);
httpMock
.scope('https://updates.jenkins.io')
.get('/current/plugin-versions.json')
.reply(200, jenkinsPluginsVersions);
expect(await getPkgReleases(newparams)).toBeNull();
});
it('returns package releases for a hit for info and releases', async () => {
httpMock
.scope('https://updates.jenkins.io')
.get('/current/update-center.actual.json')
.reply(200, jenkinsPluginsInfo);
httpMock
.scope('https://updates.jenkins.io')
.get('/current/plugin-versions.json')
.reply(200, jenkinsPluginsVersions);
let res = await getPkgReleases(params);
expect(res.releases).toHaveLength(75);
expect(res).toMatchSnapshot();
expect(res.sourceUrl).toBe(
'https://github.com/jenkinsci/email-ext-plugin'
);
expect(
res.releases.find((release) => release.version === '2.69')
).toBeDefined();
expect(
res.releases.find((release) => release.version === '12.98')
).toBeUndefined();
// check that caching is working and no http requests are done after the first call to getPkgReleases
res = await getPkgReleases(params);
expect(res.releases).toHaveLength(75);
});
it('returns package releases for a hit for info and miss for releases', async () => {
httpMock
.scope('https://updates.jenkins.io')
.get('/current/update-center.actual.json')
.reply(200, jenkinsPluginsInfo);
httpMock
.scope('https://updates.jenkins.io')
.get('/current/plugin-versions.json')
.reply(200, '{}');
const res = await getPkgReleases(params);
expect(res.releases).toBeEmpty();
expect(res).toMatchSnapshot();
expect(res.sourceUrl).toBe(
'https://github.com/jenkinsci/email-ext-plugin'
);
});
it('returns null empty response', async () => {
httpMock
.scope('https://updates.jenkins.io')
.get('/current/update-center.actual.json')
.reply(200, '{}');
httpMock
.scope('https://updates.jenkins.io')
.get('/current/plugin-versions.json')
.reply(200, '{}');
expect(await getPkgReleases(params)).toBeNull();
});
});
});