-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.test.ts
More file actions
44 lines (41 loc) · 1.48 KB
/
Copy pathengine.test.ts
File metadata and controls
44 lines (41 loc) · 1.48 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
import { describe, expect, it } from 'vitest';
import { GraphEngine } from './engine';
import { ConversationGraph } from '@conversation-trainer/types';
const graph: ConversationGraph = {
id: 'test',
name: 'Test',
description: 'Test graph',
version: '1.0.0',
entryNode: 'start',
nodes: {
start: { id: 'start', type: 'bot', content: 'start' },
next: { id: 'next', type: 'bot', content: 'next' },
end: { id: 'end', type: 'end', content: 'done' }
},
edges: [
{ id: 'a', from: 'start', to: 'next', trigger: { type: 'exact', value: 'yes' } },
{
id: 'b',
from: 'next',
to: 'end',
trigger: { type: 'intent', value: ['too expensive', 'need discount'] },
actions: [{ type: 'setVariable', target: 'discount', value: true }]
}
],
variables: [{ name: 'discount', type: 'boolean', default: false }]
};
describe('GraphEngine', () => {
it('should follow exact match edge', () => {
const engine = new GraphEngine(graph);
const context = engine.getInitialContext('conversation-1');
const result = engine.processInput(context, 'yes');
expect(result.context.currentNodeId).toBe('next');
});
it('should handle variable action updates', () => {
const engine = new GraphEngine(graph);
const context = engine.getInitialContext('conversation-1');
const mid = engine.processInput(context, 'yes');
const end = engine.processInput(mid.context, 'need discount');
expect(end.context.variables.discount).toBe(true);
});
});