diff --git a/app/imports/api/engine/action/ActionEngine.test.ts b/app/imports/api/engine/action/ActionEngine.test.ts index 22d316d7..9d079adc 100644 --- a/app/imports/api/engine/action/ActionEngine.test.ts +++ b/app/imports/api/engine/action/ActionEngine.test.ts @@ -125,7 +125,6 @@ describe('Interrupt action system', function () { name: 'New Roll', value: '7d1 [1, 1, 1, 1, 1, 1, 1] + 9\n**16**', inline: true, - silenced: undefined, }, { value: 'rollVar: 16' } diff --git a/app/imports/api/engine/action/applyProperties/applyFolderProperty.test.ts b/app/imports/api/engine/action/applyProperties/applyFolderProperty.test.ts new file mode 100644 index 00000000..3eec1b2c --- /dev/null +++ b/app/imports/api/engine/action/applyProperties/applyFolderProperty.test.ts @@ -0,0 +1,49 @@ +import { assert } from 'chai'; +import { + allMutations, + createTestCreature, + getRandomIds, + removeAllCreaturesAndProps, + runActionById +} from '/imports/api/engine/action/functions/actionEngineTest.testFn'; + +const [ + creatureId, folderId +] = getRandomIds(100); + +const actionTestCreature = { + _id: creatureId, + props: [ + { + _id: folderId, + type: 'folder', + children: [{ + type: 'note', + summary: { text: 'this should run' }, + }], + }, + ], +} + +describe('Apply folder properties', function () { + // Increase timeout + this.timeout(8000); + + before(async function () { + await removeAllCreaturesAndProps(); + await createTestCreature(actionTestCreature); + }); + + it('Applies the children of the folder', async function () { + const action = await runActionById(folderId); + assert.exists(action); + assert.deepEqual(allMutations(action), [{ + contents: [ + { + value: 'this should run' + } + ], + targetIds: [], + }]); + }); +}); diff --git a/app/imports/api/engine/action/applyProperties/applyNoteProperty.test.ts b/app/imports/api/engine/action/applyProperties/applyNoteProperty.test.ts new file mode 100644 index 00000000..e7ec36e0 --- /dev/null +++ b/app/imports/api/engine/action/applyProperties/applyNoteProperty.test.ts @@ -0,0 +1,48 @@ +import { assert } from 'chai'; +import { + allMutations, + createTestCreature, + getRandomIds, + removeAllCreaturesAndProps, + runActionById +} from '/imports/api/engine/action/functions/actionEngineTest.testFn'; + +const [ + creatureId, noteId +] = getRandomIds(2); + +const actionTestCreature = { + _id: creatureId, + props: [ + { + _id: noteId, + type: 'note', + name: 'Note Name', + summary: { text: 'Note summary {1 + 2}' } + }, + ], +} + +describe('Apply note properties', function () { + // Increase timeout + this.timeout(8000); + + before(async function () { + await removeAllCreaturesAndProps(); + await createTestCreature(actionTestCreature); + }); + + it('Applies the note text', async function () { + const action = await runActionById(noteId); + assert.exists(action); + assert.deepEqual(allMutations(action), [{ + contents: [ + { + name: 'Note Name', + value: 'Note summary 3' + } + ], + targetIds: [], + }]); + }); +}); diff --git a/app/imports/api/engine/action/applyProperties/applyRollProperty.test.ts b/app/imports/api/engine/action/applyProperties/applyRollProperty.test.ts new file mode 100644 index 00000000..26faa70d --- /dev/null +++ b/app/imports/api/engine/action/applyProperties/applyRollProperty.test.ts @@ -0,0 +1,53 @@ +import { assert } from 'chai'; +import { + allLogContent, + createTestCreature, + getRandomIds, + removeAllCreaturesAndProps, + runActionById +} from '/imports/api/engine/action/functions/actionEngineTest.testFn'; + +const [ + creatureId, rollId, +] = getRandomIds(2); + +const actionTestCreature = { + _id: creatureId, + props: [ + { + _id: rollId, + type: 'roll', + name: 'Roll Name', + variableName: 'roll1', + roll: { calculation: '7 + 15' }, + children: [ + { + type: 'note', + summary: { text: 'roll: {roll1}' }, + }, + ], + }, + ], +}; + +describe('Apply roll properties', function () { + // Increase timeout + this.timeout(8000); + + before(async function () { + await removeAllCreaturesAndProps(); + await createTestCreature(actionTestCreature); + }); + + it('Saves the value of the roll into the variable name', async function () { + const action = await runActionById(rollId); + assert.exists(action); + assert.deepEqual(allLogContent(action), [{ + inline: true, + name: 'Roll Name', + value: '**22**', + }, { + value: 'roll: 22', + }]); + }); +}); diff --git a/app/imports/api/engine/action/applyProperties/applyRollProperty.ts b/app/imports/api/engine/action/applyProperties/applyRollProperty.ts index 120eb88f..bc7694d6 100644 --- a/app/imports/api/engine/action/applyProperties/applyRollProperty.ts +++ b/app/imports/api/engine/action/applyProperties/applyRollProperty.ts @@ -52,7 +52,7 @@ export default async function applyRollProperty( name: prop.name, value: logValue.join('\n'), inline: true, - silenced: prop.silent, + ...prop.silent && { silenced: true }, }, task.targetIds); // Apply children diff --git a/app/imports/api/engine/action/functions/userInput/inputProviderForTests.testFn.ts b/app/imports/api/engine/action/functions/userInput/inputProviderForTests.testFn.ts index 54a71378..c70e31c8 100644 --- a/app/imports/api/engine/action/functions/userInput/inputProviderForTests.testFn.ts +++ b/app/imports/api/engine/action/functions/userInput/inputProviderForTests.testFn.ts @@ -6,8 +6,8 @@ const inputProviderForTests: InputProvider = { }, /** * For testing, randomness is hard to deal with - * rollDice function returns the average roll for every dice rolled - * [5d10, 1d4] => [[6,6,6,6,6], [3]] + * rollDice function returns the average roll for every dice rolled, but increasing by one each time + * [6d10, 1d4] => [[6,7,8,9,10,1], [3]] */ async rollDice(dice = []) { const result: number[][] = []; diff --git a/app/imports/api/properties/Branches.js b/app/imports/api/properties/Branches.js index fc68edb2..4f65c8a3 100644 --- a/app/imports/api/properties/Branches.js +++ b/app/imports/api/properties/Branches.js @@ -52,7 +52,7 @@ let ComputedOnlyBranchSchema = createPropertySchema({ }, }); -const ComputedBranchSchema = new SimpleSchema() +const ComputedBranchSchema = new SimpleSchema({}) .extend(BranchSchema) .extend(ComputedOnlyBranchSchema); diff --git a/app/imports/api/properties/Rolls.js b/app/imports/api/properties/Rolls.js index b97dc498..4dcb5367 100644 --- a/app/imports/api/properties/Rolls.js +++ b/app/imports/api/properties/Rolls.js @@ -56,7 +56,7 @@ let ComputedOnlyRollSchema = createPropertySchema({ }, }); -const ComputedRollSchema = new SimpleSchema() +const ComputedRollSchema = new SimpleSchema({}) .extend(RollSchema) .extend(ComputedOnlyRollSchema);