feat: reworked project location

This commit is contained in:
2026-02-14 09:40:39 +01:00
parent 0412b00f2d
commit 6ff84c2d6a
10 changed files with 366 additions and 149 deletions

View File

@@ -167,24 +167,12 @@ describe('MetaEngine', () => {
expect(tags).toContain('vue');
});
it('should persist tags to filesystem', async () => {
it('should keep tags in memory only (TagEngine handles persistence)', async () => {
await metaEngine.addTag('node');
await metaEngine.saveTags();
const metaDir = metaEngine.getMetaDir();
const tagsPath = normalizePath(`${metaDir}/tags.json`);
expect(mockFiles.has(tagsPath)).toBe(true);
});
it('should load tags from filesystem', async () => {
const metaDir = metaEngine.getMetaDir();
const tagsPath = normalizePath(`${metaDir}/tags.json`);
mockFiles.set(tagsPath, JSON.stringify(['saved-tag-1', 'saved-tag-2']));
await metaEngine.loadTags();
// Tags are now kept in memory only - TagEngine handles file persistence
const tags = await metaEngine.getTags();
expect(tags).toContain('saved-tag-1');
expect(tags).toContain('saved-tag-2');
expect(tags).toContain('node');
});
});
@@ -267,21 +255,18 @@ describe('MetaEngine', () => {
expect(categories).toContain('cat3');
});
it('should merge file tags with database tags', async () => {
// File has some tags
const metaDir = metaEngine.getMetaDir();
mockFiles.set(normalizePath(`${metaDir}/tags.json`), JSON.stringify(['file-tag']));
// Posts have different tags
it('should populate tags from database posts only', async () => {
// Tags are now populated from posts only, no file merging
// (TagEngine handles tag persistence with colors)
mockPosts = [
{ tags: JSON.stringify(['db-tag']) },
{ tags: JSON.stringify(['db-tag-1', 'db-tag-2']) },
];
await metaEngine.syncOnStartup();
const tags = await metaEngine.getTags();
expect(tags).toContain('file-tag');
expect(tags).toContain('db-tag');
expect(tags).toContain('db-tag-1');
expect(tags).toContain('db-tag-2');
});
it('should merge file categories with database categories', async () => {
@@ -307,13 +292,14 @@ describe('MetaEngine', () => {
expect(fs.mkdir).toHaveBeenCalled();
});
it('should save merged results back to file', async () => {
it('should save category changes back to file', async () => {
const metaDir = metaEngine.getMetaDir();
mockFiles.set(normalizePath(`${metaDir}/tags.json`), JSON.stringify(['existing']));
mockPosts = [{ tags: JSON.stringify(['new-from-db']), categories: JSON.stringify([]) }];
mockFiles.set(normalizePath(`${metaDir}/categories.json`), JSON.stringify(['existing-cat']));
mockPosts = [{ tags: JSON.stringify([]), categories: JSON.stringify(['new-cat-from-db']) }];
await metaEngine.syncOnStartup();
// Categories are saved to file, tags are not (handled by TagEngine)
expect(fs.writeFile).toHaveBeenCalled();
});
});

View File

@@ -529,4 +529,83 @@ describe('ProjectEngine', () => {
expect(project2.slug).toMatch(/^my-blog(-\d+)?$/);
});
});
describe('Custom dataPath', () => {
it('should create project with custom dataPath', async () => {
const customPath = '/Users/test/Documents/MyBlog';
const project = await projectEngine.createProject({
name: 'Custom Path Project',
dataPath: customPath,
});
expect(project.dataPath).toBe(customPath);
});
it('should create meta and thumbnails directories in custom dataPath', async () => {
const fs = await import('fs/promises');
const customPath = '/Users/test/Documents/MyBlog';
await projectEngine.createProject({
name: 'Custom Dirs Project',
dataPath: customPath,
});
const mkdirCalls = vi.mocked(fs.mkdir).mock.calls;
const createdPaths = mkdirCalls.map(call => call[0]);
// Should create meta/ and thumbnails/ in custom dataPath
expect(createdPaths).toContainEqual(expect.stringContaining(customPath));
expect(createdPaths.some(p => String(p).includes(customPath) && String(p).includes('meta'))).toBe(true);
expect(createdPaths.some(p => String(p).includes(customPath) && String(p).includes('thumbnails'))).toBe(true);
});
it('should create posts and media directories in custom dataPath', async () => {
const fs = await import('fs/promises');
const customPath = '/Users/test/Documents/MyBlog';
await projectEngine.createProject({
name: 'Custom Data Project',
dataPath: customPath,
});
const mkdirCalls = vi.mocked(fs.mkdir).mock.calls;
const createdPaths = mkdirCalls.map(call => call[0]);
// Should create posts/ and media/ in custom dataPath
expect(createdPaths.some(p => String(p).includes(customPath) && String(p).includes('posts'))).toBe(true);
expect(createdPaths.some(p => String(p).includes(customPath) && String(p).includes('media'))).toBe(true);
});
it('should create meta and thumbnails in internal storage when no dataPath', async () => {
const fs = await import('fs/promises');
await projectEngine.createProject({
name: 'Default Path Project',
});
const mkdirCalls = vi.mocked(fs.mkdir).mock.calls;
const createdPaths = mkdirCalls.map(call => String(call[0]));
// Should create meta/ and thumbnails/ in internal (userData) path
expect(createdPaths.some(p => p.includes('meta'))).toBe(true);
expect(createdPaths.some(p => p.includes('thumbnails'))).toBe(true);
});
it('should use getDataDir with custom dataPath', () => {
const projectId = 'test-id';
const customPath = '/Users/test/MyBlog';
const dataDir = projectEngine.getDataDir(projectId, customPath);
expect(dataDir).toBe(customPath);
});
it('should use internal dir when dataPath is null', () => {
const projectId = 'test-id';
const dataDir = projectEngine.getDataDir(projectId, null);
expect(dataDir).toContain(projectId);
});
});
});