Skip to content

Commit e473adf

Browse files
Copilotdecyjphr
andauthored
fix: address review feedback - NopCommand repo arg, milestones mock, teams test error propagation
Co-authored-by: decyjphr <57544838+decyjphr@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/safe-settings/sessions/d9420b15-2cca-40a3-a30b-869df73487f1
1 parent ff5555f commit e473adf

5 files changed

Lines changed: 29 additions & 7 deletions

File tree

lib/plugins/repository.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ module.exports = class Repository extends ErrorStash {
125125
const options = { template_owner: this.repo.owner, template_repo: this.template, owner: this.repo.owner, name: this.repo.repo, private: (this.settings.private ? this.settings.private : true), description: this.settings.description ? this.settings.description : '' }
126126

127127
if (this.nop) {
128-
this.log.debug(`Creating Repo using template ${JSON.stringify(this.github.rest.repos.createInOrg.endpoint(this.settings))} `)
128+
this.log.debug(`Creating Repo using template ${JSON.stringify(this.github.rest.repos.createUsingTemplate.endpoint(options))} `)
129129
resArray.push(new NopCommand(this.constructor.name, this.repo, this.github.rest.repos.createUsingTemplate.endpoint(options), 'Create Repo Using Template'))
130130
return Promise.resolve(resArray)
131131
}
@@ -264,7 +264,7 @@ module.exports = class Repository extends ErrorStash {
264264
} else {
265265
this.log.debug(`Disabling Dependabot alerts for for owner: ${repoData.owner.login} and repo ${repoData.name}`)
266266
if (this.nop) {
267-
resArray.push((new NopCommand(this.constructor.name, this.github.rest.repos.disableVulnerabilityAlerts.endpoint({
267+
resArray.push((new NopCommand(this.constructor.name, this.repo, this.github.rest.repos.disableVulnerabilityAlerts.endpoint({
268268
owner: repoData.owner.login,
269269
repo: repoData.name
270270
}), 'Disabling Dependabot alerts')))
@@ -302,7 +302,7 @@ module.exports = class Repository extends ErrorStash {
302302
} else {
303303
this.log.debug(`Disabling Dependabot security updates for owner: ${repoData.owner.login} and repo ${repoData.name}`)
304304
if (this.nop) {
305-
resArray.push((new NopCommand(this.constructor.name, this.github.rest.repos.disableAutomatedSecurityFixes.endpoint({
305+
resArray.push((new NopCommand(this.constructor.name, this.repo, this.github.rest.repos.disableAutomatedSecurityFixes.endpoint({
306306
owner: repoData.owner.login,
307307
repo: repoData.name
308308
}), 'Disabling Dependabot security updates')))

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
},
6969
"jest": {
7070
"testEnvironment": "node",
71+
"setupFilesAfterEnv": [
72+
"<rootDir>/test/setup.js"
73+
],
7174
"reporters": [
7275
"default",
7376
"jest-junit"

test/setup.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-disable no-undef */
2+
// Fail tests that produce unexpected console.error output.
3+
// This ensures that caught-but-logged errors in production code don't
4+
// silently slip through the test suite (e.g. TypeError inside a catch block
5+
// that logs via this.log.error = console.error).
6+
beforeEach(() => {
7+
jest.spyOn(console, 'error').mockImplementation((...args) => {
8+
throw new Error(`Unexpected console.error call in test: ${args.join(' ')}`)
9+
})
10+
})
11+
12+
afterEach(() => {
13+
jest.restoreAllMocks()
14+
})

test/unit/lib/plugins/milestones.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe.skip('Milestones', () => {
1212
paginate: jest.fn().mockImplementation(() => Promise.resolve()),
1313
rest: {
1414
issues: {
15-
listMilestonesForRepo: {
15+
listMilestones: {
1616
endpoint: {
1717
merge: jest.fn().mockImplementation(() => {})
1818
}

test/unit/lib/plugins/teams.test.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ describe('Teams', () => {
2323
beforeEach(() => {
2424
github = {
2525
paginate: jest.fn()
26-
.mockImplementation(async (fetch) => {
27-
const response = await fetch()
26+
.mockImplementation(async (fetch, params) => {
27+
if (typeof fetch !== 'function') {
28+
return []
29+
}
30+
const response = await fetch(params)
2831
return response.data
2932
}),
3033
rest: {
@@ -43,7 +46,9 @@ describe('Teams', () => {
4346
})
4447
}
4548
},
46-
request: jest.fn().mockResolvedValue()
49+
request: Object.assign(jest.fn().mockResolvedValue(), {
50+
endpoint: jest.fn().mockReturnValue({})
51+
})
4752
}
4853
})
4954

0 commit comments

Comments
 (0)