Skip to content

Commit b243cb4

Browse files
committed
Add back access commands
1 parent 486ffa6 commit b243cb4

File tree

11 files changed

+99
-97
lines changed

11 files changed

+99
-97
lines changed

packages/cli/src/oldCommands/access/add.ts renamed to packages/cli/src/commands/access/add.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import color from '@heroku-cli/color'
1+
import {color} from '@heroku-cli/color'
22
import {Command, flags} from '@heroku-cli/command'
33
import {Args, ux} from '@oclif/core'
44
import * as Heroku from '@heroku-cli/schema'
55
import {isTeamApp, getOwner} from '../../lib/teamUtils.js'
6-
import * as _ from 'lodash'
7-
/*
6+
87
export default class AccessAdd extends Command {
98
static description = 'add new users to your app'
109
static flags = {
@@ -40,7 +39,7 @@ export default class AccessAdd extends Command {
4039
this.error('Missing argument: permissions', {exit: 1})
4140
const permissionsArray = permissions ? permissions.split(',') : []
4241
permissionsArray.push('view')
43-
const permissionsArraySorted = _.uniq(permissionsArray.sort())
42+
const permissionsArraySorted = [...new Set(permissionsArray.sort())]
4443
output += ` with ${color.green(permissionsArraySorted.join(', '))} permissions`
4544
ux.action.start(output)
4645
await this.heroku.post<Heroku.TeamAppCollaborator[]>(`/teams/apps/${appName}/collaborators`, {
@@ -52,7 +51,5 @@ export default class AccessAdd extends Command {
5251
await this.heroku.post<Heroku.Collaborator[]>(`/apps/${appName}/collaborators`, {body: {user: email}})
5352
ux.action.stop()
5453
}
55-
}
5654
}
57-
*/
58-
55+
}

packages/cli/src/oldCommands/access/index.ts renamed to packages/cli/src/commands/access/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
/*
2-
import color from '@heroku-cli/color'
1+
import {color} from '@heroku-cli/color'
32
import {Command, flags} from '@heroku-cli/command'
4-
import {HerokuAPIError} from '@heroku-cli/command/lib/api-client'
3+
import {HerokuAPIError} from '@heroku-cli/command/lib/api-client.js'
54
import {ux} from '@oclif/core'
65
import {hux} from '@heroku/heroku-cli-util'
76
import * as Heroku from '@heroku-cli/schema'
8-
import * as _ from 'lodash'
9-
import {isTeamApp, getOwner} from '../../lib/teamUtils'
7+
import _ from 'lodash'
8+
import {isTeamApp, getOwner} from '../../lib/teamUtils.js'
109

1110
type MemberData = {
1211
email: string,
@@ -19,7 +18,7 @@ type AdminWithPermissions = Heroku.TeamMember & {
1918
}
2019

2120
function printJSON(collaborators: Heroku.TeamAppCollaborator[]) {
22-
ux.log(JSON.stringify(collaborators, null, 2))
21+
ux.stdout(JSON.stringify(collaborators, null, 2))
2322
}
2423

2524
function buildTableColumns(showPermissions: boolean) {
@@ -109,4 +108,3 @@ export default class AccessIndex extends Command {
109108
printAccess(app, collaborators)
110109
}
111110
}
112-
*/

packages/cli/src/oldCommands/access/remove.ts renamed to packages/cli/src/commands/access/remove.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/*
2-
import color from '@heroku-cli/color'
1+
2+
import {color} from '@heroku-cli/color'
33
import {Command, flags} from '@heroku-cli/command'
44
import {ux} from '@oclif/core'
55
import * as Heroku from '@heroku-cli/schema'
@@ -25,4 +25,3 @@ export default class AccessRemove extends Command {
2525
ux.action.stop()
2626
}
2727
}
28-
*/

packages/cli/src/oldCommands/access/update.ts renamed to packages/cli/src/commands/access/update.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
/*
2-
import color from '@heroku-cli/color'
1+
import {color} from '@heroku-cli/color'
32
import {Command, flags} from '@heroku-cli/command'
43
import {Args, ux} from '@oclif/core'
54
import * as Heroku from '@heroku-cli/schema'
6-
import {isTeamApp} from '../../lib/teamUtils'
5+
import {isTeamApp} from '../../lib/teamUtils.js'
76

87
export default class Update extends Command {
98
static topic = 'access';
@@ -40,4 +39,3 @@ export default class Update extends Command {
4039
ux.action.stop()
4140
}
4241
}
43-
*/

packages/cli/test/helpers/stubs/get.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export function apps() {
1010
}
1111

1212
export function appCollaborators(collaborators =
13-
[{user: {email: 'raulb@heroku.com'}, role: 'owner'},
14-
{user: {email: 'jeff@heroku.com'}, role: 'collaborator'}]) {
13+
[{user: {email: 'gandalf@heroku.com'}, role: 'owner'},
14+
{user: {email: 'frodo@heroku.com'}, role: 'collaborator'}]) {
1515
return nock('https://api.heroku.com:443')
1616
.get('/apps/myapp/collaborators')
1717
.reply(200, collaborators)
@@ -91,7 +91,7 @@ export function teamInfo(type = 'enterprise') {
9191

9292
export function teamInvites(invites = [
9393
{
94-
invited_by: {email: 'raulb@heroku.com'},
94+
invited_by: {email: 'gandalf@heroku.com'},
9595
role: 'admin',
9696
user: {email: '[email protected]'},
9797
},
@@ -105,9 +105,9 @@ export function teamInvites(invites = [
105105

106106
export function teamMembers(members = [
107107
{
108-
email: 'raulb@heroku.com',
108+
email: 'gandalf@heroku.com',
109109
role: 'admin',
110-
user: {email: 'raulb@heroku.com'},
110+
user: {email: 'gandalf@heroku.com'},
111111
},
112112
{
113113
@@ -130,11 +130,11 @@ export function personalApp() {
130130
.get('/apps/myapp')
131131
.reply(200, {
132132
name: 'myapp',
133-
owner: {email: 'raulb@heroku.com'},
133+
owner: {email: 'gandalf@heroku.com'},
134134
})
135135
}
136136

137-
export function userAccount(email = 'raulb@heroku.com') {
137+
export function userAccount(email = 'gandalf@heroku.com') {
138138
return nock('https://api.heroku.com:443')
139139
.get('/account')
140140
.reply(200, {email})

packages/cli/test/helpers/stubs/post.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import nock from 'nock'
33
export function collaborators() {
44
return nock('https://api.heroku.com:443')
55
.post('/apps/myapp/collaborators', {
6-
user: 'raulb@heroku.com',
6+
user: 'gandalf@heroku.com',
77
}).reply(200)
88
}
99

10-
export function teamAppCollaborators(email = 'raulb@heroku.com', permissions: string[] = [], response: {code?: number, description?: Record<string, unknown>} = {}) {
10+
export function teamAppCollaborators(email = 'gandalf@heroku.com', permissions: string[] = [], response: {code?: number, description?: Record<string, unknown>} = {}) {
1111
const body: {user: string, permissions?: string[]} = {user: email}
1212
if (permissions.length > 0) {
1313
body.permissions = permissions

packages/cli/test/helpers/testInstances.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import {APIClient} from '@heroku-cli/command'
22
import {Config} from '@oclif/core'
3+
import {fileURLToPath} from 'node:url'
4+
import path from 'node:path'
35

46
export const getConfig = async () => {
5-
const pjsonPath = require.resolve('../../package.json')
7+
const __filename = fileURLToPath(import.meta.url)
8+
const __dirname = path.dirname(__filename)
9+
const pjsonPath = path.resolve(__dirname, '../../package.json')
610
const conf = new Config({root: pjsonPath})
711
await conf.load()
812
return conf

packages/cli/test/unit/commands/access/add.unit.test.ts

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,61 @@
1-
import {stdout, stderr} from 'stdout-stderr'
2-
import * as nock from 'nock'
1+
import {stderr} from 'stdout-stderr'
2+
import nock from 'nock'
33
import {expect} from 'chai'
4-
// import Cmd from '../../../../src/commands/access/add'
4+
import Cmd from '../../../../src/commands/access/add.js'
55
import runCommand from '../../../helpers/runCommand.js'
66
import {personalApp, teamApp, teamFeatures} from '../../../helpers/stubs/get.js'
77
import {collaborators, teamAppCollaborators} from '../../../helpers/stubs/post.js'
8+
import expectOutput from '../../../helpers/utils/expectOutput.js'
9+
import tsheredoc from 'tsheredoc'
10+
const heredoc = tsheredoc.default
811

912
let apiGet: nock.Scope
1013
let apiPost: nock.Scope
1114
let apiGetOrgFeatures: nock.Scope
12-
/*
15+
1316
describe('heroku access:add', function () {
1417
context('with a team app with user permissions', function () {
1518
beforeEach(function () {
1619
apiGet = teamApp()
17-
apiPost = teamAppCollaborators('raulb@heroku.com', ['deploy', 'view'])
20+
apiPost = teamAppCollaborators('gandalf@heroku.com', ['deploy', 'view'])
1821
apiGetOrgFeatures = teamFeatures([{name: 'org-access-controls'}])
1922
})
23+
2024
afterEach(function () {
2125
return nock.cleanAll()
2226
})
23-
it('adds user to the app with permissions, and view is implicit', function () {
24-
return runCommand(Cmd, [
27+
28+
it('adds user to the app with permissions, even specifying the view permission', async function () {
29+
await runCommand(Cmd, [
2530
'--app',
2631
'myapp',
2732
'--permissions',
28-
'deploy',
29-
'raulb@heroku.com',
33+
'deploy,view',
34+
'gandalf@heroku.com',
3035
])
31-
.then(() => expect('').to.eq(stdout.output))
32-
.then(() => expect('Adding [email protected] access to the app myapp with deploy, view permissions...\nAdding [email protected] access to the app myapp with deploy, view permissions... done\n').to.eq(stderr.output))
33-
.then(() => apiGet.done())
34-
.then(() => apiGetOrgFeatures.done())
35-
.then(() => apiPost.done())
36+
expectOutput(stderr.output, heredoc(`
37+
Adding [email protected] access to the app myapp with deploy, view permissions... done
38+
`))
3639
})
37-
it('adds user to the app with permissions, even specifying the view permission', function () {
38-
return runCommand(Cmd, [
40+
41+
it('adds user to the app with permissions, and view is implicit', async function () {
42+
await runCommand(Cmd, [
3943
'--app',
4044
'myapp',
4145
'--permissions',
42-
'deploy,view',
43-
'raulb@heroku.com',
46+
'deploy',
47+
'gandalf@heroku.com',
4448
])
45-
.then(() => expect('').to.eq(stdout.output))
46-
.then(() => expect('Adding [email protected] access to the app myapp with deploy, view permissions...\nAdding [email protected] access to the app myapp with deploy, view permissions... done\n').to.eq(stderr.output))
47-
.then(() => apiGet.done())
48-
.then(() => apiGetOrgFeatures.done())
49-
.then(() => apiPost.done())
49+
expectOutput(stderr.output, heredoc(`
50+
Adding [email protected] access to the app myapp with deploy, view permissions... done
51+
`))
5052
})
53+
5154
it('raises an error when permissions are not specified', function () {
5255
return runCommand(Cmd, [
5356
'--app',
5457
'myapp',
55-
'raulb@heroku.com',
58+
'gandalf@heroku.com',
5659
])
5760
.then(() => {
5861
apiGet.done()
@@ -62,48 +65,54 @@ describe('heroku access:add', function () {
6265
.catch((error: any) => expect(error.message).to.equal('Missing argument: permissions'))
6366
})
6467
})
68+
6569
context('with a team app without user permissions', function () {
6670
beforeEach(function () {
6771
apiGet = teamApp()
6872
apiPost = collaborators()
6973
apiGetOrgFeatures = teamFeatures([])
7074
})
75+
7176
afterEach(function () {
7277
return nock.cleanAll()
7378
})
74-
it('adds user to the app', function () {
75-
return runCommand(Cmd, [
79+
80+
it('adds user to the app', async function () {
81+
await runCommand(Cmd, [
7682
'--app',
7783
'myapp',
78-
'raulb@heroku.com',
84+
'gandalf@heroku.com',
7985
])
80-
.then(() => expect('').to.eq(stdout.output))
81-
.then(() => expect('Adding [email protected] access to the app myapp...\nAdding [email protected] access to the app myapp... done\n').to.eq(stderr.output))
82-
.then(() => apiGet.done())
83-
.then(() => apiGetOrgFeatures.done())
84-
.then(() => apiPost.done())
86+
expectOutput(stderr.output, heredoc(`
87+
Adding [email protected] access to the app myapp... done
88+
`))
89+
apiGet.done()
90+
apiGetOrgFeatures.done()
91+
apiPost.done()
8592
})
8693
})
94+
8795
context('with a non team app', function () {
8896
beforeEach(function () {
8997
apiGet = personalApp()
9098
apiPost = collaborators()
9199
})
100+
92101
afterEach(function () {
93102
return nock.cleanAll()
94103
})
95-
it('adds user to the app as a collaborator', function () {
96-
return runCommand(Cmd, [
104+
105+
it('adds user to the app as a collaborator', async function () {
106+
await runCommand(Cmd, [
97107
'--app',
98108
'myapp',
99-
'raulb@heroku.com',
109+
'gandalf@heroku.com',
100110
])
101-
.then(() => expect('').to.eq(stdout.output))
102-
.then(() => expect('Adding [email protected] access to the app myapp...\nAdding [email protected] access to the app myapp... done\n').to.eq(stderr.output))
103-
.then(() => apiGet.done())
104-
.then(() => apiPost.done())
111+
expectOutput(stderr.output, heredoc(`
112+
Adding [email protected] access to the app myapp... done
113+
`))
114+
apiGet.done()
115+
apiPost.done()
105116
})
106117
})
107118
})
108-
109-
*/

packages/cli/test/unit/commands/access/index.unit.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {stdout, stderr} from 'stdout-stderr'
2-
import * as nock from 'nock'
2+
import nock from 'nock'
33
import {expect} from 'chai'
4-
// import Cmd from '../../../../src/commands/access/index'
4+
import Cmd from '../../../../src/commands/access/index.js'
55
import runCommand from '../../../helpers/runCommand.js'
6+
import stripAnsi from 'strip-ansi'
67
import {
78
personalApp,
89
appCollaborators,
@@ -12,7 +13,8 @@ import {
1213
teamAppCollaboratorsWithPermissions,
1314
} from '../../../helpers/stubs/get.js'
1415

15-
/*
16+
const removeAllWhitespace = (str: string): string => stripAnsi(str).replace(/\s+/g, '')
17+
1618
describe('heroku access', function () {
1719
context('with personal app', function () {
1820
afterEach(function () {
@@ -25,7 +27,7 @@ describe('heroku access', function () {
2527
'--app',
2628
'myapp',
2729
])
28-
.then(() => expect(stdout.output).to.contain('jeff@heroku.com collaborator \n raulb@heroku.com owner'))
30+
.then(() => expect(removeAllWhitespace(stdout.output)).to.contain(removeAllWhitespace('frodo@heroku.com collaborator \n gandalf@heroku.com owner')))
2931
.then(() => expect('').to.eq(stderr.output))
3032
.then(() => apiGetPersonalApp.done())
3133
.then(() => apiGetAppCollaborators.done())
@@ -44,7 +46,7 @@ describe('heroku access', function () {
4446
'--app',
4547
'myapp',
4648
])
47-
.then(() => expect(stdout.output).to.contain('bob@heroku.com member deploy, view \n raulb@heroku.com admin deploy, manage, operate, view \n'))
49+
.then(() => expect(removeAllWhitespace(stdout.output)).to.contain(removeAllWhitespace('[email protected] member deploy, view \n gandalf@heroku.com admin deploy, manage, operate, view \n')))
4850
.then(() => expect('').to.eq(stderr.output))
4951
.then(() => apiGetTeamApp.done())
5052
.then(() => apiGetOrgMembers.done())
@@ -53,5 +55,3 @@ describe('heroku access', function () {
5355
})
5456
})
5557
})
56-
57-
*/

0 commit comments

Comments
 (0)