-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_server.ts
More file actions
57 lines (46 loc) · 1.65 KB
/
test_server.ts
File metadata and controls
57 lines (46 loc) · 1.65 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
46
47
48
49
50
51
52
53
54
55
56
57
import { MemoryManager } from './src/memory.ts';
import assert from 'assert';
import fs from 'fs/promises';
async function testMemoryManager() {
console.log('Starting MemoryManager tests...');
// Clean up previous test file
try {
await fs.unlink('test_memory.json');
} catch (e) {}
const manager = new MemoryManager('test_memory.json');
await manager.load();
// Test Add
console.log('Testing Add...');
await manager.add('user_name', 'Keshav', 'profile', 1.0);
const m1 = await manager.get('user_name');
assert.strictEqual(m1?.value, 'Keshav');
assert.strictEqual(m1?.category, 'profile');
// Test Search
console.log('Testing Search...');
await manager.add('user_skill', 'TypeScript', 'skills', 0.9);
const results = await manager.search('type');
assert.strictEqual(results.length, 1);
assert.strictEqual(results[0].key, 'user_skill');
// Test Update
console.log('Testing Update...');
await manager.update('user_name', 'Keshav Dalmia');
const m2 = await manager.get('user_name');
assert.strictEqual(m2?.value, 'Keshav Dalmia');
// Test Persistence (Load new instance)
console.log('Testing Persistence...');
const manager2 = new MemoryManager('test_memory.json');
await manager2.load();
const m3 = await manager2.get('user_name');
assert.strictEqual(m3?.value, 'Keshav Dalmia');
// Test Delete
console.log('Testing Delete...');
await manager2.delete('user_name');
const m4 = await manager2.get('user_name');
assert.strictEqual(m4, undefined);
console.log('All tests passed!');
// Cleanup
try {
await fs.unlink('test_memory.json');
} catch (e) {}
}
testMemoryManager().catch(console.error);