From 375a84226d02c6dee123dbbaffa5d1a6c20b5ec6 Mon Sep 17 00:00:00 2001 From: Thaum Rystra <9525416+ThaumRystra@users.noreply.github.com> Date: Thu, 16 Nov 2023 14:00:26 +0200 Subject: [PATCH] Added action tests --- app/imports/api/engine/actions/Actions.ts | 8 ++-- .../api/engine/actions/actions.test.ts | 45 +++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 app/imports/api/engine/actions/actions.test.ts diff --git a/app/imports/api/engine/actions/Actions.ts b/app/imports/api/engine/actions/Actions.ts index f25fe120..fe7095db 100644 --- a/app/imports/api/engine/actions/Actions.ts +++ b/app/imports/api/engine/actions/Actions.ts @@ -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, diff --git a/app/imports/api/engine/actions/actions.test.ts b/app/imports/api/engine/actions/actions.test.ts new file mode 100644 index 00000000..5169b2c4 --- /dev/null +++ b/app/imports/api/engine/actions/actions.test.ts @@ -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); +}