import test from "node:test"; import assert from "node:assert/strict"; import { evaluateConditionSet, normalizeConditionSet, ConditionKind } from "../../shared/quests/conditions.js"; import { normalizeQuestDef, normalizeDialogueTree } from "../../shared/quests/normalize.js"; test("ConditionSet AND + NOT", () => { const set = normalizeConditionSet({ all: [ { condition: { kind: ConditionKind.hasItem, itemId: 1, quantity: 1 } }, { not: true, condition: { kind: ConditionKind.questState, questId: "q1", state: "completed" } } ] }); assert.equal(evaluateConditionSet(set, { countItem: (id) => (id === 1 ? 2 : 0), questState: () => "not-started" }), true); assert.equal(evaluateConditionSet(set, { countItem: (id) => (id === 1 ? 2 : 0), questState: () => "completed" }), false); }); test("normalize quest and dialogue", () => { const quest = normalizeQuestDef({ questId: "Fetch Ore!", title: "Fetch Ore", steps: [{ objectives: [{ text: "Have tin", when: { all: [{ kind: "hasItem", itemId: 10, quantity: 1 }] } }] }] }); assert.equal(quest.questId, "fetch-ore"); assert.equal(quest.steps[0].objectives[0].when.all[0].condition.kind, "hasItem"); const tree = normalizeDialogueTree({ dialogueId: "Smith", unique: true, steps: [{ stepId: "hi", lines: [{ speaker: "npc", text: "Hello" }], exit: { kind: "end" } }] }); assert.equal(tree.dialogueId, "smith"); assert.equal(tree.unique, true); assert.equal(tree.steps[0].exit.kind, "end"); });