Remove extraneous anonymous function.

This commit is contained in:
Blade Barringer
2015-11-15 08:24:42 -06:00
parent 5be9b88cc6
commit 037337d54f
13 changed files with 2852 additions and 2899 deletions

View File

@@ -1,60 +1,32 @@
(function() {
'use strict';
var Challenge, Group, app;
var Challenge, Group, app;
app = require("../../website/src/server");
app = require("../../website/src/server");
Group = require("../../website/src/models/group").model;
Group = require("../../website/src/models/group").model;
Challenge = require("../../website/src/models/challenge").model;
Challenge = require("../../website/src/models/challenge").model;
describe("Challenges", function() {
var challenge, group, updateTodo;
challenge = void 0;
updateTodo = void 0;
group = void 0;
beforeEach(function(done) {
return async.waterfall([
function(cb) {
return registerNewUser(cb, true);
}, function(user, cb) {
return request.post(baseURL + "/groups").send({
name: "TestGroup",
type: "party"
}).end(function(err, res) {
expectCode(res, 200);
group = res.body;
expect(group.members.length).to.equal(1);
expect(group.leader).to.equal(user._id);
return cb();
});
}, function(cb) {
return request.post(baseURL + "/challenges").send({
group: group._id,
dailys: [
{
type: "daily",
text: "Challenge Daily"
}
],
todos: [
{
type: "todo",
text: "Challenge Todo 1",
notes: "Challenge Notes"
}
],
rewards: [],
habits: []
}).end(function(err, res) {
challenge = res.body;
return done();
});
}
]);
});
describe('POST /challenge', function() {
return it("Creates a challenge", function(done) {
describe("Challenges", function() {
var challenge, group, updateTodo;
challenge = void 0;
updateTodo = void 0;
group = void 0;
beforeEach(function(done) {
return async.waterfall([
function(cb) {
return registerNewUser(cb, true);
}, function(user, cb) {
return request.post(baseURL + "/groups").send({
name: "TestGroup",
type: "party"
}).end(function(err, res) {
expectCode(res, 200);
group = res.body;
expect(group.members.length).to.equal(1);
expect(group.leader).to.equal(user._id);
return cb();
});
}, function(cb) {
return request.post(baseURL + "/challenges").send({
group: group._id,
dailys: [
@@ -68,343 +40,240 @@
type: "todo",
text: "Challenge Todo 1",
notes: "Challenge Notes"
}, {
type: "todo",
text: "Challenge Todo 2",
notes: "Challenge Notes"
}
],
rewards: [],
habits: [],
official: true
habits: []
}).end(function(err, res) {
expectCode(res, 200);
return async.parallel([
function(cb) {
return User.findById(user._id, cb);
}, function(cb) {
return Challenge.findById(res.body._id, cb);
}
], function(err, results) {
var user;
user = results[0];
challenge = results[1];
expect(user.dailys[user.dailys.length - 1].text).to.equal("Challenge Daily");
expect(challenge.official).to.equal(false);
return done();
});
});
});
});
describe('POST /challenge/:cid', function() {
it("updates the notes on user's version of a challenge task's note without updating the challenge", function(done) {
updateTodo = challenge.todos[0];
updateTodo.notes = "User overriden notes";
return async.waterfall([
function(cb) {
return request.put(baseURL + "/user/tasks/" + updateTodo.id).send(updateTodo).end(function(err, res) {
return cb();
});
}, function(cb) {
return Challenge.findById(challenge._id, cb);
}, function(chal, cb) {
expect(chal.todos[0].notes).to.eql("Challenge Notes");
return cb();
}, function(cb) {
return request.get(baseURL + "/user/tasks/" + updateTodo.id).end(function(err, res) {
expect(res.body.notes).to.eql("User overriden notes");
return done();
});
}
]);
});
it("changes user's copy of challenge tasks when the challenge is updated", function(done) {
challenge.dailys[0].text = "Updated Daily";
return request.post(baseURL + "/challenges/" + challenge._id).send(challenge).end(function(err, res) {
challenge = res.body;
expect(challenge.dailys[0].text).to.equal("Updated Daily");
return User.findById(user._id, function(err, _user) {
expectCode(res, 200);
expect(_user.dailys[_user.dailys.length - 1].text).to.equal("Updated Daily");
return done();
});
return done();
});
});
it("does not changes user's notes on tasks when challenge task notes are updated", function(done) {
challenge.todos[0].notes = "Challenge Updated Todo Notes";
return request.post(baseURL + "/challenges/" + challenge._id).send(challenge).end(function(err, res) {
challenge = res.body;
expect(challenge.todos[0].notes).to.equal("Challenge Updated Todo Notes");
return User.findById(user._id, function(err, _user) {
expectCode(res, 200);
expect(_user.todos[_user.todos.length - 1].notes).to.equal("Challenge Notes");
return done();
});
});
});
return it("shows user notes on challenge page", function(done) {
updateTodo = challenge.todos[0];
updateTodo.notes = "User overriden notes";
return async.waterfall([
function(cb) {
return request.put(baseURL + "/user/tasks/" + updateTodo.id).send(updateTodo).end(function(err, res) {
return cb();
});
}, function(cb) {
return Challenge.findById(challenge._id, cb);
}, function(chal, cb) {
expect(chal.todos[0].notes).to.eql("Challenge Notes");
return cb();
}, function(cb) {
return request.get(baseURL + "/challenges/" + challenge._id + "/member/" + user._id).end(function(err, res) {
expect(res.body.todos[res.body.todos.length - 1].notes).to.equal("User overriden notes");
return done();
});
}
]);
});
describe('POST /challenge', function() {
return it("Creates a challenge", function(done) {
return request.post(baseURL + "/challenges").send({
group: group._id,
dailys: [
{
type: "daily",
text: "Challenge Daily"
}
]);
});
});
it("Complete To-Dos", function(done) {
return User.findById(user._id, function(err, _user) {
var numTasks, u;
u = _user;
numTasks = _.size(u.todos);
return request.post(baseURL + "/user/tasks/" + u.todos[0].id + "/up").end(function(err, res) {
return request.post(baseURL + "/user/tasks/clear-completed").end(function(err, res) {
expect(_.size(res.body)).to.equal(numTasks - 1);
return done();
});
});
});
});
it("Challenge deleted, breaks task link", function(done) {
var itThis;
itThis = this;
return request.del(baseURL + "/challenges/" + challenge._id).end(function(err, res) {
return User.findById(user._id, function(err, user) {
var daily, len, unset;
len = user.dailys.length - 1;
daily = user.dailys[user.dailys.length - 1];
expect(daily.challenge.broken).to.equal("CHALLENGE_DELETED");
unset = {
$unset: {}
};
unset["$unset"]["dailys." + len + ".challenge.broken"] = 1;
return User.findByIdAndUpdate(user._id, unset, {
"new": true
}, function(err, user) {
expect(err).to.not.exist;
expect(user.dailys[len].challenge.broken).to.not.exist;
return request.post(baseURL + "/user/tasks/" + daily.id + "/up").end(function(err, res) {
return setTimeout((function() {
return User.findById(user._id, function(err, user) {
expect(user.dailys[len].challenge.broken).to.equal("CHALLENGE_DELETED");
return done();
});
}), 100);
});
});
});
});
});
it("admin creates a challenge", function(done) {
return User.findByIdAndUpdate(user._id, {
$set: {
"contributor.admin": true
}
}, {
"new": true
}, function(err, _user) {
expect(err).to.not.exist;
],
todos: [
{
type: "todo",
text: "Challenge Todo 1",
notes: "Challenge Notes"
}, {
type: "todo",
text: "Challenge Todo 2",
notes: "Challenge Notes"
}
],
rewards: [],
habits: [],
official: true
}).end(function(err, res) {
expectCode(res, 200);
return async.parallel([
function(cb) {
return request.post(baseURL + "/challenges").send({
group: group._id,
dailys: [],
todos: [],
rewards: [],
habits: [],
official: false
}).end(function(err, res) {
expect(res.body.official).to.equal(false);
return cb();
});
return User.findById(user._id, cb);
}, function(cb) {
return request.post(baseURL + "/challenges").send({
group: group._id,
dailys: [],
todos: [],
rewards: [],
habits: [],
official: true
}).end(function(err, res) {
expect(res.body.official).to.equal(true);
return cb();
});
return Challenge.findById(res.body._id, cb);
}
], done);
], function(err, results) {
var user;
user = results[0];
challenge = results[1];
expect(user.dailys[user.dailys.length - 1].text).to.equal("Challenge Daily");
expect(challenge.official).to.equal(false);
return done();
});
});
});
it("User creates a non-tavern challenge with prize, deletes it, gets refund", function(done) {
return User.findByIdAndUpdate(user._id, {
$set: {
"balance": 8
});
describe('POST /challenge/:cid', function() {
it("updates the notes on user's version of a challenge task's note without updating the challenge", function(done) {
updateTodo = challenge.todos[0];
updateTodo.notes = "User overriden notes";
return async.waterfall([
function(cb) {
return request.put(baseURL + "/user/tasks/" + updateTodo.id).send(updateTodo).end(function(err, res) {
return cb();
});
}, function(cb) {
return Challenge.findById(challenge._id, cb);
}, function(chal, cb) {
expect(chal.todos[0].notes).to.eql("Challenge Notes");
return cb();
}, function(cb) {
return request.get(baseURL + "/user/tasks/" + updateTodo.id).end(function(err, res) {
expect(res.body.notes).to.eql("User overriden notes");
return done();
});
}
}, {
"new": true
}, function(err, user) {
expect(err).to.not.be.ok;
return request.post(baseURL + "/challenges").send({
group: group._id,
dailys: [],
todos: [],
rewards: [],
habits: [],
prize: 10
}).end(function(err, res) {
expect(res.body.prize).to.equal(10);
return async.parallel([
function(cb) {
return User.findById(user._id, cb);
}, function(cb) {
return Challenge.findById(res.body._id, cb);
}
], function(err, results) {
user = results[0];
challenge = results[1];
expect(user.balance).to.equal(5.5);
return request.del(baseURL + "/challenges/" + challenge._id).end(function(err, res) {
return User.findById(user._id, function(err, _user) {
expect(_user.balance).to.equal(8);
]);
});
it("changes user's copy of challenge tasks when the challenge is updated", function(done) {
challenge.dailys[0].text = "Updated Daily";
return request.post(baseURL + "/challenges/" + challenge._id).send(challenge).end(function(err, res) {
challenge = res.body;
expect(challenge.dailys[0].text).to.equal("Updated Daily");
return User.findById(user._id, function(err, _user) {
expectCode(res, 200);
expect(_user.dailys[_user.dailys.length - 1].text).to.equal("Updated Daily");
return done();
});
});
});
it("does not changes user's notes on tasks when challenge task notes are updated", function(done) {
challenge.todos[0].notes = "Challenge Updated Todo Notes";
return request.post(baseURL + "/challenges/" + challenge._id).send(challenge).end(function(err, res) {
challenge = res.body;
expect(challenge.todos[0].notes).to.equal("Challenge Updated Todo Notes");
return User.findById(user._id, function(err, _user) {
expectCode(res, 200);
expect(_user.todos[_user.todos.length - 1].notes).to.equal("Challenge Notes");
return done();
});
});
});
return it("shows user notes on challenge page", function(done) {
updateTodo = challenge.todos[0];
updateTodo.notes = "User overriden notes";
return async.waterfall([
function(cb) {
return request.put(baseURL + "/user/tasks/" + updateTodo.id).send(updateTodo).end(function(err, res) {
return cb();
});
}, function(cb) {
return Challenge.findById(challenge._id, cb);
}, function(chal, cb) {
expect(chal.todos[0].notes).to.eql("Challenge Notes");
return cb();
}, function(cb) {
return request.get(baseURL + "/challenges/" + challenge._id + "/member/" + user._id).end(function(err, res) {
expect(res.body.todos[res.body.todos.length - 1].notes).to.equal("User overriden notes");
return done();
});
}
]);
});
});
it("Complete To-Dos", function(done) {
return User.findById(user._id, function(err, _user) {
var numTasks, u;
u = _user;
numTasks = _.size(u.todos);
return request.post(baseURL + "/user/tasks/" + u.todos[0].id + "/up").end(function(err, res) {
return request.post(baseURL + "/user/tasks/clear-completed").end(function(err, res) {
expect(_.size(res.body)).to.equal(numTasks - 1);
return done();
});
});
});
});
it("Challenge deleted, breaks task link", function(done) {
var itThis;
itThis = this;
return request.del(baseURL + "/challenges/" + challenge._id).end(function(err, res) {
return User.findById(user._id, function(err, user) {
var daily, len, unset;
len = user.dailys.length - 1;
daily = user.dailys[user.dailys.length - 1];
expect(daily.challenge.broken).to.equal("CHALLENGE_DELETED");
unset = {
$unset: {}
};
unset["$unset"]["dailys." + len + ".challenge.broken"] = 1;
return User.findByIdAndUpdate(user._id, unset, {
"new": true
}, function(err, user) {
expect(err).to.not.exist;
expect(user.dailys[len].challenge.broken).to.not.exist;
return request.post(baseURL + "/user/tasks/" + daily.id + "/up").end(function(err, res) {
return setTimeout((function() {
return User.findById(user._id, function(err, user) {
expect(user.dailys[len].challenge.broken).to.equal("CHALLENGE_DELETED");
return done();
});
});
}), 100);
});
});
});
});
it("User creates a tavern challenge with prize, deletes it, and does not get refund", function(done) {
return User.findByIdAndUpdate(user._id, {
$set: {
"balance": 8
}
}, {
"new": true
}, function(err, user) {
expect(err).to.not.be.ok;
return request.post(baseURL + "/challenges").send({
group: 'habitrpg',
dailys: [],
todos: [],
rewards: [],
habits: [],
prize: 10
}).end(function(err, res) {
expect(res.body.prize).to.equal(10);
return async.parallel([
function(cb) {
return User.findById(user._id, cb);
}, function(cb) {
return Challenge.findById(res.body._id, cb);
}
], function(err, results) {
user = results[0];
challenge = results[1];
expect(user.balance).to.equal(5.5);
return request.del(baseURL + "/challenges/" + challenge._id).end(function(err, res) {
return User.findById(user._id, function(err, _user) {
expect(_user.balance).to.equal(5.5);
return done();
});
});
});
it("admin creates a challenge", function(done) {
return User.findByIdAndUpdate(user._id, {
$set: {
"contributor.admin": true
}
}, {
"new": true
}, function(err, _user) {
expect(err).to.not.exist;
return async.parallel([
function(cb) {
return request.post(baseURL + "/challenges").send({
group: group._id,
dailys: [],
todos: [],
rewards: [],
habits: [],
official: false
}).end(function(err, res) {
expect(res.body.official).to.equal(false);
return cb();
});
});
});
}, function(cb) {
return request.post(baseURL + "/challenges").send({
group: group._id,
dailys: [],
todos: [],
rewards: [],
habits: [],
official: true
}).end(function(err, res) {
expect(res.body.official).to.equal(true);
return cb();
});
}
], done);
});
return describe("non-owner permissions", function() {
challenge = void 0;
beforeEach(function(done) {
return async.waterfall([
});
it("User creates a non-tavern challenge with prize, deletes it, gets refund", function(done) {
return User.findByIdAndUpdate(user._id, {
$set: {
"balance": 8
}
}, {
"new": true
}, function(err, user) {
expect(err).to.not.be.ok;
return request.post(baseURL + "/challenges").send({
group: group._id,
dailys: [],
todos: [],
rewards: [],
habits: [],
prize: 10
}).end(function(err, res) {
expect(res.body.prize).to.equal(10);
return async.parallel([
function(cb) {
return request.post(baseURL + "/challenges").send({
group: group._id,
name: 'challenge name',
dailys: [
{
type: "daily",
text: "Challenge Daily"
}
]
}).end(function(err, res) {
challenge = res.body;
return cb();
});
return User.findById(user._id, cb);
}, function(cb) {
return registerNewUser(done, true);
return Challenge.findById(res.body._id, cb);
}
]);
});
context("non-owner", function() {
it('can not edit challenge', function(done) {
challenge.name = 'foobar';
return request.post(baseURL + "/challenges/" + challenge._id).send(challenge).end(function(err, res) {
var error;
error = res.body.err;
expect(error).to.eql("You don't have permissions to edit this challenge");
return done();
});
});
it('can not close challenge', function(done) {
return request.post(baseURL + "/challenges/" + challenge._id + "/close?uid=" + user._id).end(function(err, res) {
var error;
error = res.body.err;
expect(error).to.eql("You don't have permissions to close this challenge");
return done();
});
});
return it('can not delete challenge', function(done) {
], function(err, results) {
user = results[0];
challenge = results[1];
expect(user.balance).to.equal(5.5);
return request.del(baseURL + "/challenges/" + challenge._id).end(function(err, res) {
var error;
error = res.body.err;
expect(error).to.eql("You don't have permissions to delete this challenge");
return done();
});
});
});
return context("non-owner that is an admin", function() {
beforeEach(function(done) {
return User.findByIdAndUpdate(user._id, {
'contributor.admin': true
}, {
"new": true
}, done);
});
it('can edit challenge', function(done) {
challenge.name = 'foobar';
return request.post(baseURL + "/challenges/" + challenge._id).send(challenge).end(function(err, res) {
expect(res.body.err).to.not.exist;
return Challenge.findById(challenge._id, function(err, chal) {
expect(chal.name).to.eql('foobar');
return done();
});
});
});
it('can close challenge', function(done) {
return request.post(baseURL + "/challenges/" + challenge._id + "/close?uid=" + user._id).end(function(err, res) {
expect(res.body.err).to.not.exist;
return User.findById(user._id, function(err, usr) {
expect(usr.achievements.challenges[0]).to.eql(challenge.name);
return done();
});
});
});
return it('can delete challenge', function(done) {
return request.del(baseURL + "/challenges/" + challenge._id).end(function(err, res) {
expect(res.body.err).to.not.exist;
return request.get(baseURL + "/challenges/" + challenge._id).end(function(err, res) {
var error;
error = res.body.err;
expect(error).to.eql("Challenge " + challenge._id + " not found");
return User.findById(user._id, function(err, _user) {
expect(_user.balance).to.equal(8);
return done();
});
});
@@ -412,5 +281,132 @@
});
});
});
}).call(this);
it("User creates a tavern challenge with prize, deletes it, and does not get refund", function(done) {
return User.findByIdAndUpdate(user._id, {
$set: {
"balance": 8
}
}, {
"new": true
}, function(err, user) {
expect(err).to.not.be.ok;
return request.post(baseURL + "/challenges").send({
group: 'habitrpg',
dailys: [],
todos: [],
rewards: [],
habits: [],
prize: 10
}).end(function(err, res) {
expect(res.body.prize).to.equal(10);
return async.parallel([
function(cb) {
return User.findById(user._id, cb);
}, function(cb) {
return Challenge.findById(res.body._id, cb);
}
], function(err, results) {
user = results[0];
challenge = results[1];
expect(user.balance).to.equal(5.5);
return request.del(baseURL + "/challenges/" + challenge._id).end(function(err, res) {
return User.findById(user._id, function(err, _user) {
expect(_user.balance).to.equal(5.5);
return done();
});
});
});
});
});
});
return describe("non-owner permissions", function() {
challenge = void 0;
beforeEach(function(done) {
return async.waterfall([
function(cb) {
return request.post(baseURL + "/challenges").send({
group: group._id,
name: 'challenge name',
dailys: [
{
type: "daily",
text: "Challenge Daily"
}
]
}).end(function(err, res) {
challenge = res.body;
return cb();
});
}, function(cb) {
return registerNewUser(done, true);
}
]);
});
context("non-owner", function() {
it('can not edit challenge', function(done) {
challenge.name = 'foobar';
return request.post(baseURL + "/challenges/" + challenge._id).send(challenge).end(function(err, res) {
var error;
error = res.body.err;
expect(error).to.eql("You don't have permissions to edit this challenge");
return done();
});
});
it('can not close challenge', function(done) {
return request.post(baseURL + "/challenges/" + challenge._id + "/close?uid=" + user._id).end(function(err, res) {
var error;
error = res.body.err;
expect(error).to.eql("You don't have permissions to close this challenge");
return done();
});
});
return it('can not delete challenge', function(done) {
return request.del(baseURL + "/challenges/" + challenge._id).end(function(err, res) {
var error;
error = res.body.err;
expect(error).to.eql("You don't have permissions to delete this challenge");
return done();
});
});
});
return context("non-owner that is an admin", function() {
beforeEach(function(done) {
return User.findByIdAndUpdate(user._id, {
'contributor.admin': true
}, {
"new": true
}, done);
});
it('can edit challenge', function(done) {
challenge.name = 'foobar';
return request.post(baseURL + "/challenges/" + challenge._id).send(challenge).end(function(err, res) {
expect(res.body.err).to.not.exist;
return Challenge.findById(challenge._id, function(err, chal) {
expect(chal.name).to.eql('foobar');
return done();
});
});
});
it('can close challenge', function(done) {
return request.post(baseURL + "/challenges/" + challenge._id + "/close?uid=" + user._id).end(function(err, res) {
expect(res.body.err).to.not.exist;
return User.findById(user._id, function(err, usr) {
expect(usr.achievements.challenges[0]).to.eql(challenge.name);
return done();
});
});
});
return it('can delete challenge', function(done) {
return request.del(baseURL + "/challenges/" + challenge._id).end(function(err, res) {
expect(res.body.err).to.not.exist;
return request.get(baseURL + "/challenges/" + challenge._id).end(function(err, res) {
var error;
error = res.body.err;
expect(error).to.eql("Challenge " + challenge._id + " not found");
return done();
});
});
});
});
});
});

View File

@@ -1,75 +1,71 @@
(function() {
'use strict';
var Group, app, diff;
var Group, app, diff;
diff = require("deep-diff");
diff = require("deep-diff");
Group = require("../../website/src/models/group").model;
Group = require("../../website/src/models/group").model;
app = require("../../website/src/server");
app = require("../../website/src/server");
describe("Chat", function() {
var chat, group;
group = void 0;
before(function(done) {
return async.waterfall([
function(cb) {
return registerNewUser(cb, true);
}, function(user, cb) {
return request.post(baseURL + "/groups").send({
name: "TestGroup",
type: "party"
}).end(function(err, res) {
expectCode(res, 200);
group = res.body;
expect(group.members.length).to.equal(1);
expect(group.leader).to.equal(user._id);
return cb();
});
}
], done);
});
chat = void 0;
return it("removes a user's chat notifications when user is kicked", function(done) {
var userToRemove;
userToRemove = null;
return async.waterfall([
function(cb) {
return registerManyUsers(1, cb);
}, function(members, cb) {
userToRemove = members[0];
return request.post(baseURL + "/groups/" + group._id + "/invite").send({
uuids: [userToRemove._id]
}).end(function() {
return cb();
});
}, function(cb) {
return request.post(baseURL + "/groups/" + group._id + "/join").set("X-API-User", userToRemove._id).set("X-API-Key", userToRemove.apiToken).end(function(err, res) {
return cb();
});
}, function(cb) {
var msg;
msg = "TestMsg";
return request.post(baseURL + "/groups/" + group._id + "/chat?message=" + msg).end(function(err, res) {
return cb();
});
}, function(cb) {
return request.get(baseURL + "/user").set("X-API-User", userToRemove._id).set("X-API-Key", userToRemove.apiToken).end(function(err, res) {
expect(res.body.newMessages[group._id]).to.exist;
return cb();
});
}, function(cb) {
return request.post(baseURL + "/groups/" + group._id + "/removeMember?uuid=" + userToRemove._id).end(function(err, res) {
return cb();
});
}, function(cb) {
return request.get(baseURL + "/user").set("X-API-User", userToRemove._id).set("X-API-Key", userToRemove.apiToken).end(function(err, res) {
expect(res.body.newMessages[group._id]).to.not.exist;
return cb();
});
}
], done);
});
describe("Chat", function() {
var chat, group;
group = void 0;
before(function(done) {
return async.waterfall([
function(cb) {
return registerNewUser(cb, true);
}, function(user, cb) {
return request.post(baseURL + "/groups").send({
name: "TestGroup",
type: "party"
}).end(function(err, res) {
expectCode(res, 200);
group = res.body;
expect(group.members.length).to.equal(1);
expect(group.leader).to.equal(user._id);
return cb();
});
}
], done);
});
}).call(this);
chat = void 0;
return it("removes a user's chat notifications when user is kicked", function(done) {
var userToRemove;
userToRemove = null;
return async.waterfall([
function(cb) {
return registerManyUsers(1, cb);
}, function(members, cb) {
userToRemove = members[0];
return request.post(baseURL + "/groups/" + group._id + "/invite").send({
uuids: [userToRemove._id]
}).end(function() {
return cb();
});
}, function(cb) {
return request.post(baseURL + "/groups/" + group._id + "/join").set("X-API-User", userToRemove._id).set("X-API-Key", userToRemove.apiToken).end(function(err, res) {
return cb();
});
}, function(cb) {
var msg;
msg = "TestMsg";
return request.post(baseURL + "/groups/" + group._id + "/chat?message=" + msg).end(function(err, res) {
return cb();
});
}, function(cb) {
return request.get(baseURL + "/user").set("X-API-User", userToRemove._id).set("X-API-Key", userToRemove.apiToken).end(function(err, res) {
expect(res.body.newMessages[group._id]).to.exist;
return cb();
});
}, function(cb) {
return request.post(baseURL + "/groups/" + group._id + "/removeMember?uuid=" + userToRemove._id).end(function(err, res) {
return cb();
});
}, function(cb) {
return request.get(baseURL + "/user").set("X-API-User", userToRemove._id).set("X-API-Key", userToRemove.apiToken).end(function(err, res) {
expect(res.body.newMessages[group._id]).to.not.exist;
return cb();
});
}
], done);
});
});

View File

@@ -1,222 +1,218 @@
(function() {
'use strict';
var Coupon, app, makeSudoUser;
var Coupon, app, makeSudoUser;
app = require("../../website/src/server");
app = require("../../website/src/server");
Coupon = require("../../website/src/models/coupon").model;
Coupon = require("../../website/src/models/coupon").model;
makeSudoUser = function(usr, cb) {
return registerNewUser(function() {
var sudoUpdate;
sudoUpdate = {
"$set": {
"contributor.sudo": true
}
};
return User.findByIdAndUpdate(user._id, sudoUpdate, {
"new": true
}, function(err, _user) {
usr = _user;
return cb();
});
}, true);
};
describe("Coupons", function() {
var coupons;
before(function(done) {
return async.parallel([
function(cb) {
return mongoose.connection.collections['coupons'].drop(function(err) {
return cb();
});
}, function(cb) {
return mongoose.connection.collections['users'].drop(function(err) {
return cb();
});
}
], done);
makeSudoUser = function(usr, cb) {
return registerNewUser(function() {
var sudoUpdate;
sudoUpdate = {
"$set": {
"contributor.sudo": true
}
};
return User.findByIdAndUpdate(user._id, sudoUpdate, {
"new": true
}, function(err, _user) {
usr = _user;
return cb();
});
coupons = null;
describe("POST /api/v2/coupons/generate/:event", function() {
context("while sudo user", function() {
before(function(done) {
return makeSudoUser(user, done);
}, true);
};
describe("Coupons", function() {
var coupons;
before(function(done) {
return async.parallel([
function(cb) {
return mongoose.connection.collections['coupons'].drop(function(err) {
return cb();
});
return it("generates coupons", function(done) {
var queries;
queries = '?count=10';
return request.post(baseURL + '/coupons/generate/wondercon' + queries).end(function(err, res) {
expectCode(res, 200);
return Coupon.find({
event: 'wondercon'
}, function(err, _coupons) {
coupons = _coupons;
expect(coupons.length).to.equal(10);
_(coupons).each(function(c) {
return expect(c.event).to.equal('wondercon');
});
return done();
});
});
}, function(cb) {
return mongoose.connection.collections['users'].drop(function(err) {
return cb();
});
}
], done);
});
coupons = null;
describe("POST /api/v2/coupons/generate/:event", function() {
context("while sudo user", function() {
before(function(done) {
return makeSudoUser(user, done);
});
return context("while regular user", function() {
before(function(done) {
return registerNewUser(done, true);
});
return it("does not generate coupons", function(done) {
var queries;
queries = '?count=10';
return request.post(baseURL + '/coupons/generate/wondercon' + queries).end(function(err, res) {
expectCode(res, 401);
expect(res.body.err).to.equal('You don\'t have admin access');
return done();
});
});
});
});
describe("GET /api/v2/coupons", function() {
context("while sudo user", function() {
before(function(done) {
return makeSudoUser(user, done);
});
it("gets coupons", function(done) {
var queries;
queries = '?_id=' + user._id + '&apiToken=' + user.apiToken;
return request.get(baseURL + '/coupons' + queries).end(function(err, res) {
var codes;
expectCode(res, 200);
codes = res.text;
expect(codes).to.contain('code');
return it("generates coupons", function(done) {
var queries;
queries = '?count=10';
return request.post(baseURL + '/coupons/generate/wondercon' + queries).end(function(err, res) {
expectCode(res, 200);
return Coupon.find({
event: 'wondercon'
}, function(err, _coupons) {
coupons = _coupons;
expect(coupons.length).to.equal(10);
_(coupons).each(function(c) {
return expect(codes).to.contain(c._id);
return expect(c.event).to.equal('wondercon');
});
return done();
});
});
it("gets first 5 coupons out of 10 when a limit of 5 is set", function(done) {
var queries;
queries = '?_id=' + user._id + '&apiToken=' + user.apiToken + '&limit=5';
return request.get(baseURL + '/coupons' + queries).end(function(err, res) {
var codes, firstHalf, secondHalf, sortedCoupons;
expectCode(res, 200);
codes = res.text;
sortedCoupons = _.sortBy(coupons, 'seq');
firstHalf = sortedCoupons.slice(0, 5);
secondHalf = sortedCoupons.slice(5, 10);
_(firstHalf).each(function(c) {
return expect(codes).to.contain(c._id);
});
_(secondHalf).each(function(c) {
return expect(codes).to.not.contain(c._id);
});
return done();
});
});
return it("gets last 5 coupons out of 10 when a limit of 5 is set", function(done) {
var queries;
queries = '?_id=' + user._id + '&apiToken=' + user.apiToken + '&skip=5';
return request.get(baseURL + '/coupons' + queries).end(function(err, res) {
var codes, firstHalf, secondHalf, sortedCoupons;
expectCode(res, 200);
codes = res.text;
sortedCoupons = _.sortBy(coupons, 'seq');
firstHalf = sortedCoupons.slice(0, 5);
secondHalf = sortedCoupons.slice(5, 10);
_(firstHalf).each(function(c) {
return expect(codes).to.not.contain(c._id);
});
_(secondHalf).each(function(c) {
return expect(codes).to.contain(c._id);
});
return done();
});
});
});
return context("while regular user", function() {
before(function(done) {
return registerNewUser(done, true);
});
return it("does not get coupons", function(done) {
var queries;
queries = '?_id=' + user._id + '&apiToken=' + user.apiToken;
return request.get(baseURL + '/coupons' + queries).end(function(err, res) {
expectCode(res, 401);
expect(res.body.err).to.equal('You don\'t have admin access');
return done();
});
});
});
});
return describe("POST /api/v2/user/coupon/:code", function() {
var specialGear;
specialGear = function(gear, has) {
var items;
items = ['body_special_wondercon_gold', 'body_special_wondercon_black', 'body_special_wondercon_red', 'back_special_wondercon_red', 'back_special_wondercon_black', 'back_special_wondercon_red', 'eyewear_special_wondercon_black', 'eyewear_special_wondercon_red'];
return _(items).each(function(i) {
if (has) {
return expect(gear[i]).to.exist;
} else {
return expect(gear[i]).to.not.exist;
}
});
};
beforeEach(function(done) {
return registerNewUser(function() {
var gear;
gear = user.items.gear.owned;
specialGear(gear, false);
return done();
}, true);
return context("while regular user", function() {
before(function(done) {
return registerNewUser(done, true);
});
context("unused coupon", function() {
return it("applies coupon and awards equipment", function(done) {
var code;
code = coupons[0]._id;
return request.post(baseURL + '/user/coupon/' + code).end(function(err, res) {
return it("does not generate coupons", function(done) {
var queries;
queries = '?count=10';
return request.post(baseURL + '/coupons/generate/wondercon' + queries).end(function(err, res) {
expectCode(res, 401);
expect(res.body.err).to.equal('You don\'t have admin access');
return done();
});
});
});
});
describe("GET /api/v2/coupons", function() {
context("while sudo user", function() {
before(function(done) {
return makeSudoUser(user, done);
});
it("gets coupons", function(done) {
var queries;
queries = '?_id=' + user._id + '&apiToken=' + user.apiToken;
return request.get(baseURL + '/coupons' + queries).end(function(err, res) {
var codes;
expectCode(res, 200);
codes = res.text;
expect(codes).to.contain('code');
_(coupons).each(function(c) {
return expect(codes).to.contain(c._id);
});
return done();
});
});
it("gets first 5 coupons out of 10 when a limit of 5 is set", function(done) {
var queries;
queries = '?_id=' + user._id + '&apiToken=' + user.apiToken + '&limit=5';
return request.get(baseURL + '/coupons' + queries).end(function(err, res) {
var codes, firstHalf, secondHalf, sortedCoupons;
expectCode(res, 200);
codes = res.text;
sortedCoupons = _.sortBy(coupons, 'seq');
firstHalf = sortedCoupons.slice(0, 5);
secondHalf = sortedCoupons.slice(5, 10);
_(firstHalf).each(function(c) {
return expect(codes).to.contain(c._id);
});
_(secondHalf).each(function(c) {
return expect(codes).to.not.contain(c._id);
});
return done();
});
});
return it("gets last 5 coupons out of 10 when a limit of 5 is set", function(done) {
var queries;
queries = '?_id=' + user._id + '&apiToken=' + user.apiToken + '&skip=5';
return request.get(baseURL + '/coupons' + queries).end(function(err, res) {
var codes, firstHalf, secondHalf, sortedCoupons;
expectCode(res, 200);
codes = res.text;
sortedCoupons = _.sortBy(coupons, 'seq');
firstHalf = sortedCoupons.slice(0, 5);
secondHalf = sortedCoupons.slice(5, 10);
_(firstHalf).each(function(c) {
return expect(codes).to.not.contain(c._id);
});
_(secondHalf).each(function(c) {
return expect(codes).to.contain(c._id);
});
return done();
});
});
});
return context("while regular user", function() {
before(function(done) {
return registerNewUser(done, true);
});
return it("does not get coupons", function(done) {
var queries;
queries = '?_id=' + user._id + '&apiToken=' + user.apiToken;
return request.get(baseURL + '/coupons' + queries).end(function(err, res) {
expectCode(res, 401);
expect(res.body.err).to.equal('You don\'t have admin access');
return done();
});
});
});
});
return describe("POST /api/v2/user/coupon/:code", function() {
var specialGear;
specialGear = function(gear, has) {
var items;
items = ['body_special_wondercon_gold', 'body_special_wondercon_black', 'body_special_wondercon_red', 'back_special_wondercon_red', 'back_special_wondercon_black', 'back_special_wondercon_red', 'eyewear_special_wondercon_black', 'eyewear_special_wondercon_red'];
return _(items).each(function(i) {
if (has) {
return expect(gear[i]).to.exist;
} else {
return expect(gear[i]).to.not.exist;
}
});
};
beforeEach(function(done) {
return registerNewUser(function() {
var gear;
gear = user.items.gear.owned;
specialGear(gear, false);
return done();
}, true);
});
context("unused coupon", function() {
return it("applies coupon and awards equipment", function(done) {
var code;
code = coupons[0]._id;
return request.post(baseURL + '/user/coupon/' + code).end(function(err, res) {
var gear;
expectCode(res, 200);
gear = res.body.items.gear.owned;
specialGear(gear, true);
return done();
});
});
});
context("already used coupon", function() {
return it("does not apply coupon and does not award equipment", function(done) {
var code;
code = coupons[0]._id;
return request.post(baseURL + '/user/coupon/' + code).end(function(err, res) {
expectCode(res, 400);
expect(res.body.err).to.equal("Coupon already used");
return User.findById(user._id, function(err, _user) {
var gear;
expectCode(res, 200);
gear = res.body.items.gear.owned;
specialGear(gear, true);
gear = _user.items.gear.owned;
specialGear(gear, false);
return done();
});
});
});
context("already used coupon", function() {
return it("does not apply coupon and does not award equipment", function(done) {
var code;
code = coupons[0]._id;
return request.post(baseURL + '/user/coupon/' + code).end(function(err, res) {
expectCode(res, 400);
expect(res.body.err).to.equal("Coupon already used");
return User.findById(user._id, function(err, _user) {
var gear;
gear = _user.items.gear.owned;
specialGear(gear, false);
return done();
});
});
});
});
return context("invalid coupon", function() {
return it("does not apply coupon and does not award equipment", function(done) {
var code;
code = "not-a-real-coupon";
return request.post(baseURL + '/user/coupon/' + code).end(function(err, res) {
expectCode(res, 400);
expect(res.body.err).to.equal("Invalid coupon code");
return User.findById(user._id, function(err, _user) {
var gear;
gear = _user.items.gear.owned;
specialGear(gear, false);
return done();
});
});
return context("invalid coupon", function() {
return it("does not apply coupon and does not award equipment", function(done) {
var code;
code = "not-a-real-coupon";
return request.post(baseURL + '/user/coupon/' + code).end(function(err, res) {
expectCode(res, 400);
expect(res.body.err).to.equal("Invalid coupon code");
return User.findById(user._id, function(err, _user) {
var gear;
gear = _user.items.gear.owned;
specialGear(gear, false);
return done();
});
});
});
});
});
}).call(this);
});

View File

@@ -1,370 +1,366 @@
(function() {
'use strict';
var app, iapMock, inApp, rewire, sinon;
var app, iapMock, inApp, rewire, sinon;
app = require('../../website/src/server');
app = require('../../website/src/server');
rewire = require('rewire');
rewire = require('rewire');
sinon = require('sinon');
sinon = require('sinon');
inApp = rewire('../../website/src/controllers/payments/iap');
inApp = rewire('../../website/src/controllers/payments/iap');
iapMock = {};
iapMock = {};
inApp.__set__('iap', iapMock);
inApp.__set__('iap', iapMock);
describe('In-App Purchases', function() {
describe('Android', function() {
var next, paymentSpy, req, res;
req = {
body: {
transaction: {
reciept: 'foo',
signature: 'sig'
}
describe('In-App Purchases', function() {
describe('Android', function() {
var next, paymentSpy, req, res;
req = {
body: {
transaction: {
reciept: 'foo',
signature: 'sig'
}
};
res = {
locals: {
user: {
_id: 'user'
}
},
json: sinon.spy()
};
next = function() {
return true;
};
paymentSpy = sinon.spy();
}
};
res = {
locals: {
user: {
_id: 'user'
}
},
json: sinon.spy()
};
next = function() {
return true;
};
paymentSpy = sinon.spy();
before(function() {
return inApp.__set__('payments.buyGems', paymentSpy);
});
afterEach(function() {
paymentSpy.reset();
return res.json.reset();
});
context('successful app purchase', function() {
before(function() {
return inApp.__set__('payments.buyGems', paymentSpy);
iapMock.setup = function(cb) {
return cb(null);
};
iapMock.validate = function(iapGoogle, iapBodyReciept, cb) {
return cb(null, true);
};
iapMock.isValidated = function(googleRes) {
return googleRes;
};
return iapMock.GOOGLE = 'google';
});
afterEach(function() {
paymentSpy.reset();
return res.json.reset();
it('calls res.json with succesful result object', function() {
var expectedResObj;
expectedResObj = {
ok: true,
data: true
};
inApp.androidVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
context('successful app purchase', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
iapMock.validate = function(iapGoogle, iapBodyReciept, cb) {
return cb(null, true);
};
iapMock.isValidated = function(googleRes) {
return googleRes;
};
return iapMock.GOOGLE = 'google';
});
it('calls res.json with succesful result object', function() {
var expectedResObj;
expectedResObj = {
ok: true,
data: true
};
inApp.androidVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('calls payments.buyGems function', function() {
inApp.androidVerify(req, res, next);
expect(paymentSpy).to.be.calledOnce;
return expect(paymentSpy).to.be.calledWith({
user: res.locals.user,
paymentMethod: 'IAP GooglePlay'
});
});
});
context('error in setup', function() {
before(function() {
return iapMock.setup = function(cb) {
return cb("error in setup");
};
});
it('calls res.json with setup error object', function() {
var expectedResObj;
expectedResObj = {
ok: false,
data: 'IAP Error'
};
inApp.androidVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('does not calls payments.buyGems function', function() {
inApp.androidVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
});
context('error in validation', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
return iapMock.validate = function(iapGoogle, iapBodyReciept, cb) {
return cb('error in validation', true);
};
});
it('calls res.json with validation error object', function() {
var expectedResObj;
expectedResObj = {
ok: false,
data: {
code: 6778001,
message: 'error in validation'
}
};
inApp.androidVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('does not calls payments.buyGems function', function() {
inApp.androidVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
});
return context('iap is not valid', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
iapMock.validate = function(iapGoogle, iapBodyReciept, cb) {
return cb(null, false);
};
return iapMock.isValidated = function(googleRes) {
return googleRes;
};
});
it('does not call res.json', function() {
inApp.androidVerify(req, res, next);
return expect(res.json).to.not.be.called;
});
return it('does not calls payments.buyGems function', function() {
inApp.androidVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
return it('calls payments.buyGems function', function() {
inApp.androidVerify(req, res, next);
expect(paymentSpy).to.be.calledOnce;
return expect(paymentSpy).to.be.calledWith({
user: res.locals.user,
paymentMethod: 'IAP GooglePlay'
});
});
});
return describe('iOS', function() {
var next, paymentSpy, req, res;
req = {
body: {
transaction: {
reciept: 'foo'
}
}
};
res = {
locals: {
user: {
_id: 'user'
}
},
json: sinon.spy()
};
next = function() {
return true;
};
paymentSpy = sinon.spy();
context('error in setup', function() {
before(function() {
return inApp.__set__('payments.buyGems', paymentSpy);
return iapMock.setup = function(cb) {
return cb("error in setup");
};
});
afterEach(function() {
paymentSpy.reset();
return res.json.reset();
it('calls res.json with setup error object', function() {
var expectedResObj;
expectedResObj = {
ok: false,
data: 'IAP Error'
};
inApp.androidVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
context('successful app purchase', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
iapMock.validate = function(iapApple, iapBodyReciept, cb) {
return cb(null, true);
};
iapMock.isValidated = function(appleRes) {
return appleRes;
};
iapMock.getPurchaseData = function(appleRes) {
return [
{
productId: 'com.habitrpg.ios.Habitica.20gems'
}
];
};
return iapMock.APPLE = 'apple';
});
it('calls res.json with succesful result object', function() {
var expectedResObj;
expectedResObj = {
ok: true,
data: true
};
inApp.iosVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('calls payments.buyGems function', function() {
inApp.iosVerify(req, res, next);
expect(paymentSpy).to.be.calledOnce;
return expect(paymentSpy).to.be.calledWith({
user: res.locals.user,
paymentMethod: 'IAP AppleStore',
amount: 5.25
});
});
return it('does not calls payments.buyGems function', function() {
inApp.androidVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
context('error in setup', function() {
before(function() {
return iapMock.setup = function(cb) {
return cb("error in setup");
};
});
it('calls res.json with setup error object', function() {
var expectedResObj;
expectedResObj = {
ok: false,
data: 'IAP Error'
};
inApp.iosVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('does not calls payments.buyGems function', function() {
inApp.iosVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
});
context('error in validation', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
return iapMock.validate = function(iapGoogle, iapBodyReciept, cb) {
return cb('error in validation', true);
};
});
context('error in validation', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
return iapMock.validate = function(iapApple, iapBodyReciept, cb) {
return cb('error in validation', true);
};
});
it('calls res.json with validation error object', function() {
var expectedResObj;
expectedResObj = {
ok: false,
data: {
code: 6778001,
message: 'error in validation'
}
};
inApp.iosVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('does not calls payments.buyGems function', function() {
inApp.iosVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
it('calls res.json with validation error object', function() {
var expectedResObj;
expectedResObj = {
ok: false,
data: {
code: 6778001,
message: 'error in validation'
}
};
inApp.androidVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
context('iap is not valid', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
iapMock.validate = function(iapApple, iapBodyReciept, cb) {
return cb(null, false);
};
return iapMock.isValidated = function(appleRes) {
return appleRes;
};
});
it('does not call res.json', function() {
var expectedResObj;
inApp.iosVerify(req, res, next);
expectedResObj = {
ok: false,
data: {
code: 6778001,
message: 'Invalid receipt'
}
};
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('does not calls payments.buyGems function', function() {
inApp.iosVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
return it('does not calls payments.buyGems function', function() {
inApp.androidVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
context('iap is valid but has no purchaseDataList', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
iapMock.validate = function(iapApple, iapBodyReciept, cb) {
return cb(null, true);
};
iapMock.isValidated = function(appleRes) {
return appleRes;
};
iapMock.getPurchaseData = function(appleRes) {
return [];
};
return iapMock.APPLE = 'apple';
});
it('calls res.json with succesful result object', function() {
var expectedResObj;
expectedResObj = {
ok: false,
data: {
code: 6778001,
message: 'Incorrect receipt content'
}
};
inApp.iosVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('does not calls payments.buyGems function', function() {
inApp.iosVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
});
return context('iap is not valid', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
iapMock.validate = function(iapGoogle, iapBodyReciept, cb) {
return cb(null, false);
};
return iapMock.isValidated = function(googleRes) {
return googleRes;
};
});
return context('iap is valid, has purchaseDataList, but productId does not match', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
iapMock.validate = function(iapApple, iapBodyReciept, cb) {
return cb(null, true);
};
iapMock.isValidated = function(appleRes) {
return appleRes;
};
iapMock.getPurchaseData = function(appleRes) {
return [
{
productId: 'com.another.company'
}
];
};
return iapMock.APPLE = 'apple';
});
it('calls res.json with incorrect reciept obj', function() {
var expectedResObj;
expectedResObj = {
ok: false,
data: {
code: 6778001,
message: 'Incorrect receipt content'
}
};
inApp.iosVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('does not calls payments.buyGems function', function() {
inApp.iosVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
it('does not call res.json', function() {
inApp.androidVerify(req, res, next);
return expect(res.json).to.not.be.called;
});
return it('does not calls payments.buyGems function', function() {
inApp.androidVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
});
});
}).call(this);
return describe('iOS', function() {
var next, paymentSpy, req, res;
req = {
body: {
transaction: {
reciept: 'foo'
}
}
};
res = {
locals: {
user: {
_id: 'user'
}
},
json: sinon.spy()
};
next = function() {
return true;
};
paymentSpy = sinon.spy();
before(function() {
return inApp.__set__('payments.buyGems', paymentSpy);
});
afterEach(function() {
paymentSpy.reset();
return res.json.reset();
});
context('successful app purchase', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
iapMock.validate = function(iapApple, iapBodyReciept, cb) {
return cb(null, true);
};
iapMock.isValidated = function(appleRes) {
return appleRes;
};
iapMock.getPurchaseData = function(appleRes) {
return [
{
productId: 'com.habitrpg.ios.Habitica.20gems'
}
];
};
return iapMock.APPLE = 'apple';
});
it('calls res.json with succesful result object', function() {
var expectedResObj;
expectedResObj = {
ok: true,
data: true
};
inApp.iosVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('calls payments.buyGems function', function() {
inApp.iosVerify(req, res, next);
expect(paymentSpy).to.be.calledOnce;
return expect(paymentSpy).to.be.calledWith({
user: res.locals.user,
paymentMethod: 'IAP AppleStore',
amount: 5.25
});
});
});
context('error in setup', function() {
before(function() {
return iapMock.setup = function(cb) {
return cb("error in setup");
};
});
it('calls res.json with setup error object', function() {
var expectedResObj;
expectedResObj = {
ok: false,
data: 'IAP Error'
};
inApp.iosVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('does not calls payments.buyGems function', function() {
inApp.iosVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
});
context('error in validation', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
return iapMock.validate = function(iapApple, iapBodyReciept, cb) {
return cb('error in validation', true);
};
});
it('calls res.json with validation error object', function() {
var expectedResObj;
expectedResObj = {
ok: false,
data: {
code: 6778001,
message: 'error in validation'
}
};
inApp.iosVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('does not calls payments.buyGems function', function() {
inApp.iosVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
});
context('iap is not valid', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
iapMock.validate = function(iapApple, iapBodyReciept, cb) {
return cb(null, false);
};
return iapMock.isValidated = function(appleRes) {
return appleRes;
};
});
it('does not call res.json', function() {
var expectedResObj;
inApp.iosVerify(req, res, next);
expectedResObj = {
ok: false,
data: {
code: 6778001,
message: 'Invalid receipt'
}
};
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('does not calls payments.buyGems function', function() {
inApp.iosVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
});
context('iap is valid but has no purchaseDataList', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
iapMock.validate = function(iapApple, iapBodyReciept, cb) {
return cb(null, true);
};
iapMock.isValidated = function(appleRes) {
return appleRes;
};
iapMock.getPurchaseData = function(appleRes) {
return [];
};
return iapMock.APPLE = 'apple';
});
it('calls res.json with succesful result object', function() {
var expectedResObj;
expectedResObj = {
ok: false,
data: {
code: 6778001,
message: 'Incorrect receipt content'
}
};
inApp.iosVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('does not calls payments.buyGems function', function() {
inApp.iosVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
});
return context('iap is valid, has purchaseDataList, but productId does not match', function() {
before(function() {
iapMock.setup = function(cb) {
return cb(null);
};
iapMock.validate = function(iapApple, iapBodyReciept, cb) {
return cb(null, true);
};
iapMock.isValidated = function(appleRes) {
return appleRes;
};
iapMock.getPurchaseData = function(appleRes) {
return [
{
productId: 'com.another.company'
}
];
};
return iapMock.APPLE = 'apple';
});
it('calls res.json with incorrect reciept obj', function() {
var expectedResObj;
expectedResObj = {
ok: false,
data: {
code: 6778001,
message: 'Incorrect receipt content'
}
};
inApp.iosVerify(req, res, next);
expect(res.json).to.be.calledOnce;
return expect(res.json).to.be.calledWith(expectedResObj);
});
return it('does not calls payments.buyGems function', function() {
inApp.iosVerify(req, res, next);
return expect(paymentSpy).to.not.be.called;
});
});
});
});

View File

@@ -1,237 +1,74 @@
(function() {
'use strict';
var Group, app, diff;
var Group, app, diff;
diff = require("deep-diff");
diff = require("deep-diff");
Group = require("../../website/src/models/group").model;
Group = require("../../website/src/models/group").model;
app = require("../../website/src/server");
app = require("../../website/src/server");
describe("Party", function() {
return context("Quests", function() {
var group, notParticipating, participating, party;
party = void 0;
group = void 0;
participating = [];
notParticipating = [];
beforeEach(function(done) {
Group.update({
_id: "habitrpg"
}, {
$set: {
quest: {
key: "dilatory",
active: true,
progress: {
hp: shared.content.quests.dilatory.boss.hp,
rage: 0
}
describe("Party", function() {
return context("Quests", function() {
var group, notParticipating, participating, party;
party = void 0;
group = void 0;
participating = [];
notParticipating = [];
beforeEach(function(done) {
Group.update({
_id: "habitrpg"
}, {
$set: {
quest: {
key: "dilatory",
active: true,
progress: {
hp: shared.content.quests.dilatory.boss.hp,
rage: 0
}
}
}).exec();
return async.waterfall([
function(cb) {
return registerNewUser(cb, true);
}, function(user, cb) {
return request.post(baseURL + "/groups").send({
name: "TestGroup",
type: "party"
}).end(function(err, res) {
expectCode(res, 200);
group = res.body;
expect(group.members.length).to.equal(1);
expect(group.leader).to.equal(user._id);
return cb();
});
}, function(cb) {
return request.post(baseURL + '/user/tasks').send({
type: 'daily',
text: 'daily one'
}).end(function(err, res) {
return cb();
});
}, function(cb) {
return request.post(baseURL + '/user/tasks').send({
type: 'daily',
text: 'daily two'
}).end(function(err, res) {
return cb();
});
}, function(cb) {
return User.findByIdAndUpdate(user._id, {
$set: {
"stats.lvl": 50
}
}, {
"new": true
}, function(err, _user) {
return cb(null, _user);
});
}, function(_user, cb) {
var user;
user = _user;
return request.post(baseURL + "/user/batch-update").send([
{
op: "score",
params: {
direction: "up",
id: user.dailys[0].id
}
}, {
op: "score",
params: {
direction: "up",
id: user.dailys[0].id
}
}, {
op: "update",
body: {
"stats.lvl": 50
}
}
]).end(function(err, res) {
user = res.body;
expect(user.party.quest.progress.up).to.be.above(0);
return async.waterfall([
function(cb) {
return registerManyUsers(3, cb);
}, function(_party, cb) {
var inviteURL;
party = _party;
inviteURL = baseURL + "/groups/" + group._id + "/invite";
return async.parallel([
function(cb2) {
return request.post(inviteURL).send({
uuids: [party[0]._id]
}).end(function() {
return cb2();
});
}, function(cb2) {
return request.post(inviteURL).send({
uuids: [party[1]._id]
}).end(function() {
return cb2();
});
}, function(cb2) {
return request.post(inviteURL).send({
uuids: [party[2]._id]
}).end(function(err, res) {
return cb2();
});
}
], cb);
}, function(results, cb) {
var series;
series = _.reduce(party, function(m, v, i) {
m.push(function(cb2) {
return request.post(baseURL + "/groups/" + group._id + "/join").set("X-API-User", party[i]._id).set("X-API-Key", party[i].apiToken).end(function() {
return cb2();
});
});
return m;
}, []);
return async.series(series, cb);
}, function(whatever, cb) {
return Group.findById(group._id, function(err, g) {
group = g;
expect(g.members.length).to.equal(4);
return cb();
});
}
], function() {
return async.waterfall([
function(cb) {
return request.post(baseURL + "/groups/" + group._id + "/questAccept?key=vice3").end(function(err, res) {
expectCode(res, 400);
return User.findByIdAndUpdate(user._id, {
$set: {
"items.quests.vice3": 1
}
}, {
"new": true
}, cb);
});
}, function(_user, cb) {
return request.post(baseURL + "/groups/" + group._id + "/questAccept?key=vice3").end(function(err, res) {
expectCode(res, 200);
return Group.findById(group._id, cb);
});
}, function(_group, cb) {
expect(_group.quest.key).to.equal("vice3");
expect(_group.quest.active).to.equal(false);
return request.post(baseURL + "/groups/" + group._id + "/questAccept").set("X-API-User", party[0]._id).set("X-API-Key", party[0].apiToken).end(function() {
return request.post(baseURL + "/groups/" + group._id + "/questAccept").set("X-API-User", party[1]._id).set("X-API-Key", party[1].apiToken).end(function(err, res) {
return request.post(baseURL + "/groups/" + group._id + "/questReject").set("X-API-User", party[2]._id).set("X-API-Key", party[2].apiToken).end(function(err, res) {
group = res.body;
expect(group.quest.active).to.equal(true);
return cb();
});
});
});
}
], done);
});
});
}
]);
});
it("Casts a spell", function(done) {
var mp;
mp = user.stats.mp;
return request.get(baseURL + "/members/" + party[0]._id).end(function(err, res) {
party[0] = res.body;
return request.post(baseURL + "/user/class/cast/snowball?targetType=user&targetId=" + party[0]._id).end(function(err, res) {
return request.get(baseURL + "/members/" + party[0]._id).end(function(err, res) {
var difference, member;
member = res.body;
expect(member.achievements.snowball).to.equal(1);
expect(member.stats.buffs.snowball).to.exist;
difference = diff(member, party[0]);
expect(_.size(difference)).to.equal(2);
return request.put(baseURL + "/user").send({
"stats.lvl": 5
}).end(function(err, res) {
return request.put(baseURL + "/user").send({
"stats.mp": 100
}).end(function(err, res) {
return request.post(baseURL + "/user/class/cast/valorousPresence?targetType=party").end(function(err, res) {
return request.get(baseURL + "/members/" + member._id).end(function(err, res) {
expect(res.body.stats.buffs.str).to.be.above(0);
expect(diff(res.body, member).length).to.equal(1);
return done();
});
});
});
});
});
}
}).exec();
return async.waterfall([
function(cb) {
return registerNewUser(cb, true);
}, function(user, cb) {
return request.post(baseURL + "/groups").send({
name: "TestGroup",
type: "party"
}).end(function(err, res) {
expectCode(res, 200);
group = res.body;
expect(group.members.length).to.equal(1);
expect(group.leader).to.equal(user._id);
return cb();
});
});
});
it("Doesn't include people who aren't participating", function(done) {
return request.get(baseURL + "/groups/" + group._id).end(function(err, res) {
expect(_.size(res.body.quest.members)).to.equal(3);
return done();
});
});
it("allows quest participants to leave quest", function(done) {
var leavingMember;
leavingMember = party[1];
expect(group.quest.members[leavingMember._id]).to.eql(true);
return request.post(baseURL + "/groups/" + group._id + "/questLeave").set("X-API-User", leavingMember._id).set("X-API-Key", leavingMember.apiToken).end(function(err, res) {
expectCode(res, 204);
return request.get(baseURL + '/groups/party').end(function(err, res) {
expect(res.body.quest.members[leavingMember._id]).to.not.be.ok;
return done();
}, function(cb) {
return request.post(baseURL + '/user/tasks').send({
type: 'daily',
text: 'daily one'
}).end(function(err, res) {
return cb();
});
});
});
return xit("Hurts the boss", function(done) {
return request.post(baseURL + "/user/batch-update").end(function(err, res) {
var up, user;
user = res.body;
up = user.party.quest.progress.up;
expect(up).to.be.above(0);
}, function(cb) {
return request.post(baseURL + '/user/tasks').send({
type: 'daily',
text: 'daily two'
}).end(function(err, res) {
return cb();
});
}, function(cb) {
return User.findByIdAndUpdate(user._id, {
$set: {
"stats.lvl": 50
}
}, {
"new": true
}, function(err, _user) {
return cb(null, _user);
});
}, function(_user, cb) {
var user;
user = _user;
return request.post(baseURL + "/user/batch-update").send([
{
op: "score",
@@ -239,138 +76,297 @@
direction: "up",
id: user.dailys[0].id
}
}, {
op: "score",
params: {
direction: "up",
id: user.dailys[0].id
}
}, {
op: "update",
body: {
lastCron: moment().subtract(1, "days")
"stats.lvl": 50
}
}
]).end(function(err, res) {
expect(res.body.party.quest.progress.up).to.be.above(up);
return request.post(baseURL + "/user/batch-update").end(function() {
return request.get(baseURL + "/groups/party").end(function(err, res) {
return async.waterfall([
function(cb) {
return async.parallel([
function(cb2) {
return Group.findById("habitrpg", {
quest: 1
}, function(err, tavern) {
expect(tavern.quest.progress.hp).to.be.below(shared.content.quests.dilatory.boss.hp);
expect(tavern.quest.progress.rage).to.be.above(0);
return cb2();
});
}, function(cb2) {
var _party;
expect(res.body.quest.progress.hp).to.be.below(shared.content.quests.vice3.boss.hp);
_party = res.body.members;
expect(_.find(_party, {
_id: party[0]._id
}).stats.hp).to.be.below(50);
expect(_.find(_party, {
_id: party[1]._id
}).stats.hp).to.be.below(50);
expect(_.find(_party, {
_id: party[2]._id
}).stats.hp).to.be(50);
return cb2();
}
], cb);
}, function(whatever, cb) {
return async.waterfall([
function(cb2) {
expect(user.items.pets["MantisShrimp-Base"]).to.not.be.ok();
return Group.update({
_id: "habitrpg"
}, {
$set: {
"quest.progress.hp": 0
}
}, cb2);
}, function(arg1, arg2, cb2) {
expect(user.items.gear.owned.weapon_special_2).to.not.be.ok();
return Group.findByIdAndUpdate(group._id, {
$set: {
"quest.progress.hp": 0
}
}, {
"new": true
}, cb2);
}
], cb);
}, function(_group, cb) {
return request.post(baseURL + "/user/batch-update").send([
{
op: "score",
params: {
direction: "up",
id: user.dailys[1].id
}
}, {
op: "update",
body: {
lastCron: moment().subtract(1, "days")
}
}
]).end(function() {
return cb();
user = res.body;
expect(user.party.quest.progress.up).to.be.above(0);
return async.waterfall([
function(cb) {
return registerManyUsers(3, cb);
}, function(_party, cb) {
var inviteURL;
party = _party;
inviteURL = baseURL + "/groups/" + group._id + "/invite";
return async.parallel([
function(cb2) {
return request.post(inviteURL).send({
uuids: [party[0]._id]
}).end(function() {
return cb2();
});
}, function(cb) {
return request.post(baseURL + "/user/batch-update").end(function(err, res) {
return cb(null, res.body);
}, function(cb2) {
return request.post(inviteURL).send({
uuids: [party[1]._id]
}).end(function() {
return cb2();
});
}, function(cb2) {
return request.post(inviteURL).send({
uuids: [party[2]._id]
}).end(function(err, res) {
return cb2();
});
}, function(_user, cb) {
return User.findById(_user._id, cb);
}, function(_user, cb) {
user = _user;
return Group.findById(group._id, cb);
}, function(_group, cb) {
var cummExp, cummGp;
cummExp = shared.content.quests.vice3.drop.exp + shared.content.quests.dilatory.drop.exp;
cummGp = shared.content.quests.vice3.drop.gp + shared.content.quests.dilatory.drop.gp;
return async.parallel([
function(cb2) {
return Group.findById("habitrpg", function(err, tavern) {
expect(_.isEmpty(tavern.get("quest"))).to.equal(true);
expect(user.items.pets["MantisShrimp-Base"]).to.equal(5);
expect(user.items.mounts["MantisShrimp-Base"]).to.equal(true);
expect(user.items.eggs.Dragon).to.equal(2);
expect(user.items.hatchingPotions.Shade).to.equal(2);
return cb2();
});
}, function(cb2) {
expect(_.isEmpty(_group.get("quest"))).to.equal(true);
expect(user.items.gear.owned.weapon_special_2).to.equal(true);
expect(user.items.eggs.Dragon).to.equal(2);
expect(user.items.hatchingPotions.Shade).to.equal(2);
return async.parallel([
function(cb3) {
return User.findById(party[0].id, function(err, mbr) {
expect(mbr.items.gear.owned.weapon_special_2).to.equal(true);
return cb3();
});
}, function(cb3) {
return User.findById(party[1].id, function(err, mbr) {
expect(mbr.items.gear.owned.weapon_special_2).to.equal(true);
return cb3();
});
}, function(cb3) {
return User.findById(party[2].id, function(err, mbr) {
expect(mbr.items.gear.owned.weapon_special_2).to.not.be.ok();
return cb3();
});
}
], cb2);
}
], cb);
}
], done);
], cb);
}, function(results, cb) {
var series;
series = _.reduce(party, function(m, v, i) {
m.push(function(cb2) {
return request.post(baseURL + "/groups/" + group._id + "/join").set("X-API-User", party[i]._id).set("X-API-Key", party[i].apiToken).end(function() {
return cb2();
});
});
return m;
}, []);
return async.series(series, cb);
}, function(whatever, cb) {
return Group.findById(group._id, function(err, g) {
group = g;
expect(g.members.length).to.equal(4);
return cb();
});
}
], function() {
return async.waterfall([
function(cb) {
return request.post(baseURL + "/groups/" + group._id + "/questAccept?key=vice3").end(function(err, res) {
expectCode(res, 400);
return User.findByIdAndUpdate(user._id, {
$set: {
"items.quests.vice3": 1
}
}, {
"new": true
}, cb);
});
}, function(_user, cb) {
return request.post(baseURL + "/groups/" + group._id + "/questAccept?key=vice3").end(function(err, res) {
expectCode(res, 200);
return Group.findById(group._id, cb);
});
}, function(_group, cb) {
expect(_group.quest.key).to.equal("vice3");
expect(_group.quest.active).to.equal(false);
return request.post(baseURL + "/groups/" + group._id + "/questAccept").set("X-API-User", party[0]._id).set("X-API-Key", party[0].apiToken).end(function() {
return request.post(baseURL + "/groups/" + group._id + "/questAccept").set("X-API-User", party[1]._id).set("X-API-Key", party[1].apiToken).end(function(err, res) {
return request.post(baseURL + "/groups/" + group._id + "/questReject").set("X-API-User", party[2]._id).set("X-API-Key", party[2].apiToken).end(function(err, res) {
group = res.body;
expect(group.quest.active).to.equal(true);
return cb();
});
});
});
}
], done);
});
});
}
]);
});
it("Casts a spell", function(done) {
var mp;
mp = user.stats.mp;
return request.get(baseURL + "/members/" + party[0]._id).end(function(err, res) {
party[0] = res.body;
return request.post(baseURL + "/user/class/cast/snowball?targetType=user&targetId=" + party[0]._id).end(function(err, res) {
return request.get(baseURL + "/members/" + party[0]._id).end(function(err, res) {
var difference, member;
member = res.body;
expect(member.achievements.snowball).to.equal(1);
expect(member.stats.buffs.snowball).to.exist;
difference = diff(member, party[0]);
expect(_.size(difference)).to.equal(2);
return request.put(baseURL + "/user").send({
"stats.lvl": 5
}).end(function(err, res) {
return request.put(baseURL + "/user").send({
"stats.mp": 100
}).end(function(err, res) {
return request.post(baseURL + "/user/class/cast/valorousPresence?targetType=party").end(function(err, res) {
return request.get(baseURL + "/members/" + member._id).end(function(err, res) {
expect(res.body.stats.buffs.str).to.be.above(0);
expect(diff(res.body, member).length).to.equal(1);
return done();
});
});
});
});
});
});
});
});
it("Doesn't include people who aren't participating", function(done) {
return request.get(baseURL + "/groups/" + group._id).end(function(err, res) {
expect(_.size(res.body.quest.members)).to.equal(3);
return done();
});
});
it("allows quest participants to leave quest", function(done) {
var leavingMember;
leavingMember = party[1];
expect(group.quest.members[leavingMember._id]).to.eql(true);
return request.post(baseURL + "/groups/" + group._id + "/questLeave").set("X-API-User", leavingMember._id).set("X-API-Key", leavingMember.apiToken).end(function(err, res) {
expectCode(res, 204);
return request.get(baseURL + '/groups/party').end(function(err, res) {
expect(res.body.quest.members[leavingMember._id]).to.not.be.ok;
return done();
});
});
});
return xit("Hurts the boss", function(done) {
return request.post(baseURL + "/user/batch-update").end(function(err, res) {
var up, user;
user = res.body;
up = user.party.quest.progress.up;
expect(up).to.be.above(0);
return request.post(baseURL + "/user/batch-update").send([
{
op: "score",
params: {
direction: "up",
id: user.dailys[0].id
}
}, {
op: "update",
body: {
lastCron: moment().subtract(1, "days")
}
}
]).end(function(err, res) {
expect(res.body.party.quest.progress.up).to.be.above(up);
return request.post(baseURL + "/user/batch-update").end(function() {
return request.get(baseURL + "/groups/party").end(function(err, res) {
return async.waterfall([
function(cb) {
return async.parallel([
function(cb2) {
return Group.findById("habitrpg", {
quest: 1
}, function(err, tavern) {
expect(tavern.quest.progress.hp).to.be.below(shared.content.quests.dilatory.boss.hp);
expect(tavern.quest.progress.rage).to.be.above(0);
return cb2();
});
}, function(cb2) {
var _party;
expect(res.body.quest.progress.hp).to.be.below(shared.content.quests.vice3.boss.hp);
_party = res.body.members;
expect(_.find(_party, {
_id: party[0]._id
}).stats.hp).to.be.below(50);
expect(_.find(_party, {
_id: party[1]._id
}).stats.hp).to.be.below(50);
expect(_.find(_party, {
_id: party[2]._id
}).stats.hp).to.be(50);
return cb2();
}
], cb);
}, function(whatever, cb) {
return async.waterfall([
function(cb2) {
expect(user.items.pets["MantisShrimp-Base"]).to.not.be.ok();
return Group.update({
_id: "habitrpg"
}, {
$set: {
"quest.progress.hp": 0
}
}, cb2);
}, function(arg1, arg2, cb2) {
expect(user.items.gear.owned.weapon_special_2).to.not.be.ok();
return Group.findByIdAndUpdate(group._id, {
$set: {
"quest.progress.hp": 0
}
}, {
"new": true
}, cb2);
}
], cb);
}, function(_group, cb) {
return request.post(baseURL + "/user/batch-update").send([
{
op: "score",
params: {
direction: "up",
id: user.dailys[1].id
}
}, {
op: "update",
body: {
lastCron: moment().subtract(1, "days")
}
}
]).end(function() {
return cb();
});
}, function(cb) {
return request.post(baseURL + "/user/batch-update").end(function(err, res) {
return cb(null, res.body);
});
}, function(_user, cb) {
return User.findById(_user._id, cb);
}, function(_user, cb) {
user = _user;
return Group.findById(group._id, cb);
}, function(_group, cb) {
var cummExp, cummGp;
cummExp = shared.content.quests.vice3.drop.exp + shared.content.quests.dilatory.drop.exp;
cummGp = shared.content.quests.vice3.drop.gp + shared.content.quests.dilatory.drop.gp;
return async.parallel([
function(cb2) {
return Group.findById("habitrpg", function(err, tavern) {
expect(_.isEmpty(tavern.get("quest"))).to.equal(true);
expect(user.items.pets["MantisShrimp-Base"]).to.equal(5);
expect(user.items.mounts["MantisShrimp-Base"]).to.equal(true);
expect(user.items.eggs.Dragon).to.equal(2);
expect(user.items.hatchingPotions.Shade).to.equal(2);
return cb2();
});
}, function(cb2) {
expect(_.isEmpty(_group.get("quest"))).to.equal(true);
expect(user.items.gear.owned.weapon_special_2).to.equal(true);
expect(user.items.eggs.Dragon).to.equal(2);
expect(user.items.hatchingPotions.Shade).to.equal(2);
return async.parallel([
function(cb3) {
return User.findById(party[0].id, function(err, mbr) {
expect(mbr.items.gear.owned.weapon_special_2).to.equal(true);
return cb3();
});
}, function(cb3) {
return User.findById(party[1].id, function(err, mbr) {
expect(mbr.items.gear.owned.weapon_special_2).to.equal(true);
return cb3();
});
}, function(cb3) {
return User.findById(party[2].id, function(err, mbr) {
expect(mbr.items.gear.owned.weapon_special_2).to.not.be.ok();
return cb3();
});
}
], cb2);
}
], cb);
}
], done);
});
});
});
});
});
});
}).call(this);
});

View File

@@ -1,434 +1,430 @@
(function() {
'use strict';
var app, rewire, sinon;
var app, rewire, sinon;
app = require("../../website/src/server");
app = require("../../website/src/server");
rewire = require('rewire');
rewire = require('rewire');
sinon = require('sinon');
sinon = require('sinon');
describe("Push-Notifications", function() {
before(function(done) {
return registerNewUser(done, true);
describe("Push-Notifications", function() {
before(function(done) {
return registerNewUser(done, true);
});
return describe("Events that send push notifications", function() {
var pushSpy;
pushSpy = {
sendNotify: sinon.spy()
};
afterEach(function(done) {
pushSpy.sendNotify.reset();
return done();
});
return describe("Events that send push notifications", function() {
var pushSpy;
pushSpy = {
sendNotify: sinon.spy()
context("Challenges", function() {
var challengeMock, challenges, userMock;
challenges = rewire("../../website/src/controllers/api-v2/challenges");
challenges.__set__('pushNotify', pushSpy);
challengeMock = {
findById: function(arg, cb) {
return cb(null, {
leader: user._id,
name: 'challenge-name'
});
}
};
afterEach(function(done) {
pushSpy.sendNotify.reset();
return done();
userMock = {
findById: function(arg, cb) {
return cb(null, user);
}
};
challenges.__set__('Challenge', challengeMock);
challenges.__set__('User', userMock);
challenges.__set__('closeChal', function() {
return true;
});
context("Challenges", function() {
var challengeMock, challenges, userMock;
challenges = rewire("../../website/src/controllers/api-v2/challenges");
challenges.__set__('pushNotify', pushSpy);
challengeMock = {
findById: function(arg, cb) {
return cb(null, {
leader: user._id,
name: 'challenge-name'
});
}
};
userMock = {
findById: function(arg, cb) {
beforeEach(function(done) {
return registerNewUser(function() {
user.preferences.emailNotifications.wonChallenge = false;
user.save = function(cb) {
return cb(null, user);
};
return done();
}, true);
});
return it("sends a push notification when you win a challenge", function(done) {
var req, res;
req = {
params: {
cid: 'challenge-id'
},
query: {
uid: 'user-id'
}
};
challenges.__set__('Challenge', challengeMock);
challenges.__set__('User', userMock);
challenges.__set__('closeChal', function() {
return true;
});
beforeEach(function(done) {
return registerNewUser(function() {
user.preferences.emailNotifications.wonChallenge = false;
user.save = function(cb) {
return cb(null, user);
};
return done();
}, true);
});
return it("sends a push notification when you win a challenge", function(done) {
var req, res;
req = {
params: {
cid: 'challenge-id'
},
query: {
uid: 'user-id'
}
};
res = {
locals: {
user: user
}
};
challenges.selectWinner(req, res);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(user, 'You won a Challenge!', 'challenge-name');
return done();
}, 100);
});
res = {
locals: {
user: user
}
};
challenges.selectWinner(req, res);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(user, 'You won a Challenge!', 'challenge-name');
return done();
}, 100);
});
context("Groups", function() {
var groups, recipient;
recipient = null;
groups = rewire("../../website/src/controllers/api-v2/groups");
groups.__set__('pushNotify', pushSpy);
before(function(done) {
return registerNewUser(function(err, _user) {
var userMock;
recipient = _user;
recipient.invitations.guilds = [];
recipient.save = function(cb) {
return cb(null, recipient);
};
recipient.preferences.emailNotifications.invitedGuild = false;
recipient.preferences.emailNotifications.invitedParty = false;
recipient.preferences.emailNotifications.invitedQuest = false;
userMock = {
findById: function(arg, cb) {
return cb(null, recipient);
},
find: function(arg, arg2, cb) {
return cb(null, [recipient]);
},
update: function(arg, arg2) {
return {
exec: function() {
return true;
}
};
}
};
groups.__set__('User', userMock);
return done();
}, false);
});
it("sends a push notification when invited to a guild", function(done) {
var group, req, res;
group = {
_id: 'guild-id',
name: 'guild-name',
type: 'guild',
members: [user._id],
invites: []
};
group.save = function(cb) {
return cb(null, group);
};
req = {
body: {
uuids: [recipient._id]
}
};
res = {
locals: {
group: group,
user: user
},
json: function() {
return true;
}
};
groups.invite(req, res);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'Invited To Guild', group.name);
return done();
}, 100);
});
it("sends a push notification when invited to a party", function(done) {
var group, req, res;
group = {
_id: 'party-id',
name: 'party-name',
type: 'party',
members: [user._id],
invites: []
};
group.save = function(cb) {
return cb(null, group);
};
req = {
body: {
uuids: [recipient._id]
}
};
res = {
locals: {
group: group,
user: user
},
json: function() {
return true;
}
};
groups.invite(req, res);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'Invited To Party', group.name);
return done();
}, 100);
});
it("sends a push notification when invited to a quest", function(done) {
var group, req, res;
group = {
_id: 'party-id',
name: 'party-name',
type: 'party',
members: [user._id, recipient._id],
invites: [],
quest: {}
};
user.items.quests.hedgehog = 5;
group.save = function(cb) {
return cb(null, group);
};
group.markModified = function() {
return true;
};
req = {
body: {
uuids: [recipient._id]
},
query: {
key: 'hedgehog'
}
};
res = {
locals: {
group: group,
user: user
},
json: function() {
return true;
}
};
groups.questAccept(req, res);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'Quest Invitation', 'Invitation for the Quest The Hedgebeast');
return done();
}, 100);
});
return it("sends a push notification to participating members when quest starts", function(done) {
var group, req, res, userMock;
group = {
_id: 'party-id',
name: 'party-name',
type: 'party',
members: [user._id, recipient._id],
invites: []
};
group.quest = {
key: 'hedgehog',
progress: {
hp: 100
},
members: {}
};
group.quest.members[recipient._id] = true;
group.save = function(cb) {
return cb(null, group);
};
group.markModified = function() {
return true;
};
req = {
body: {
uuids: [recipient._id]
},
query: {}
};
res = {
locals: {
group: group,
user: user
},
json: function() {
return true;
}
});
context("Groups", function() {
var groups, recipient;
recipient = null;
groups = rewire("../../website/src/controllers/api-v2/groups");
groups.__set__('pushNotify', pushSpy);
before(function(done) {
return registerNewUser(function(err, _user) {
var userMock;
recipient = _user;
recipient.invitations.guilds = [];
recipient.save = function(cb) {
return cb(null, recipient);
};
recipient.preferences.emailNotifications.invitedGuild = false;
recipient.preferences.emailNotifications.invitedParty = false;
recipient.preferences.emailNotifications.invitedQuest = false;
userMock = {
findOne: function(arg, arg2, cb) {
findById: function(arg, cb) {
return cb(null, recipient);
},
update: function(arg, arg2, cb) {
if (cb) {
return cb(null, user);
} else {
return {
exec: function() {
return true;
}
};
}
find: function(arg, arg2, cb) {
return cb(null, [recipient]);
},
update: function(arg, arg2) {
return {
exec: function() {
return true;
}
};
}
};
groups.__set__('User', userMock);
groups.__set__('populateQuery', function(arg, arg2, arg3) {
return {
exec: function() {
return group.members;
return done();
}, false);
});
it("sends a push notification when invited to a guild", function(done) {
var group, req, res;
group = {
_id: 'guild-id',
name: 'guild-name',
type: 'guild',
members: [user._id],
invites: []
};
group.save = function(cb) {
return cb(null, group);
};
req = {
body: {
uuids: [recipient._id]
}
};
res = {
locals: {
group: group,
user: user
},
json: function() {
return true;
}
};
groups.invite(req, res);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'Invited To Guild', group.name);
return done();
}, 100);
});
it("sends a push notification when invited to a party", function(done) {
var group, req, res;
group = {
_id: 'party-id',
name: 'party-name',
type: 'party',
members: [user._id],
invites: []
};
group.save = function(cb) {
return cb(null, group);
};
req = {
body: {
uuids: [recipient._id]
}
};
res = {
locals: {
group: group,
user: user
},
json: function() {
return true;
}
};
groups.invite(req, res);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'Invited To Party', group.name);
return done();
}, 100);
});
it("sends a push notification when invited to a quest", function(done) {
var group, req, res;
group = {
_id: 'party-id',
name: 'party-name',
type: 'party',
members: [user._id, recipient._id],
invites: [],
quest: {}
};
user.items.quests.hedgehog = 5;
group.save = function(cb) {
return cb(null, group);
};
group.markModified = function() {
return true;
};
req = {
body: {
uuids: [recipient._id]
},
query: {
key: 'hedgehog'
}
};
res = {
locals: {
group: group,
user: user
},
json: function() {
return true;
}
};
groups.questAccept(req, res);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'Quest Invitation', 'Invitation for the Quest The Hedgebeast');
return done();
}, 100);
});
return it("sends a push notification to participating members when quest starts", function(done) {
var group, req, res, userMock;
group = {
_id: 'party-id',
name: 'party-name',
type: 'party',
members: [user._id, recipient._id],
invites: []
};
group.quest = {
key: 'hedgehog',
progress: {
hp: 100
},
members: {}
};
group.quest.members[recipient._id] = true;
group.save = function(cb) {
return cb(null, group);
};
group.markModified = function() {
return true;
};
req = {
body: {
uuids: [recipient._id]
},
query: {}
};
res = {
locals: {
group: group,
user: user
},
json: function() {
return true;
}
};
userMock = {
findOne: function(arg, arg2, cb) {
return cb(null, recipient);
},
update: function(arg, arg2, cb) {
if (cb) {
return cb(null, user);
} else {
return {
exec: function() {
return true;
}
};
}
}
};
groups.__set__('User', userMock);
groups.__set__('populateQuery', function(arg, arg2, arg3) {
return {
exec: function() {
return group.members;
}
};
});
groups.questAccept(req, res);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledTwice;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'HabitRPG', 'Your Quest has Begun: The Hedgebeast');
return done();
}, 100);
});
});
return describe("Gifts", function() {
var recipient;
recipient = null;
before(function(done) {
return registerNewUser(function(err, _user) {
recipient = _user;
recipient.preferences.emailNotifications.giftedGems = false;
user.balance = 4;
user.save = function() {
return true;
};
recipient.save = function() {
return true;
};
return done();
}, false);
});
context("sending gems from balance", function() {
var members;
members = rewire("../../website/src/controllers/api-v2/members");
members.sendMessage = function() {
return true;
};
members.__set__('pushNotify', pushSpy);
members.__set__('fetchMember', function(id) {
return function(cb) {
return cb(null, recipient);
};
});
return it("sends a push notification", function(done) {
var req, res;
req = {
params: {
uuid: "uuid"
},
body: {
type: 'gems',
gems: {
amount: 1
}
};
});
groups.questAccept(req, res);
}
};
res = {
locals: {
user: user
}
};
members.sendGift(req, res);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledTwice;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'HabitRPG', 'Your Quest has Begun: The Hedgebeast');
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'Gifted Gems', '1 Gems - by ' + user.profile.name);
return done();
}, 100);
});
});
return describe("Gifts", function() {
var recipient;
recipient = null;
before(function(done) {
return registerNewUser(function(err, _user) {
recipient = _user;
recipient.preferences.emailNotifications.giftedGems = false;
user.balance = 4;
user.save = function() {
return true;
};
recipient.save = function() {
return true;
};
return done();
}, false);
});
context("sending gems from balance", function() {
var members;
members = rewire("../../website/src/controllers/api-v2/members");
members.sendMessage = function() {
return describe("Purchases", function() {
var membersMock, payments;
payments = rewire("../../website/src/controllers/payments");
payments.__set__('pushNotify', pushSpy);
membersMock = {
sendMessage: function() {
return true;
};
members.__set__('pushNotify', pushSpy);
members.__set__('fetchMember', function(id) {
return function(cb) {
return cb(null, recipient);
};
});
return it("sends a push notification", function(done) {
var req, res;
req = {
params: {
uuid: "uuid"
},
body: {
type: 'gems',
}
};
payments.__set__('members', membersMock);
context("buying gems as a purchased gift", function() {
it("sends a push notification", function(done) {
var data;
data = {
user: user,
gift: {
member: recipient,
gems: {
amount: 1
}
}
};
res = {
locals: {
user: user
}
};
members.sendGift(req, res);
payments.buyGems(data);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'Gifted Gems', '1 Gems - by ' + user.profile.name);
return done();
}, 100);
});
});
return describe("Purchases", function() {
var membersMock, payments;
payments = rewire("../../website/src/controllers/payments");
payments.__set__('pushNotify', pushSpy);
membersMock = {
sendMessage: function() {
return true;
}
};
payments.__set__('members', membersMock);
context("buying gems as a purchased gift", function() {
it("sends a push notification", function(done) {
var data;
data = {
user: user,
gift: {
member: recipient,
gems: {
amount: 1
}
return it("does not send a push notification if buying gems for self", function(done) {
var data;
data = {
user: user,
gift: {
member: user,
gems: {
amount: 1
}
};
payments.buyGems(data);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'Gifted Gems', '1 Gems - by ' + user.profile.name);
return done();
}, 100);
});
return it("does not send a push notification if buying gems for self", function(done) {
var data;
data = {
user: user,
gift: {
member: user,
gems: {
amount: 1
}
}
};
payments.buyGems(data);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.not.have.been.called;
return done();
}, 100);
});
}
};
payments.buyGems(data);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.not.have.been.called;
return done();
}, 100);
});
return context("sending a subscription as a purchased gift", function() {
it("sends a push notification", function(done) {
var data;
data = {
user: user,
gift: {
member: recipient,
subscription: {
key: 'basic_6mo'
}
});
return context("sending a subscription as a purchased gift", function() {
it("sends a push notification", function(done) {
var data;
data = {
user: user,
gift: {
member: recipient,
subscription: {
key: 'basic_6mo'
}
};
payments.createSubscription(data);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'Gifted Subscription', '6 months - by ' + user.profile.name);
return done();
}, 100);
});
return it("does not send a push notification if buying subscription for self", function(done) {
var data;
data = {
user: user,
gift: {
member: user,
subscription: {
key: 'basic_6mo'
}
}
};
payments.createSubscription(data);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.have.been.calledOnce;
expect(pushSpy.sendNotify).to.have.been.calledWith(recipient, 'Gifted Subscription', '6 months - by ' + user.profile.name);
return done();
}, 100);
});
return it("does not send a push notification if buying subscription for self", function(done) {
var data;
data = {
user: user,
gift: {
member: user,
subscription: {
key: 'basic_6mo'
}
};
payments.createSubscription(data);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.not.have.been.called;
return done();
}, 100);
});
}
};
payments.createSubscription(data);
return setTimeout(function() {
expect(pushSpy.sendNotify).to.not.have.been.called;
return done();
}, 100);
});
});
});
});
});
}).call(this);
});

View File

@@ -1,146 +1,142 @@
(function() {
'use strict';
require("../../website/src/server");
require("../../website/src/server");
describe("Score", function() {
before(function(done) {
return registerNewUser(done, true);
});
context("Todos that did not previously exist", function() {
it("creates a completed a todo when using up url", function(done) {
return request.post(baseURL + "/user/tasks/withUp/up").send({
type: "todo",
text: "withUp"
}).end(function(err, res) {
expectCode(res, 200);
request.get(baseURL + "/user/tasks/withUp").end(function(err, res) {
var upTodo;
upTodo = res.body;
return expect(upTodo.completed).to.equal(true);
});
return done();
});
});
it("creates an uncompleted todo when using down url", function(done) {
return request.post(baseURL + "/user/tasks/withDown/down").send({
type: "todo",
text: "withDown"
}).end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/withDown").end(function(err, res) {
var downTodo;
downTodo = res.body;
expect(downTodo.completed).to.equal(false);
return done();
});
});
});
it("creates a completed a todo overriding the complete parameter when using up url", function(done) {
return request.post(baseURL + "/user/tasks/withUpWithComplete/up").send({
type: "todo",
text: "withUpWithComplete",
completed: false
}).end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/withUpWithComplete").end(function(err, res) {
var upTodo;
upTodo = res.body;
expect(upTodo.completed).to.equal(true);
return done();
});
});
});
return it("Creates an uncompleted todo overriding the completed parameter when using down url", function(done) {
return request.post(baseURL + "/user/tasks/withDownWithUncomplete/down").send({
type: "todo",
text: "withDownWithUncomplete",
completed: true
}).end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/withDownWithUncomplete").end(function(err, res) {
var downTodo;
downTodo = res.body;
expect(downTodo.completed).to.equal(false);
return done();
});
});
});
});
context("Todo that already exists", function() {
it("It completes a todo when using up url", function(done) {
return request.post(baseURL + "/user/tasks").send({
type: "todo",
text: "Sample Todo"
}).end(function(err, res) {
var unCompletedTodo;
expectCode(res, 200);
unCompletedTodo = res.body;
expect(unCompletedTodo.completed).to.equal(false);
return request.post(baseURL + "/user/tasks/" + unCompletedTodo._id + "/up").end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/" + unCompletedTodo._id).end(function(err, res) {
unCompletedTodo = res.body;
expect(unCompletedTodo.completed).to.equal(true);
return done();
});
});
});
});
return it("It uncompletes a todo when using down url", function(done) {
return request.post(baseURL + "/user/tasks").send({
type: "todo",
text: "Sample Todo",
completed: true
}).end(function(err, res) {
var completedTodo;
expectCode(res, 200);
completedTodo = res.body;
expect(completedTodo.completed).to.equal(true);
return request.post(baseURL + "/user/tasks/" + completedTodo._id + "/down").end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/" + completedTodo._id).end(function(err, res) {
completedTodo = res.body;
expect(completedTodo.completed).to.equal(false);
return done();
});
});
});
});
});
it("Creates and scores up a habit when using up url", function(done) {
var upHabit;
upHabit = void 0;
return request.post(baseURL + "/user/tasks/habitWithUp/up").send({
type: "habit",
text: "testTitle",
completed: true
describe("Score", function() {
before(function(done) {
return registerNewUser(done, true);
});
context("Todos that did not previously exist", function() {
it("creates a completed a todo when using up url", function(done) {
return request.post(baseURL + "/user/tasks/withUp/up").send({
type: "todo",
text: "withUp"
}).end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/habitWithUp").end(function(err, res) {
upHabit = res.body;
expect(upHabit.value).to.be.at.least(1);
expect(upHabit.type).to.equal("habit");
request.get(baseURL + "/user/tasks/withUp").end(function(err, res) {
var upTodo;
upTodo = res.body;
return expect(upTodo.completed).to.equal(true);
});
return done();
});
});
it("creates an uncompleted todo when using down url", function(done) {
return request.post(baseURL + "/user/tasks/withDown/down").send({
type: "todo",
text: "withDown"
}).end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/withDown").end(function(err, res) {
var downTodo;
downTodo = res.body;
expect(downTodo.completed).to.equal(false);
return done();
});
});
});
return it("Creates and scores down a habit when using down url", function(done) {
var downHabit;
downHabit = void 0;
return request.post(baseURL + "/user/tasks/habitWithDown/down").send({
type: "habit",
text: "testTitle",
it("creates a completed a todo overriding the complete parameter when using up url", function(done) {
return request.post(baseURL + "/user/tasks/withUpWithComplete/up").send({
type: "todo",
text: "withUpWithComplete",
completed: false
}).end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/withUpWithComplete").end(function(err, res) {
var upTodo;
upTodo = res.body;
expect(upTodo.completed).to.equal(true);
return done();
});
});
});
return it("Creates an uncompleted todo overriding the completed parameter when using down url", function(done) {
return request.post(baseURL + "/user/tasks/withDownWithUncomplete/down").send({
type: "todo",
text: "withDownWithUncomplete",
completed: true
}).end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/habitWithDown").end(function(err, res) {
downHabit = res.body;
expect(downHabit.value).to.have.at.most(-1);
expect(downHabit.type).to.equal("habit");
return request.get(baseURL + "/user/tasks/withDownWithUncomplete").end(function(err, res) {
var downTodo;
downTodo = res.body;
expect(downTodo.completed).to.equal(false);
return done();
});
});
});
});
}).call(this);
context("Todo that already exists", function() {
it("It completes a todo when using up url", function(done) {
return request.post(baseURL + "/user/tasks").send({
type: "todo",
text: "Sample Todo"
}).end(function(err, res) {
var unCompletedTodo;
expectCode(res, 200);
unCompletedTodo = res.body;
expect(unCompletedTodo.completed).to.equal(false);
return request.post(baseURL + "/user/tasks/" + unCompletedTodo._id + "/up").end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/" + unCompletedTodo._id).end(function(err, res) {
unCompletedTodo = res.body;
expect(unCompletedTodo.completed).to.equal(true);
return done();
});
});
});
});
return it("It uncompletes a todo when using down url", function(done) {
return request.post(baseURL + "/user/tasks").send({
type: "todo",
text: "Sample Todo",
completed: true
}).end(function(err, res) {
var completedTodo;
expectCode(res, 200);
completedTodo = res.body;
expect(completedTodo.completed).to.equal(true);
return request.post(baseURL + "/user/tasks/" + completedTodo._id + "/down").end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/" + completedTodo._id).end(function(err, res) {
completedTodo = res.body;
expect(completedTodo.completed).to.equal(false);
return done();
});
});
});
});
});
it("Creates and scores up a habit when using up url", function(done) {
var upHabit;
upHabit = void 0;
return request.post(baseURL + "/user/tasks/habitWithUp/up").send({
type: "habit",
text: "testTitle",
completed: true
}).end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/habitWithUp").end(function(err, res) {
upHabit = res.body;
expect(upHabit.value).to.be.at.least(1);
expect(upHabit.type).to.equal("habit");
return done();
});
});
});
return it("Creates and scores down a habit when using down url", function(done) {
var downHabit;
downHabit = void 0;
return request.post(baseURL + "/user/tasks/habitWithDown/down").send({
type: "habit",
text: "testTitle",
completed: true
}).end(function(err, res) {
expectCode(res, 200);
return request.get(baseURL + "/user/tasks/habitWithDown").end(function(err, res) {
downHabit = res.body;
expect(downHabit.value).to.have.at.most(-1);
expect(downHabit.type).to.equal("habit");
return done();
});
});
});
});

View File

@@ -1,54 +1,50 @@
(function() {
'use strict';
var app, payments;
var app, payments;
payments = require("../../website/src/controllers/payments");
payments = require("../../website/src/controllers/payments");
app = require("../../website/src/server");
app = require("../../website/src/server");
describe("Subscriptions", function() {
before(function(done) {
return registerNewUser(done, true);
});
return it("Handles unsubscription", function(done) {
var cron;
cron = function() {
user.lastCron = moment().subtract(1, "d");
return user.fns.cron();
};
expect(user.purchased.plan.customerId).to.not.exist;
payments.createSubscription({
user: user,
customerId: "123",
paymentMethod: "Stripe",
sub: {
key: 'basic_6mo'
}
});
expect(user.purchased.plan.customerId).to.exist;
shared.wrap(user);
cron();
expect(user.purchased.plan.customerId).to.exist;
payments.cancelSubscription({
user: user
});
cron();
expect(user.purchased.plan.customerId).to.exist;
expect(user.purchased.plan.dateTerminated).to.exist;
user.purchased.plan.dateTerminated = moment().subtract(2, "d");
cron();
expect(user.purchased.plan.customerId).to.not.exist;
payments.createSubscription({
user: user,
customerId: "123",
paymentMethod: "Stripe",
sub: {
key: 'basic_6mo'
}
});
expect(user.purchased.plan.dateTerminated).to.not.exist;
return done();
});
describe("Subscriptions", function() {
before(function(done) {
return registerNewUser(done, true);
});
}).call(this);
return it("Handles unsubscription", function(done) {
var cron;
cron = function() {
user.lastCron = moment().subtract(1, "d");
return user.fns.cron();
};
expect(user.purchased.plan.customerId).to.not.exist;
payments.createSubscription({
user: user,
customerId: "123",
paymentMethod: "Stripe",
sub: {
key: 'basic_6mo'
}
});
expect(user.purchased.plan.customerId).to.exist;
shared.wrap(user);
cron();
expect(user.purchased.plan.customerId).to.exist;
payments.cancelSubscription({
user: user
});
cron();
expect(user.purchased.plan.customerId).to.exist;
expect(user.purchased.plan.dateTerminated).to.exist;
user.purchased.plan.dateTerminated = moment().subtract(2, "d");
cron();
expect(user.purchased.plan.customerId).to.not.exist;
payments.createSubscription({
user: user,
customerId: "123",
paymentMethod: "Stripe",
sub: {
key: 'basic_6mo'
}
});
expect(user.purchased.plan.dateTerminated).to.not.exist;
return done();
});
});

View File

@@ -1,91 +1,87 @@
(function() {
'use strict';
require("../../website/src/server");
require("../../website/src/server");
describe("Todos", function() {
before(function(done) {
return registerNewUser(done, true);
describe("Todos", function() {
before(function(done) {
return registerNewUser(done, true);
});
beforeEach(function(done) {
return User.findById(user._id, function(err, _user) {
var user;
user = _user;
shared.wrap(user);
return done();
});
beforeEach(function(done) {
return User.findById(user._id, function(err, _user) {
var user;
user = _user;
shared.wrap(user);
return done();
});
});
return it("Archives old todos", function(done) {
var numTasks;
numTasks = _.size(user.todos);
return request.post(baseURL + "/user/batch-update?_v=999").send([
});
return it("Archives old todos", function(done) {
var numTasks;
numTasks = _.size(user.todos);
return request.post(baseURL + "/user/batch-update?_v=999").send([
{
op: "addTask",
body: {
type: "todo"
}
}, {
op: "addTask",
body: {
type: "todo"
}
}, {
op: "addTask",
body: {
type: "todo"
}
}
]).end(function(err, res) {
expectCode(res, 200);
expect(_.size(res.body.todos)).to.equal(numTasks + 3);
numTasks += 3;
return request.post(baseURL + "/user/batch-update?_v=998").send([
{
op: "addTask",
body: {
type: "todo"
op: "score",
params: {
direction: "up",
id: res.body.todos[0].id
}
}, {
op: "addTask",
body: {
type: "todo"
op: "score",
params: {
direction: "up",
id: res.body.todos[1].id
}
}, {
op: "addTask",
body: {
type: "todo"
op: "score",
params: {
direction: "up",
id: res.body.todos[2].id
}
}
]).end(function(err, res) {
expectCode(res, 200);
expect(_.size(res.body.todos)).to.equal(numTasks + 3);
numTasks += 3;
return request.post(baseURL + "/user/batch-update?_v=998").send([
expect(_.size(res.body.todos)).to.equal(numTasks);
return request.post(baseURL + "/user/batch-update?_v=997").send([
{
op: "score",
op: "updateTask",
params: {
direction: "up",
id: res.body.todos[0].id
},
body: {
dateCompleted: moment().subtract(4, "days")
}
}, {
op: "score",
op: "updateTask",
params: {
direction: "up",
id: res.body.todos[1].id
}
}, {
op: "score",
params: {
direction: "up",
id: res.body.todos[2].id
},
body: {
dateCompleted: moment().subtract(4, "days")
}
}
]).end(function(err, res) {
expectCode(res, 200);
expect(_.size(res.body.todos)).to.equal(numTasks);
return request.post(baseURL + "/user/batch-update?_v=997").send([
{
op: "updateTask",
params: {
id: res.body.todos[0].id
},
body: {
dateCompleted: moment().subtract(4, "days")
}
}, {
op: "updateTask",
params: {
id: res.body.todos[1].id
},
body: {
dateCompleted: moment().subtract(4, "days")
}
}
]).end(function(err, res) {
expect(_.size(res.body.todos)).to.equal(numTasks - 2);
return done();
});
expect(_.size(res.body.todos)).to.equal(numTasks - 2);
return done();
});
});
});
});
}).call(this);
});

File diff suppressed because it is too large Load Diff

View File

@@ -1,164 +1,161 @@
(function() {
var $w, _, id, modes, shared, user;
var $w, _, id, modes, shared, user;
shared = require('../../../common/script/index.js');
shared = require('../../../common/script/index.js');
_ = require('lodash');
_ = require('lodash');
$w = function(s) {
return s.split(' ');
};
$w = function(s) {
return s.split(' ');
};
id = shared.uuid();
id = shared.uuid();
user = {
stats: {
"class": 'warrior',
lvl: 1,
hp: 50,
gp: 0,
exp: 10,
user = {
stats: {
"class": 'warrior',
lvl: 1,
hp: 50,
gp: 0,
exp: 10,
per: 0,
int: 0,
con: 0,
str: 0,
buffs: {
per: 0,
int: 0,
con: 0,
str: 0,
buffs: {
str: 0
},
training: {
int: 0,
con: 0,
per: 0,
str: 0
}
},
preferences: {
automaticAllocation: false
},
party: {
quest: {
key: 'evilsanta',
progress: {
up: 0,
down: 0
}
}
},
achievements: {},
items: {
eggs: {},
hatchingPotions: {},
food: {},
gear: {
equipped: {
weapon: 'weapon_warrior_4',
armor: 'armor_warrior_4',
shield: 'shield_warrior_4',
head: 'head_warrior_4'
}
}
},
habits: [
{
id: 'a',
value: 1,
type: 'habit',
attribute: 'str'
}
],
dailys: [
{
id: 'b',
value: 1,
type: 'daily',
attribute: 'str'
}
],
todos: [
{
id: 'c',
value: 1,
type: 'todo',
attribute: 'con'
}, {
id: 'd',
value: 1,
type: 'todo',
attribute: 'per'
}, {
id: 'e',
value: 1,
type: 'todo',
attribute: 'int'
}
],
rewards: []
};
modes = {
flat: _.cloneDeep(user),
classbased_warrior: _.cloneDeep(user),
classbased_rogue: _.cloneDeep(user),
classbased_wizard: _.cloneDeep(user),
classbased_healer: _.cloneDeep(user),
taskbased: _.cloneDeep(user)
};
modes.classbased_warrior.stats["class"] = 'warrior';
modes.classbased_rogue.stats["class"] = 'rogue';
modes.classbased_wizard.stats["class"] = 'wizard';
modes.classbased_healer.stats["class"] = 'healer';
_.each($w('flat classbased_warrior classbased_rogue classbased_wizard classbased_healer taskbased'), function(mode) {
_.merge(modes[mode].preferences, {
automaticAllocation: true,
allocationMode: mode.indexOf('classbased') === 0 ? 'classbased' : mode
});
return shared.wrap(modes[mode]);
});
console.log("\n\n================================================");
console.log("New Simulation");
console.log("================================================\n\n");
_.times([20], function(lvl) {
console.log("[lvl " + lvl + "]\n--------------\n");
return _.each($w('flat classbased_warrior classbased_rogue classbased_wizard classbased_healer taskbased'), function(mode) {
var str, u;
u = modes[mode];
u.stats.exp = shared.tnl(lvl) + 1;
if (mode === 'taskbased') {
_.merge(u.stats, {
per: 0,
int: 0,
con: 0,
int: 0,
str: 0
});
}
u.habits[0].attribute = u.fns.randomVal({
str: 'str',
int: 'int',
per: 'per',
con: 'con'
});
u.ops.score({
params: {
id: u.habits[0].id
},
training: {
int: 0,
con: 0,
per: 0,
str: 0
}
},
preferences: {
automaticAllocation: false
},
party: {
quest: {
key: 'evilsanta',
progress: {
up: 0,
down: 0
}
}
},
achievements: {},
items: {
eggs: {},
hatchingPotions: {},
food: {},
gear: {
equipped: {
weapon: 'weapon_warrior_4',
armor: 'armor_warrior_4',
shield: 'shield_warrior_4',
head: 'head_warrior_4'
}
}
},
habits: [
{
id: 'a',
value: 1,
type: 'habit',
attribute: 'str'
}
],
dailys: [
{
id: 'b',
value: 1,
type: 'daily',
attribute: 'str'
}
],
todos: [
{
id: 'c',
value: 1,
type: 'todo',
attribute: 'con'
}, {
id: 'd',
value: 1,
type: 'todo',
attribute: 'per'
}, {
id: 'e',
value: 1,
type: 'todo',
attribute: 'int'
}
],
rewards: []
};
modes = {
flat: _.cloneDeep(user),
classbased_warrior: _.cloneDeep(user),
classbased_rogue: _.cloneDeep(user),
classbased_wizard: _.cloneDeep(user),
classbased_healer: _.cloneDeep(user),
taskbased: _.cloneDeep(user)
};
modes.classbased_warrior.stats["class"] = 'warrior';
modes.classbased_rogue.stats["class"] = 'rogue';
modes.classbased_wizard.stats["class"] = 'wizard';
modes.classbased_healer.stats["class"] = 'healer';
_.each($w('flat classbased_warrior classbased_rogue classbased_wizard classbased_healer taskbased'), function(mode) {
_.merge(modes[mode].preferences, {
automaticAllocation: true,
allocationMode: mode.indexOf('classbased') === 0 ? 'classbased' : mode
direction: 'up'
});
return shared.wrap(modes[mode]);
u.fns.updateStats(u.stats);
str = mode + (mode === 'taskbased' ? " (" + u.habits[0].attribute + ")" : "");
return console.log(str, _.pick(u.stats, $w('per int con str')));
});
console.log("\n\n================================================");
console.log("New Simulation");
console.log("================================================\n\n");
_.times([20], function(lvl) {
console.log("[lvl " + lvl + "]\n--------------\n");
return _.each($w('flat classbased_warrior classbased_rogue classbased_wizard classbased_healer taskbased'), function(mode) {
var str, u;
u = modes[mode];
u.stats.exp = shared.tnl(lvl) + 1;
if (mode === 'taskbased') {
_.merge(u.stats, {
per: 0,
con: 0,
int: 0,
str: 0
});
}
u.habits[0].attribute = u.fns.randomVal({
str: 'str',
int: 'int',
per: 'per',
con: 'con'
});
u.ops.score({
params: {
id: u.habits[0].id
},
direction: 'up'
});
u.fns.updateStats(u.stats);
str = mode + (mode === 'taskbased' ? " (" + u.habits[0].attribute + ")" : "");
return console.log(str, _.pick(u.stats, $w('per int con str')));
});
});
}).call(this);
});

View File

@@ -1,294 +1,291 @@
(function() {
var _, clearUser, id, party, s, shared, task, user;
var _, clearUser, id, party, s, shared, task, user;
shared = require('../../../common/script/index.js');
shared = require('../../../common/script/index.js');
_ = require('lodash');
_ = require('lodash');
id = shared.uuid();
id = shared.uuid();
user = {
stats: {
"class": 'warrior',
buffs: {
per: 0,
int: 0,
con: 0,
str: 0
}
},
party: {
quest: {
key: 'evilsanta',
progress: {
up: 0,
down: 0
}
}
},
preferences: {
automaticAllocation: false
},
achievements: {},
flags: {
levelDrops: {}
},
items: {
eggs: {},
hatchingPotions: {},
food: {},
quests: {},
gear: {
equipped: {
weapon: 'weapon_warrior_4',
armor: 'armor_warrior_4',
shield: 'shield_warrior_4',
head: 'head_warrior_4'
}
}
},
habits: [
shared.taskDefaults({
id: id,
value: 0
})
],
dailys: [
{
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}
],
todos: [],
rewards: []
};
shared.wrap(user);
s = user.stats;
task = user.tasks[id];
party = [user];
console.log("\n\n================================================");
console.log("New Simulation");
console.log("================================================\n\n");
clearUser = function(lvl) {
if (lvl == null) {
lvl = 1;
}
_.merge(user.stats, {
exp: 0,
gp: 0,
hp: 50,
lvl: lvl,
str: lvl * 1.5,
con: lvl * 1.5,
per: lvl * 1.5,
int: lvl * 1.5,
mp: 100
});
_.merge(s.buffs, {
str: 0,
con: 0,
user = {
stats: {
"class": 'warrior',
buffs: {
per: 0,
int: 0,
per: 0
});
_.merge(user.party.quest.progress, {
up: 0,
down: 0
});
return user.items.lastDrop = {
count: 0
};
};
con: 0,
str: 0
}
},
party: {
quest: {
key: 'evilsanta',
progress: {
up: 0,
down: 0
}
}
},
preferences: {
automaticAllocation: false
},
achievements: {},
flags: {
levelDrops: {}
},
items: {
eggs: {},
hatchingPotions: {},
food: {},
quests: {},
gear: {
equipped: {
weapon: 'weapon_warrior_4',
armor: 'armor_warrior_4',
shield: 'shield_warrior_4',
head: 'head_warrior_4'
}
}
},
habits: [
shared.taskDefaults({
id: id,
value: 0
})
],
dailys: [
{
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}, {
"text": "1"
}
],
todos: [],
rewards: []
};
_.each([1, 25, 50, 75, 100], function(lvl) {
console.log("[LEVEL " + lvl + "] (" + (lvl * 2) + " points total in every attr)\n\n");
_.each({
red: -25,
yellow: 0,
green: 35
}, function(taskVal, color) {
var _party, b4, str;
console.log("[task.value = " + taskVal + " (" + color + ")]");
console.log("direction\texpΔ\t\thpΔ\tgpΔ\ttask.valΔ\ttask.valΔ bonus\t\tboss-hit");
_.each(['up', 'down'], function(direction) {
var b4, delta;
clearUser(lvl);
b4 = {
hp: s.hp,
taskVal: taskVal
};
task.value = taskVal;
if (direction === 'up') {
task.type = 'daily';
}
delta = user.ops.score({
params: {
id: id,
direction: direction
}
});
return console.log((direction === 'up' ? '↑' : '↓') + "\t\t" + s.exp + "/" + (shared.tnl(s.lvl)) + "\t\t" + ((b4.hp - s.hp).toFixed(1)) + "\t" + (s.gp.toFixed(1)) + "\t" + (delta.toFixed(1)) + "\t\t" + ((task.value - b4.taskVal - delta).toFixed(1)) + "\t\t\t" + (user.party.quest.progress.up.toFixed(1)));
});
str = '- [Wizard]';
task.value = taskVal;
clearUser(lvl);
b4 = {
taskVal: taskVal
};
shared.content.spells.wizard.fireball.cast(user, task);
str += "\tfireball(task.valΔ:" + ((task.value - taskVal).toFixed(1)) + " exp:" + (s.exp.toFixed(1)) + " bossHit:" + (user.party.quest.progress.up.toFixed(2)) + ")";
task.value = taskVal;
clearUser(lvl);
_party = [
user, {
stats: {
mp: 0
}
}
];
shared.content.spells.wizard.mpheal.cast(user, _party);
str += "\t| mpheal(mp:" + _party[1].stats.mp + ")";
task.value = taskVal;
clearUser(lvl);
shared.content.spells.wizard.earth.cast(user, party);
str += "\t\t\t\t| earth(buffs.int:" + s.buffs.int + ")";
s.buffs.int = 0;
task.value = taskVal;
clearUser(lvl);
shared.content.spells.wizard.frost.cast(user, {});
str += "\t\t\t| frost(N/A)";
console.log(str);
str = '- [Warrior]';
task.value = taskVal;
clearUser(lvl);
shared.content.spells.warrior.smash.cast(user, task);
b4 = {
taskVal: taskVal
};
str += "\tsmash(task.valΔ:" + ((task.value - taskVal).toFixed(1)) + ")";
task.value = taskVal;
clearUser(lvl);
shared.content.spells.warrior.defensiveStance.cast(user, {});
str += "\t\t| defensiveStance(buffs.con:" + s.buffs.con + ")";
s.buffs.con = 0;
task.value = taskVal;
clearUser(lvl);
shared.content.spells.warrior.valorousPresence.cast(user, party);
str += "\t\t\t| valorousPresence(buffs.str:" + s.buffs.str + ")";
s.buffs.str = 0;
task.value = taskVal;
clearUser(lvl);
shared.content.spells.warrior.intimidate.cast(user, party);
str += "\t\t| intimidate(buffs.con:" + s.buffs.con + ")";
s.buffs.con = 0;
console.log(str);
str = '- [Rogue]';
task.value = taskVal;
clearUser(lvl);
shared.content.spells.rogue.pickPocket.cast(user, task);
str += "\tpickPocket(gp:" + (s.gp.toFixed(1)) + ")";
task.value = taskVal;
clearUser(lvl);
shared.content.spells.rogue.backStab.cast(user, task);
b4 = {
taskVal: taskVal
};
str += "\t\t| backStab(task.valΔ:" + ((task.value - b4.taskVal).toFixed(1)) + " exp:" + (s.exp.toFixed(1)) + " gp:" + (s.gp.toFixed(1)) + ")";
task.value = taskVal;
clearUser(lvl);
shared.content.spells.rogue.toolsOfTrade.cast(user, party);
str += "\t| toolsOfTrade(buffs.per:" + s.buffs.per + ")";
s.buffs.per = 0;
task.value = taskVal;
clearUser(lvl);
shared.content.spells.rogue.stealth.cast(user, {});
str += "\t\t| stealth(avoiding " + user.stats.buffs.stealth + " tasks)";
user.stats.buffs.stealth = 0;
console.log(str);
str = '- [Healer]';
task.value = taskVal;
clearUser(lvl);
s.hp = 0;
shared.content.spells.healer.heal.cast(user, {});
str += "\theal(hp:" + (s.hp.toFixed(1)) + ")";
task.value = taskVal;
clearUser(lvl);
shared.content.spells.healer.brightness.cast(user, {});
b4 = {
taskVal: taskVal
};
str += "\t\t\t| brightness(task.valΔ:" + ((task.value - b4.taskVal).toFixed(1)) + ")";
task.value = taskVal;
clearUser(lvl);
shared.content.spells.healer.protectAura.cast(user, party);
str += "\t\t\t| protectAura(buffs.con:" + s.buffs.con + ")";
s.buffs.con = 0;
task.value = taskVal;
clearUser(lvl);
s.hp = 0;
shared.content.spells.healer.heallAll.cast(user, party);
str += "\t\t| heallAll(hp:" + (s.hp.toFixed(1)) + ")";
console.log(str);
return console.log('\n');
});
return console.log('------------------------------------------------------------');
shared.wrap(user);
s = user.stats;
task = user.tasks[id];
party = [user];
console.log("\n\n================================================");
console.log("New Simulation");
console.log("================================================\n\n");
clearUser = function(lvl) {
if (lvl == null) {
lvl = 1;
}
_.merge(user.stats, {
exp: 0,
gp: 0,
hp: 50,
lvl: lvl,
str: lvl * 1.5,
con: lvl * 1.5,
per: lvl * 1.5,
int: lvl * 1.5,
mp: 100
});
_.merge(s.buffs, {
str: 0,
con: 0,
int: 0,
per: 0
});
_.merge(user.party.quest.progress, {
up: 0,
down: 0
});
return user.items.lastDrop = {
count: 0
};
};
_.each([1, 25, 50, 75, 100], function(lvl) {
console.log("[LEVEL " + lvl + "] (" + (lvl * 2) + " points total in every attr)\n\n");
_.each({
red: -25,
yellow: 0,
green: 35
}, function(taskVal, color) {
var _party, b4, str;
console.log("[task.value = " + taskVal + " (" + color + ")]");
console.log("direction\texpΔ\t\thpΔ\tgpΔ\ttask.valΔ\ttask.valΔ bonus\t\tboss-hit");
_.each(['up', 'down'], function(direction) {
var b4, delta;
clearUser(lvl);
b4 = {
hp: s.hp,
taskVal: taskVal
};
task.value = taskVal;
if (direction === 'up') {
task.type = 'daily';
}
delta = user.ops.score({
params: {
id: id,
direction: direction
}
});
return console.log((direction === 'up' ? '↑' : '↓') + "\t\t" + s.exp + "/" + (shared.tnl(s.lvl)) + "\t\t" + ((b4.hp - s.hp).toFixed(1)) + "\t" + (s.gp.toFixed(1)) + "\t" + (delta.toFixed(1)) + "\t\t" + ((task.value - b4.taskVal - delta).toFixed(1)) + "\t\t\t" + (user.party.quest.progress.up.toFixed(1)));
});
str = '- [Wizard]';
task.value = taskVal;
clearUser(lvl);
b4 = {
taskVal: taskVal
};
shared.content.spells.wizard.fireball.cast(user, task);
str += "\tfireball(task.valΔ:" + ((task.value - taskVal).toFixed(1)) + " exp:" + (s.exp.toFixed(1)) + " bossHit:" + (user.party.quest.progress.up.toFixed(2)) + ")";
task.value = taskVal;
clearUser(lvl);
_party = [
user, {
stats: {
mp: 0
}
}
];
shared.content.spells.wizard.mpheal.cast(user, _party);
str += "\t| mpheal(mp:" + _party[1].stats.mp + ")";
task.value = taskVal;
clearUser(lvl);
shared.content.spells.wizard.earth.cast(user, party);
str += "\t\t\t\t| earth(buffs.int:" + s.buffs.int + ")";
s.buffs.int = 0;
task.value = taskVal;
clearUser(lvl);
shared.content.spells.wizard.frost.cast(user, {});
str += "\t\t\t| frost(N/A)";
console.log(str);
str = '- [Warrior]';
task.value = taskVal;
clearUser(lvl);
shared.content.spells.warrior.smash.cast(user, task);
b4 = {
taskVal: taskVal
};
str += "\tsmash(task.valΔ:" + ((task.value - taskVal).toFixed(1)) + ")";
task.value = taskVal;
clearUser(lvl);
shared.content.spells.warrior.defensiveStance.cast(user, {});
str += "\t\t| defensiveStance(buffs.con:" + s.buffs.con + ")";
s.buffs.con = 0;
task.value = taskVal;
clearUser(lvl);
shared.content.spells.warrior.valorousPresence.cast(user, party);
str += "\t\t\t| valorousPresence(buffs.str:" + s.buffs.str + ")";
s.buffs.str = 0;
task.value = taskVal;
clearUser(lvl);
shared.content.spells.warrior.intimidate.cast(user, party);
str += "\t\t| intimidate(buffs.con:" + s.buffs.con + ")";
s.buffs.con = 0;
console.log(str);
str = '- [Rogue]';
task.value = taskVal;
clearUser(lvl);
shared.content.spells.rogue.pickPocket.cast(user, task);
str += "\tpickPocket(gp:" + (s.gp.toFixed(1)) + ")";
task.value = taskVal;
clearUser(lvl);
shared.content.spells.rogue.backStab.cast(user, task);
b4 = {
taskVal: taskVal
};
str += "\t\t| backStab(task.valΔ:" + ((task.value - b4.taskVal).toFixed(1)) + " exp:" + (s.exp.toFixed(1)) + " gp:" + (s.gp.toFixed(1)) + ")";
task.value = taskVal;
clearUser(lvl);
shared.content.spells.rogue.toolsOfTrade.cast(user, party);
str += "\t| toolsOfTrade(buffs.per:" + s.buffs.per + ")";
s.buffs.per = 0;
task.value = taskVal;
clearUser(lvl);
shared.content.spells.rogue.stealth.cast(user, {});
str += "\t\t| stealth(avoiding " + user.stats.buffs.stealth + " tasks)";
user.stats.buffs.stealth = 0;
console.log(str);
str = '- [Healer]';
task.value = taskVal;
clearUser(lvl);
s.hp = 0;
shared.content.spells.healer.heal.cast(user, {});
str += "\theal(hp:" + (s.hp.toFixed(1)) + ")";
task.value = taskVal;
clearUser(lvl);
shared.content.spells.healer.brightness.cast(user, {});
b4 = {
taskVal: taskVal
};
str += "\t\t\t| brightness(task.valΔ:" + ((task.value - b4.taskVal).toFixed(1)) + ")";
task.value = taskVal;
clearUser(lvl);
shared.content.spells.healer.protectAura.cast(user, party);
str += "\t\t\t| protectAura(buffs.con:" + s.buffs.con + ")";
s.buffs.con = 0;
task.value = taskVal;
clearUser(lvl);
s.hp = 0;
shared.content.spells.healer.heallAll.cast(user, party);
str += "\t\t| heallAll(hp:" + (s.hp.toFixed(1)) + ")";
console.log(str);
return console.log('\n');
});
return console.log('------------------------------------------------------------');
});
/*
_.each [1,25,50,75,100,125], (lvl) ->
console.log "[LEVEL #{lvl}] (#{lvl*2} points in every attr)\n\n"
_.each {red:-25,yellow:0,green:35}, (taskVal, color) ->
console.log "[task.value = #{taskVal} (#{color})]"
console.log "direction\texpΔ\t\thpΔ\tgpΔ\ttask.valΔ\ttask.valΔ bonus\t\tboss-hit"
_.each ['up','down'], (direction) ->
clearUser(lvl)
b4 = {hp:s.hp, taskVal}
task.value = taskVal
task.type = 'daily' if direction is 'up'
delta = user.ops.score params:{id, direction}
console.log "#{if direction is 'up' then '↑' else '↓'}\t\t#{s.exp}/#{shared.tnl(s.lvl)}\t\t#{(b4.hp-s.hp).toFixed(1)}\t#{s.gp.toFixed(1)}\t#{delta.toFixed(1)}\t\t#{(task.value-b4.taskVal-delta).toFixed(1)}\t\t\t#{user.party.quest.progress.up.toFixed(1)}"
/*
_.each [1,25,50,75,100,125], (lvl) ->
console.log "[LEVEL #{lvl}] (#{lvl*2} points in every attr)\n\n"
_.each {red:-25,yellow:0,green:35}, (taskVal, color) ->
console.log "[task.value = #{taskVal} (#{color})]"
console.log "direction\texpΔ\t\thpΔ\tgpΔ\ttask.valΔ\ttask.valΔ bonus\t\tboss-hit"
_.each ['up','down'], (direction) ->
clearUser(lvl)
b4 = {hp:s.hp, taskVal}
task.value = taskVal
task.type = 'daily' if direction is 'up'
delta = user.ops.score params:{id, direction}
console.log "#{if direction is 'up' then '↑' else '↓'}\t\t#{s.exp}/#{shared.tnl(s.lvl)}\t\t#{(b4.hp-s.hp).toFixed(1)}\t#{s.gp.toFixed(1)}\t#{delta.toFixed(1)}\t\t#{(task.value-b4.taskVal-delta).toFixed(1)}\t\t\t#{user.party.quest.progress.up.toFixed(1)}"
task.value = taskVal;clearUser(lvl)
shared.content.spells.rogue.stealth.cast(user,{})
console.log "\t\t| stealth(avoiding #{user.stats.buffs.stealth} tasks)"
user.stats.buffs.stealth = 0
task.value = taskVal;clearUser(lvl)
shared.content.spells.rogue.stealth.cast(user,{})
console.log "\t\t| stealth(avoiding #{user.stats.buffs.stealth} tasks)"
user.stats.buffs.stealth = 0
console.log user.dailys.length
*/
}).call(this);
console.log user.dailys.length
*/

View File

@@ -1,5 +1,3 @@
'use strict';
var shared = require('../../common/script/index.js');
shared.i18n.translations = require('../../website/src/libs/i18n.js').translations