mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-08 17:59:09 +00:00
refactor(question): effectify QuestionService (#17432)
This commit is contained in:
@@ -5,6 +5,14 @@ import { QuestionID } from "../../src/question/schema"
|
||||
import { tmpdir } from "../fixture/fixture"
|
||||
import { SessionID } from "../../src/session/schema"
|
||||
|
||||
/** Reject all pending questions so dangling Deferred fibers don't hang the test. */
|
||||
async function rejectAll() {
|
||||
const pending = await Question.list()
|
||||
for (const req of pending) {
|
||||
await Question.reject(req.id)
|
||||
}
|
||||
}
|
||||
|
||||
test("ask - returns pending promise", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await Instance.provide({
|
||||
@@ -24,6 +32,8 @@ test("ask - returns pending promise", async () => {
|
||||
],
|
||||
})
|
||||
expect(promise).toBeInstanceOf(Promise)
|
||||
await rejectAll()
|
||||
await promise.catch(() => {})
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -44,7 +54,7 @@ test("ask - adds to pending list", async () => {
|
||||
},
|
||||
]
|
||||
|
||||
Question.ask({
|
||||
const askPromise = Question.ask({
|
||||
sessionID: SessionID.make("ses_test"),
|
||||
questions,
|
||||
})
|
||||
@@ -52,6 +62,8 @@ test("ask - adds to pending list", async () => {
|
||||
const pending = await Question.list()
|
||||
expect(pending.length).toBe(1)
|
||||
expect(pending[0].questions).toEqual(questions)
|
||||
await rejectAll()
|
||||
await askPromise.catch(() => {})
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -98,7 +110,7 @@ test("reply - removes from pending list", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
Question.ask({
|
||||
const askPromise = Question.ask({
|
||||
sessionID: SessionID.make("ses_test"),
|
||||
questions: [
|
||||
{
|
||||
@@ -119,6 +131,7 @@ test("reply - removes from pending list", async () => {
|
||||
requestID: pending[0].id,
|
||||
answers: [["Option 1"]],
|
||||
})
|
||||
await askPromise
|
||||
|
||||
const pendingAfter = await Question.list()
|
||||
expect(pendingAfter.length).toBe(0)
|
||||
@@ -262,7 +275,7 @@ test("list - returns all pending requests", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
Question.ask({
|
||||
const p1 = Question.ask({
|
||||
sessionID: SessionID.make("ses_test1"),
|
||||
questions: [
|
||||
{
|
||||
@@ -273,7 +286,7 @@ test("list - returns all pending requests", async () => {
|
||||
],
|
||||
})
|
||||
|
||||
Question.ask({
|
||||
const p2 = Question.ask({
|
||||
sessionID: SessionID.make("ses_test2"),
|
||||
questions: [
|
||||
{
|
||||
@@ -286,6 +299,9 @@ test("list - returns all pending requests", async () => {
|
||||
|
||||
const pending = await Question.list()
|
||||
expect(pending.length).toBe(2)
|
||||
await rejectAll()
|
||||
p1.catch(() => {})
|
||||
p2.catch(() => {})
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user