forked from renovatebot/renovate
/
index.spec.ts
136 lines (135 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
126
127
128
129
130
131
132
133
134
135
136
import { getDigest, getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { getName } from '../../../test/util';
import { id as datasource } from '.';
describe(getName(), () => {
beforeEach(() => {
httpMock.reset();
httpMock.setup();
});
afterEach(() => {
httpMock.reset();
});
describe('getReleases', () => {
it('returns tags from bitbucket cloud', async () => {
const body = {
pagelen: 3,
values: [
{
name: 'v1.0.0',
target: {
date: '2020-11-19T09:05:35+00:00',
},
},
{
name: 'v1.1.0',
target: {},
},
{
name: 'v1.1.1',
},
],
page: 1,
};
httpMock
.scope('https://api.bitbucket.org')
.get('/2.0/repositories/some/dep2/refs/tags')
.reply(200, body);
const res = await getPkgReleases({
datasource,
depName: 'some/dep2',
});
expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(3);
expect(httpMock.getTrace()).toMatchSnapshot();
});
});
describe('getDigest', () => {
it('returns commits from bitbucket cloud', async () => {
const body = {
pagelen: 3,
values: [
{
hash: '123',
date: '2020-11-19T09:05:35+00:00',
},
{
hash: '133',
date: '2020-11-19T09:05:36+00:00',
},
{
hash: '333',
date: '2020-11-19T09:05:37+00:00',
},
],
page: 1,
};
httpMock
.scope('https://api.bitbucket.org')
.get('/2.0/repositories/some/dep2')
.reply(200, { mainbranch: { name: 'master' } });
httpMock
.scope('https://api.bitbucket.org')
.get('/2.0/repositories/some/dep2/commits/master')
.reply(200, body);
const res = await getDigest({
datasource,
depName: 'some/dep2',
});
expect(res).toMatchSnapshot();
expect(res).toBeString();
expect(res).toEqual('123');
expect(httpMock.getTrace()).toMatchSnapshot();
});
});
describe('getDigest with no commits', () => {
it('returns commits from bitbucket cloud', async () => {
const body = {
pagelen: 0,
values: [],
page: 1,
};
httpMock
.scope('https://api.bitbucket.org')
.get('/2.0/repositories/some/dep2')
.reply(200, { mainbranch: { name: 'master' } });
httpMock
.scope('https://api.bitbucket.org')
.get('/2.0/repositories/some/dep2/commits/master')
.reply(200, body);
const res = await getDigest({
datasource,
depName: 'some/dep2',
});
expect(res).toMatchSnapshot();
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
});
describe('getTagCommit', () => {
it('returns tags commit hash from bitbucket cloud', async () => {
const body = {
name: 'v1.0.0',
target: {
date: '2020-11-19T09:05:35+00:00',
hash: '123',
},
};
httpMock
.scope('https://api.bitbucket.org')
.get('/2.0/repositories/some/dep2/refs/tags/v1.0.0')
.reply(200, body);
const res = await getDigest(
{
datasource,
depName: 'some/dep2',
},
'v1.0.0'
);
expect(res).toMatchSnapshot();
expect(res).toBeString();
expect(res).toEqual('123');
expect(httpMock.getTrace()).toMatchSnapshot();
});
});
});