- Implemented `findMobDependencies.ts` to identify foreign key constraints referencing the Mob table and log dependent rows. - Created `fullServerSetup.ts` for idempotent server setup, including economy items, item recipes, game areas, mobs, and optional demo mob attacks. - Developed `removeInvalidMobsWithDeps.ts` to delete invalid mobs and their dependencies, backing up affected scheduled mob attacks. - Added unit tests in `testMobUnit.ts` and `mob.test.ts` for mob functionality, including stats computation and instance retrieval. - Introduced reward modification tests in `testRewardMods.ts` and `rewardMods.unit.ts` to validate drop selection and coin multiplier behavior. - Enhanced command handling for mob deletion in `mobDelete.ts` and setup examples in `setup.ts`, ensuring proper permissions and feedback. - Created utility functions in `testHelpers.ts` for deterministic drop selection from mob definitions.
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import assert from "assert";
|
|
import {
|
|
computeMobStats,
|
|
getMobInstance,
|
|
MOB_DEFINITIONS,
|
|
} from "../src/game/mobs/mobData";
|
|
import { createOrUpdateMob } from "../src/game/mobs/admin";
|
|
|
|
async function run() {
|
|
console.log("Running mob unit tests...");
|
|
|
|
// computeMobStats basic
|
|
const def = MOB_DEFINITIONS[0];
|
|
const statsLv1 = computeMobStats(def, 1);
|
|
assert(typeof statsLv1.hp === "number", "hp should be number");
|
|
assert(typeof statsLv1.attack === "number", "attack should be number");
|
|
|
|
// scaling test
|
|
const statsLv5 = computeMobStats(def, 5);
|
|
if ((def.scaling && def.scaling.hpPerLevel) || 0) {
|
|
assert(statsLv5.hp >= statsLv1.hp, "hp should not decrease with level");
|
|
}
|
|
|
|
console.log("computeMobStats: OK");
|
|
|
|
// getMobInstance basic
|
|
const key = def.key;
|
|
const inst = getMobInstance(key, 3);
|
|
assert(inst !== null, "getMobInstance should return instance");
|
|
assert(inst!.scaled.hp > 0, "instance hp > 0");
|
|
console.log("getMobInstance: OK");
|
|
|
|
// createOrUpdateMob (non-DB mode should return def)
|
|
try {
|
|
const res = await createOrUpdateMob({
|
|
...def,
|
|
key: "unit.test.mob",
|
|
} as any);
|
|
if (!res || !res.def) throw new Error("createOrUpdateMob returned invalid");
|
|
console.log("createOrUpdateMob: OK (no-DB mode)");
|
|
} catch (e) {
|
|
console.warn(
|
|
"createOrUpdateMob: skipped (DB may be required) -",
|
|
(e as any)?.message ?? e
|
|
);
|
|
}
|
|
|
|
console.log("All mob unit tests passed.");
|
|
}
|
|
|
|
run().catch((e) => {
|
|
console.error("Tests failed:", e);
|
|
process.exit(1);
|
|
});
|