Added missing done to tests. Fixed partyCtrl tests

This commit is contained in:
Keith Holliday
2016-05-06 09:10:47 -05:00
parent fd244ac021
commit 6556c2a670
3 changed files with 64 additions and 39 deletions

View File

@@ -398,7 +398,7 @@ describe('Challenges Controller', function() {
scope.save(challenge); scope.save(challenge);
}); });
it('saves new challenge and syncs User', function() { it('saves new challenge and syncs User', function(done) {
sinon.stub(notification, 'text'); sinon.stub(notification, 'text');
var challenge = specHelper.newChallenge(); var challenge = specHelper.newChallenge();
@@ -703,8 +703,8 @@ describe('Challenges Controller', function() {
members.selectMember.returns(Promise.resolve()); members.selectMember.returns(Promise.resolve());
}); });
describe('sendMessageToChallengeParticipant', function(done) { describe('sendMessageToChallengeParticipant', function() {
it('opens private-message modal', function() { it('opens private-message modal', function(done) {
scope.sendMessageToChallengeParticipant(user._id); scope.sendMessageToChallengeParticipant(user._id);
setTimeout(function() { setTimeout(function() {
@@ -719,7 +719,7 @@ describe('Challenges Controller', function() {
}); });
describe('sendGiftToChallengeParticipant', function() { describe('sendGiftToChallengeParticipant', function() {
it('opens send-gift modal', function() { it('opens send-gift modal', function(done) {
scope.sendGiftToChallengeParticipant(user._id); scope.sendGiftToChallengeParticipant(user._id);
setTimeout(function() { setTimeout(function() {

View File

@@ -97,7 +97,7 @@ describe("Party Controller", function() {
}); });
context('user has "Party Up" but not "Party On" achievement', 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; user.achievements.partyUp = true;
initializeControllerWithStubbedState(); initializeControllerWithStubbedState();
@@ -115,18 +115,18 @@ describe("Party Controller", function() {
}); });
context('user has neither "Party Up" nor "Party On" achievements', 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(); initializeControllerWithStubbedState();
setTimeout(function(){ setTimeout(function(){
expect(User.set).to.be.calledTwice; expect(User.set).to.have.been.called;
expect(User.set).to.be.calledWith( expect(User.set).to.be.calledWith(
{ 'achievements.partyUp': true} { 'achievements.partyUp': true}
); );
expect(User.set).to.be.calledWith( expect(User.set).to.be.calledWith(
{ 'achievements.partyOn': true} { '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/partyUp');
expect(rootScope.openModal).to.be.calledWith('achievements/partyOn'); expect(rootScope.openModal).to.be.calledWith('achievements/partyOn');
done(); done();
@@ -168,72 +168,87 @@ describe("Party Controller", function() {
}); });
describe('questAccept', function() { describe('questAccept', function() {
var sendAction;
var memberResponse;
beforeEach(function() { beforeEach(function() {
scope.group = { scope.group = {
quest: { members: { 'user-id': true } } 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() { it('calls Quests.sendAction', function() {
scope.questAccept(); scope.questAccept();
expect(questsService.sendAction).to.be.calledOnce; 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 = { scope.group.quest = {
members: { user: true, another: true } 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() { describe('questReject', function() {
var memberResponse;
beforeEach(function() { beforeEach(function() {
scope.group = { scope.group = {
quest: { members: { 'user-id': true } } 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() { it('calls Quests.sendAction', function() {
scope.questReject(); scope.questReject();
expect(questsService.sendAction).to.be.calledOnce; 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 = { scope.group.quest = {
members: { user: true, another: true } 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() { describe('questCancel', function() {
var party, cancelSpy, windowSpy; var party, cancelSpy, windowSpy, memberResponse;
beforeEach(function() { beforeEach(function() {
scope.group = { scope.group = {
quest: { members: { 'user-id': true } } 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() { 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.calledOnce;
expect(window.confirm).to.be.calledWith(window.env.t('sureCancel')); expect(window.confirm).to.be.calledWith(window.env.t('sureCancel'));
expect(questsService.sendAction).to.be.calledOnce; 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() { it('does not call Quests.sendAction when alert box is not confirmed', function() {
@@ -258,13 +273,16 @@ describe("Party Controller", function() {
}); });
describe('questAbort', function() { describe('questAbort', function() {
var memberResponse;
beforeEach(function() { beforeEach(function() {
scope.group = { scope.group = {
quest: { members: { 'user-id': true } } 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() { 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(window.confirm).to.be.calledWith(window.env.t('doubleSureAbort'));
expect(questsService.sendAction).to.be.calledOnce; 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() { 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() { describe('#questLeave', function() {
var memberResponse;
beforeEach(function() { beforeEach(function() {
scope.group = { scope.group = {
quest: { members: { 'user-id': true } } 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() { 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.calledOnce;
expect(window.confirm).to.be.calledWith(window.env.t('sureLeave')); expect(window.confirm).to.be.calledWith(window.env.t('sureLeave'));
expect(questsService.sendAction).to.be.calledOnce; 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() { 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; 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 = { scope.group.quest = {
members: { user: true, another: true } members: { user: true, another: true }
}; };
sandbox.stub(window, "confirm").returns(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: {}, leader: {},
quest: {} quest: {}
}); });
scope.group = party;
}); });
it('returns false if user is not the quest leader', function() { it('returns false if user is not the quest leader', function() {

View File

@@ -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); Chat.markChatSeen($scope.group._id);
} }