Began actually testing :(
This commit is contained in:
34
rpg-docs/tests/mocha/server/model/character/character.js
Normal file
34
rpg-docs/tests/mocha/server/model/character/character.js
Normal file
@@ -0,0 +1,34 @@
|
||||
if (!(typeof MochaWeb === 'undefined')){
|
||||
MochaWeb.testOnly(function(){
|
||||
var charId;
|
||||
describe("Character", function(){
|
||||
describe("insert", function(){
|
||||
it("should create a character", function(done){
|
||||
Characters.insert({owner: "FWeGYyDY5jc4HuTh8"}, function(err, id){
|
||||
charId = id;
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("attribute.adjustment", function(){
|
||||
Characters.insert({owner: "FWeGYyDY5jc4HuTh8"}, function(err, id){
|
||||
charId = id;
|
||||
done(err);
|
||||
});
|
||||
it("should track attribute adjustments", function(){
|
||||
Characters.update(charId, {$set: {"strength.adjustment": -12}},{},function(err, num){
|
||||
console.log(num);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
it("should report the adjusted attribute correctly", function(){
|
||||
var val = Characters.findOne(charId).attributeValue("strength");
|
||||
chai.assert.equal(val, -12);
|
||||
val = 0;
|
||||
val = Characters.findOne(charId).fieldValue("strength");
|
||||
chai.assert.equal(val, -12);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
98
rpg-docs/tests/mocha/server/model/character/effects.js
vendored
Normal file
98
rpg-docs/tests/mocha/server/model/character/effects.js
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
var getEffect = function(charId, op, value){
|
||||
return {
|
||||
charId: charId,
|
||||
type: "inate",
|
||||
stat: "constitution",
|
||||
operation: op,
|
||||
value: value,
|
||||
parent: {
|
||||
id: charId,
|
||||
collection: "Characters"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (!(typeof MochaWeb === 'undefined')){
|
||||
MochaWeb.testOnly(function(){
|
||||
describe("Character", function(){
|
||||
Effects.remove({});
|
||||
Characters.remove({});
|
||||
var charId = Characters.insert({owner: "FWeGYyDY5jc4HuTh8"});
|
||||
var char = Characters.findOne(charId);
|
||||
var con = function(){return char.attributeValue("constitution")};
|
||||
|
||||
describe("effects", function(){
|
||||
describe("attributeValue", function(){
|
||||
|
||||
it("should be set to highest base", function(done){
|
||||
Effects.insert(getEffect(charId, "base", 10), function(err, id){
|
||||
if(err) done(err);
|
||||
});
|
||||
Effects.insert(getEffect(charId, "base", 6), function(err, id){
|
||||
if(err) done(err);
|
||||
});
|
||||
chai.assert.equal(10, con());
|
||||
done();
|
||||
});
|
||||
|
||||
it("should add", function(done){
|
||||
Effects.insert(getEffect(charId, "add", 2), function(err, id){
|
||||
if(err) done(err);
|
||||
});
|
||||
chai.assert.equal(12, con());
|
||||
done();
|
||||
});
|
||||
|
||||
it("should multiply", function(done){
|
||||
Effects.insert(getEffect(charId, "mul", 2), function(err, id){
|
||||
if(err) done(err);
|
||||
});
|
||||
chai.assert.equal(24, con());
|
||||
done();
|
||||
});
|
||||
|
||||
it("should be at least highest min", function(done){
|
||||
Effects.insert(getEffect(charId, "min", 22), function(err, id){
|
||||
if(err) done(err);
|
||||
});
|
||||
chai.assert.equal(con(), 24);
|
||||
Effects.insert(getEffect(charId, "min", 28), function(err, id){
|
||||
if(err) done(err);
|
||||
});
|
||||
chai.assert.equal(28, con());
|
||||
done();
|
||||
});
|
||||
|
||||
it("should be at most lowest max", function(done){
|
||||
Effects.insert(getEffect(charId, "max", 30), function(err, id){
|
||||
if(err) done(err);
|
||||
});
|
||||
chai.assert.equal(28, con());
|
||||
Effects.insert(getEffect(charId, "max", 5), function(err, id){
|
||||
if(err) done(err);
|
||||
});
|
||||
chai.assert.equal(5, con());
|
||||
done();
|
||||
});
|
||||
|
||||
it("should respect adjustment", function(done){
|
||||
Characters.update(charId, {$set: {"constitution.adjustment": -2}}, function(err, num){
|
||||
if(err) done(err);
|
||||
})
|
||||
chai.assert.equal(3, con());
|
||||
var conBase = char.attributeBase("constitution");
|
||||
chai.assert.equal(5, conBase)
|
||||
done();
|
||||
});
|
||||
|
||||
it("should be removed when the character is deleted", function(){
|
||||
Characters.remove(charId);
|
||||
var count = Effects.find({charId: charId}).count();
|
||||
chai.assert.equal(count, 0);
|
||||
})
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user