-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor members:add tests and test utils
- Loading branch information
Showing
3 changed files
with
78 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as nock from 'nock' | ||
|
||
export function sendInvite(email = 'raulb@heroku.com', role = 'admin') { | ||
return nock('https://api.heroku.com:443') | ||
.put('/teams/myteam/invitations', {email, role}) | ||
.reply(200) | ||
} | ||
|
||
export function updateMemberRole(email = 'raulb@heroku.com', role = 'admin') { | ||
return nock('https://api.heroku.com:443') | ||
.put('/teams/myteam/members', {email, role}) | ||
.reply(200) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import {stdout, stderr} from 'stdout-stderr' | ||
import {expect} from 'chai' | ||
import * as nock from 'nock' | ||
import Cmd from '../../../../src/commands/members/add' | ||
import runCommand from '../../../helpers/runCommand' | ||
import {sendInvite, updateMemberRole} from '../../../helpers/stubs/put' | ||
import { | ||
teamFeatures, | ||
teamInfo, | ||
variableSizeTeamInvites, | ||
variableSizeTeamMembers, | ||
} from '../../../helpers/stubs/get' | ||
|
||
describe('heroku members:add', () => { | ||
let apiUpdateMemberRole: nock.Scope | ||
afterEach(() => nock.cleanAll()) | ||
|
||
context('without the feature flag team-invite-acceptance', () => { | ||
beforeEach(() => { | ||
teamFeatures([]) | ||
}) | ||
context('and group is an enterprise org', () => { | ||
beforeEach(() => { | ||
teamInfo('enterprise') | ||
variableSizeTeamMembers(1) | ||
}) | ||
it('adds a member to an org', () => { | ||
apiUpdateMemberRole = updateMemberRole('foo@foo.com', 'admin') | ||
return runCommand(Cmd, [ | ||
'--team', | ||
'myteam', | ||
'--role', | ||
'admin', | ||
'foo@foo.com', | ||
]) | ||
.then(() => expect('').to.eq(stdout.output)) | ||
.then(() => expect('Adding foo@foo.com to myteam as admin...\nAdding foo@foo.com to myteam as admin... done\n').to.eq(stderr.output)) | ||
.then(() => apiUpdateMemberRole.done()) | ||
}) | ||
}) | ||
}) | ||
context('with the feature flag team-invite-acceptance for a team', () => { | ||
beforeEach(() => { | ||
teamFeatures([{name: 'team-invite-acceptance', enabled: true}]) | ||
teamInfo('team') | ||
}) | ||
it('sends an invite when adding a new user to the team', () => { | ||
const apiSendInvite = sendInvite('foo@foo.com', 'admin') | ||
variableSizeTeamMembers(1) | ||
variableSizeTeamInvites(0) | ||
return runCommand(Cmd, [ | ||
'--role', | ||
'admin', | ||
'--team', | ||
'myteam', | ||
'foo@foo.com', | ||
]) | ||
.then(() => expect('').to.eq(stdout.output)) | ||
.then(() => expect('Inviting foo@foo.com to myteam as admin...\nInviting foo@foo.com to myteam as admin... done\n').to.eq(stderr.output)) | ||
.then(() => apiSendInvite.done()) | ||
}) | ||
}) | ||
}) |