This repository was archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathassistantController.test.ts
62 lines (49 loc) · 1.89 KB
/
assistantController.test.ts
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
import { createSuperAdminForTesting } from "@/__tests__/utils";
import { app } from "@/index";
import { redis } from "@/infrastructure/adaptaters/redisAdapter";
import { test, expect, describe } from "bun:test";
import { UNAUTHORIZED_MISSING_TOKEN } from "../../ports/returnValues";
describe("assistantController", async () => {
const token = await createSuperAdminForTesting();
test("allows creating an assistant and the assistant is saved in the database", async () => {
const name = "test assistant";
const request = new Request("http://localhost:8080/assistant", {
headers: {
authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify({
name,
model: 'gpt-4',
instruction: 'You are a plant teacher. Always respond with "sprout"'
}),
});
const response = await app.handle(request);
const responseJson: any = await response.json();
expect(responseJson).toHaveProperty("id");
const id = responseJson.id;
// Retrieve the assistant data from Redis
const assistantData = await redis.get(`assistant:${id}`);
expect(assistantData).not.toBeNull();
const assistant = JSON.parse(assistantData!);
expect(assistant.name).toBe(name);
});
test("prevents from creating an assistant if there is no api token present", async () => {
const request = new Request("http://localhost:3000/assistant", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "sprout_assistant",
model: "gpt-4",
instruction: "You are a plant teacher. Always respond with 'sprout'"
}),
});
const response: any = await app
.handle(request)
.then((response) => response.json());
expect(response.message).toBe(UNAUTHORIZED_MISSING_TOKEN.message);
});
});