48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { initializePersonalMemoryCandidateStore } from './personal-memory-candidate-store.mjs';
|
|
|
|
test('admin initializes the candidate schema before creating its store', async () => {
|
|
const calls = [];
|
|
const pool = { query() {} };
|
|
const store = { listCandidates() {} };
|
|
|
|
const result = await initializePersonalMemoryCandidateStore(pool, {
|
|
async importMemindModule(subpath) {
|
|
assert.equal(subpath, 'memory-v2-personal-store.mjs');
|
|
return {
|
|
async ensurePersonalMemoryCandidateSchema(receivedPool) {
|
|
assert.equal(receivedPool, pool);
|
|
calls.push('ensure');
|
|
},
|
|
createPersonalMemoryCandidateStore(receivedPool) {
|
|
assert.equal(receivedPool, pool);
|
|
calls.push('create');
|
|
return store;
|
|
},
|
|
};
|
|
},
|
|
});
|
|
|
|
assert.equal(result, store);
|
|
assert.deepEqual(calls, ['ensure', 'create']);
|
|
});
|
|
|
|
test('admin fails bootstrap when the candidate schema cannot be initialized', async () => {
|
|
await assert.rejects(
|
|
initializePersonalMemoryCandidateStore({}, {
|
|
async importMemindModule() {
|
|
return {
|
|
async ensurePersonalMemoryCandidateSchema() {
|
|
throw new Error('candidate ddl failed');
|
|
},
|
|
createPersonalMemoryCandidateStore() {
|
|
throw new Error('store must not be created');
|
|
},
|
|
};
|
|
},
|
|
}),
|
|
/candidate ddl failed/,
|
|
);
|
|
});
|