tap.test('listFiles fail', async (t) => { const scope = nock('https://api.github.com') .filteringPath(ignoreQueryParams) .get(`/repos/${options.owner}/${options.repo}/pulls/${options.prId}/files`) .reply(500) await t.rejects(listFiles(options)) scope.done() t.end() })
nocks.forEach(function(n) { n.filteringPath(path => filteringPath(n, path)); n.filteringRequestBody((b, rb) => filteringRequestBody(b, rb)); });
tap.test('pingOwners success', async (t) => { const fixture = readFixture('pull-request-create-comment.json') const owners = [ '@owner1', '@owner2' ] const body = JSON.stringify({ body: getCommentForOwners(owners) }) const scope = nock('https://api.github.com') .filteringPath(ignoreQueryParams) .post(`/repos/${options.owner}/${options.repo}/issues/${options.prId}/comments`, body) .reply(201, fixture) await pingOwners(options, owners) scope.done() t.end() })
tap.test('getDefaultBranch success', async (t) => { const fixture = readFixture('get-repository.json') const scope = nock('https://api.github.com') .filteringPath(ignoreQueryParams) .get(`/repos/${options.owner}/${options.repo}`) .reply(200, fixture) const defaultBranch = await getDefaultBranch(options) t.strictDeepEqual(defaultBranch, fixture.default_branch) scope.done() t.end() })
function setupListCommitsMock (repoName) { const commitsResponse = readFixture('pr-commits.json') return nock('https://api.github.com') .filteringPath(ignoreQueryParams) .get(`/repos/nodejs/${repoName}/pulls/12345/commits`) .reply(200, commitsResponse) }
tap.test('fetchExistingLabels(): caches existing repository labels', async (t) => { const owner = 'nodejs' const repo = 'node1' // Test passes if nock is only called once, no other checks to run const scope = nock('https://api.github.com') .filteringPath(ignoreQueryParams) .get(`/repos/${owner}/${repo}/labels`) .once() // should only be called once .reply(200, []) await nodeRepo._fetchExistingLabels({ owner, repo, logger }) await nodeRepo._fetchExistingLabels({ owner, repo, logger }) scope.done() })
tap.test('fetchExistingLabels(): yields an array of existing label names', async (t) => { const labelsFixture = readFixture('repo-labels.json') const owner = 'nodejs' const repo = 'node3' const scope = nock('https://api.github.com') .filteringPath(ignoreQueryParams) .get(`/repos/${owner}/${repo}/labels`) .reply(200, labelsFixture.data) t.plan(1) const existingLabels = await nodeRepo._fetchExistingLabels({ owner, repo, logger }) t.ok(existingLabels.includes('cluster')) scope.done() })
tap.test('removeLabelFromPR(): should remove label', async (t) => { const owner = 'nodejs' const repo = 'node7' const prId = '3' const label = '3' const scope = nock('https://api.github.com') .filteringPath(ignoreQueryParams) .delete(`/repos/${owner}/${repo}/issues/${prId}/labels/${label}`) .reply(200) t.plan(1) const response = await nodeRepo.removeLabelFromPR({ owner, repo, prId, logger }, label) t.same(label, response) scope.done() })
tap.test('listFiles success', async (t) => { const fixture = readFixture('pull-request-files.json') const scope = nock('https://api.github.com') .filteringPath(ignoreQueryParams) .get(`/repos/${options.owner}/${options.repo}/pulls/${options.prId}/files`) .reply(200, fixture) const files = await listFiles(options) t.strictDeepEqual(files, fixture.map(({ filename }) => filename)) scope.done() t.end() })
tap.test('getCodeOwnersFile fail', async (t) => { const base = 'https://localhost' const filePath = '/CODEOWNERS' const url = `${base}${filePath}` const scope = nock(base) .filteringPath(ignoreQueryParams) .get(filePath) .reply(500) await t.rejects(getCodeOwnersFile(url, options)) scope.done() t.end() })
tap.test('getDefaultBranch empty response', async (t) => { const scope = nock('https://api.github.com') .filteringPath(ignoreQueryParams) .get(`/repos/${options.owner}/${options.repo}`) .reply(200) await t.rejects(getDefaultBranch(options)) scope.done() t.end() })
tap.test('getCodeOwnersFile success', async (t) => { const fixture = readFixture('CODEOWNERS') const base = 'https://localhost' const filePath = '/CODEOWNERS' const url = `${base}${filePath}` const scope = nock(base) .filteringPath(ignoreQueryParams) .get(filePath) .reply(200, fixture) const file = await getCodeOwnersFile(url, options) t.strictDeepEqual(file, fixture) scope.done() t.end() })
tap.test('pingOwners fail', async (t) => { const scope = nock('https://api.github.com') .filteringPath(ignoreQueryParams) .post(`/repos/${options.owner}/${options.repo}/issues/${options.prId}/comments`) .reply(500) await t.rejects(pingOwners(options, [])) scope.done() t.end() })
tap.test('getBotPrLabels(): returns labels added by nodejs-github-bot', (t) => { const events = readFixture('pull-request-events.json') const owner = 'nodejs' const repo = 'node5' const prId = '1' const scope = nock('https://api.github.com') .filteringPath(ignoreQueryParams) .get(`/repos/${owner}/${repo}/issues/${prId}/events`) .reply(200, events.data) t.plan(1) nodeRepo.getBotPrLabels({ owner, repo, prId }, (_, labels) => { t.same(labels, ['testlabel']) scope.done() }) })
tap.test('getDefaultBranch fail', async (t) => { const scope = nock('https://api.github.com') .filteringPath(ignoreQueryParams) .get(`/repos/${options.owner}/${options.repo}`) .reply(500) await t.rejects(getDefaultBranch(options)) scope.done() t.end() })