Added action tests

This commit is contained in:
Thaum Rystra
2023-11-16 14:00:26 +02:00
parent 6d8dfc2255
commit 375a84226d
2 changed files with 50 additions and 3 deletions

View File

@@ -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,

View 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);
}