feat: Add scripts for mob dependency management and server setup
- 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.
This commit is contained in:
46
test/mob.test.ts
Normal file
46
test/mob.test.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import assert from "assert";
|
||||
import {
|
||||
computeMobStats,
|
||||
getMobInstance,
|
||||
MOB_DEFINITIONS,
|
||||
} from "../src/game/mobs/mobData";
|
||||
import { createOrUpdateMob } from "../src/game/mobs/admin";
|
||||
|
||||
async function main() {
|
||||
console.log("Starting formal mob tests...");
|
||||
|
||||
// Test computeMobStats deterministic
|
||||
const def = MOB_DEFINITIONS[0];
|
||||
const s1 = computeMobStats(def, 1);
|
||||
const s2 = computeMobStats(def, 2);
|
||||
assert(s2.hp >= s1.hp, "HP should increase or stay with level");
|
||||
console.log("computeMobStats OK");
|
||||
|
||||
// Test getMobInstance
|
||||
const inst = getMobInstance(def.key, 3);
|
||||
assert(inst !== null, "getMobInstance should return an instance");
|
||||
assert(
|
||||
typeof inst!.scaled.hp === "number",
|
||||
"instance scaled.hp should be a number"
|
||||
);
|
||||
console.log("getMobInstance OK");
|
||||
|
||||
// Test createOrUpdateMob in no-db mode (should not throw)
|
||||
try {
|
||||
const r = await createOrUpdateMob({ ...def, key: "test.unit.mob" } as any);
|
||||
assert(r && r.def, "createOrUpdateMob must return def");
|
||||
console.log("createOrUpdateMob (no-db) OK");
|
||||
} catch (e) {
|
||||
console.warn(
|
||||
"createOrUpdateMob test skipped (DB needed):",
|
||||
(e as any)?.message ?? e
|
||||
);
|
||||
}
|
||||
|
||||
console.log("All formal mob tests passed");
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user