forked from ericc-ch/copilot-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.test.ts
More file actions
45 lines (34 loc) · 1.28 KB
/
utils.test.ts
File metadata and controls
45 lines (34 loc) · 1.28 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
import { describe, test, expect, mock, beforeEach } from "bun:test"
import type { ModelsResponse } from "../src/services/copilot/get-models"
// ---------------------------------------------------------------------------
// cacheModels — integration test against the real state singleton,
// with the service function mocked.
// ---------------------------------------------------------------------------
const fakeModels: ModelsResponse = {
object: "list",
data: [],
}
const mockGetModels = mock(() => Promise.resolve(fakeModels))
void mock.module("../src/services/copilot/get-models", () => ({
getModels: mockGetModels,
}))
// Import after mocking so the mocks are active
import { state } from "../src/lib/state"
import { cacheModels } from "../src/lib/utils"
describe("cacheModels", () => {
beforeEach(() => {
state.models = undefined
mockGetModels.mockReset()
})
test("sets state.models with value from service", async () => {
mockGetModels.mockResolvedValue(fakeModels)
expect(state.models).toBeUndefined()
await cacheModels()
expect(state.models).toEqual(fakeModels)
})
test("calls getModels exactly once", async () => {
mockGetModels.mockResolvedValue(fakeModels)
await cacheModels()
expect(mockGetModels).toHaveBeenCalledTimes(1)
})
})