-
Notifications
You must be signed in to change notification settings - Fork 1
/
initChat.test.ts
53 lines (48 loc) · 1.72 KB
/
initChat.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
import { expect } from 'chai';
import { describe, it, before } from 'mocha';
import { OpenCopilotSdk } from '../src';
import { Copilot } from '../src/models';
describe('Copilot Integration Tests', function () {
this.timeout(20000);
let sdk: OpenCopilotSdk;
let createdCopilot: Copilot;
before(function () {
sdk = new OpenCopilotSdk("http://127.0.0.1:8888/backend");
});
it('should create a Copilot and update it', async function () {
try {
createdCopilot = await sdk.copilot.createCopilot({
name: "TestCopilot"
});
expect(createdCopilot.name).to.equal("TestCopilot");
} catch (error: any) {
console.error("Error in Copilot integration tests:", error.message);
expect.fail(error.message);
}
});
it('should use the created Copilot to init chat', async function () {
try {
const result = await sdk.chat.initChat("abc1234", createdCopilot.token)
expect(result).to.have.keys('bot_name', 'faq', 'history', 'initial_questions', 'logo');
expect(result.bot_name).to.be.a('string');
expect(result.faq).to.be.an('array');
expect(result.history).to.be.an('array');
expect(result.initial_questions).to.be.an('array');
expect(result.logo).to.be.a('string');
} catch (error: any) {
console.error("Error in another operation:", error.message);
expect.fail(error.message);
}
});
after(async function () {
try {
if (createdCopilot) {
const deletionResult = await sdk.copilot.deleteCopilot(createdCopilot.id);
console.log("Test: Delete Copilot - Passed", deletionResult);
}
} catch (error: any) {
console.error("Error in cleanup:", error.message);
expect.fail(error.message);
}
});
});