Fixed failing tests

This commit is contained in:
Stefan Zermatten
2022-08-15 09:38:34 +02:00
parent ee0e764294
commit 263f2d8424
5 changed files with 46 additions and 34 deletions

View File

@@ -1,11 +1,53 @@
import '/imports/api/simpleSchemaConfig.js';
//import testTypes from './testTypes/index.js';
import { doActionWork } from './doAction.js';
import createAction from './tests/createAction.testFn.js';
import { CreatureLogSchema } from '/imports/api/creature/log/CreatureLogs.js';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
import Creatures from '/imports/api/creature/creatures/Creatures.js';
function cleanProp(prop){
let schema = CreatureProperties.simpleSchema(prop);
return schema.clean(prop);
}
function cleanCreature(creature){
let schema = Creatures.simpleSchema(creature);
return schema.clean(creature);
}
// Fake ActionContext to test actions with
const creatureId = 'actionTestCreatureId';
const creatureName = 'Action Test Creature';
const testActionContext = {
creature: cleanCreature({
_id: creatureId,
}),
log: CreatureLogSchema.clean({
creatureId: creatureId,
creatureName: creatureName,
}),
scope: {},
addLog(content) {
if (content.name || content.value){
this.log.content.push(content);
}
},
writeLog: () => { },
}
const action = cleanProp({
type: 'action',
});
const actionAncestors = [];
describe('Do Action', function(){
it('Does an empty action', function(){
doActionWork(createAction({properties: [{type: 'action'}]}));
doActionWork({
properties: [action],
ancestors: actionAncestors,
actionContext: testActionContext,
methodScope: {},
});
});
//testTypes.forEach(test => it(test.text, test.fn));
});

View File

@@ -1,26 +0,0 @@
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
import Creatures from '/imports/api/creature/creatures/Creatures.js';
export default function createAction({
creature = {_id: 'creatureId'},
targets = [],
properties = [],
ancestors = [],
method
} = {}){
properties = properties.map(cleanProp);
ancestors = ancestors.map(cleanProp);
creature = cleanCreature(creature);
ancestors = ancestors.map(cleanCreature);
return {creature, targets, properties, ancestors, method};
}
function cleanProp(prop){
let schema = CreatureProperties.simpleSchema(prop);
return schema.clean(prop);
}
function cleanCreature(creature){
let schema = Creatures.simpleSchema(creature);
return schema.clean(creature);
}

View File

@@ -1,6 +0,0 @@
import applyAction from './applyAction.testFn.js';
export default [{
text: 'Applies actions',
fn: applyAction,
},];

View File

@@ -124,6 +124,7 @@ const expectedMigratedAttribute = {
damage: 3,
value: 17,
constitutionMod: 2,
dirty: true,
}
const exampleAttack = {
@@ -221,6 +222,7 @@ describe('migrateProperty', function() {
prop: newAction,
reversed: true,
});
delete reversedAction.dirty;
assert.deepEqual(action, exampleAction, 'action should not be bashed');
assert.deepEqual(exampleAction, reversedAction, 'operation should be reversible');
});