diff --git a/test/platform/github/__snapshots__/index.spec.js.snap b/test/platform/github/__snapshots__/index.spec.js.snap index fb9fb126093cea58dc582debc305b344e0f59579..a2978b99ac9f9c2f50936711a2abe8bea793a83b 100644 --- a/test/platform/github/__snapshots__/index.spec.js.snap +++ b/test/platform/github/__snapshots__/index.spec.js.snap @@ -37,15 +37,6 @@ Array [ Array [ "repos/some/repo", ], - Array [ - "repos/some/repo/pulls?per_page=100&state=all", - Object { - "paginate": true, - }, - ], - Array [ - "repos/some/repo/git/trees/master?recursive=true", - ], Array [ "repos/some/repo/git/refs/heads/master", ], @@ -66,15 +57,6 @@ Array [ Array [ "repos/some/repo", ], - Array [ - "repos/some/repo/pulls?per_page=100&state=all", - Object { - "paginate": true, - }, - ], - Array [ - "repos/some/repo/git/trees/master?recursive=true", - ], Array [ "repos/some/repo/git/refs/heads/master", ], @@ -203,9 +185,6 @@ Array [ "paginate": true, }, ], - Array [ - "repos/some/repo/git/trees/master?recursive=true", - ], ] `; @@ -223,12 +202,6 @@ Array [ Array [ "repos/some/repo", ], - Array [ - "repos/some/repo/pulls?per_page=100&state=all", - Object { - "paginate": true, - }, - ], Array [ "repos/some/repo/git/trees/master?recursive=true", ], @@ -251,12 +224,6 @@ Array [ Array [ "repos/some/repo", ], - Array [ - "repos/some/repo/pulls?per_page=100&state=all", - Object { - "paginate": true, - }, - ], Array [ "repos/some/repo/git/trees/master?recursive=true", ], @@ -271,12 +238,6 @@ Array [ Array [ "repos/some/repo", ], - Array [ - "repos/some/repo/pulls?per_page=100&state=all", - Object { - "paginate": true, - }, - ], Array [ "repos/some/repo/git/trees/master?recursive=true", ], @@ -291,12 +252,6 @@ Array [ Array [ "repos/some/repo", ], - Array [ - "repos/some/repo/pulls?per_page=100&state=all", - Object { - "paginate": true, - }, - ], Array [ "repos/some/repo/git/trees/master?recursive=true", ], @@ -503,15 +458,6 @@ Array [ Array [ "repos/some/repo", ], - Array [ - "repos/some/repo/pulls?per_page=100&state=all", - Object { - "paginate": true, - }, - ], - Array [ - "repos/some/repo/git/trees/master?recursive=true", - ], ] `; @@ -527,15 +473,6 @@ Array [ Array [ "repos/some/repo", ], - Array [ - "repos/some/repo/pulls?per_page=100&state=all", - Object { - "paginate": true, - }, - ], - Array [ - "repos/some/repo/git/trees/master?recursive=true", - ], ] `; @@ -551,15 +488,6 @@ Array [ Array [ "repos/some/repo", ], - Array [ - "repos/some/repo/pulls?per_page=100&state=all", - Object { - "paginate": true, - }, - ], - Array [ - "repos/some/repo/git/trees/master?recursive=true", - ], ] `; @@ -610,15 +538,6 @@ Array [ Array [ "repos/some/repo", ], - Array [ - "repos/some/repo/pulls?per_page=100&state=all", - Object { - "paginate": true, - }, - ], - Array [ - "repos/some/repo/git/trees/master?recursive=true", - ], Array [ "repos/some/repo/git/refs/heads/thebranchname", ], @@ -658,15 +577,6 @@ Array [ Array [ "repos/some/repo", ], - Array [ - "repos/some/repo/pulls?per_page=100&state=all", - Object { - "paginate": true, - }, - ], - Array [ - "repos/some/repo/git/trees/master?recursive=true", - ], Array [ "repos/some/repo/git/refs/heads/thebranchname", ], @@ -697,15 +607,6 @@ Array [ Array [ "repos/some/repo", ], - Array [ - "repos/some/repo/pulls?per_page=100&state=all", - Object { - "paginate": true, - }, - ], - Array [ - "repos/some/repo/git/trees/master?recursive=true", - ], Array [ "repos/some/repo/git/trees/some-branch?recursive=true", ], diff --git a/test/platform/github/index.spec.js b/test/platform/github/index.spec.js index 5a55507ef8aded7b84160d06e4b6f8db7a485cb2..e83b28d724123cb132a8517daf38ae6f24c47597 100644 --- a/test/platform/github/index.spec.js +++ b/test/platform/github/index.spec.js @@ -60,25 +60,6 @@ describe('platform/github', () => { allow_merge_commit: true, }, })); - // getPrList - get.mockImplementationOnce(() => ({ - body: [], - })); - // getFileList - get.mockImplementationOnce(() => ({ - body: { - tree: [ - { - type: 'blob', - path: 'package.json', - }, - { - type: 'blob', - path: 'package-lock.json', - }, - ], - }, - })); return github.initRepo(...args); } @@ -126,14 +107,6 @@ describe('platform/github', () => { allow_merge_commit: true, }, })); - // getPrList - get.mockImplementationOnce(() => ({ - body: [], - })); - // getFileList - get.mockImplementationOnce(() => ({ - body: [], - })); return github.initRepo(...args); } const config = await squashInitRepo({ @@ -172,14 +145,6 @@ describe('platform/github', () => { get.post.mockImplementationOnce(() => ({ body: {}, })); - // getPrList - get.mockImplementationOnce(() => ({ - body: [], - })); - // getFileList - get.mockImplementationOnce(() => ({ - body: [], - })); return github.initRepo(...args); } const config = await forkInitRepo({ @@ -224,14 +189,6 @@ describe('platform/github', () => { get.post.mockImplementationOnce(() => ({ body: { full_name: 'forked_repo' }, })); - // getPrList - get.mockImplementationOnce(() => ({ - body: [], - })); - // getFileList - get.mockImplementationOnce(() => ({ - body: [], - })); return github.initRepo(...args); } const config = await forkInitRepo({ @@ -256,14 +213,6 @@ describe('platform/github', () => { allow_merge_commit: true, }, })); - // getPrList - get.mockImplementationOnce(() => ({ - body: [], - })); - // getFileList - get.mockImplementationOnce(() => ({ - body: [], - })); return github.initRepo(...args); } const config = await mergeInitRepo({ @@ -286,14 +235,6 @@ describe('platform/github', () => { allow_merge_commit: true, }, })); - // getPrList - get.mockImplementationOnce(() => ({ - body: [], - })); - // getFileList - get.mockImplementationOnce(() => ({ - body: [], - })); return github.initRepo(...args); } const config = await mergeInitRepo({ @@ -313,14 +254,6 @@ describe('platform/github', () => { default_branch: 'master', }, })); - // getPrList - get.mockImplementationOnce(() => ({ - body: [], - })); - // getFileList - get.mockImplementationOnce(() => ({ - body: [], - })); return github.initRepo(...args); } const config = await mergeInitRepo({ @@ -1465,7 +1398,7 @@ describe('platform/github', () => { expect(await github.mergePr(pr)).toBe(true); expect(get.put.mock.calls).toHaveLength(1); expect(get.delete.mock.calls).toHaveLength(1); - expect(get.mock.calls).toHaveLength(3); + expect(get.mock.calls).toHaveLength(1); }); it('should handle merge error', async () => { await initRepo({ repository: 'some/repo', token: 'token' }); @@ -1481,7 +1414,7 @@ describe('platform/github', () => { expect(await github.mergePr(pr)).toBe(false); expect(get.put.mock.calls).toHaveLength(1); expect(get.delete.mock.calls).toHaveLength(0); - expect(get.mock.calls).toHaveLength(3); + expect(get.mock.calls).toHaveLength(1); }); }); describe('getPrBody(input)', () => { @@ -1511,14 +1444,6 @@ describe('platform/github', () => { default_branch: 'master', }, })); - // getPrList - get.mockImplementationOnce(() => ({ - body: [], - })); - // getFileList - get.mockImplementationOnce(() => ({ - body: [], - })); // getBranchCommit get.mockImplementationOnce(() => ({ body: { @@ -1614,6 +1539,21 @@ describe('platform/github', () => { describe('getFile()', () => { it('should return the encoded file content', async () => { await initRepo({ repository: 'some/repo', token: 'token' }); + // getFileList + get.mockImplementationOnce(() => ({ + body: { + tree: [ + { + type: 'blob', + path: 'package.json', + }, + { + type: 'blob', + path: 'package-lock.json', + }, + ], + }, + })); get.mockImplementationOnce(() => ({ body: { content: Buffer.from('hello world').toString('base64'), @@ -1625,11 +1565,41 @@ describe('platform/github', () => { }); it('should return null if not in file list', async () => { await initRepo({ repository: 'some/repo', token: 'token' }); + // getFileList + get.mockImplementationOnce(() => ({ + body: { + tree: [ + { + type: 'blob', + path: 'package.json', + }, + { + type: 'blob', + path: 'package-lock.json', + }, + ], + }, + })); const content = await github.getFile('.npmrc'); expect(content).toBe(null); }); it('should return null if GitHub returns a 404', async () => { await initRepo({ repository: 'some/repo', token: 'token' }); + // getFileList + get.mockImplementationOnce(() => ({ + body: { + tree: [ + { + type: 'blob', + path: 'package.json', + }, + { + type: 'blob', + path: 'package-lock.json', + }, + ], + }, + })); get.mockImplementationOnce(() => Promise.reject({ statusCode: 404, @@ -1641,6 +1611,21 @@ describe('platform/github', () => { }); it('should return large file via git API', async () => { await initRepo({ repository: 'some/repo', token: 'token' }); + // getFileList + get.mockImplementationOnce(() => ({ + body: { + tree: [ + { + type: 'blob', + path: 'package.json', + }, + { + type: 'blob', + path: 'package-lock.json', + }, + ], + }, + })); get.mockImplementationOnce(() => Promise.reject({ statusCode: 403, @@ -1668,6 +1653,21 @@ describe('platform/github', () => { }); it('should throw if cannot find large file via git API', async () => { await initRepo({ repository: 'some/repo', token: 'token' }); + // getFileList + get.mockImplementationOnce(() => ({ + body: { + tree: [ + { + type: 'blob', + path: 'package.json', + }, + { + type: 'blob', + path: 'package-lock.json', + }, + ], + }, + })); get.mockImplementationOnce(() => Promise.reject({ statusCode: 403, @@ -1689,6 +1689,21 @@ describe('platform/github', () => { }); it('should return null if getFile returns nothing', async () => { await initRepo({ repository: 'some/repo', token: 'token' }); + // getFileList + get.mockImplementationOnce(() => ({ + body: { + tree: [ + { + type: 'blob', + path: 'package.json', + }, + { + type: 'blob', + path: 'package-lock.json', + }, + ], + }, + })); get.mockImplementationOnce(() => ({ body: {}, })); @@ -1698,6 +1713,21 @@ describe('platform/github', () => { }); it('should return propagate unknown errors', async () => { await initRepo({ repository: 'some/repo', token: 'token' }); + // getFileList + get.mockImplementationOnce(() => ({ + body: { + tree: [ + { + type: 'blob', + path: 'package.json', + }, + { + type: 'blob', + path: 'package-lock.json', + }, + ], + }, + })); get.mockImplementationOnce(() => { throw new Error('Something went wrong'); });