Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions app/models/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function(mongoose) {
});

playerSchema.virtual('displayName').get(function(){
return this.fname + ' ' + this.nickname + ' ' + this.lname;
return this.fname + ' "' + this.nickname + '" ' + this.lname;
});

playerSchema.virtual('fullName').get(function(){
Expand Down Expand Up @@ -91,10 +91,7 @@ module.exports = function(mongoose) {
} else {
f('break');
}
} else {
console.log('neither one matches??????');
f();
}
}
}, function(err){
if (err && err != 'break') {
cb(err);
Expand Down
53 changes: 29 additions & 24 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
{
"name": "Ping-Pong",
"version": "1.0.0",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.3.7",
"ejs": "0.8.4",
"mongoose": "3.6.18",
"express-ejs-layouts": "0.3.1",
"stylus": "0.37.0",
"supertest": "0.7.1",
"expect.js": "0.2.0",
"nconf": "0.6.7",
"async": "0.2.9",
"nodemailer": "0.5.2",
"cron": "1.0.1",
"twitter": "0.2.2",
"winston": "0.7.2",
"mocha": "~1.13",
"MD5": "1.1.x"
}
}
{
"name": "Ping-Pong",
"version": "1.0.0",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.3.7",
"ejs": "0.8.4",
"mongoose": "3.6.18",
"express-ejs-layouts": "0.3.1",
"stylus": "0.37.0",
"nconf": "0.6.7",
"async": "0.2.9",
"nodemailer": "0.5.2",
"cron": "1.0.1",
"twitter": "0.2.2",
"winston": "0.7.2",
"MD5": "1.1.x"
},
"devDependencies": {
"expect.js": "0.2.0",
"supertest": "0.7.1",
"mocha": "~1.13",
"sandboxed-module": "~0.2.2",
"jasmine-node": "~1.11.0",
"jasmine-stealth": "0.0.13"
}
}
128 changes: 128 additions & 0 deletions spec/player.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// Dependencies
require('../app/node_modules/jasmine-stealth');
var sandbox = require('./../app/node_modules/sandboxed-module');
var realMongoose = require("./../app/node_modules/mongoose");
var md5 = jasmine.createSpy("MD5");
var mongoose = jasmine.createSpyObj("mongoose", ["Schema", "model", "count"]);
var schema = sandbox.require("./../app/models/Player", { requires: { MD5: md5 } });

// Setup spy methods
mongoose.Schema.andCallFake(function(){
return realMongoose.Schema.apply(realMongoose, arguments);
});
mongoose.model.andCallFake(function(name, schema){
if (name === "players"){
return realMongoose.model.apply(realMongoose, arguments);
} else if (name === "matches"){
return mongoose;
}
});
mongoose.count.andCallFake(function(params, cb){
cb(null, 12);
});

// Create fake players
var Player = schema(mongoose).Players;
var player = new Player({
fname: 'Test',
lname: 'Player',
nickname: 'Hotness',
email: "hotness@email.com",
wins: 6,
losses: 6,
streak: -1
});
var player2 = new Player({
fname: 'Foo',
lname: 'Baby',
nickname: 'Bar',
wins: 4,
losses: 4,
streak: 4
});

describe("Player", function(){
describe("#gravatar", function(){
beforeEach(function(done){
md5.when("hotness@email.com").thenReturn("md5hotness");
done();
});

it("should return a gravatar url", function(done){
expect(player.gravatar).toBe('http://www.gravatar.com/avatar/md5hotness?d=mm');
done();
});
});

describe("#displayName", function(){
it("should return a player's display name", function(done){
expect(player.displayName).toBe('Test "Hotness" Player');
done();
});
});

describe("#fullname", function(){
it("should return a player's full name", function(done){
expect(player.fullName).toBe("Test Player");
done();
});
});

describe("#matchesPlayed", function(){
it("should return the number of games a player has played", function(done){
expect(player.matchesPlayed).toBe(12);
done();
});
});

describe("#ratio", function(){
it("should return a player's win percentage", function(done){
expect(player.ratio).toBe((50).toFixed(1));
done();
});
});

describe("#currentStreak", function(){
it("should return a Lx when negative", function(done){
expect(player.currentStreak).toBe("L1");
done();
});

it("should return a Wx when positive", function(done){
expect(player2.currentStreak).toBe("W4");
done();
});
});

describe("#recalculateWins", function(){
beforeEach(function(done){
spyOn(player, "save").andCallFake(function(cb){
cb(null, player);
});
done();
});

it("should return the correct number of wins", function(done){
player.recalculateWins(function(err, p){
expect(p.wins).toBe(12);
done();
});
});
});

describe("#recalculateLosses", function(){
beforeEach(function(done){
spyOn(player, "save").andCallFake(function(cb){
cb(null, player);
});
done();
});

it("should return the correct number of losses", function(done){
player.recalculateLosses(function(err, p){
expect(p.losses).toBe(12);
done();
});
});
});
});