Added action tests
This commit is contained in:
@@ -117,11 +117,11 @@ const ActionSchema = new SimpleSchema({
|
||||
'results.$.propId': {
|
||||
type: Object,
|
||||
},
|
||||
'result.$.targetIds': {
|
||||
'results.$.targetIds': {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'result.$.targetIds.$': {
|
||||
'results.$.targetIds.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
@@ -155,11 +155,13 @@ const ActionSchema = new SimpleSchema({
|
||||
|
||||
Actions.attachSchema(ActionSchema);
|
||||
|
||||
export default Actions;
|
||||
|
||||
/**
|
||||
* Create a new action ready to be run starting at the given property (or its 'before' triggers)
|
||||
* @param prop
|
||||
*/
|
||||
export async function createAction(prop) {
|
||||
export function createAction(prop) {
|
||||
const action: Action = {
|
||||
creatureId: prop.ancestors[0].id,
|
||||
rootPropId: prop._id,
|
||||
|
||||
45
app/imports/api/engine/actions/actions.test.ts
Normal file
45
app/imports/api/engine/actions/actions.test.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { assert } from 'chai';
|
||||
import '/imports/api/simpleSchemaConfig.js';
|
||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
|
||||
import { propsFromForest } from '/imports/api/properties/tests/propTestBuilder.testFn';
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures';
|
||||
import CreatureVariables from '/imports/api/creature/creatures/CreatureVariables';
|
||||
import Actions, { createAction } from '/imports/api/engine/actions/Actions';
|
||||
|
||||
describe('Interrupt action system', async function () {
|
||||
CreatureProperties.remove({});
|
||||
Creatures.remove({});
|
||||
CreatureVariables.remove({});
|
||||
const creatureId = await Creatures.insertAsync({
|
||||
name: 'action test creature',
|
||||
owner: Random.id(),
|
||||
});
|
||||
await insertActionTestProps();
|
||||
|
||||
it('creates an action', async function () {
|
||||
const note1 = await CreatureProperties.findOneAsync(note1Id);
|
||||
const actionId = await createAction(note1);
|
||||
const action = await Actions.findOneAsync(actionId);
|
||||
console.log(action);
|
||||
});
|
||||
});
|
||||
|
||||
const creatureId = Random.id();
|
||||
const note1Id = Random.id();
|
||||
|
||||
const propForest = [
|
||||
{
|
||||
_id: note1Id,
|
||||
type: 'note',
|
||||
summary: {
|
||||
text: 'Note 1 summary. 1 + 1 = {1 + 1}'
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
function insertActionTestProps() {
|
||||
const promises = propsFromForest(propForest, [{ id: creatureId, collection: 'creatures' }]).map(prop => {
|
||||
return CreatureProperties.insertAsync(prop);
|
||||
});
|
||||
return Promise.all(promises);
|
||||
}
|
||||
Reference in New Issue
Block a user