Updated quest service to use new api-v3 (#7126)
* Updated quest service to use new api-v3 * Updated inviteToQuest function name. Used quest return rather than syncing party
This commit is contained in:
committed by
Matteo Pagliazzi
parent
01c07ae6df
commit
78a8eea79a
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
describe('Quests Service', function() {
|
||||
var groupsService, quest, questsService, user, content, resolveSpy, rejectSpy;
|
||||
var groupsService, quest, questsService, user, content, resolveSpy, rejectSpy, state;
|
||||
|
||||
beforeEach(function() {
|
||||
user = specHelper.newUser();
|
||||
@@ -16,10 +16,11 @@ describe('Quests Service', function() {
|
||||
$provide.value('User', {sync: sinon.stub(), user: user});
|
||||
});
|
||||
|
||||
inject(function(Quests, Groups, Content) {
|
||||
inject(function(Quests, Groups, Content, _$state_) {
|
||||
questsService = Quests;
|
||||
groupsService = Groups;
|
||||
content = Content;
|
||||
state = _$state_;
|
||||
});
|
||||
|
||||
sandbox.stub(groupsService, 'inviteOrStartParty');
|
||||
@@ -335,13 +336,36 @@ describe('Quests Service', function() {
|
||||
});
|
||||
|
||||
describe('#initQuest', function() {
|
||||
var fakeBackend, scope, key = 'whale';
|
||||
|
||||
beforeEach(inject(function($httpBackend, $rootScope) {
|
||||
scope = $rootScope.$new();
|
||||
fakeBackend = $httpBackend;
|
||||
var partyResponse = {data:{_id: 'party-id'}};
|
||||
|
||||
fakeBackend.when('GET', 'partials/main.html').respond({});
|
||||
fakeBackend.when('GET', 'partials/main.html').respond({});
|
||||
fakeBackend.when('GET', '/api/v3/groups/party').respond(partyResponse);
|
||||
fakeBackend.when('POST', '/api/v3/groups/party-id/quests/invite/' + key).respond({quest: { key: 'whale' } });
|
||||
fakeBackend.flush();
|
||||
}));
|
||||
|
||||
it('returns a promise', function() {
|
||||
var promise = questsService.initQuest('whale');
|
||||
var promise = questsService.initQuest(key);
|
||||
expect(promise).to.respondTo('then');
|
||||
});
|
||||
|
||||
it('accepts quest');
|
||||
it('starts a quest', function(done) {
|
||||
fakeBackend.expectPOST( '/api/v3/groups/party-id/quests/invite/' + key);
|
||||
|
||||
questsService.initQuest(key)
|
||||
.then(function(res) {
|
||||
done();
|
||||
});
|
||||
|
||||
fakeBackend.flush();
|
||||
scope.$apply();
|
||||
});
|
||||
|
||||
it('brings user to party page');
|
||||
});
|
||||
@@ -352,22 +376,23 @@ describe('Quests Service', function() {
|
||||
beforeEach(inject(function($httpBackend, $rootScope) {
|
||||
scope = $rootScope.$new();
|
||||
fakeBackend = $httpBackend;
|
||||
var partyResponse = {data:{_id: 'party-id'}};
|
||||
|
||||
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.when('GET', '/api/v3/groups/party').respond(partyResponse);
|
||||
fakeBackend.when('POST', '/api/v3/groups/party-id/quests/reject').respond({quest: { key: 'whale' } });
|
||||
fakeBackend.flush();
|
||||
}));
|
||||
|
||||
it('returns a promise', function() {
|
||||
var promise = questsService.sendAction('questReject');
|
||||
var promise = questsService.sendAction('quests/reject');
|
||||
expect(promise).to.respondTo('then');
|
||||
});
|
||||
|
||||
it('calls specified quest endpoint', function(done) {
|
||||
fakeBackend.expectPOST('/api/v2/groups/party-id/questReject');
|
||||
fakeBackend.expectPOST('/api/v3/groups/party-id/quests/reject');
|
||||
|
||||
questsService.sendAction('questReject')
|
||||
questsService.sendAction('quests/reject')
|
||||
.then(function(res) {
|
||||
expect(res.key).to.eql('whale');
|
||||
done();
|
||||
@@ -378,7 +403,7 @@ describe('Quests Service', function() {
|
||||
});
|
||||
|
||||
it('syncs User', function() {
|
||||
questsService.sendAction('questReject')
|
||||
questsService.sendAction('quests/reject')
|
||||
.then(function(res) {
|
||||
expect(User.sync).to.be.calledOnce;
|
||||
done();
|
||||
|
||||
@@ -149,7 +149,7 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
|
||||
$scope.questCancel = function(){
|
||||
if (!confirm(window.env.t('sureCancel'))) return;
|
||||
|
||||
Quests.sendAction('questCancel')
|
||||
Quests.sendAction('quests/cancel')
|
||||
.then(function(quest) {
|
||||
$scope.group.quest = quest;
|
||||
});
|
||||
@@ -159,7 +159,7 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
|
||||
if (!confirm(window.env.t('sureAbort'))) return;
|
||||
if (!confirm(window.env.t('doubleSureAbort'))) return;
|
||||
|
||||
Quests.sendAction('questAbort')
|
||||
Quests.sendAction('quests/abort')
|
||||
.then(function(quest) {
|
||||
$scope.group.quest = quest;
|
||||
});
|
||||
@@ -168,28 +168,35 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
|
||||
$scope.questLeave = function(){
|
||||
if (!confirm(window.env.t('sureLeave'))) return;
|
||||
|
||||
Quests.sendAction('questLeave')
|
||||
Quests.sendAction('quests/leave')
|
||||
.then(function(quest) {
|
||||
$scope.group.quest = quest;
|
||||
});
|
||||
}
|
||||
|
||||
$scope.questAccept = function(){
|
||||
Quests.sendAction('questAccept')
|
||||
Quests.sendAction('quests/accept')
|
||||
.then(function(quest) {
|
||||
$scope.group.quest = quest;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.questForceStart = function(){
|
||||
Quests.sendAction('quests/force-start')
|
||||
.then(function(quest) {
|
||||
$scope.group.quest = quest;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.questReject = function(){
|
||||
Quests.sendAction('questReject')
|
||||
Quests.sendAction('quests/reject')
|
||||
.then(function(quest) {
|
||||
$scope.group.quest = quest;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.canEditQuest = function(party) {
|
||||
var isQuestLeader = party.quest && party.quest.leader === User.user._id;
|
||||
$scope.canEditQuest = function() {
|
||||
var isQuestLeader = $scope.group.quest && $scope.group.quest.leader === User.user._id;
|
||||
|
||||
return isQuestLeader;
|
||||
};
|
||||
|
||||
@@ -94,10 +94,10 @@ angular.module('habitrpg')
|
||||
});
|
||||
};
|
||||
|
||||
Group.startQuest = function(gid) {
|
||||
Group.inviteToQuest = function(gid, key) {
|
||||
return $http({
|
||||
method: "POST",
|
||||
url: groupApiURLPrefix + '/' + gid + '/questAccept',
|
||||
url: groupApiURLPrefix + '/' + gid + '/quests/invite/' + key,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
(function(){
|
||||
angular
|
||||
.module('habitrpg')
|
||||
.factory('Quests', questsFactory);
|
||||
|
||||
questsFactory.$inject = [
|
||||
'$http',
|
||||
'$state',
|
||||
'$q',
|
||||
'ApiUrl',
|
||||
'Content',
|
||||
'Groups',
|
||||
'User',
|
||||
'Analytics'
|
||||
];
|
||||
|
||||
angular.module('habitrpg')
|
||||
.factory('Quests', ['$http', '$state','$q', 'ApiUrl', 'Content', 'Groups', 'User', 'Analytics',
|
||||
function questsFactory($http, $state, $q, ApiUrl, Content, Groups, User, Analytics) {
|
||||
|
||||
var user = User.user;
|
||||
var party = Groups.party();
|
||||
var party;
|
||||
|
||||
Groups.party()
|
||||
.then(function (partyFound) {
|
||||
party = partyFound;
|
||||
});
|
||||
|
||||
function lockQuest(quest,ignoreLevel) {
|
||||
if (!ignoreLevel){
|
||||
@@ -106,20 +97,21 @@
|
||||
|
||||
function initQuest(key) {
|
||||
return $q(function(resolve, reject) {
|
||||
Analytics.track({'hitType':'event','eventCategory':'behavior','eventAction':'quest','owner':true,'response':'accept','questName': key});
|
||||
Analytics.updateUser({'partyID':party._id,'partySize':party.memberCount});
|
||||
party.$startQuest({key:key}, function(){
|
||||
party.$syncParty();
|
||||
$state.go('options.social.party');
|
||||
resolve();
|
||||
});
|
||||
Analytics.track({'hitType':'event', 'eventCategory':'behavior', 'eventAction':'quest', 'owner':true, 'response':'accept', 'questName': key});
|
||||
Analytics.updateUser({'partyID': party._id, 'partySize': party.memberCount});
|
||||
Groups.Group.inviteToQuest(party._id, key)
|
||||
.then(function(response) {
|
||||
party.quest = response.data.data;
|
||||
Groups.data.party = party;
|
||||
$state.go('options.social.party');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function sendAction(action) {
|
||||
return $q(function(resolve, reject) {
|
||||
|
||||
$http.post(ApiUrl.get() + '/api/v2/groups/' + party._id + '/' + action)
|
||||
$http.post(ApiUrl.get() + '/api/v3/groups/' + party._id + '/' + action)
|
||||
.then(function(response) {
|
||||
User.sync();
|
||||
|
||||
@@ -142,5 +134,4 @@
|
||||
showQuest: showQuest,
|
||||
initQuest: initQuest
|
||||
}
|
||||
}
|
||||
}());
|
||||
}]);
|
||||
|
||||
@@ -23,7 +23,7 @@ div(ng-if='group.quest.active===true')
|
||||
include ./ianQuestInfo
|
||||
|
||||
unless tavern
|
||||
button.btn.btn-sm.btn-warning(ng-if='::canEditQuest(party)',
|
||||
button.btn.btn-sm.btn-warning(ng-if='::canEditQuest()',
|
||||
ng-click='questAbort()')=env.t('abort')
|
||||
button.btn.btn-sm.btn-warning(ng-if='!(group.quest.leader && group.quest.leader === user._id) && isMemberOfRunningQuest(user._id,group)',
|
||||
ng-click='questLeave()')=env.t('leaveQuest')
|
||||
|
||||
@@ -26,6 +26,6 @@ div(ng-if='group.quest.active===false')
|
||||
button.btn.btn-sm.btn-success(ng-click='questAccept()')=env.t('accept')
|
||||
button.btn.btn-sm.btn-danger(ng-click='questReject()')=env.t('reject')
|
||||
|
||||
span(ng-if='::canEditQuest(party)')
|
||||
button.btn.btn-sm.btn-warning(ng-click='party.$startQuest({"force":true})')=env.t('begin')
|
||||
span(ng-if='::canEditQuest()')
|
||||
button.btn.btn-sm.btn-warning(ng-click='questForceStart()')=env.t('begin')
|
||||
button.btn.btn-sm.btn-danger(ng-click='questCancel()')=env.t('cancel')
|
||||
|
||||
Reference in New Issue
Block a user