Skip to content

Commit 8e3019e

Browse files
fix: broken tests
1 parent e1f5149 commit 8e3019e

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

__tests__/api-helper1.test.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const createCommitResponse = createResponse<Octokit.GitCreateCommitResponse>({
6060
verified: true,
6161
},
6262
});
63+
const escape = value => encodeURIComponent(value).replace(new RegExp('%2F', 'g'), '%252F');
6364

6465
describe('ApiHelper', () => {
6566
disableNetConnect(nock);
@@ -213,7 +214,7 @@ describe('ApiHelper', () => {
213214
const fn1 = jest.fn();
214215
const fn2 = jest.fn();
215216
nock('https://api.github.com')
216-
.patch('/repos/hello/world/git/refs/' + encodeURIComponent('heads/test'), body => {
217+
.patch('/repos/hello/world/git/refs/' + escape('heads/test'), body => {
217218
fn1();
218219
expect(body).toHaveProperty('sha');
219220
return body;
@@ -234,7 +235,7 @@ describe('ApiHelper', () => {
234235
const fn2 = jest.fn();
235236
const fn3 = jest.fn();
236237
nock('https://api.github.com')
237-
.patch('/repos/hello/world/git/refs/' + encodeURIComponent('heads/new-topic'), body => {
238+
.patch('/repos/hello/world/git/refs/' + escape('heads/new-topic'), body => {
238239
fn1();
239240
expect(body).toHaveProperty('sha');
240241
return body;
@@ -263,7 +264,7 @@ describe('ApiHelper', () => {
263264
it('should cache PR get api', async() => {
264265
const fn = jest.fn();
265266
nock('https://api.github.com')
266-
.patch('/repos/hello/world/git/refs/' + encodeURIComponent('heads/new-topic'))
267+
.patch('/repos/hello/world/git/refs/' + escape('heads/new-topic'))
267268
.reply(200, () => {
268269
return getApiFixture(rootDir, 'repos.git.refs.update');
269270
})
@@ -286,7 +287,7 @@ describe('ApiHelper', () => {
286287

287288
it('should output warning', async() => {
288289
nock('https://api.github.com')
289-
.patch('/repos/hello/world/git/refs/' + encodeURIComponent('heads/test'), body => {
290+
.patch('/repos/hello/world/git/refs/' + escape('heads/test'), body => {
290291
expect(body).toHaveProperty('sha');
291292
return body;
292293
})
@@ -326,7 +327,7 @@ describe('ApiHelper', () => {
326327
it('should create ref', async() => {
327328
const fn = jest.fn();
328329
nock('https://api.github.com')
329-
.delete('/repos/hello/world/git/refs/heads/featureA')
330+
.delete('/repos/hello/world/git/refs/' + encodeURIComponent('heads/featureA'))
330331
.reply(204, () => {
331332
fn();
332333
return getApiFixture(rootDir, 'repos.git.refs.create');
@@ -579,7 +580,7 @@ describe('ApiHelper', () => {
579580
.reply(201, () => getApiFixture(rootDir, 'repos.git.trees'))
580581
.post('/repos/hello/world/git/commits')
581582
.reply(201, () => getApiFixture(rootDir, 'repos.git.commits'))
582-
.patch('/repos/hello/world/git/refs/' + encodeURIComponent('heads/test'))
583+
.patch('/repos/hello/world/git/refs/' + escape('heads/test'))
583584
.reply(200, () => getApiFixture(rootDir, 'repos.git.refs.update'));
584585

585586
expect(await helper.commit(rootDir, 'test commit message', ['build1.json', 'build2.json'])).toBe(true);
@@ -625,7 +626,7 @@ describe('ApiHelper', () => {
625626
.reply(201, () => getApiFixture(rootDir, 'repos.git.trees'))
626627
.post('/repos/hello/world/git/commits')
627628
.reply(201, () => getApiFixture(rootDir, 'repos.git.commits'))
628-
.get('/repos/hello/world/git/ref/heads/create/test')
629+
.get('/repos/hello/world/git/ref/' + encodeURIComponent('heads/create/test'))
629630
.reply(404)
630631
.post('/repos/hello/world/git/refs')
631632
.reply(201, () => getApiFixture(rootDir, 'repos.git.refs.create'))
@@ -679,9 +680,9 @@ describe('ApiHelper', () => {
679680
.reply(201, () => getApiFixture(rootDir, 'repos.git.trees'))
680681
.post('/repos/hello/world/git/commits')
681682
.reply(201, () => getApiFixture(rootDir, 'repos.git.commits'))
682-
.get('/repos/hello/world/git/ref/heads/create/test')
683+
.get('/repos/hello/world/git/ref/' + encodeURIComponent('heads/create/test'))
683684
.reply(200, () => getApiFixture(rootDir, 'repos.git.ref'))
684-
.patch('/repos/hello/world/git/refs/heads/create/test')
685+
.patch('/repos/hello/world/git/refs/' + encodeURIComponent('heads/create/test'))
685686
.reply(200, () => getApiFixture(rootDir, 'repos.git.refs.update'))
686687
.post('/repos/hello/world/git/refs')
687688
.reply(201, () => getApiFixture(rootDir, 'repos.git.refs.create'))
@@ -730,7 +731,7 @@ describe('ApiHelper', () => {
730731
.reply(200, () => getApiFixture(rootDir, 'pulls.list'))
731732
.patch('/repos/hello/world/pulls/1347')
732733
.reply(200, () => getApiFixture(rootDir, 'pulls.update'))
733-
.delete('/repos/hello/world/git/refs/heads/close/test')
734+
.delete('/repos/hello/world/git/refs/' + encodeURIComponent('heads/close/test'))
734735
.reply(204);
735736

736737
await helper.closePR('close/test');
@@ -753,7 +754,7 @@ describe('ApiHelper', () => {
753754
.reply(201)
754755
.patch('/repos/hello/world/pulls/1347')
755756
.reply(200, () => getApiFixture(rootDir, 'pulls.update'))
756-
.delete('/repos/hello/world/git/refs/heads/close/test')
757+
.delete('/repos/hello/world/git/refs/' + encodeURIComponent('heads/close/test'))
757758
.reply(204);
758759

759760
await helper.closePR('close/test', 'close message');
@@ -772,9 +773,9 @@ describe('ApiHelper', () => {
772773
.persist()
773774
.get('/repos/hello/world/pulls?head=hello%3Aclose%2Ftest')
774775
.reply(200, () => [])
775-
.get('/repos/hello/world/git/ref/heads/close/test')
776+
.get('/repos/hello/world/git/ref/' + encodeURIComponent('heads/close/test'))
776777
.reply(200, () => getApiFixture(rootDir, 'repos.git.ref'))
777-
.delete('/repos/hello/world/git/refs/heads/close/test')
778+
.delete('/repos/hello/world/git/refs/' + encodeURIComponent('heads/close/test'))
778779
.reply(204);
779780

780781
await helper.closePR('close/test');
@@ -792,7 +793,7 @@ describe('ApiHelper', () => {
792793
.persist()
793794
.get('/repos/hello/world/pulls?head=hello%3Aclose%2Ftest')
794795
.reply(200, () => [])
795-
.get('/repos/hello/world/git/ref/heads/close/test')
796+
.get('/repos/hello/world/git/ref/' + encodeURIComponent('heads/close/test'))
796797
.reply(404);
797798

798799
await helper.closePR('close/test');

__tests__/api-helper2.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe('ApiHelper with params', () => {
217217
it('should get tags', async() => {
218218
nock('https://api.github.com')
219219
.persist()
220-
.get('/repos/hello/world/git/matching-refs/tags/')
220+
.get('/repos/hello/world/git/matching-refs/tags%2F')
221221
.reply(200, () => getApiFixture(rootDir, 'repos.git.matching-refs'));
222222

223223
expect(await helper.getTags()).toEqual([
@@ -230,7 +230,7 @@ describe('ApiHelper with params', () => {
230230
it('should get tags', async() => {
231231
nock('https://api.github.com')
232232
.persist()
233-
.get('/repos/hello/world/git/matching-refs/tags/')
233+
.get('/repos/hello/world/git/matching-refs/tags%2F')
234234
.reply(200, () => []);
235235

236236
expect(await helper.getTags()).toEqual([]);
@@ -241,7 +241,7 @@ describe('ApiHelper with params', () => {
241241
it('should get tags', async() => {
242242
nock('https://api.github.com')
243243
.persist()
244-
.get('/repos/hello/world/git/matching-refs/tags/')
244+
.get('/repos/hello/world/git/matching-refs/tags%2F')
245245
.reply(200, () => getApiFixture(rootDir, 'repos.git.matching-refs'));
246246

247247
expect(await helper.getLastTag()).toBe('v2.0.0');
@@ -250,7 +250,7 @@ describe('ApiHelper with params', () => {
250250
it('should get tags', async() => {
251251
nock('https://api.github.com')
252252
.persist()
253-
.get('/repos/hello/world/git/matching-refs/tags/')
253+
.get('/repos/hello/world/git/matching-refs/tags%2F')
254254
.reply(200, () => []);
255255

256256
expect(await helper.getLastTag()).toBe('v0.0.0');
@@ -261,7 +261,7 @@ describe('ApiHelper with params', () => {
261261
it('should get tags', async() => {
262262
nock('https://api.github.com')
263263
.persist()
264-
.get('/repos/hello/world/git/matching-refs/tags/')
264+
.get('/repos/hello/world/git/matching-refs/tags%2F')
265265
.reply(200, () => getApiFixture(rootDir, 'repos.git.matching-refs'));
266266

267267
expect(await helper.getNewPatchVersion()).toBe('v2.0.1');
@@ -270,7 +270,7 @@ describe('ApiHelper with params', () => {
270270
it('should get tags', async() => {
271271
nock('https://api.github.com')
272272
.persist()
273-
.get('/repos/hello/world/git/matching-refs/tags/')
273+
.get('/repos/hello/world/git/matching-refs/tags%2F')
274274
.reply(200, () => []);
275275

276276
expect(await helper.getNewPatchVersion()).toBe('v0.0.1');
@@ -281,7 +281,7 @@ describe('ApiHelper with params', () => {
281281
it('should get tags', async() => {
282282
nock('https://api.github.com')
283283
.persist()
284-
.get('/repos/hello/world/git/matching-refs/tags/')
284+
.get('/repos/hello/world/git/matching-refs/tags%2F')
285285
.reply(200, () => getApiFixture(rootDir, 'repos.git.matching-refs'));
286286

287287
expect(await helper.getNewMinorVersion()).toBe('v2.1.0');
@@ -290,7 +290,7 @@ describe('ApiHelper with params', () => {
290290
it('should get tags', async() => {
291291
nock('https://api.github.com')
292292
.persist()
293-
.get('/repos/hello/world/git/matching-refs/tags/')
293+
.get('/repos/hello/world/git/matching-refs/tags%2F')
294294
.reply(200, () => []);
295295

296296
expect(await helper.getNewMinorVersion()).toBe('v0.1.0');
@@ -301,7 +301,7 @@ describe('ApiHelper with params', () => {
301301
it('should get tags', async() => {
302302
nock('https://api.github.com')
303303
.persist()
304-
.get('/repos/hello/world/git/matching-refs/tags/')
304+
.get('/repos/hello/world/git/matching-refs/tags%2F')
305305
.reply(200, () => getApiFixture(rootDir, 'repos.git.matching-refs'));
306306

307307
expect(await helper.getNewMajorVersion()).toBe('v3.0.0');
@@ -310,7 +310,7 @@ describe('ApiHelper with params', () => {
310310
it('should get tags', async() => {
311311
nock('https://api.github.com')
312312
.persist()
313-
.get('/repos/hello/world/git/matching-refs/tags/')
313+
.get('/repos/hello/world/git/matching-refs/tags%2F')
314314
.reply(200, () => []);
315315

316316
expect(await helper.getNewMajorVersion()).toBe('v1.0.0');

0 commit comments

Comments
 (0)