|
1 | 1 | import { |
2 | 2 | AddOrUpdateAiAgentOperation, |
| 3 | + AiConnectionString, |
3 | 4 | IDocumentStore, |
4 | | - PutConnectionStringOperation, |
5 | | - RavenConnectionString |
| 5 | + OpenAiSettings, |
| 6 | + PutConnectionStringOperation |
6 | 7 | } from "../../../../src/index.js"; |
7 | 8 | import {disposeTestDocumentStore, RavenTestContext, testContext} from "../../../Utils/TestUtil.js"; |
8 | 9 | import {assertThat, assertThrows} from "../../../Utils/AssertExtensions.js"; |
9 | 10 | import {AiAgentConfiguration} from "../../../../src/Documents/Operations/AI/Agents/config/AiAgentConfiguration.js"; |
10 | 11 |
|
11 | 12 | ((RavenTestContext.isRavenDbServerVersion("7.1") && !RavenTestContext.isPullRequest) ? describe : describe.skip)("AiAgentTest", function () { |
12 | | - |
13 | 13 | let store: IDocumentStore; |
14 | 14 |
|
15 | | - beforeEach(async function () { |
16 | | - store = await testContext.getDocumentStore(); |
17 | | - }); |
| 15 | + beforeEach(async () => store = await testContext.getDocumentStore()); |
18 | 16 |
|
19 | 17 | afterEach(async () => |
20 | 18 | await disposeTestDocumentStore(store)); |
21 | 19 |
|
| 20 | + async function putAiConnectionString() { |
| 21 | + const csName = `ai-agents-${Date.now()}`; |
| 22 | + const aiConnectionString = new AiConnectionString(); |
| 23 | + aiConnectionString.name = csName; |
| 24 | + aiConnectionString.identifier = "openai-test"; |
| 25 | + aiConnectionString.modelType = "Chat"; |
| 26 | + aiConnectionString.openAiSettings = new OpenAiSettings("test-api-key", "https://api.openai.example", "gpt-test"); |
| 27 | + |
| 28 | + await store.maintenance.send(new PutConnectionStringOperation(aiConnectionString)); |
| 29 | + return csName; |
| 30 | + } |
| 31 | + |
22 | 32 | it("canCreateAiAgent", async () => { |
23 | | - const csName = `r1-${Date.now()}`; |
24 | | - const ravenConnectionString = Object.assign(new RavenConnectionString(), { |
25 | | - database: store.database, |
26 | | - topologyDiscoveryUrls: ["http://localhost:8080"], |
27 | | - name: csName |
28 | | - }); |
29 | | - await store.maintenance.send(new PutConnectionStringOperation(ravenConnectionString)); |
| 33 | + const csName = await putAiConnectionString(); |
30 | 34 |
|
31 | 35 | const agentConfiguration: AiAgentConfiguration = { |
32 | 36 | name: `TestAgent-${Date.now()}`, |
@@ -66,13 +70,7 @@ import {AiAgentConfiguration} from "../../../../src/Documents/Operations/AI/Agen |
66 | 70 | }); |
67 | 71 |
|
68 | 72 | it("canUpdateAiAgent", async () => { |
69 | | - const csName = `r1-${Date.now()}`; |
70 | | - const ravenConnectionString = Object.assign(new RavenConnectionString(), { |
71 | | - database: store.database, |
72 | | - topologyDiscoveryUrls: ["http://localhost:8080"], |
73 | | - name: csName |
74 | | - }); |
75 | | - await store.maintenance.send(new PutConnectionStringOperation(ravenConnectionString)); |
| 73 | + const csName = await putAiConnectionString(); |
76 | 74 |
|
77 | 75 | const name = `Agent-${Date.now()}`; |
78 | 76 | const initialConfig: AiAgentConfiguration = { |
@@ -101,13 +99,7 @@ import {AiAgentConfiguration} from "../../../../src/Documents/Operations/AI/Agen |
101 | 99 | }); |
102 | 100 |
|
103 | 101 | it("canListAndDeleteAiAgent", async () => { |
104 | | - const csName = `r1-${Date.now()}`; |
105 | | - const ravenConnectionString = Object.assign(new RavenConnectionString(), { |
106 | | - database: store.database, |
107 | | - topologyDiscoveryUrls: ["http://localhost:8080"], |
108 | | - name: csName |
109 | | - }); |
110 | | - await store.maintenance.send(new PutConnectionStringOperation(ravenConnectionString)); |
| 102 | + const csName = await putAiConnectionString(); |
111 | 103 |
|
112 | 104 | const name = `agent-${Date.now()}`; |
113 | 105 | const config: AiAgentConfiguration = { |
|
0 commit comments