Pull in client side changes for quest routes
This commit is contained in:
@@ -157,6 +157,72 @@ describe('Inventory Controller', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#buyQuest', function() {
|
||||
var quests, questObject;
|
||||
|
||||
beforeEach(inject(function(Quests) {
|
||||
quests = Quests;
|
||||
questObject = { key: 'whale' };
|
||||
|
||||
sandbox.stub(quests, 'buyQuest').returns({ then: function(res) { res(questObject); } });
|
||||
}));
|
||||
|
||||
it('calls Quests.buyQuest', function() {
|
||||
scope.buyQuest('foo');
|
||||
|
||||
expect(quests.buyQuest).to.be.calledOnce;
|
||||
expect(quests.buyQuest).to.be.calledWith('foo');
|
||||
});
|
||||
|
||||
it('sets selectedQuest to resolved quest object', function() {
|
||||
scope.buyQuest('whale');
|
||||
|
||||
expect(rootScope.selectedQuest).to.eql(questObject);
|
||||
});
|
||||
|
||||
it('opens buyQuest modal', function() {
|
||||
sandbox.spy(rootScope, 'openModal');
|
||||
|
||||
scope.buyQuest('whale');
|
||||
|
||||
expect(rootScope.openModal).to.be.calledOnce;
|
||||
expect(rootScope.openModal).to.be.calledWith('buyQuest', {controller: 'InventoryCtrl'});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#showQuest', function() {
|
||||
var quests, questObject;
|
||||
|
||||
beforeEach(inject(function(Quests) {
|
||||
quests = Quests;
|
||||
questObject = { key: 'whale' };
|
||||
|
||||
sandbox.stub(quests, 'showQuest').returns({ then: function(res) { res(questObject); } });
|
||||
}));
|
||||
|
||||
it('calls Quests.showQuest', function() {
|
||||
scope.showQuest('foo');
|
||||
|
||||
expect(quests.showQuest).to.be.calledOnce;
|
||||
expect(quests.showQuest).to.be.calledWith('foo');
|
||||
});
|
||||
|
||||
it('sets selectedQuest to resolved quest object', function() {
|
||||
scope.showQuest('whale');
|
||||
|
||||
expect(rootScope.selectedQuest).to.eql(questObject);
|
||||
});
|
||||
|
||||
it('opens showQuest modal', function() {
|
||||
sandbox.spy(rootScope, 'openModal');
|
||||
|
||||
scope.showQuest('whale');
|
||||
|
||||
expect(rootScope.openModal).to.be.calledOnce;
|
||||
expect(rootScope.openModal).to.be.calledWith('showQuest', {controller: 'InventoryCtrl'});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#hasAllTimeTravelerItems', function() {
|
||||
it('returns false if there are items left in the time traveler store', function() {
|
||||
expect(scope.hasAllTimeTravelerItems()).to.eql(false);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
describe("Party Controller", function() {
|
||||
var scope, ctrl, user, User, groups, rootScope, $controller;
|
||||
var scope, ctrl, user, User, questsService, groups, rootScope, $controller;
|
||||
|
||||
beforeEach(function() {
|
||||
user = specHelper.newUser(),
|
||||
@@ -15,7 +15,7 @@ describe("Party Controller", function() {
|
||||
$provide.value('User', User);
|
||||
});
|
||||
|
||||
inject(function(_$rootScope_, _$controller_, Groups){
|
||||
inject(function(_$rootScope_, _$controller_, Groups, Quests){
|
||||
|
||||
rootScope = _$rootScope_;
|
||||
|
||||
@@ -24,6 +24,7 @@ describe("Party Controller", function() {
|
||||
$controller = _$controller_;
|
||||
|
||||
groups = Groups;
|
||||
questsService = Quests;
|
||||
|
||||
// Load RootCtrl to ensure shared behaviors are loaded
|
||||
$controller('RootCtrl', {$scope: scope, User: User});
|
||||
@@ -33,129 +34,180 @@ describe("Party Controller", function() {
|
||||
});
|
||||
|
||||
describe('questAccept', function() {
|
||||
it('calls Groups.questAccept', function() {
|
||||
var party = {};
|
||||
var groupSpy = sandbox.stub(groups, "questAccept", function(){return true;});
|
||||
scope.questAccept(party);
|
||||
groupSpy.should.have.been.calledOnce;
|
||||
beforeEach(function() {
|
||||
scope.group = {
|
||||
quest: { members: { 'user-id': true } }
|
||||
};
|
||||
sandbox.stub(questsService, 'sendAction').returns({
|
||||
then: sandbox.stub().yields({members: {another: true}})
|
||||
});
|
||||
});
|
||||
|
||||
it('calls Quests.sendAction', function() {
|
||||
scope.questAccept();
|
||||
|
||||
expect(questsService.sendAction).to.be.calledOnce;
|
||||
expect(questsService.sendAction).to.be.calledWith('questAccept');
|
||||
});
|
||||
|
||||
|
||||
it('updates quest object with new participants list', function() {
|
||||
scope.group.quest = {
|
||||
members: { user: true, another: true }
|
||||
};
|
||||
|
||||
scope.questAccept();
|
||||
|
||||
expect(scope.group.quest).to.eql({members: { another: true }});
|
||||
});
|
||||
});
|
||||
|
||||
describe('questReject', function() {
|
||||
it('calls Groups.questReject', function() {
|
||||
var party = {};
|
||||
var groupSpy = sandbox.stub(groups, "questReject", function(){return true;});
|
||||
scope.questReject(party);
|
||||
groupSpy.should.have.been.calledOnce;
|
||||
beforeEach(function() {
|
||||
scope.group = {
|
||||
quest: { members: { 'user-id': true } }
|
||||
};
|
||||
sandbox.stub(questsService, 'sendAction').returns({
|
||||
then: sandbox.stub().yields({members: {another: true}})
|
||||
});
|
||||
});
|
||||
|
||||
it('calls Quests.sendAction', function() {
|
||||
scope.questReject();
|
||||
|
||||
expect(questsService.sendAction).to.be.calledOnce;
|
||||
expect(questsService.sendAction).to.be.calledWith('questReject');
|
||||
});
|
||||
|
||||
|
||||
it('updates quest object with new participants list', function() {
|
||||
scope.group.quest = {
|
||||
members: { user: true, another: true }
|
||||
};
|
||||
|
||||
scope.questReject();
|
||||
|
||||
expect(scope.group.quest).to.eql({members: { another: true }});
|
||||
});
|
||||
});
|
||||
|
||||
describe('questCancel', function() {
|
||||
var party, cancelSpy, windowSpy;
|
||||
beforeEach(function() {
|
||||
party = {};
|
||||
cancelSpy = sandbox.stub(groups, "questCancel", function(){return true;});
|
||||
sandbox.stub(questsService, 'sendAction').returns({
|
||||
then: sandbox.stub().yields({members: {another: true}})
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
windowSpy.restore();
|
||||
cancelSpy.restore();
|
||||
it('calls Quests.sendAction when alert box is confirmed', function() {
|
||||
sandbox.stub(window, "confirm").returns(true);
|
||||
|
||||
scope.questCancel();
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
it('calls Groups.questCancel when alert box is confirmed', function() {
|
||||
windowSpy = sandbox.stub(window, "confirm", function(){return true});
|
||||
it('does not call Quests.sendAction when alert box is not confirmed', function() {
|
||||
sandbox.stub(window, "confirm").returns(false);
|
||||
|
||||
scope.questCancel(party);
|
||||
windowSpy.should.have.been.calledOnce;
|
||||
windowSpy.should.have.been.calledWith(window.env.t('sureCancel'));
|
||||
cancelSpy.should.have.been.calledOnce;
|
||||
});
|
||||
scope.questCancel();
|
||||
|
||||
it('does not call Groups.questCancel when alert box is not confirmed', function() {
|
||||
windowSpy = sandbox.stub(window, "confirm", function(){return false});
|
||||
|
||||
scope.questCancel(party);
|
||||
windowSpy.should.have.been.calledOnce;
|
||||
cancelSpy.should.not.have.been.calledOnce;
|
||||
expect(window.confirm).to.be.calledOnce;
|
||||
expect(questsService.sendAction).to.not.be.called;
|
||||
});
|
||||
});
|
||||
|
||||
describe('questAbort', function() {
|
||||
var party, abortSpy, windowSpy;
|
||||
beforeEach(function() {
|
||||
party = {};
|
||||
abortSpy = sandbox.stub(groups, "questAbort", function(){return true;});
|
||||
sandbox.stub(questsService, 'sendAction').returns({
|
||||
then: sandbox.stub().yields({members: {another: true}})
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
windowSpy.restore();
|
||||
abortSpy.restore();
|
||||
it('calls Quests.sendAction when two alert boxes are confirmed', function() {
|
||||
sandbox.stub(window, "confirm", function(){return true});
|
||||
|
||||
scope.questAbort();
|
||||
expect(window.confirm).to.be.calledTwice;
|
||||
expect(window.confirm).to.be.calledWith(window.env.t('sureAbort'));
|
||||
expect(window.confirm).to.be.calledWith(window.env.t('doubleSureAbort'));
|
||||
|
||||
expect(questsService.sendAction).to.be.calledOnce;
|
||||
expect(questsService.sendAction).to.be.calledWith('questAbort');
|
||||
});
|
||||
|
||||
it('calls Groups.questAbort when two alert boxes are confirmed', function() {
|
||||
windowSpy = sandbox.stub(window, "confirm", function(){return true});
|
||||
it('does not call Quests.sendAction when first alert box is not confirmed', function() {
|
||||
sandbox.stub(window, "confirm", function(){return false});
|
||||
|
||||
scope.questAbort(party);
|
||||
windowSpy.should.have.been.calledTwice;
|
||||
windowSpy.should.have.been.calledWith(window.env.t('sureAbort'));
|
||||
windowSpy.should.have.been.calledWith(window.env.t('doubleSureAbort'));
|
||||
abortSpy.should.have.been.calledOnce;
|
||||
scope.questAbort();
|
||||
|
||||
expect(window.confirm).to.be.calledOnce;
|
||||
expect(window.confirm).to.be.calledWith(window.env.t('sureAbort'));
|
||||
expect(window.confirm).to.not.be.calledWith(window.env.t('doubleSureAbort'));
|
||||
|
||||
expect(questsService.sendAction).to.not.be.called;
|
||||
});
|
||||
|
||||
it('does not call Groups.questAbort when first alert box is not confirmed', function() {
|
||||
windowSpy = sandbox.stub(window, "confirm", function(){return false});
|
||||
|
||||
scope.questAbort(party);
|
||||
windowSpy.should.have.been.calledOnce;
|
||||
windowSpy.should.have.been.calledWith(window.env.t('sureAbort'));
|
||||
windowSpy.should.not.have.been.calledWith(window.env.t('doubleSureAbort'));
|
||||
abortSpy.should.not.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('does not call Groups.questAbort when first alert box is confirmed but second one is not', function() {
|
||||
it('does not call Quests.sendAction when first alert box is confirmed but second one is not', function() {
|
||||
// Hack to confirm first window, but not second
|
||||
// Should not be necessary when we upgrade sinon
|
||||
var shouldReturn = false;
|
||||
windowSpy = sandbox.stub(window, "confirm", function(){
|
||||
sandbox.stub(window, 'confirm', function(){
|
||||
shouldReturn = !shouldReturn;
|
||||
return shouldReturn;
|
||||
});
|
||||
|
||||
scope.questAbort(party);
|
||||
windowSpy.should.have.been.calledTwice;
|
||||
windowSpy.should.have.been.calledWith(window.env.t('sureAbort'));
|
||||
windowSpy.should.have.been.calledWith(window.env.t('doubleSureAbort'));
|
||||
abortSpy.should.not.have.been.calledOnce;
|
||||
scope.questAbort();
|
||||
|
||||
expect(window.confirm).to.be.calledTwice;
|
||||
expect(window.confirm).to.be.calledWith(window.env.t('sureAbort'));
|
||||
expect(window.confirm).to.be.calledWith(window.env.t('doubleSureAbort'));
|
||||
expect(questsService.sendAction).to.not.be.called;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#questLeave', function() {
|
||||
var party, leaveSpy, windowSpy;
|
||||
|
||||
beforeEach(function() {
|
||||
party = {};
|
||||
scope.group = {
|
||||
quest: { members: { 'user-id': true } }
|
||||
};
|
||||
leaveSpy = sandbox.stub(groups, 'questLeave').returns({
|
||||
then: sandbox.stub().yields()
|
||||
sandbox.stub(questsService, 'sendAction').returns({
|
||||
then: sandbox.stub().yields({members: {another: true}})
|
||||
});
|
||||
});
|
||||
|
||||
it('calls Groups.questLeave when alert box is confirmed', function() {
|
||||
windowSpy = sandbox.stub(window, "confirm").returns(true);
|
||||
it('calls Quests.sendAction when alert box is confirmed', function() {
|
||||
sandbox.stub(window, "confirm").returns(true);
|
||||
|
||||
scope.questLeave(party);
|
||||
windowSpy.should.have.been.calledOnce;
|
||||
windowSpy.should.have.been.calledWith(window.env.t('sureLeave'));
|
||||
leaveSpy.should.have.been.calledOnce;
|
||||
scope.questLeave();
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
it('does not call Groups.questLeave when alert box is not confirmed', function() {
|
||||
windowSpy = sandbox.stub(window, "confirm").returns(false);
|
||||
it('does not call Quests.sendAction when alert box is not confirmed', function() {
|
||||
sandbox.stub(window, "confirm").returns(false);
|
||||
|
||||
scope.questLeave(party);
|
||||
windowSpy.should.have.been.calledOnce;
|
||||
leaveSpy.should.not.have.been.calledOnce;
|
||||
scope.questLeave();
|
||||
|
||||
expect(window.confirm).to.be.calledOnce;
|
||||
questsService.sendAction.should.not.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('updates quest object with new participants list', function() {
|
||||
scope.group.quest = {
|
||||
members: { user: true, another: true }
|
||||
};
|
||||
sandbox.stub(window, "confirm").returns(true);
|
||||
|
||||
scope.questLeave();
|
||||
|
||||
expect(scope.group.quest).to.eql({members: { another: true }});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -241,4 +293,28 @@ describe("Party Controller", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#canEditQuest', function() {
|
||||
var party;
|
||||
|
||||
beforeEach(function() {
|
||||
party = specHelper.newGroup({
|
||||
type: 'party',
|
||||
leader: {},
|
||||
quest: {}
|
||||
});
|
||||
});
|
||||
|
||||
it('returns false if user is not the quest leader', function() {
|
||||
party.quest.leader = 'another-user';
|
||||
|
||||
expect(scope.canEditQuest(party)).to.eql(false);
|
||||
});
|
||||
|
||||
it('returns true if user is quest leader', function() {
|
||||
party.quest.leader = 'unique-user-id';
|
||||
|
||||
expect(scope.canEditQuest(party)).to.eql(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -39,67 +39,4 @@ describe('groupServices', function() {
|
||||
groups.myGuilds();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
context('quest function wrappers', function() {
|
||||
var successPromise, failPromise;
|
||||
|
||||
beforeEach(function() {
|
||||
sandbox.spy(user, 'sync');
|
||||
sandbox.stub(console, 'log');
|
||||
|
||||
successPromise = sandbox.stub().returns({
|
||||
then: function(success, failure) {
|
||||
return success();
|
||||
}
|
||||
});
|
||||
|
||||
failPromise = sandbox.stub().returns({
|
||||
then: function(success, failure) {
|
||||
return failure('fail');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var questFunctions = [
|
||||
'questAccept',
|
||||
'questReject',
|
||||
'questCancel',
|
||||
'questAbort',
|
||||
'questLeave'
|
||||
];
|
||||
|
||||
for (var i in questFunctions) {
|
||||
var questFunc = questFunctions[i];
|
||||
|
||||
describe('#' + questFunc, function() {
|
||||
it('calls party.$' + questFunc, function() {
|
||||
var party = { };
|
||||
party['$' + questFunc] = successPromise;
|
||||
|
||||
groups[questFunc](party);
|
||||
|
||||
expect(party['$' + questFunc]).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('syncs user if $' + questFunc + ' succeeds', function() {
|
||||
var successParty = { };
|
||||
successParty['$' + questFunc] = successPromise;
|
||||
|
||||
groups[questFunc](successParty);
|
||||
|
||||
user.sync.should.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('does not sync user if $' + questFunc + ' fails', function() {
|
||||
var failParty = { };
|
||||
failParty['$' + questFunc] = failPromise;
|
||||
|
||||
groups[questFunc](failParty);
|
||||
|
||||
user.sync.should.not.have.been.calledOnce;
|
||||
console.log.should.have.been.calledWith('fail');
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
describe('Quests Service', function() {
|
||||
var scope, rootScope, groupsService, quest, questsService, user, content;
|
||||
var groupsService, quest, questsService, user, content, resolveSpy, rejectSpy;
|
||||
|
||||
beforeEach(function() {
|
||||
user = specHelper.newUser();
|
||||
@@ -16,105 +16,365 @@ describe('Quests Service', function() {
|
||||
$provide.value('User', {user: user});
|
||||
});
|
||||
|
||||
inject(function($rootScope, $controller, Quests, Groups, Content) {
|
||||
scope = $rootScope.$new();
|
||||
rootScope = $rootScope;
|
||||
$controller('RootCtrl', {$scope: scope, User: {user: user}});
|
||||
inject(function(Quests, Groups, Content) {
|
||||
questsService = Quests;
|
||||
groupsService = Groups;
|
||||
content = Content;
|
||||
});
|
||||
|
||||
sandbox.stub(groupsService, 'inviteOrStartParty');
|
||||
sandbox.stub(rootScope, 'openModal');
|
||||
sandbox.stub(window,'confirm',function(){return true});
|
||||
sandbox.stub(window,'confirm');
|
||||
sandbox.stub(window,'alert');
|
||||
resolveSpy = sandbox.spy();
|
||||
rejectSpy = sandbox.spy();
|
||||
});
|
||||
|
||||
context('functions', function() {
|
||||
describe('#lockQuest', function() {
|
||||
|
||||
describe('lock quest', function() {
|
||||
it('locks quest when user does not meet level requirement', function() {
|
||||
user.stats.lvl = 15;
|
||||
|
||||
it('locks quest when user does not meet level requirement', function() {
|
||||
user.stats.lvl = 15;
|
||||
expect(questsService.lockQuest(quest)).to.be.ok;
|
||||
});
|
||||
|
||||
expect(questsService.lockQuest(quest)).to.be.ok;
|
||||
});
|
||||
it('does not lock quest if we ignore level requirement', function() {
|
||||
user.stats.lvl = 15;
|
||||
|
||||
it('does not lock quest if we ignore level requirement', function() {
|
||||
user.stats.lvl = 15;
|
||||
expect(questsService.lockQuest(quest,true)).to.not.be.ok;
|
||||
});
|
||||
|
||||
expect(questsService.lockQuest(quest,true)).to.not.be.ok;
|
||||
});
|
||||
it('does not lock quest if user meets level requirement', function() {
|
||||
user.stats.lvl = 20;
|
||||
|
||||
it('does not lock quest if user meets level requirement', function() {
|
||||
user.stats.lvl = 20;
|
||||
expect(questsService.lockQuest(quest)).to.not.be.ok;
|
||||
});
|
||||
|
||||
expect(questsService.lockQuest(quest)).to.not.be.ok;
|
||||
});
|
||||
it('locks quest if user has not completed previous quest in series', function() {
|
||||
quest.previous = 'priorQuest';
|
||||
user.stats.lvl = 25;
|
||||
|
||||
it('locks quest if user has not completed previous quest in series', function() {
|
||||
quest.previous = 'priorQuest';
|
||||
user.stats.lvl = 25;
|
||||
expect(questsService.lockQuest(quest)).to.be.ok;
|
||||
});
|
||||
|
||||
expect(questsService.lockQuest(quest)).to.be.ok;
|
||||
});
|
||||
it('does not lock quest if user has completed previous quest in series', function() {
|
||||
quest.previous = 'priorQuest';
|
||||
user.stats.lvl = 25;
|
||||
user.achievements.quests.priorQuest = 1;
|
||||
|
||||
it('does not lock quest if user has completed previous quest in series', function() {
|
||||
quest.previous = 'priorQuest';
|
||||
user.stats.lvl = 25;
|
||||
user.achievements.quests.priorQuest = 1;
|
||||
expect(questsService.lockQuest(quest)).to.not.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
expect(questsService.lockQuest(quest)).to.not.be.ok;
|
||||
describe('#buyQuest', function() {
|
||||
var scope;
|
||||
|
||||
beforeEach(inject(function($rootScope) {
|
||||
scope = $rootScope.$new();
|
||||
}));
|
||||
|
||||
it('returns a promise', function() {
|
||||
var promise = questsService.buyQuest('whale');
|
||||
expect(promise).to.respondTo('then');
|
||||
});
|
||||
|
||||
context('Quest key does not exist', function() {
|
||||
it('rejects with message that quest is not found', function(done) {
|
||||
questsService.buyQuest('foo')
|
||||
.then(resolveSpy, function(rej) {
|
||||
expect(rej).to.eql('No quest with that key found');
|
||||
expect(resolveSpy).to.not.be.called;
|
||||
done();
|
||||
});
|
||||
|
||||
scope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
describe('buy quest', function() {
|
||||
|
||||
context('invite friends', function() {
|
||||
it('prompts user to invite friends to party for invite reward quests', function() {
|
||||
questsService.buyQuest('basilist');
|
||||
|
||||
expect(window.confirm).to.have.been.calledOnce;
|
||||
expect(groupsService.inviteOrStartParty).to.have.been.calledOnce;
|
||||
expect(rootScope.openModal).to.have.been.notCalled;
|
||||
expect(window.confirm).to.be.calledOnce;
|
||||
expect(window.confirm).to.be.calledWith(env.t('mustInviteFriend'));
|
||||
});
|
||||
|
||||
it('does not allow user to buy quests whose previous quests are incomplete', function() {
|
||||
it('rejects promise if confirm is cancelled', function(done) {
|
||||
window.confirm.returns(false);
|
||||
|
||||
questsService.buyQuest('basilist')
|
||||
.then(resolveSpy, function(rej) {
|
||||
expect(rej).to.eql('Did not want to invite friends');
|
||||
expect(window.confirm).to.be.calledOnce;
|
||||
expect(groupsService.inviteOrStartParty).to.not.be.called;
|
||||
done();
|
||||
});
|
||||
|
||||
scope.$apply();
|
||||
});
|
||||
|
||||
it('rejects promise if confirm is cofirmed and calls groups service', function(done) {
|
||||
window.confirm.returns(true);
|
||||
|
||||
questsService.buyQuest('basilist')
|
||||
.then(resolveSpy, function(rej) {
|
||||
expect(rej).to.eql('Invite or start party');
|
||||
expect(window.confirm).to.be.calledOnce;
|
||||
expect(groupsService.inviteOrStartParty).to.be.calledOnce;
|
||||
done();
|
||||
});
|
||||
|
||||
scope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
context('quests in a series', function() {
|
||||
it('does not allow user to buy subsquent quests in a series if user has no quest achievements', function(done) {
|
||||
user.stats.lvl = 100;
|
||||
user.achievements.quests = undefined;
|
||||
|
||||
questsService.buyQuest('goldenknight2');
|
||||
questsService.buyQuest('goldenknight2')
|
||||
.then(resolveSpy, function(res) {
|
||||
expect(window.alert).to.have.been.calledOnce;
|
||||
expect(res).to.eql('unlockByQuesting');
|
||||
expect(resolveSpy).to.not.be.called;
|
||||
done();
|
||||
});
|
||||
|
||||
expect(window.alert).to.have.been.calledOnce;
|
||||
expect(rootScope.openModal).to.have.been.notCalled;
|
||||
scope.$apply();
|
||||
});
|
||||
|
||||
it('does not allow user to buy quests beyond their level', function() {
|
||||
it('does not allow user to buy quests whose previous quests are incomplete', function(done) {
|
||||
user.stats.lvl = 100;
|
||||
user.achievements.quests = {
|
||||
'atom1': 1
|
||||
};
|
||||
|
||||
questsService.buyQuest('goldenknight2')
|
||||
.then(resolveSpy, function(res) {
|
||||
expect(window.alert).to.have.been.calledOnce;
|
||||
expect(resolveSpy).to.not.be.called;
|
||||
done();
|
||||
});
|
||||
|
||||
scope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
context('quests with level requirement', function() {
|
||||
it('does not allow user to buy quests beyond their level', function(done) {
|
||||
user.stats.lvl = 1;
|
||||
|
||||
questsService.buyQuest('vice1');
|
||||
questsService.buyQuest('vice1')
|
||||
.then(resolveSpy, function(res) {
|
||||
expect(window.alert).to.have.been.calledOnce;
|
||||
expect(res).to.eql('mustLvlQuest');
|
||||
done();
|
||||
});
|
||||
|
||||
expect(window.alert).to.have.been.calledOnce;
|
||||
expect(rootScope.openModal).to.have.been.notCalled;
|
||||
scope.$apply();
|
||||
});
|
||||
|
||||
it('opens purchase modal if Gem quest prerequisites are met', function() {
|
||||
user.stats.lvl = 100;
|
||||
user.achievements.quests.atom1 = 2;
|
||||
it('allows user to buy quest if they meet level requirement', function(done) {
|
||||
user.stats.lvl = 30;
|
||||
|
||||
questsService.buyQuest('atom2');
|
||||
questsService.buyQuest('vice1')
|
||||
.then(function(res) {
|
||||
expect(res).to.eql(content.quests.vice1);
|
||||
expect(window.alert).to.not.be.called;
|
||||
expect(rejectSpy).to.not.be.called;
|
||||
done();
|
||||
}, rejectSpy);
|
||||
|
||||
expect(scope.selectedQuest).to.eql(content.quests.atom2);
|
||||
expect(rootScope.openModal).to.have.been.calledOnce;
|
||||
expect(rootScope.openModal).to.have.been.calledWith('buyQuest');
|
||||
scope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
it('opens purchase modal if quest is Gold-purchasable', function() {
|
||||
questsService.buyQuest('dilatoryDistress1');
|
||||
context('gold purchasable quests', function() {
|
||||
it('sends quest object', function(done) {
|
||||
questsService.buyQuest('dilatoryDistress1')
|
||||
.then(function(res) {
|
||||
expect(res).to.eql(content.quests.dilatoryDistress1);
|
||||
expect(window.alert).to.not.be.called;
|
||||
expect(rejectSpy).to.not.be.called;
|
||||
done();
|
||||
}, rejectSpy);
|
||||
|
||||
expect(scope.selectedQuest).to.eql(content.quests.dilatoryDistress1);
|
||||
expect(rootScope.openModal).to.have.been.calledOnce;
|
||||
expect(rootScope.openModal).to.have.been.calledWith('buyQuest');
|
||||
scope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
context('all other quests', function() {
|
||||
it('sends quest object', function(done) {
|
||||
questsService.buyQuest('whale')
|
||||
.then(function(res) {
|
||||
expect(res).to.eql(content.quests.whale);
|
||||
expect(window.alert).to.not.be.called;
|
||||
expect(rejectSpy).to.not.be.called;
|
||||
done();
|
||||
}, rejectSpy);
|
||||
|
||||
scope.$apply();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#showQuest', function() {
|
||||
var scope;
|
||||
|
||||
beforeEach(inject(function($rootScope) {
|
||||
scope = $rootScope.$new();
|
||||
}));
|
||||
|
||||
it('returns a promise', function() {
|
||||
var promise = questsService.showQuest('whale');
|
||||
expect(promise).to.respondTo('then');
|
||||
});
|
||||
|
||||
context('Quest key does not exist', function() {
|
||||
it('rejects with message that quest is not found', function(done) {
|
||||
questsService.showQuest('foo')
|
||||
.then(resolveSpy, function(rej) {
|
||||
expect(rej).to.eql('No quest with that key found');
|
||||
expect(resolveSpy).to.not.be.called;
|
||||
done();
|
||||
});
|
||||
|
||||
scope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
context('quests in a series', function() {
|
||||
it('does not allow user to buy subsquent quests in a series if user has no quest achievements', function(done) {
|
||||
user.stats.lvl = 100;
|
||||
user.achievements.quests = undefined;
|
||||
|
||||
questsService.showQuest('goldenknight2')
|
||||
.then(resolveSpy, function(res) {
|
||||
expect(window.alert).to.have.been.calledOnce;
|
||||
expect(res).to.eql('unlockByQuesting');
|
||||
expect(resolveSpy).to.not.be.called;
|
||||
done();
|
||||
});
|
||||
|
||||
scope.$apply();
|
||||
});
|
||||
|
||||
it('does not allow user to buy quests whose previous quests are incomplete', function(done) {
|
||||
user.stats.lvl = 100;
|
||||
user.achievements.quests = {
|
||||
'atom1': 1
|
||||
};
|
||||
|
||||
questsService.showQuest('goldenknight2')
|
||||
.then(resolveSpy, function(res) {
|
||||
expect(window.alert).to.have.been.calledOnce;
|
||||
expect(resolveSpy).to.not.be.called;
|
||||
done();
|
||||
});
|
||||
|
||||
scope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
context('quests with level requirement', function() {
|
||||
it('does not allow user to buy quests beyond their level', function(done) {
|
||||
user.stats.lvl = 1;
|
||||
|
||||
questsService.showQuest('vice1')
|
||||
.then(resolveSpy, function(res) {
|
||||
expect(window.alert).to.have.been.calledOnce;
|
||||
expect(res).to.eql('mustLvlQuest');
|
||||
done();
|
||||
});
|
||||
|
||||
scope.$apply();
|
||||
});
|
||||
|
||||
it('allows user to buy quest if they meet level requirement', function(done) {
|
||||
user.stats.lvl = 30;
|
||||
|
||||
questsService.showQuest('vice1')
|
||||
.then(function(res) {
|
||||
expect(res).to.eql(content.quests.vice1);
|
||||
expect(window.alert).to.not.be.called;
|
||||
expect(rejectSpy).to.not.be.called;
|
||||
done();
|
||||
}, rejectSpy);
|
||||
|
||||
scope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
context('gold purchasable quests', function() {
|
||||
it('sends quest object', function(done) {
|
||||
questsService.showQuest('dilatoryDistress1')
|
||||
.then(function(res) {
|
||||
expect(res).to.eql(content.quests.dilatoryDistress1);
|
||||
expect(window.alert).to.not.be.called;
|
||||
expect(rejectSpy).to.not.be.called;
|
||||
done();
|
||||
}, rejectSpy);
|
||||
|
||||
scope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
context('all other quests', function() {
|
||||
it('sends quest object', function(done) {
|
||||
questsService.showQuest('whale')
|
||||
.then(function(res) {
|
||||
expect(res).to.eql(content.quests.whale);
|
||||
expect(window.alert).to.not.be.called;
|
||||
expect(rejectSpy).to.not.be.called;
|
||||
done();
|
||||
}, rejectSpy);
|
||||
|
||||
scope.$apply();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#initQuest', function() {
|
||||
|
||||
it('returns a promise', function() {
|
||||
var promise = questsService.initQuest('whale');
|
||||
expect(promise).to.respondTo('then');
|
||||
});
|
||||
|
||||
it('accepts quest');
|
||||
|
||||
it('brings user to party page');
|
||||
});
|
||||
|
||||
describe('#sendAction', function() {
|
||||
var fakeBackend, scope;
|
||||
|
||||
beforeEach(inject(function($httpBackend, $rootScope) {
|
||||
scope = $rootScope.$new();
|
||||
fakeBackend = $httpBackend;
|
||||
|
||||
fakeBackend.when('GET', 'partials/main.html').respond({});
|
||||
fakeBackend.when('GET', '/api/v2/groups/party').respond({_id: 'party-id'});
|
||||
fakeBackend.when('POST', '/api/v2/groups/party-id/questReject').respond({quest: { key: 'whale' } });
|
||||
fakeBackend.flush();
|
||||
}));
|
||||
|
||||
it('returns a promise', function() {
|
||||
var promise = questsService.sendAction('questReject');
|
||||
expect(promise).to.respondTo('then');
|
||||
});
|
||||
|
||||
it('calls specified endpoint endpoint', function(done) {
|
||||
fakeBackend.expectPOST('/api/v2/groups/party-id/questReject');
|
||||
|
||||
questsService.sendAction('questReject')
|
||||
.then(function(res) {
|
||||
expect(res.key).to.eql('whale');
|
||||
done();
|
||||
});
|
||||
|
||||
fakeBackend.flush();
|
||||
scope.$apply();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user