forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession-select.test.ts
More file actions
67 lines (57 loc) · 2.12 KB
/
Copy pathsession-select.test.ts
File metadata and controls
67 lines (57 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { describe, expect } from "bun:test"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { Effect, Layer } from "effect"
import { Session } from "@/session/session"
import { TestInstance } from "../fixture/fixture"
import { testEffect } from "../lib/effect"
import { httpApiLayer, requestInDirectory } from "./httpapi-layer"
const it = testEffect(Layer.mergeAll(LayerNode.compile(Session.node), httpApiLayer))
describe("tui.selectSession endpoint", () => {
it.instance(
"should return 200 when called with valid session",
() =>
Effect.gen(function* () {
const tmp = yield* TestInstance
const session = yield* Session.use.create({})
const response = yield* requestInDirectory("/tui/select-session", tmp.directory, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ sessionID: session.id }),
})
expect(response.status).toBe(200)
const body = yield* response.json
expect(body).toBe(true)
}),
{ git: true },
)
it.instance(
"should return 404 when session does not exist",
() =>
Effect.gen(function* () {
const tmp = yield* TestInstance
const nonExistentSessionID = "ses_nonexistent123"
const response = yield* requestInDirectory("/tui/select-session", tmp.directory, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ sessionID: nonExistentSessionID }),
})
expect(response.status).toBe(404)
}),
{ git: true },
)
it.instance(
"should return 400 when session ID format is invalid",
() =>
Effect.gen(function* () {
const tmp = yield* TestInstance
const invalidSessionID = "invalid_session_id"
const response = yield* requestInDirectory("/tui/select-session", tmp.directory, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ sessionID: invalidSessionID }),
})
expect(response.status).toBe(400)
}),
{ git: true },
)
})