Simplify method name

This commit is contained in:
Alberto Fernández Capel 2018-06-07 15:35:18 +01:00
parent 30b935befd
commit 670f24ef6f
5 changed files with 15 additions and 15 deletions

View file

@ -33,7 +33,7 @@ module.exports = SubscriptionGroupHandler =
userViewModel = buildUserViewModel(user) userViewModel = buildUserViewModel(user)
callback(err, userViewModel) callback(err, userViewModel)
else else
TeamInvitesHandler.createManagerInvite adminUserId, newEmail, (err) -> TeamInvitesHandler.createInvite adminUserId, newEmail, (err) ->
return callback(err) if err? return callback(err) if err?
userViewModel = buildEmailInviteViewModel(newEmail) userViewModel = buildEmailInviteViewModel(newEmail)
callback(err, userViewModel) callback(err, userViewModel)

View file

@ -10,7 +10,7 @@ module.exports =
teamManagerId = AuthenticationController.getLoggedInUserId(req) teamManagerId = AuthenticationController.getLoggedInUserId(req)
email = req.body.email email = req.body.email
TeamInvitesHandler.createManagerInvite teamManagerId, email, (err, invite) -> TeamInvitesHandler.createInvite teamManagerId, email, (err, invite) ->
return handleError(err, req, res, next) if err? return handleError(err, req, res, next) if err?
inviteView = { user: inviteView = { user:
{ email: invite.email, sentAt: invite.sentAt, invite: true } { email: invite.email, sentAt: invite.sentAt, invite: true }

View file

@ -24,7 +24,7 @@ module.exports = TeamInvitesHandler =
invite = subscription.teamInvites.find (i) -> i.token == token invite = subscription.teamInvites.find (i) -> i.token == token
return callback(null, invite, subscription) return callback(null, invite, subscription)
createManagerInvite: (teamManagerId, email, callback) -> createInvite: (teamManagerId, email, callback) ->
logger.log {teamManagerId, email}, "Creating manager team invite" logger.log {teamManagerId, email}, "Creating manager team invite"
UserGetter.getUser teamManagerId, (error, teamManager) -> UserGetter.getUser teamManagerId, (error, teamManager) ->
return callback(error) if error? return callback(error) if error?
@ -73,7 +73,7 @@ module.exports = TeamInvitesHandler =
return callback(err) if err? return callback(err) if err?
async.map teams, async.map teams,
(team, cb) -> TeamInvitesHandler.createManagerInvite(team.admin_id, email, cb) (team, cb) -> TeamInvitesHandler.createInvite(team.admin_id, email, cb)
, callback , callback
createInvite = (subscription, email, inviterName, callback) -> createInvite = (subscription, email, inviterName, callback) ->

View file

@ -29,7 +29,7 @@ describe "SubscriptionGroupHandler", ->
removeUserFromGroup: sinon.stub().callsArgWith(2) removeUserFromGroup: sinon.stub().callsArgWith(2)
@TeamInvitesHandler = @TeamInvitesHandler =
createManagerInvite: sinon.stub().callsArgWith(2) createInvite: sinon.stub().callsArgWith(2)
@UserGetter = @UserGetter =
getUser: sinon.stub() getUser: sinon.stub()
@ -106,7 +106,7 @@ describe "SubscriptionGroupHandler", ->
it "should add an email invite if no user is found", (done) -> it "should add an email invite if no user is found", (done) ->
@UserGetter.getUserByMainEmail.callsArgWith(1, null, null) @UserGetter.getUserByMainEmail.callsArgWith(1, null, null)
@Handler.addUserToGroup @adminUser_id, @newEmail, (err)=> @Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
@TeamInvitesHandler.createManagerInvite.calledWith(@adminUser_id, @newEmail).should.equal true @TeamInvitesHandler.createInvite.calledWith(@adminUser_id, @newEmail).should.equal true
done() done()
describe "removeUserFromGroup", -> describe "removeUserFromGroup", ->

View file

@ -98,9 +98,9 @@ describe "TeamInvitesHandler", ->
expect(err).to.deep.eq(teamNotFound: true) expect(err).to.deep.eq(teamNotFound: true)
done() done()
describe "createManagerInvite", -> describe "createInvite", ->
it "adds the team invite to the subscription", (done) -> it "adds the team invite to the subscription", (done) ->
@TeamInvitesHandler.createManagerInvite @manager.id, "John.Snow@nightwatch.com", (err, invite) => @TeamInvitesHandler.createInvite @manager.id, "John.Snow@nightwatch.com", (err, invite) =>
expect(err).to.eq(null) expect(err).to.eq(null)
expect(invite.token).to.eq(@newToken) expect(invite.token).to.eq(@newToken)
expect(invite.email).to.eq("john.snow@nightwatch.com") expect(invite.email).to.eq("john.snow@nightwatch.com")
@ -109,7 +109,7 @@ describe "TeamInvitesHandler", ->
done() done()
it "sends an email", (done) -> it "sends an email", (done) ->
@TeamInvitesHandler.createManagerInvite @manager.id, "John.Snow@nightwatch.com", (err, invite) => @TeamInvitesHandler.createInvite @manager.id, "John.Snow@nightwatch.com", (err, invite) =>
@EmailHandler.sendEmail.calledWith("verifyEmailToJoinTeam", @EmailHandler.sendEmail.calledWith("verifyEmailToJoinTeam",
sinon.match({ sinon.match({
to: "john.snow@nightwatch.com", to: "john.snow@nightwatch.com",
@ -122,7 +122,7 @@ describe "TeamInvitesHandler", ->
it "refreshes the existing invite if the email has already been invited", (done) -> it "refreshes the existing invite if the email has already been invited", (done) ->
originalInvite = Object.assign({}, @teamInvite) originalInvite = Object.assign({}, @teamInvite)
@TeamInvitesHandler.createManagerInvite @manager.id, originalInvite.email, (err, invite) => @TeamInvitesHandler.createInvite @manager.id, originalInvite.email, (err, invite) =>
expect(err).to.eq(null) expect(err).to.eq(null)
expect(invite).to.exist expect(invite).to.exist
@ -206,26 +206,26 @@ describe "TeamInvitesHandler", ->
describe "createTeamInvitesForLegacyInvitedEmail", (done) -> describe "createTeamInvitesForLegacyInvitedEmail", (done) ->
beforeEach -> beforeEach ->
@subscription.invited_emails = ["eddard@stark.com", "robert@stark.com"] @subscription.invited_emails = ["eddard@stark.com", "robert@stark.com"]
@TeamInvitesHandler.createManagerInvite = sinon.stub().yields(null) @TeamInvitesHandler.createInvite = sinon.stub().yields(null)
@SubscriptionLocator.getGroupsWithEmailInvite = sinon.stub().yields(null, [@subscription]) @SubscriptionLocator.getGroupsWithEmailInvite = sinon.stub().yields(null, [@subscription])
it "sends an invitation email to addresses in the legacy invited_emails field", (done) -> it "sends an invitation email to addresses in the legacy invited_emails field", (done) ->
@TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail "eddard@stark.com", (err, invite) => @TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail "eddard@stark.com", (err, invite) =>
expect(err).not.to.exist expect(err).not.to.exist
@TeamInvitesHandler.createManagerInvite.calledWith( @TeamInvitesHandler.createInvite.calledWith(
@subscription.admin_id, @subscription.admin_id,
"eddard@stark.com" "eddard@stark.com"
).should.eq true ).should.eq true
@TeamInvitesHandler.createManagerInvite.callCount.should.eq 1 @TeamInvitesHandler.createInvite.callCount.should.eq 1
done() done()
describe "validation", -> describe "validation", ->
it "doesn't create an invite if the team limit has been reached", (done) -> it "doesn't create an invite if the team limit has been reached", (done) ->
@LimitationsManager.teamHasReachedMemberLimit = sinon.stub().returns(true) @LimitationsManager.teamHasReachedMemberLimit = sinon.stub().returns(true)
@TeamInvitesHandler.createManagerInvite @manager.id, "John.Snow@nightwatch.com", (err, invite) => @TeamInvitesHandler.createInvite @manager.id, "John.Snow@nightwatch.com", (err, invite) =>
expect(err).to.deep.equal(limitReached: true) expect(err).to.deep.equal(limitReached: true)
done() done()
@ -239,7 +239,7 @@ describe "TeamInvitesHandler", ->
@subscription.member_ids = [member.id] @subscription.member_ids = [member.id]
@UserGetter.getUserByAnyEmail.withArgs(member.email).yields(null, member) @UserGetter.getUserByAnyEmail.withArgs(member.email).yields(null, member)
@TeamInvitesHandler.createManagerInvite @manager.id, "tyrion@lannister.com", (err, invite) => @TeamInvitesHandler.createInvite @manager.id, "tyrion@lannister.com", (err, invite) =>
expect(err).to.deep.equal(alreadyInTeam: true) expect(err).to.deep.equal(alreadyInTeam: true)
expect(invite).not.to.exist expect(invite).not.to.exist
done() done()