session-list.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { describe, expect, test } from "bun:test"
  2. import path from "path"
  3. import { Instance } from "../../src/project/instance"
  4. import { Server } from "../../src/server/server"
  5. import { Session } from "../../src/session"
  6. import { Log } from "../../src/util/log"
  7. const projectRoot = path.join(__dirname, "../..")
  8. Log.init({ print: false })
  9. describe("session.list", () => {
  10. test("filters by directory", async () => {
  11. await Instance.provide({
  12. directory: projectRoot,
  13. fn: async () => {
  14. const app = Server.App()
  15. const first = await Session.create({})
  16. const otherDir = path.join(projectRoot, "..", "__session_list_other")
  17. const second = await Instance.provide({
  18. directory: otherDir,
  19. fn: async () => Session.create({}),
  20. })
  21. const response = await app.request(`/session?directory=${encodeURIComponent(projectRoot)}`)
  22. expect(response.status).toBe(200)
  23. const body = (await response.json()) as unknown[]
  24. const ids = body
  25. .map((s) => (typeof s === "object" && s && "id" in s ? (s as { id: string }).id : undefined))
  26. .filter((x): x is string => typeof x === "string")
  27. expect(ids).toContain(first.id)
  28. expect(ids).not.toContain(second.id)
  29. },
  30. })
  31. })
  32. })