fix: wired up python macro stuff
This commit is contained in:
@@ -90,6 +90,10 @@ export const ENGINE_MAP: Record<string, EngineGetter> = {
|
|||||||
const { getScriptEngine } = require('../engine/ScriptEngine');
|
const { getScriptEngine } = require('../engine/ScriptEngine');
|
||||||
return getScriptEngine();
|
return getScriptEngine();
|
||||||
},
|
},
|
||||||
|
templates: () => {
|
||||||
|
const { getTemplateEngine } = require('../engine/TemplateEngine');
|
||||||
|
return getTemplateEngine();
|
||||||
|
},
|
||||||
tasks: () => {
|
tasks: () => {
|
||||||
const { taskManager } = require('../engine/TaskManager');
|
const { taskManager } = require('../engine/TaskManager');
|
||||||
return taskManager;
|
return taskManager;
|
||||||
@@ -190,6 +194,14 @@ const METHOD_NAME_MAP: Record<string, string> = {
|
|||||||
'scripts.get': 'getScript',
|
'scripts.get': 'getScript',
|
||||||
'scripts.getAll': 'getAllScripts',
|
'scripts.getAll': 'getAllScripts',
|
||||||
'scripts.rebuildFromFiles': 'rebuildDatabaseFromFiles',
|
'scripts.rebuildFromFiles': 'rebuildDatabaseFromFiles',
|
||||||
|
'templates.create': 'createTemplate',
|
||||||
|
'templates.update': 'updateTemplate',
|
||||||
|
'templates.delete': 'deleteTemplate',
|
||||||
|
'templates.get': 'getTemplate',
|
||||||
|
'templates.getAll': 'getAllTemplates',
|
||||||
|
'templates.getEnabledByKind': 'getEnabledTemplatesByKind',
|
||||||
|
'templates.validate': 'validateTemplate',
|
||||||
|
'templates.rebuildFromFiles': 'rebuildDatabaseFromFiles',
|
||||||
'tasks.getAll': 'getAllTasks',
|
'tasks.getAll': 'getAllTasks',
|
||||||
'tasks.getRunning': 'getRunningTasks',
|
'tasks.getRunning': 'getRunningTasks',
|
||||||
'tasks.cancel': 'cancelTask',
|
'tasks.cancel': 'cancelTask',
|
||||||
|
|||||||
@@ -39,6 +39,17 @@ const mockScriptEngine: Record<string, ReturnType<typeof vi.fn>> = {
|
|||||||
rebuildDatabaseFromFiles: vi.fn().mockResolvedValue(undefined),
|
rebuildDatabaseFromFiles: vi.fn().mockResolvedValue(undefined),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mockTemplateEngine: Record<string, ReturnType<typeof vi.fn>> = {
|
||||||
|
createTemplate: vi.fn().mockResolvedValue({ id: 't1' }),
|
||||||
|
updateTemplate: vi.fn().mockResolvedValue(null),
|
||||||
|
deleteTemplate: vi.fn().mockResolvedValue({ deleted: true }),
|
||||||
|
getTemplate: vi.fn().mockResolvedValue(null),
|
||||||
|
getAllTemplates: vi.fn().mockResolvedValue([]),
|
||||||
|
getEnabledTemplatesByKind: vi.fn().mockResolvedValue([]),
|
||||||
|
validateTemplate: vi.fn().mockResolvedValue({ valid: true, errors: [] }),
|
||||||
|
rebuildDatabaseFromFiles: vi.fn().mockResolvedValue(undefined),
|
||||||
|
};
|
||||||
|
|
||||||
const mockTagEngine: Record<string, ReturnType<typeof vi.fn>> = {
|
const mockTagEngine: Record<string, ReturnType<typeof vi.fn>> = {
|
||||||
getAllTags: vi.fn().mockResolvedValue([]),
|
getAllTags: vi.fn().mockResolvedValue([]),
|
||||||
getTagsWithCounts: vi.fn().mockResolvedValue([]),
|
getTagsWithCounts: vi.fn().mockResolvedValue([]),
|
||||||
@@ -145,6 +156,7 @@ describe('invokeMainProcessPythonApi', () => {
|
|||||||
ENGINE_MAP.meta = () => mockMetaEngine as Record<string, (...args: unknown[]) => unknown>;
|
ENGINE_MAP.meta = () => mockMetaEngine as Record<string, (...args: unknown[]) => unknown>;
|
||||||
ENGINE_MAP.tags = () => mockTagEngine as Record<string, (...args: unknown[]) => unknown>;
|
ENGINE_MAP.tags = () => mockTagEngine as Record<string, (...args: unknown[]) => unknown>;
|
||||||
ENGINE_MAP.scripts = () => mockScriptEngine as Record<string, (...args: unknown[]) => unknown>;
|
ENGINE_MAP.scripts = () => mockScriptEngine as Record<string, (...args: unknown[]) => unknown>;
|
||||||
|
ENGINE_MAP.templates = () => mockTemplateEngine as Record<string, (...args: unknown[]) => unknown>;
|
||||||
ENGINE_MAP.tasks = () => mockTaskManager as Record<string, (...args: unknown[]) => unknown>;
|
ENGINE_MAP.tasks = () => mockTaskManager as Record<string, (...args: unknown[]) => unknown>;
|
||||||
ENGINE_MAP.sync = () => mockGitApiAdapter as Record<string, (...args: unknown[]) => unknown>;
|
ENGINE_MAP.sync = () => mockGitApiAdapter as Record<string, (...args: unknown[]) => unknown>;
|
||||||
ENGINE_MAP.publish = () => mockPublishApiAdapter as Record<string, (...args: unknown[]) => unknown>;
|
ENGINE_MAP.publish = () => mockPublishApiAdapter as Record<string, (...args: unknown[]) => unknown>;
|
||||||
@@ -188,6 +200,42 @@ describe('invokeMainProcessPythonApi', () => {
|
|||||||
expect(mockScriptEngine.deleteScript).toHaveBeenCalledWith('s1');
|
expect(mockScriptEngine.deleteScript).toHaveBeenCalledWith('s1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('routes templates.create to TemplateEngine.createTemplate', async () => {
|
||||||
|
const data = { title: 'My Template', kind: 'post', content: '<p>hello</p>' };
|
||||||
|
await invokeMainProcessPythonApi('templates.create', { data });
|
||||||
|
expect(mockTemplateEngine.createTemplate).toHaveBeenCalledWith(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('routes templates.get to TemplateEngine.getTemplate', async () => {
|
||||||
|
await invokeMainProcessPythonApi('templates.get', { id: 't1' });
|
||||||
|
expect(mockTemplateEngine.getTemplate).toHaveBeenCalledWith('t1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('routes templates.delete to TemplateEngine.deleteTemplate', async () => {
|
||||||
|
await invokeMainProcessPythonApi('templates.delete', { id: 't1' });
|
||||||
|
expect(mockTemplateEngine.deleteTemplate).toHaveBeenCalledWith('t1', undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('routes templates.getAll to TemplateEngine.getAllTemplates', async () => {
|
||||||
|
await invokeMainProcessPythonApi('templates.getAll', {});
|
||||||
|
expect(mockTemplateEngine.getAllTemplates).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('routes templates.getEnabledByKind to TemplateEngine.getEnabledTemplatesByKind', async () => {
|
||||||
|
await invokeMainProcessPythonApi('templates.getEnabledByKind', { kind: 'post' });
|
||||||
|
expect(mockTemplateEngine.getEnabledTemplatesByKind).toHaveBeenCalledWith('post');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('routes templates.validate to TemplateEngine.validateTemplate', async () => {
|
||||||
|
await invokeMainProcessPythonApi('templates.validate', { content: '<p>{{ title }}</p>' });
|
||||||
|
expect(mockTemplateEngine.validateTemplate).toHaveBeenCalledWith('<p>{{ title }}</p>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('routes templates.rebuildFromFiles to TemplateEngine.rebuildDatabaseFromFiles', async () => {
|
||||||
|
await invokeMainProcessPythonApi('templates.rebuildFromFiles', {});
|
||||||
|
expect(mockTemplateEngine.rebuildDatabaseFromFiles).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
|
||||||
it('routes tags.getAll to TagEngine.getAllTags', async () => {
|
it('routes tags.getAll to TagEngine.getAllTags', async () => {
|
||||||
await invokeMainProcessPythonApi('tags.getAll', {});
|
await invokeMainProcessPythonApi('tags.getAll', {});
|
||||||
expect(mockTagEngine.getAllTags).toHaveBeenCalledWith();
|
expect(mockTagEngine.getAllTags).toHaveBeenCalledWith();
|
||||||
|
|||||||
Reference in New Issue
Block a user