Merge branch 'develop' into hairlessbear-quest_invite_modal_on_user_sync
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
'use strict';
|
||||
|
||||
describe('groupServices', function() {
|
||||
var $httpBackend, $http, groups, user;
|
||||
|
||||
beforeEach(function() {
|
||||
module(function($provide) {
|
||||
$provide.value('User', {});
|
||||
});
|
||||
|
||||
inject(function(_$httpBackend_, Groups, User) {
|
||||
$httpBackend = _$httpBackend_;
|
||||
groups = Groups;
|
||||
user = User;
|
||||
user.sync = function(){};
|
||||
});
|
||||
});
|
||||
|
||||
it('calls party endpoint', function() {
|
||||
$httpBackend.expectGET('/api/v2/groups/party').respond({});
|
||||
groups.party();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls tavern endpoint', function() {
|
||||
$httpBackend.expectGET('/api/v2/groups/habitrpg').respond({});
|
||||
groups.tavern();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls public guilds endpoint', function() {
|
||||
$httpBackend.expectGET('/api/v2/groups?type=public').respond([]);
|
||||
groups.publicGuilds();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls my guilds endpoint', function() {
|
||||
$httpBackend.expectGET('/api/v2/groups?type=guilds').respond([]);
|
||||
groups.myGuilds();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
context('quest function wrappers', function() {
|
||||
var successPromise = function() {
|
||||
return {
|
||||
then: function(success, failure) {
|
||||
success();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var successParty = {
|
||||
$questAccept: successPromise,
|
||||
$questReject: successPromise,
|
||||
$questCancel: successPromise,
|
||||
$questAbort: successPromise
|
||||
}
|
||||
|
||||
var failPromise = function() {
|
||||
return {
|
||||
then: function(success, failure) {
|
||||
failure('fail');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var failParty = {
|
||||
$questAccept: failPromise,
|
||||
$questReject: failPromise,
|
||||
$questCancel: failPromise,
|
||||
$questAbort: failPromise
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
sinon.spy(user, 'sync');
|
||||
sinon.stub(console, 'log', function(arg) { return true; });
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
user.sync.restore();
|
||||
console.log.restore();
|
||||
});
|
||||
|
||||
describe('questAccept', function() {
|
||||
it('syncs user if $questAccept succeeds', function() {
|
||||
groups.questAccept(successParty);
|
||||
user.sync.should.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('does not sync user if $questAccept fails', function() {
|
||||
groups.questAccept(failParty);
|
||||
user.sync.should.not.have.been.calledOnce;
|
||||
console.log.should.have.been.calledWith('fail');
|
||||
});
|
||||
});
|
||||
|
||||
describe('questReject', function() {
|
||||
it('syncs user if $questReject succeeds', function() {
|
||||
groups.questReject(successParty);
|
||||
user.sync.should.have.been.calledOnce;
|
||||
console.log.should.not.have.been.called;
|
||||
});
|
||||
|
||||
it('does not sync user if $questReject fails', function() {
|
||||
groups.questReject(failParty);
|
||||
user.sync.should.not.have.been.calledOnce;
|
||||
console.log.should.have.been.calledWith('fail');
|
||||
});
|
||||
});
|
||||
|
||||
describe('questCancel', function() {
|
||||
it('syncs user if $questCancel succeeds', function() {
|
||||
groups.questCancel(successParty);
|
||||
user.sync.should.have.been.calledOnce;
|
||||
console.log.should.not.have.been.called;
|
||||
});
|
||||
|
||||
it('does not sync user if $questCancel fails', function() {
|
||||
groups.questCancel(failParty);
|
||||
user.sync.should.not.have.been.calledOnce;
|
||||
console.log.should.have.been.calledWith('fail');
|
||||
});
|
||||
});
|
||||
|
||||
describe('questAbort', function() {
|
||||
it('syncs user if $questAbort succeeds', function() {
|
||||
groups.questAbort(successParty);
|
||||
user.sync.should.have.been.calledOnce;
|
||||
console.log.should.not.have.been.called;
|
||||
});
|
||||
|
||||
it('does not sync user if $questAbort fails', function() {
|
||||
groups.questAbort(failParty);
|
||||
user.sync.should.not.have.been.calledOnce;
|
||||
console.log.should.have.been.calledWith('fail');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
describe('memberServices', function() {
|
||||
var $httpBackend, members;
|
||||
|
||||
beforeEach(inject(function (_$httpBackend_, Members) {
|
||||
$httpBackend = _$httpBackend_;
|
||||
members = Members;
|
||||
}));
|
||||
|
||||
it('has no members at the beginning', function() {
|
||||
expect(members.members).to.be.an('object');
|
||||
expect(members.members).to.eql({});
|
||||
expect(members.selectedMember).to.be.undefined;
|
||||
});
|
||||
|
||||
it('populates members', function(){
|
||||
var uid = 'abc';
|
||||
members.populate({
|
||||
members: [{ _id: uid }]
|
||||
});
|
||||
expect(members.members).to.eql({
|
||||
abc: { _id: uid }
|
||||
});
|
||||
});
|
||||
|
||||
it('selects a member', function(){
|
||||
var uid = 'abc';
|
||||
$httpBackend.expectGET('/api/v2/members/' + uid).respond({ _id: uid });
|
||||
members.selectMember(uid, function(){});
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(members.selectedMember._id).to.eql(uid);
|
||||
expect(members.members).to.have.property(uid);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,208 @@
|
||||
'use strict';
|
||||
|
||||
describe('notificationServices', function() {
|
||||
var notification;
|
||||
|
||||
before(function(){
|
||||
sinon.stub($, 'pnotify', function(){
|
||||
return { click: function(){}}
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(function() {
|
||||
module(function($provide){
|
||||
$provide.value('User', {});
|
||||
});
|
||||
|
||||
inject(function(Notification) {
|
||||
notification = Notification;
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
$.pnotify.reset();
|
||||
});
|
||||
|
||||
it('notifies coins amount', function() {
|
||||
var SILVER_COIN = "<span class='notification-icon shop_silver'></span>";
|
||||
var GOLD_COIN = "<span class='notification-icon shop_gold'></span>";
|
||||
|
||||
expect(notification.coins(0)).to.not.exist;
|
||||
expect(notification.coins(0.01)).to.eql("1 " + SILVER_COIN);
|
||||
expect(notification.coins(0.1)).to.eql("10 " + SILVER_COIN);
|
||||
expect(notification.coins(1)).to.eql("1 " + GOLD_COIN);
|
||||
expect(notification.coins(12.34)).to.eql("12 " + GOLD_COIN +" 33 " + SILVER_COIN);
|
||||
});
|
||||
|
||||
it('sends crit notification', function() {
|
||||
notification.crit(5);
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('crit');
|
||||
expect(arg.text).to.eql('Critical Hit! Bonus: 5%');
|
||||
expect(arg.icon).to.eql('glyphicon glyphicon-certificate');
|
||||
});
|
||||
|
||||
it('sends drop notification for unspecified item', function() {
|
||||
notification.drop('msg');
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('drop');
|
||||
expect(arg.text).to.eql('msg');
|
||||
expect(arg.icon).to.eql(false);
|
||||
});
|
||||
|
||||
it('sends drop notification for Egg', function() {
|
||||
var item = { type: 'Egg', key: 'wolf' };
|
||||
notification.drop('msg', item);
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('drop');
|
||||
expect(arg.text).to.eql('msg');
|
||||
expect(arg.icon).to.eql('Pet_Egg_wolf');
|
||||
});
|
||||
|
||||
it('sends drop notification for Hatching Potion', function() {
|
||||
var item = { type: 'HatchingPotion', key: 'red' };
|
||||
notification.drop('msg', item);
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('drop');
|
||||
expect(arg.text).to.eql('msg');
|
||||
expect(arg.icon).to.eql('Pet_HatchingPotion_red');
|
||||
});
|
||||
|
||||
it('sends drop notification for Food', function() {
|
||||
var item = { type: 'Food', key: 'meat' };
|
||||
notification.drop('msg', item);
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('drop');
|
||||
expect(arg.text).to.eql('msg');
|
||||
expect(arg.icon).to.eql('Pet_Food_meat');
|
||||
});
|
||||
|
||||
it('does not send exp notification if val < -50', function() {
|
||||
notification.exp(-51);
|
||||
expect($.pnotify).to.not.have.been.called;
|
||||
});
|
||||
|
||||
it('sends exp notification if val >= -50', function() {
|
||||
notification.exp(50);
|
||||
notification.exp(0);
|
||||
notification.exp(-50);
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledThrice;
|
||||
expect(arg.type).to.eql('xp');
|
||||
expect(arg.text).to.eql('+ 50 XP');
|
||||
expect(arg.icon).to.eql('glyphicon glyphicon-star');
|
||||
});
|
||||
|
||||
it('sends exp notification with rounded value', function() {
|
||||
notification.exp(50.23333);
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('xp');
|
||||
expect(arg.text).to.eql('+ 50.2 XP');
|
||||
expect(arg.icon).to.eql('glyphicon glyphicon-star');
|
||||
});
|
||||
|
||||
it('sends error notification', function() {
|
||||
notification.error('there was an error');
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('danger');
|
||||
expect(arg.text).to.eql('there was an error');
|
||||
expect(arg.icon).to.eql('glyphicon glyphicon-exclamation-sign');
|
||||
});
|
||||
|
||||
it('sends gp gained notification', function() {
|
||||
notification.gp(50, 4);
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('gp');
|
||||
expect(arg.text).to.eql('+ 46 <span class=\'notification-icon shop_gold\'></span>');
|
||||
expect(arg.icon).to.eql(false);
|
||||
});
|
||||
|
||||
it('sends hp notification', function() {
|
||||
notification.hp(10);
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('hp');
|
||||
expect(arg.text).to.eql('+ 10 HP');
|
||||
expect(arg.icon).to.eql('glyphicon glyphicon-heart');
|
||||
});
|
||||
|
||||
it('sends level up notification', function() {
|
||||
notification.lvl(10);
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('lvl');
|
||||
expect(arg.text).to.eql('Level Up!');
|
||||
expect(arg.icon).to.eql('glyphicon glyphicon-chevron-up');
|
||||
});
|
||||
|
||||
it('sends markdown parsed notification', function() {
|
||||
notification.markdown(":smile: - task name");
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('info');
|
||||
expect(arg.text).to.eql('<p><span class="emoji" style="background-image:url(common/img/emoji/unicode/1f604.png)">:smile:</span> - task name</p>\n');
|
||||
expect(arg.icon).to.eql(false);
|
||||
});
|
||||
|
||||
it('does not send markdown notification if no text is given', function() {
|
||||
notification.markdown();
|
||||
|
||||
expect($.pnotify).to.not.have.been.called;
|
||||
});
|
||||
|
||||
it('sends mp notification', function() {
|
||||
notification.mp(10);
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('mp');
|
||||
expect(arg.text).to.eql('+ 10 MP');
|
||||
expect(arg.icon).to.eql('glyphicon glyphicon-fire');
|
||||
});
|
||||
|
||||
it('sends streak notification', function() {
|
||||
notification.streak(10);
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('streak');
|
||||
expect(arg.text).to.eql('Streak Achievements: 10');
|
||||
expect(arg.icon).to.eql('glyphicon glyphicon-repeat');
|
||||
});
|
||||
|
||||
it('sends text notification', function() {
|
||||
notification.text('task name');
|
||||
var arg = $.pnotify.args[0][0];
|
||||
|
||||
expect($.pnotify).to.have.been.calledOnce;
|
||||
expect(arg.type).to.eql('info');
|
||||
expect(arg.text).to.eql('task name');
|
||||
expect(arg.icon).to.eql(false);
|
||||
});
|
||||
|
||||
it('does not send text notification if no text is given', function() {
|
||||
notification.text();
|
||||
|
||||
expect($.pnotify).to.not.have.been.called;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
|
||||
describe('userServices', function() {
|
||||
var $httpBackend, $window, user, STORAGE_USER_ID, STORAGE_SETTINGS_ID;
|
||||
|
||||
beforeEach(module('habitrpg'));
|
||||
|
||||
beforeEach(function(){
|
||||
module(function($provide){
|
||||
$window = {href: '', alert: sinon.spy(), location: {search: '', pathname: ''}};
|
||||
$provide.value('$window', $window);
|
||||
});
|
||||
|
||||
inject(function(_$httpBackend_, User, _STORAGE_USER_ID_, _STORAGE_SETTINGS_ID_) {
|
||||
$httpBackend = _$httpBackend_;
|
||||
user = User;
|
||||
STORAGE_USER_ID = _STORAGE_USER_ID_;
|
||||
STORAGE_SETTINGS_ID = _STORAGE_SETTINGS_ID_;
|
||||
});
|
||||
localStorage.removeItem(STORAGE_SETTINGS_ID);
|
||||
localStorage.removeItem(STORAGE_USER_ID);
|
||||
});
|
||||
|
||||
it('checks online status', function(){
|
||||
user.online(true);
|
||||
expect(user.settings.online).to.be.true;
|
||||
user.online(false);
|
||||
expect(user.settings.online).to.be.false;
|
||||
})
|
||||
|
||||
it('saves user data to local storage', function(){
|
||||
user.save();
|
||||
var settings = JSON.parse(localStorage[STORAGE_SETTINGS_ID]);
|
||||
var user_id = JSON.parse(localStorage[STORAGE_USER_ID]);
|
||||
expect(settings).to.eql(user.settings);
|
||||
expect(user_id).to.eql(user.user);
|
||||
});
|
||||
|
||||
it('alerts when not authenticated', function(){
|
||||
user.log();
|
||||
expect($window.alert).to.have.been.calledWith("Not authenticated, can't sync, go to settings first.");
|
||||
});
|
||||
|
||||
it('puts items in que queue', function(){
|
||||
user.log({});
|
||||
//TODO where does that null comes from?
|
||||
expect(user.settings.sync.queue).to.eql([null, {}]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user