mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Added missing done to tests. Fixed partyCtrl tests
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user