From a8c64a4524aeeac3ea403ade489c1be75c5252d0 Mon Sep 17 00:00:00 2001 From: Joby Walker Date: Sat, 2 Aug 2014 14:18:39 -0700 Subject: [PATCH 1/4] Use explicit get for 'quest' Quest is currently set to null when quests end. Mongoose wraps the value in an object so the test will fail. --- test/api.mocha.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/api.mocha.js b/test/api.mocha.js index 681c3aef98..9e71e48266 100644 --- a/test/api.mocha.js +++ b/test/api.mocha.js @@ -545,8 +545,9 @@ describe('API', function () { // Tavern Boss function(cb2){ Group.findById('habitrpg',function(err,tavern){ - expect(_.isEmpty(tavern.quest)).to.be(true); expect(user.items.pets['MantisShrimp-Base']).to.be(true); + //use an explicit get because mongoose wraps the null in an object + expect(_.isEmpty(tavern.get('quest'))).to.be(true); expect(user.items.mounts['MantisShrimp-Base']).to.be(true); expect(user.items.eggs.Dragon).to.be(2); expect(user.items.hatchingPotions.Shade).to.be(2); @@ -556,7 +557,8 @@ describe('API', function () { // Party Boss function(cb2){ - expect(_.isEmpty(_group.quest)).to.be(true); + //use an explicit get because mongoose wraps the null in an object + expect(_.isEmpty(_group.get('quest'))).to.be(true); expect(user.items.gear.owned.weapon_special_2).to.be(true); expect(user.items.eggs.Dragon).to.be(2); expect(user.items.hatchingPotions.Shade).to.be(2); From 937920c5a52ae020bd2566aa688a8fda60e62de2 Mon Sep 17 00:00:00 2001 From: Joby Walker Date: Sat, 2 Aug 2014 14:19:30 -0700 Subject: [PATCH 2/4] Pets are set to 5 not true. --- test/api.mocha.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/api.mocha.js b/test/api.mocha.js index 9e71e48266..f4464f1457 100644 --- a/test/api.mocha.js +++ b/test/api.mocha.js @@ -545,9 +545,9 @@ describe('API', function () { // Tavern Boss function(cb2){ Group.findById('habitrpg',function(err,tavern){ - expect(user.items.pets['MantisShrimp-Base']).to.be(true); //use an explicit get because mongoose wraps the null in an object expect(_.isEmpty(tavern.get('quest'))).to.be(true); + expect(user.items.pets['MantisShrimp-Base']).to.be(5); expect(user.items.mounts['MantisShrimp-Base']).to.be(true); expect(user.items.eggs.Dragon).to.be(2); expect(user.items.hatchingPotions.Shade).to.be(2); From 7e059fe4968b366b8fb531eed2a7bb6a3365dfe8 Mon Sep 17 00:00:00 2001 From: Joby Walker Date: Sat, 2 Aug 2014 14:20:42 -0700 Subject: [PATCH 3/4] Fetch each member to get correct data _group.members is an array of IDs not the user objects. Fetch each one to test. --- test/api.mocha.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/api.mocha.js b/test/api.mocha.js index f4464f1457..d0f32276bf 100644 --- a/test/api.mocha.js +++ b/test/api.mocha.js @@ -562,9 +562,17 @@ describe('API', function () { expect(user.items.gear.owned.weapon_special_2).to.be(true); expect(user.items.eggs.Dragon).to.be(2); expect(user.items.hatchingPotions.Shade).to.be(2); - expect(_.find(_group.members,{_id:party[0]._id}).items.gear.owned.weapon_special_2).to.be(true); - expect(_.find(_group.members,{_id:party[1]._id}).items.gear.owned.weapon_special_2).to.be(true); - expect(_.find(_group.members,{_id:party[2]._id}).items.gear.owned.weapon_special_2).to.not.be.ok(); + + // need to fetch users to get updated data + User.findById(party[0].id,function(err,mbr){ + expect(mbr.items.gear.owned.weapon_special_2).to.be(true); + }); + User.findById(party[1].id,function(err,mbr){ + expect(mbr.items.gear.owned.weapon_special_2).to.be(true); + }); + User.findById(party[2].id,function(err,mbr){ + expect(mbr.items.gear.owned.weapon_special_2).to.not.be.ok(); + }); cb2() } From 8d1b17320aea82970e8ac5b5e07d509010cef8fa Mon Sep 17 00:00:00 2001 From: Joby Walker Date: Wed, 6 Aug 2014 21:10:54 -0700 Subject: [PATCH 4/4] Update to wrap async calls with async.parallel --- test/api.mocha.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/test/api.mocha.js b/test/api.mocha.js index d0f32276bf..8ae20dc54c 100644 --- a/test/api.mocha.js +++ b/test/api.mocha.js @@ -564,18 +564,27 @@ describe('API', function () { expect(user.items.hatchingPotions.Shade).to.be(2); // need to fetch users to get updated data - User.findById(party[0].id,function(err,mbr){ - expect(mbr.items.gear.owned.weapon_special_2).to.be(true); - }); - User.findById(party[1].id,function(err,mbr){ - expect(mbr.items.gear.owned.weapon_special_2).to.be(true); - }); - User.findById(party[2].id,function(err,mbr){ - expect(mbr.items.gear.owned.weapon_special_2).to.not.be.ok(); - }); - cb2() + async.parallel([ + function(cb3){ + User.findById(party[0].id,function(err,mbr){ + expect(mbr.items.gear.owned.weapon_special_2).to.be(true); + cb3(); + }); + }, + function(cb3){ + User.findById(party[1].id,function(err,mbr){ + expect(mbr.items.gear.owned.weapon_special_2).to.be(true); + cb3(); + }); + }, + function(cb3){ + User.findById(party[2].id,function(err,mbr){ + expect(mbr.items.gear.owned.weapon_special_2).to.not.be.ok(); + cb3(); + }); + } + ], cb2); } - ],cb) } ],done);