From 6556c2a670d406627d93e46ecd60437e27cf2290 Mon Sep 17 00:00:00 2001 From: Keith Holliday Date: Fri, 6 May 2016 09:10:47 -0500 Subject: [PATCH] Added missing done to tests. Fixed partyCtrl tests --- test/spec/controllers/challengesCtrlSpec.js | 8 +- test/spec/controllers/partyCtrlSpec.js | 93 +++++++++++++-------- website/public/js/controllers/partyCtrl.js | 2 +- 3 files changed, 64 insertions(+), 39 deletions(-) diff --git a/test/spec/controllers/challengesCtrlSpec.js b/test/spec/controllers/challengesCtrlSpec.js index 3b2f60e7c6..e465336d53 100644 --- a/test/spec/controllers/challengesCtrlSpec.js +++ b/test/spec/controllers/challengesCtrlSpec.js @@ -398,7 +398,7 @@ describe('Challenges Controller', function() { scope.save(challenge); }); - it('saves new challenge and syncs User', function() { + it('saves new challenge and syncs User', function(done) { sinon.stub(notification, 'text'); var challenge = specHelper.newChallenge(); @@ -703,8 +703,8 @@ describe('Challenges Controller', function() { members.selectMember.returns(Promise.resolve()); }); - describe('sendMessageToChallengeParticipant', function(done) { - it('opens private-message modal', function() { + describe('sendMessageToChallengeParticipant', function() { + it('opens private-message modal', function(done) { scope.sendMessageToChallengeParticipant(user._id); setTimeout(function() { @@ -719,7 +719,7 @@ describe('Challenges Controller', function() { }); describe('sendGiftToChallengeParticipant', function() { - it('opens send-gift modal', function() { + it('opens send-gift modal', function(done) { scope.sendGiftToChallengeParticipant(user._id); setTimeout(function() { diff --git a/test/spec/controllers/partyCtrlSpec.js b/test/spec/controllers/partyCtrlSpec.js index 1b629288b5..88a94cfc28 100644 --- a/test/spec/controllers/partyCtrlSpec.js +++ b/test/spec/controllers/partyCtrlSpec.js @@ -97,7 +97,7 @@ describe("Party Controller", function() { }); context('user has "Party Up" but not "Party On" achievement', function() { - it('awards "Party On" achievement', function() { + it('awards "Party On" achievement', function(done) { user.achievements.partyUp = true; initializeControllerWithStubbedState(); @@ -115,18 +115,18 @@ describe("Party Controller", function() { }); context('user has neither "Party Up" nor "Party On" achievements', function() { - it('awards "Party Up" and "Party On" achievements', function() { + it('awards "Party Up" and "Party On" achievements', function(done) { initializeControllerWithStubbedState(); setTimeout(function(){ - expect(User.set).to.be.calledTwice; + expect(User.set).to.have.been.called; expect(User.set).to.be.calledWith( { 'achievements.partyUp': true} ); expect(User.set).to.be.calledWith( { 'achievements.partyOn': true} ); - expect(rootScope.openModal).to.be.calledTwice; + expect(rootScope.openModal).to.have.been.called; expect(rootScope.openModal).to.be.calledWith('achievements/partyUp'); expect(rootScope.openModal).to.be.calledWith('achievements/partyOn'); done(); @@ -168,72 +168,87 @@ describe("Party Controller", function() { }); describe('questAccept', function() { + var sendAction; + var memberResponse; + beforeEach(function() { scope.group = { quest: { members: { 'user-id': true } } }; - sandbox.stub(questsService, 'sendAction').returns({ - then: sandbox.stub().yields({members: {another: true}}) - }); + + memberResponse = {members: {another: true}}; + sinon.stub(questsService, 'sendAction') + questsService.sendAction.returns(Promise.resolve(memberResponse)); }); it('calls Quests.sendAction', function() { scope.questAccept(); expect(questsService.sendAction).to.be.calledOnce; - expect(questsService.sendAction).to.be.calledWith('questAccept'); + expect(questsService.sendAction).to.be.calledWith('quests/accept'); }); - it('updates quest object with new participants list', function() { + it('updates quest object with new participants list', function(done) { scope.group.quest = { members: { user: true, another: true } }; - scope.questAccept(); + setTimeout(function(){ + expect(scope.group.quest).to.eql(memberResponse); + done(); + }, 1000); - expect(scope.group.quest).to.eql({members: { another: true }}); + scope.questAccept(); }); }); describe('questReject', function() { + var memberResponse; + beforeEach(function() { scope.group = { quest: { members: { 'user-id': true } } }; - sandbox.stub(questsService, 'sendAction').returns({ - then: sandbox.stub().yields({members: {another: true}}) - }); + + memberResponse = {members: {another: true}}; + var sendAction = sinon.stub(questsService, 'sendAction') + sendAction.returns(Promise.resolve(memberResponse)); }); it('calls Quests.sendAction', function() { scope.questReject(); expect(questsService.sendAction).to.be.calledOnce; - expect(questsService.sendAction).to.be.calledWith('questReject'); + expect(questsService.sendAction).to.be.calledWith('quests/reject'); }); - it('updates quest object with new participants list', function() { + it('updates quest object with new participants list', function(done) { scope.group.quest = { members: { user: true, another: true } }; - scope.questReject(); + setTimeout(function(){ + expect(scope.group.quest).to.eql(memberResponse); + done(); + }, 1000); - expect(scope.group.quest).to.eql({members: { another: true }}); + scope.questReject(); }); }); describe('questCancel', function() { - var party, cancelSpy, windowSpy; + var party, cancelSpy, windowSpy, memberResponse; + beforeEach(function() { scope.group = { quest: { members: { 'user-id': true } } }; - sandbox.stub(questsService, 'sendAction').returns({ - then: sandbox.stub().yields({members: {another: true}}) - }); + + memberResponse = {members: {another: true}}; + sinon.stub(questsService, 'sendAction') + questsService.sendAction.returns(Promise.resolve(memberResponse)); }); it('calls Quests.sendAction when alert box is confirmed', function() { @@ -244,7 +259,7 @@ describe("Party Controller", function() { expect(window.confirm).to.be.calledOnce; expect(window.confirm).to.be.calledWith(window.env.t('sureCancel')); expect(questsService.sendAction).to.be.calledOnce; - expect(questsService.sendAction).to.be.calledWith('questCancel'); + expect(questsService.sendAction).to.be.calledWith('quests/cancel'); }); it('does not call Quests.sendAction when alert box is not confirmed', function() { @@ -258,13 +273,16 @@ describe("Party Controller", function() { }); describe('questAbort', function() { + var memberResponse; + beforeEach(function() { scope.group = { quest: { members: { 'user-id': true } } }; - sandbox.stub(questsService, 'sendAction').returns({ - then: sandbox.stub().yields({members: {another: true}}) - }); + + memberResponse = {members: {another: true}}; + sinon.stub(questsService, 'sendAction') + questsService.sendAction.returns(Promise.resolve(memberResponse)); }); it('calls Quests.sendAction when two alert boxes are confirmed', function() { @@ -276,7 +294,7 @@ describe("Party Controller", function() { expect(window.confirm).to.be.calledWith(window.env.t('doubleSureAbort')); expect(questsService.sendAction).to.be.calledOnce; - expect(questsService.sendAction).to.be.calledWith('questAbort'); + expect(questsService.sendAction).to.be.calledWith('quests/abort'); }); it('does not call Quests.sendAction when first alert box is not confirmed', function() { @@ -310,13 +328,16 @@ describe("Party Controller", function() { }); describe('#questLeave', function() { + var memberResponse; + beforeEach(function() { scope.group = { quest: { members: { 'user-id': true } } }; - sandbox.stub(questsService, 'sendAction').returns({ - then: sandbox.stub().yields({members: {another: true}}) - }); + + memberResponse = {members: {another: true}}; + sinon.stub(questsService, 'sendAction') + questsService.sendAction.returns(Promise.resolve(memberResponse)); }); it('calls Quests.sendAction when alert box is confirmed', function() { @@ -327,7 +348,7 @@ describe("Party Controller", function() { expect(window.confirm).to.be.calledOnce; expect(window.confirm).to.be.calledWith(window.env.t('sureLeave')); expect(questsService.sendAction).to.be.calledOnce; - expect(questsService.sendAction).to.be.calledWith('questLeave'); + expect(questsService.sendAction).to.be.calledWith('quests/leave'); }); it('does not call Quests.sendAction when alert box is not confirmed', function() { @@ -339,15 +360,18 @@ describe("Party Controller", function() { questsService.sendAction.should.not.have.been.calledOnce; }); - it('updates quest object with new participants list', function() { + it('updates quest object with new participants list', function(done) { scope.group.quest = { members: { user: true, another: true } }; sandbox.stub(window, "confirm").returns(true); - scope.questLeave(); + setTimeout(function(){ + expect(scope.group.quest).to.eql(memberResponse); + done(); + }, 1000); - expect(scope.group.quest).to.eql({members: { another: true }}); + scope.questLeave(); }); }); @@ -443,6 +467,7 @@ describe("Party Controller", function() { leader: {}, quest: {} }); + scope.group = party; }); it('returns false if user is not the quest leader', function() { diff --git a/website/public/js/controllers/partyCtrl.js b/website/public/js/controllers/partyCtrl.js index dba584899b..4ed77885f7 100644 --- a/website/public/js/controllers/partyCtrl.js +++ b/website/public/js/controllers/partyCtrl.js @@ -46,7 +46,7 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User',' } } - if ($scope.group) { + if ($scope.group && $scope.group._id) { Chat.markChatSeen($scope.group._id); }