Skip to content

Commit

Permalink
test cases fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelad02 committed Apr 3, 2024
1 parent 7b077db commit 9500003
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/reminders.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class BaseReminder {
// only set if adv or dis, the die roller doesn't handle when both are true correctly
if (advantage && !disadvantage) {
options.advantage = true;
options.disadvantage = false;
if (options.disadvantage) options.disadvantage = false;
} else if (!advantage && disadvantage) {
options.advantage = false;
if (options.advantage) options.advantage = false;
options.disadvantage = true;
} else {
options.advantage = false;
options.disadvantage = false;
if (options.advantage) options.advantage = false;
if (options.disadvantage) options.disadvantage = false;
}
},
};
Expand Down
13 changes: 13 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ export default function commonTestInit() {
lastObj[lastProp] = value;
};

globalThis.getProperty = (object, key) => {
if (!key) return undefined;
if (key in object) return object[key];
let target = object;
for (let p of key.split(".")) {
getType(target);
if (!(typeof target === "object")) return undefined;
if (p in target) target = target[p];
else return undefined;
}
return target;
};

globalThis.flattenObject = (obj, _d = 0) => {
const flat = {};
if (_d > 100) {
Expand Down
19 changes: 5 additions & 14 deletions test/messages.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, jest, test } from "@jest/globals";
import { beforeAll, describe, expect, jest, test } from "@jest/globals";
import {
AbilityCheckMessage,
AbilitySaveMessage,
Expand All @@ -7,20 +7,11 @@ import {
DeathSaveMessage,
SkillMessage,
} from "../src/messages";
import commonTestInit from "./common.js";

// fakes
globalThis.setProperty = (object, key, value) => {
// split the key into parts, removing the last one
const parts = key.split(".");
const lastProp = parts.pop();
// recursively create objects out the key parts
const lastObj = parts.reduce((obj, prop) => {
if (!obj.hasOwnProperty(prop)) obj[prop] = {};
return obj[prop];
}, object);
// set the value using the last key part
lastObj[lastProp] = value;
};
beforeAll(() => {
commonTestInit();
});

function createActorWithEffects(...keyValuePairs) {
const appliedEffects = keyValuePairs.map(createEffect);
Expand Down

0 comments on commit 9500003

Please sign in to comment.