fix: deduplicate distractors, replace tautological test, add distractor failure test
This commit is contained in:
parent
3d16ab0fff
commit
a02f3b139d
3 changed files with 81 additions and 14 deletions
|
|
@ -85,20 +85,22 @@ describe("createGameSession", () => {
|
|||
}
|
||||
});
|
||||
|
||||
it("distractors are never the correct answer", async () => {
|
||||
it("correct answer appears exactly once even if getDistractors returns a duplicate", async () => {
|
||||
mockGetDistractors.mockResolvedValueOnce([
|
||||
"cane",
|
||||
"wrong2",
|
||||
"wrong3",
|
||||
"wrong4",
|
||||
"wrong5",
|
||||
"wrong6",
|
||||
]);
|
||||
|
||||
const session = await createGameSession(validRequest, store, "user-1");
|
||||
const question = session.questions[0]!;
|
||||
const optionTexts = question.options.map((o) => o.text);
|
||||
|
||||
for (let i = 0; i < session.questions.length; i++) {
|
||||
const question = session.questions[i]!;
|
||||
const correctText = fakeTerms[i]!.targetText;
|
||||
const distractorTexts = question.options
|
||||
.map((o) => o.text)
|
||||
.filter((t) => t !== correctText);
|
||||
|
||||
for (const text of distractorTexts) {
|
||||
expect(text).not.toBe(correctText);
|
||||
}
|
||||
}
|
||||
expect(optionTexts.filter((t) => t === "cane")).toHaveLength(1);
|
||||
expect(question.options).toHaveLength(4);
|
||||
});
|
||||
|
||||
it("sets the prompt from the source text", async () => {
|
||||
|
|
@ -141,6 +143,14 @@ describe("createGameSession", () => {
|
|||
createGameSession(validRequest, store, "user-1"),
|
||||
).rejects.toThrow("connection refused");
|
||||
});
|
||||
|
||||
it("propagates getDistractors failure", async () => {
|
||||
mockGetDistractors.mockRejectedValue(new Error("db timeout"));
|
||||
|
||||
await expect(
|
||||
createGameSession(validRequest, store, "user-1"),
|
||||
).rejects.toThrow("db timeout");
|
||||
});
|
||||
});
|
||||
|
||||
describe("evaluateAnswer", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue