forked from heroku/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request heroku#44 from heroku/eb/warn-users-when-adding-si…
…xth-member Warn users when going over free team limit
- Loading branch information
Showing
3 changed files
with
93 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,64 @@ | ||
'use strict'; | ||
|
||
let cmd = require('../../../commands/members/add').add; | ||
let stubGet = require('../../stub/get'); | ||
|
||
describe('heroku members:add', () => { | ||
beforeEach(() => cli.mockConsole()); | ||
afterEach(() => nock.cleanAll()); | ||
|
||
it('adds a member to an org', () => { | ||
stubGet.variableSizeOrgMembers(1); | ||
stubGet.userFeatureFlags([]); | ||
let api = nock('https://api.heroku.com:443') | ||
.put('/organizations/myorg/members', {email: '[email protected]', role: 'admin'}) | ||
.reply(200); | ||
|
||
return cmd.run({org: 'myorg', args: {email: '[email protected]'}, flags: {role: 'admin'}}) | ||
.then(() => expect(``).to.eq(cli.stdout)) | ||
.then(() => expect(`Adding [email protected] to myorg as admin... done\n`).to.eq(cli.stderr)) | ||
.then(() => api.done()); | ||
}); | ||
|
||
context('adding a member with the standard org creation flag', () => { | ||
beforeEach(() => { | ||
stubGet.userFeatureFlags([{name: 'standard-org-creation'}]); | ||
}); | ||
|
||
it('does not warn the user when under the free org limit', () => { | ||
stubGet.variableSizeOrgMembers(1); | ||
let api = nock('https://api.heroku.com:443') | ||
.put('/organizations/myorg/members', {email: '[email protected]', role: 'admin'}) | ||
.reply(200); | ||
|
||
return cmd.run({org: 'myorg', args: {email: '[email protected]'}, flags: {role: 'admin'}}) | ||
.then(() => expect(``).to.eq(cli.stdout)) | ||
.then(() => expect(`Adding [email protected] to myorg as admin... done\n`).to.eq(cli.stderr)) | ||
.then(() => api.done()); | ||
}); | ||
|
||
it('does not warn the user when over the free org limit', () => { | ||
stubGet.variableSizeOrgMembers(7); | ||
let api = nock('https://api.heroku.com:443') | ||
.put('/organizations/myorg/members', {email: '[email protected]', role: 'admin'}) | ||
.reply(200); | ||
|
||
return cmd.run({org: 'myorg', args: {email: '[email protected]'}, flags: {role: 'admin'}}) | ||
.then(() => expect(``).to.eq(cli.stdout)) | ||
.then(() => expect(`Adding [email protected] to myorg as admin... done\n`).to.eq(cli.stderr)) | ||
.then(() => api.done()); | ||
}); | ||
|
||
it('does warn the user when at the free org limit', () => { | ||
stubGet.variableSizeOrgMembers(6); | ||
let api = nock('https://api.heroku.com:443') | ||
.put('/organizations/myorg/members', {email: '[email protected]', role: 'admin'}) | ||
.reply(200); | ||
|
||
return cmd.run({org: 'myorg', args: {email: '[email protected]'}, flags: {role: 'admin'}}) | ||
.then(() => expect(`You'll be billed monthly for teams over 5 members.\n`).to.eq(cli.stdout)) | ||
.then(() => expect(`Adding [email protected] to myorg as admin... done\n`).to.eq(cli.stderr)) | ||
.then(() => api.done()); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use strict'; | ||
|
||
function appCollaborators() { | ||
return nock('https://api.heroku.com:443') | ||
.get('/apps/myapp/collaborators') | ||
|
@@ -82,21 +84,33 @@ function orgMembers() { | |
return nock('https://api.heroku.com:443') | ||
.get('/organizations/myorg/members') | ||
.reply(200, [ | ||
{ | ||
email: '[email protected]', role: 'admin', | ||
user: { email: '[email protected]' } | ||
}, | ||
{ | ||
email: '[email protected]', role: 'viewer', | ||
user: { email: '[email protected]' } | ||
}, | ||
{ | ||
email: '[email protected]', role: 'collaborator', | ||
user: { email: '[email protected]' } | ||
} | ||
{ | ||
email: '[email protected]', role: 'admin', | ||
user: { email: '[email protected]' } | ||
}, | ||
{ | ||
email: '[email protected]', role: 'viewer', | ||
user: { email: '[email protected]' } | ||
}, | ||
{ | ||
email: '[email protected]', role: 'collaborator', | ||
user: { email: '[email protected]' } | ||
} | ||
]); | ||
} | ||
|
||
function variableSizeOrgMembers(orgSize) { | ||
orgSize = (typeof(orgSize) === 'undefined') ? 1 : orgSize; | ||
let orgMembers = []; | ||
for(let i = 0; i < orgSize; i++) { | ||
orgMembers.push({email: `test${i}@heroku.com`, role: 'admin', | ||
user: { email: `test${i}@heroku.com` }}); | ||
} | ||
return nock('https://api.heroku.com:443') | ||
.get('/organizations/myorg/members') | ||
.reply(200, orgMembers); | ||
} | ||
|
||
function personalApp() { | ||
return nock('https://api.heroku.com:443') | ||
.get('/apps/myapp') | ||
|
@@ -106,6 +120,12 @@ function personalApp() { | |
}); | ||
} | ||
|
||
function userFeatureFlags(flags) { | ||
return nock('https://api.heroku.com:443') | ||
.get('/account/features') | ||
.reply(200, flags); | ||
} | ||
|
||
module.exports = { | ||
appCollaborators: appCollaborators, | ||
appPrivileges: appPrivileges, | ||
|
@@ -114,5 +134,7 @@ module.exports = { | |
orgAppCollaboratorsWithPrivileges: orgAppCollaboratorsWithPrivileges, | ||
orgFlags: orgFlags, | ||
orgMembers: orgMembers, | ||
personalApp: personalApp | ||
personalApp: personalApp, | ||
userFeatureFlags: userFeatureFlags, | ||
variableSizeOrgMembers: variableSizeOrgMembers | ||
}; |