fix: beheben von Lint- und Prettier-Fehlern in Tests und Config
This commit is contained in:
1 parent
94bdb32adf
commit
c717353037
28 files changed
+675
-372
No files matched your search
+27
-10
@@ -15,17 +15,27 @@ function createTestVault(): string {
|
||||
|
||||
// 12 Ordner
|
||||
const dirs = [
|
||||
'00_Inbox', '00_Inbox/Verarbeitet', '00_Inbox/Problemfaelle',
|
||||
'01_Daily', '10_Wiki', '10_Wiki/Seiten',
|
||||
'20_Projekte', '90_Templates',
|
||||
'99_System', '99_System/Skripte', '99_System/Logs', '99_System/Cache',
|
||||
'00_Inbox',
|
||||
'00_Inbox/Verarbeitet',
|
||||
'00_Inbox/Problemfaelle',
|
||||
'01_Daily',
|
||||
'10_Wiki',
|
||||
'10_Wiki/Seiten',
|
||||
'20_Projekte',
|
||||
'90_Templates',
|
||||
'99_System',
|
||||
'99_System/Skripte',
|
||||
'99_System/Logs',
|
||||
'99_System/Cache',
|
||||
];
|
||||
for (const d of dirs) {
|
||||
mkdirSync(join(dir, d), { recursive: true });
|
||||
}
|
||||
|
||||
// 3 Test-Notizen mit deterministischen Wikilinks
|
||||
writeFileSync(join(dir, '00_Inbox', '2026-01-01_A.md'), `---
|
||||
writeFileSync(
|
||||
join(dir, '00_Inbox', '2026-01-01_A.md'),
|
||||
`---
|
||||
title: A
|
||||
created: 2026-01-01
|
||||
---
|
||||
@@ -33,8 +43,11 @@ created: 2026-01-01
|
||||
# A
|
||||
|
||||
Verweist auf [[B]] und [[C]].
|
||||
`);
|
||||
writeFileSync(join(dir, '00_Inbox', '2026-01-02_B.md'), `---
|
||||
`,
|
||||
);
|
||||
writeFileSync(
|
||||
join(dir, '00_Inbox', '2026-01-02_B.md'),
|
||||
`---
|
||||
title: B
|
||||
created: 2026-01-02
|
||||
---
|
||||
@@ -42,8 +55,11 @@ created: 2026-01-02
|
||||
# B
|
||||
|
||||
Verweist auf [[A]].
|
||||
`);
|
||||
writeFileSync(join(dir, '00_Inbox', '2026-01-03_C.md'), `---
|
||||
`,
|
||||
);
|
||||
writeFileSync(
|
||||
join(dir, '00_Inbox', '2026-01-03_C.md'),
|
||||
`---
|
||||
title: C
|
||||
created: 2026-01-03
|
||||
---
|
||||
@@ -51,7 +67,8 @@ created: 2026-01-03
|
||||
# C
|
||||
|
||||
Kein Link.
|
||||
`);
|
||||
`,
|
||||
);
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
+12
-3
@@ -21,13 +21,22 @@ test.describe('Mind-o-Mat Webapp', () => {
|
||||
|
||||
test('Tab-Wechsel funktioniert', async ({ page }) => {
|
||||
// Graph ist initial aktiv
|
||||
await expect(page.getByRole('button', { name: 'Graph' })).toHaveCSS('background-color', 'rgb(255, 255, 255)');
|
||||
await expect(page.getByRole('button', { name: 'Graph' })).toHaveCSS(
|
||||
'background-color',
|
||||
'rgb(255, 255, 255)',
|
||||
);
|
||||
// Klick auf Cluster-Karte -> wechselt aktiv-Status
|
||||
await page.getByRole('button', { name: 'Cluster-Karte' }).click();
|
||||
await expect(page.getByRole('button', { name: 'Cluster-Karte' })).toHaveCSS('background-color', 'rgb(255, 255, 255)');
|
||||
await expect(page.getByRole('button', { name: 'Cluster-Karte' })).toHaveCSS(
|
||||
'background-color',
|
||||
'rgb(255, 255, 255)',
|
||||
);
|
||||
// Klick auf Radial
|
||||
await page.getByRole('button', { name: 'Radial' }).click();
|
||||
await expect(page.getByRole('button', { name: 'Radial' })).toHaveCSS('background-color', 'rgb(255, 255, 255)');
|
||||
await expect(page.getByRole('button', { name: 'Radial' })).toHaveCSS(
|
||||
'background-color',
|
||||
'rgb(255, 255, 255)',
|
||||
);
|
||||
});
|
||||
|
||||
test('Legend ist sichtbar', async ({ page }) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Direkter Unit-Test fuer findSimilarGroups (v0.5)
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { describe, it, expect, afterEach } from 'vitest';
|
||||
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
@@ -14,8 +14,14 @@ afterEach(() => {
|
||||
function setupVault(files: Record<string, string>): string {
|
||||
const vault = mkdtempSync(join(tmpdir(), 'mindomat-similar-direct-'));
|
||||
for (const d of [
|
||||
'00_Inbox', '10_Wiki/Seiten', '01_Daily', '20_Projekte',
|
||||
'99_System', '99_System/Skripte', '99_System/Logs', '99_System/Cache',
|
||||
'00_Inbox',
|
||||
'10_Wiki/Seiten',
|
||||
'01_Daily',
|
||||
'20_Projekte',
|
||||
'99_System',
|
||||
'99_System/Skripte',
|
||||
'99_System/Logs',
|
||||
'99_System/Cache',
|
||||
]) {
|
||||
mkdirSync(join(vault, d), { recursive: true });
|
||||
}
|
||||
@@ -103,9 +109,9 @@ Ich gehe joggen im Park.`,
|
||||
// Es sollte mindestens eine Gruppe geben (A und B sind aehnlich)
|
||||
expect(groups.length).toBeGreaterThanOrEqual(1);
|
||||
// Die aehnlichste Gruppe sollte A+B sein
|
||||
const abGroup = groups.find((g) =>
|
||||
g.nodes.some((n) => n.id.includes('_A.md')) &&
|
||||
g.nodes.some((n) => n.id.includes('_B.md')),
|
||||
const abGroup = groups.find(
|
||||
(g) =>
|
||||
g.nodes.some((n) => n.id.includes('_A.md')) && g.nodes.some((n) => n.id.includes('_B.md')),
|
||||
);
|
||||
expect(abGroup).toBeDefined();
|
||||
});
|
||||
@@ -124,10 +130,7 @@ title: Test
|
||||
Kaffee Tee Brot Butter`,
|
||||
});
|
||||
vaults.push(vault);
|
||||
const nodes = [
|
||||
node('01_Daily/2026-09-05_A.md'),
|
||||
node('01_Daily/2026-09-05_B.md'),
|
||||
];
|
||||
const nodes = [node('01_Daily/2026-09-05_A.md'), node('01_Daily/2026-09-05_B.md')];
|
||||
const low = findSimilarGroups(vault, nodes, 0.1);
|
||||
const high = findSimilarGroups(vault, nodes, 0.99);
|
||||
expect(low.length).toBeGreaterThanOrEqual(high.length);
|
||||
|
||||
@@ -13,16 +13,26 @@ const CLI = `node ${TOOL}/bin/mindomat.mjs`;
|
||||
function setupVault(files: Record<string, string> = {}, includeKonfig = true): string {
|
||||
const vault = mkdtempSync(join(tmpdir(), 'mindomat-edge-'));
|
||||
for (const d of [
|
||||
'00_Inbox', '00_Inbox/Verarbeitet', '00_Inbox/Problemfaelle',
|
||||
'01_Daily', '10_Wiki', '10_Wiki/Seiten',
|
||||
'20_Projekte', '90_Templates',
|
||||
'99_System', '99_System/Skripte', '99_System/Logs', '99_System/Cache',
|
||||
'00_Inbox',
|
||||
'00_Inbox/Verarbeitet',
|
||||
'00_Inbox/Problemfaelle',
|
||||
'01_Daily',
|
||||
'10_Wiki',
|
||||
'10_Wiki/Seiten',
|
||||
'20_Projekte',
|
||||
'90_Templates',
|
||||
'99_System',
|
||||
'99_System/Skripte',
|
||||
'99_System/Logs',
|
||||
'99_System/Cache',
|
||||
]) {
|
||||
mkdirSync(join(vault, d), { recursive: true });
|
||||
}
|
||||
if (includeKonfig) {
|
||||
writeFileSync(join(vault, '99_System/Konfig.md'),
|
||||
'---\nveraltet_schwellwert_monate: 12\n---\n');
|
||||
writeFileSync(
|
||||
join(vault, '99_System/Konfig.md'),
|
||||
'---\nveraltet_schwellwert_monate: 12\n---\n',
|
||||
);
|
||||
}
|
||||
for (const [rel, content] of Object.entries(files)) {
|
||||
const full = join(vault, rel);
|
||||
@@ -87,8 +97,7 @@ describe('Indexer Edge Cases', () => {
|
||||
|
||||
it('tote Wikilinks erscheinen in Index.md', () => {
|
||||
const vault = setupVault({
|
||||
'00_Inbox/2026-09-05_A.md':
|
||||
'---\ntitle: A\n---\n\nVerweist auf [[B_Datei_Nicht_Da]].',
|
||||
'00_Inbox/2026-09-05_A.md': '---\ntitle: A\n---\n\nVerweist auf [[B_Datei_Nicht_Da]].',
|
||||
});
|
||||
vaults.push(vault);
|
||||
runIndexer(vault);
|
||||
|
||||
@@ -3,7 +3,16 @@
|
||||
|
||||
import { describe, it, expect, afterEach } from 'vitest';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { mkdtempSync, writeFileSync, mkdirSync, readFileSync, existsSync, rmSync, copyFileSync, readdirSync } from 'node:fs';
|
||||
import {
|
||||
mkdtempSync,
|
||||
writeFileSync,
|
||||
mkdirSync,
|
||||
readFileSync,
|
||||
existsSync,
|
||||
rmSync,
|
||||
copyFileSync,
|
||||
readdirSync,
|
||||
} from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
|
||||
@@ -13,17 +22,26 @@ const CLI = `node ${TOOL}/bin/mindomat.mjs`;
|
||||
function setupTestVault(): string {
|
||||
const vault = mkdtempSync(join(tmpdir(), 'mindomat-ingest-e2e-'));
|
||||
const dirs = [
|
||||
'00_Inbox', '00_Inbox/Verarbeitet', '00_Inbox/Problemfaelle',
|
||||
'01_Daily', '10_Wiki', '10_Wiki/Seiten',
|
||||
'20_Projekte', '90_Templates',
|
||||
'99_System', '99_System/Skripte', '99_System/Logs', '99_System/Cache',
|
||||
'00_Inbox',
|
||||
'00_Inbox/Verarbeitet',
|
||||
'00_Inbox/Problemfaelle',
|
||||
'01_Daily',
|
||||
'10_Wiki',
|
||||
'10_Wiki/Seiten',
|
||||
'20_Projekte',
|
||||
'90_Templates',
|
||||
'99_System',
|
||||
'99_System/Skripte',
|
||||
'99_System/Logs',
|
||||
'99_System/Cache',
|
||||
];
|
||||
for (const d of dirs) {
|
||||
mkdirSync(join(vault, d), { recursive: true });
|
||||
}
|
||||
|
||||
// Konfig
|
||||
writeFileSync(join(vault, '99_System', 'Konfig.md'),
|
||||
writeFileSync(
|
||||
join(vault, '99_System', 'Konfig.md'),
|
||||
`---
|
||||
veraltet_schwellwert_monate: 12
|
||||
ki_provider: minimax
|
||||
@@ -31,7 +49,8 @@ ki_modell: MiniMax-M3
|
||||
ki_api_url: https://api.minimaxi.chat/v1
|
||||
ki_api_key_env: MINIMAX_API_KEY
|
||||
---
|
||||
`);
|
||||
`,
|
||||
);
|
||||
|
||||
// Schema
|
||||
copyFileSync(join(TOOL, 'src/templates/_Schema.md'), join(vault, '10_Wiki/_Schema.md'));
|
||||
@@ -53,7 +72,8 @@ describe('Ingest E2E mit --mock', () => {
|
||||
vaults.push(vault);
|
||||
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
writeFileSync(join(vault, '00_Inbox', `${today}_Kaffee_Ritual.md`),
|
||||
writeFileSync(
|
||||
join(vault, '00_Inbox', `${today}_Kaffee_Ritual.md`),
|
||||
`---
|
||||
title: Kaffee_Ritual
|
||||
created: ${today}
|
||||
@@ -63,7 +83,8 @@ tags: [Gewohnheit]
|
||||
# Kaffee Ritual
|
||||
|
||||
Jeden Morgen Kaffee, schwarz, aus der Handmuehle.
|
||||
`);
|
||||
`,
|
||||
);
|
||||
|
||||
execSync(`${CLI} ingest --vault "${vault}" --mock`, { stdio: 'pipe' });
|
||||
|
||||
|
||||
+12
-4
@@ -15,10 +15,18 @@ afterEach(() => {
|
||||
function setupVault(files: Record<string, string> = {}): string {
|
||||
const vault = mkdtempSync(join(tmpdir(), 'mindomat-notes-api-'));
|
||||
for (const d of [
|
||||
'00_Inbox', '00_Inbox/Verarbeitet', '00_Inbox/Problemfaelle',
|
||||
'01_Daily', '10_Wiki', '10_Wiki/Seiten',
|
||||
'20_Projekte', '90_Templates',
|
||||
'99_System', '99_System/Skripte', '99_System/Logs', '99_System/Cache',
|
||||
'00_Inbox',
|
||||
'00_Inbox/Verarbeitet',
|
||||
'00_Inbox/Problemfaelle',
|
||||
'01_Daily',
|
||||
'10_Wiki',
|
||||
'10_Wiki/Seiten',
|
||||
'20_Projekte',
|
||||
'90_Templates',
|
||||
'99_System',
|
||||
'99_System/Skripte',
|
||||
'99_System/Logs',
|
||||
'99_System/Cache',
|
||||
]) {
|
||||
mkdirSync(join(vault, d), { recursive: true });
|
||||
}
|
||||
|
||||
@@ -7,11 +7,19 @@ import { describe, it, expect, beforeEach } from 'vitest';
|
||||
const store = new Map<string, string>();
|
||||
(globalThis as any).localStorage = {
|
||||
getItem: (key: string) => store.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => { store.set(key, value); },
|
||||
removeItem: (key: string) => { store.delete(key); },
|
||||
clear: () => { store.clear(); },
|
||||
setItem: (key: string, value: string) => {
|
||||
store.set(key, value);
|
||||
},
|
||||
removeItem: (key: string) => {
|
||||
store.delete(key);
|
||||
},
|
||||
clear: () => {
|
||||
store.clear();
|
||||
},
|
||||
key: (i: number) => Array.from(store.keys())[i] ?? null,
|
||||
get length() { return store.size; },
|
||||
get length() {
|
||||
return store.size;
|
||||
},
|
||||
};
|
||||
|
||||
import {
|
||||
|
||||
+14
-10
@@ -61,11 +61,13 @@ describe('resolveVaultPath', () => {
|
||||
});
|
||||
|
||||
it('wirft VaultPathError MISSING, wenn weder CLI noch Env', () => {
|
||||
expect(() => resolveVaultPath({
|
||||
args: [],
|
||||
env: {},
|
||||
cwd,
|
||||
})).toThrow(VaultPathError);
|
||||
expect(() =>
|
||||
resolveVaultPath({
|
||||
args: [],
|
||||
env: {},
|
||||
cwd,
|
||||
}),
|
||||
).toThrow(VaultPathError);
|
||||
try {
|
||||
resolveVaultPath({ args: [], env: {}, cwd });
|
||||
} catch (err) {
|
||||
@@ -75,11 +77,13 @@ describe('resolveVaultPath', () => {
|
||||
});
|
||||
|
||||
it('wirft VaultPathError MISSING, wenn Env-Var leer', () => {
|
||||
expect(() => resolveVaultPath({
|
||||
args: [],
|
||||
env: { MINDOMAT_VAULT_PATH: ' ' },
|
||||
cwd,
|
||||
})).toThrow(VaultPathError);
|
||||
expect(() =>
|
||||
resolveVaultPath({
|
||||
args: [],
|
||||
env: { MINDOMAT_VAULT_PATH: ' ' },
|
||||
cwd,
|
||||
}),
|
||||
).toThrow(VaultPathError);
|
||||
});
|
||||
|
||||
it('loest relative Pfade gegen cwd auf', () => {
|
||||
|
||||
+22
-8
@@ -2,7 +2,7 @@
|
||||
// Bonus 21: Watcher-Edge-Cases
|
||||
|
||||
import { describe, it, expect, afterEach } from 'vitest';
|
||||
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
|
||||
import { mkdtempSync, mkdirSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { startInboxWatcher, type ActiveWatcher } from '../src/watcher.js';
|
||||
@@ -27,7 +27,9 @@ describe('startInboxWatcher', () => {
|
||||
const inbox = setupInbox();
|
||||
const processed: string[] = [];
|
||||
const watcher = await startInboxWatcher(inbox, {
|
||||
processNote: async (p) => { processed.push(p); },
|
||||
processNote: async (p) => {
|
||||
processed.push(p);
|
||||
},
|
||||
debounceMs: 50,
|
||||
});
|
||||
watchers.push(watcher);
|
||||
@@ -40,7 +42,9 @@ describe('startInboxWatcher', () => {
|
||||
const inbox = setupInbox();
|
||||
const processed: string[] = [];
|
||||
const watcher = await startInboxWatcher(inbox, {
|
||||
processNote: async (p) => { processed.push(p); },
|
||||
processNote: async (p) => {
|
||||
processed.push(p);
|
||||
},
|
||||
debounceMs: 100,
|
||||
});
|
||||
watchers.push(watcher);
|
||||
@@ -63,7 +67,9 @@ describe('startInboxWatcher', () => {
|
||||
const inbox = setupInbox();
|
||||
const processed: string[] = [];
|
||||
const watcher = await startInboxWatcher(inbox, {
|
||||
processNote: async (p) => { processed.push(p); },
|
||||
processNote: async (p) => {
|
||||
processed.push(p);
|
||||
},
|
||||
debounceMs: 100,
|
||||
});
|
||||
watchers.push(watcher);
|
||||
@@ -81,7 +87,9 @@ describe('startInboxWatcher', () => {
|
||||
const inbox = setupInbox();
|
||||
const processed: string[] = [];
|
||||
const watcher = await startInboxWatcher(inbox, {
|
||||
processNote: async (p) => { processed.push(p); },
|
||||
processNote: async (p) => {
|
||||
processed.push(p);
|
||||
},
|
||||
debounceMs: 100,
|
||||
});
|
||||
watchers.push(watcher);
|
||||
@@ -99,7 +107,9 @@ describe('startInboxWatcher', () => {
|
||||
const inbox = setupInbox();
|
||||
const processed: string[] = [];
|
||||
const watcher = await startInboxWatcher(inbox, {
|
||||
processNote: async (p) => { processed.push(p); },
|
||||
processNote: async (p) => {
|
||||
processed.push(p);
|
||||
},
|
||||
debounceMs: 500,
|
||||
});
|
||||
watchers.push(watcher);
|
||||
@@ -123,8 +133,12 @@ describe('startInboxWatcher', () => {
|
||||
const inbox = setupInbox();
|
||||
const errors: Array<{ err: Error; path: string }> = [];
|
||||
const watcher = await startInboxWatcher(inbox, {
|
||||
processNote: async () => { throw new Error('Test-Fehler'); },
|
||||
onError: (err, path) => { errors.push({ err, path }); },
|
||||
processNote: async () => {
|
||||
throw new Error('Test-Fehler');
|
||||
},
|
||||
onError: (err, path) => {
|
||||
errors.push({ err, path });
|
||||
},
|
||||
debounceMs: 100,
|
||||
});
|
||||
watchers.push(watcher);
|
||||
|
||||
@@ -24,7 +24,9 @@ describe('PWA-Manifest', () => {
|
||||
});
|
||||
|
||||
it('verweist auf existierende Icons', () => {
|
||||
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8')) as { icons: Array<{ src: string }> };
|
||||
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8')) as {
|
||||
icons: Array<{ src: string }>;
|
||||
};
|
||||
for (const icon of manifest.icons) {
|
||||
const iconPath = join(WEBAPP_DIR, 'public', icon.src);
|
||||
expect(existsSync(iconPath), `Icon fehlt: ${icon.src}`).toBe(true);
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
// Phase 4.1
|
||||
|
||||
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
|
||||
import { loadNote, saveNote, triggerSync, listNotes, type NoteData } from '../../webapp/src/notes-api';
|
||||
import {
|
||||
loadNote,
|
||||
saveNote,
|
||||
triggerSync,
|
||||
listNotes,
|
||||
type NoteData,
|
||||
} from '../../webapp/src/notes-api';
|
||||
|
||||
describe('notes-api Client', () => {
|
||||
let originalFetch: typeof globalThis.fetch;
|
||||
@@ -18,8 +24,8 @@ describe('notes-api Client', () => {
|
||||
|
||||
describe('loadNote', () => {
|
||||
it('gibt null zurueck bei 404', async () => {
|
||||
globalThis.fetch = vi.fn(async () =>
|
||||
new Response('Not Found', { status: 404, statusText: 'Not Found' }),
|
||||
globalThis.fetch = vi.fn(
|
||||
async () => new Response('Not Found', { status: 404, statusText: 'Not Found' }),
|
||||
) as typeof fetch;
|
||||
const result = await loadNote('notiz.md');
|
||||
expect(result).toBeNull();
|
||||
@@ -32,19 +38,21 @@ describe('notes-api Client', () => {
|
||||
frontmatter: { title: 'Test' },
|
||||
lastModified: '2026-09-05T10:00:00Z',
|
||||
};
|
||||
globalThis.fetch = vi.fn(async () =>
|
||||
new Response(JSON.stringify(noteData), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}),
|
||||
globalThis.fetch = vi.fn(
|
||||
async () =>
|
||||
new Response(JSON.stringify(noteData), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}),
|
||||
) as typeof fetch;
|
||||
const result = await loadNote('test.md');
|
||||
expect(result).toEqual(noteData);
|
||||
});
|
||||
|
||||
it('wirft bei HTTP-Fehler (500)', async () => {
|
||||
globalThis.fetch = vi.fn(async () =>
|
||||
new Response('Server Error', { status: 500, statusText: 'Internal Server Error' }),
|
||||
globalThis.fetch = vi.fn(
|
||||
async () =>
|
||||
new Response('Server Error', { status: 500, statusText: 'Internal Server Error' }),
|
||||
) as typeof fetch;
|
||||
await expect(loadNote('test.md')).rejects.toThrow('HTTP 500');
|
||||
});
|
||||
@@ -53,19 +61,21 @@ describe('notes-api Client', () => {
|
||||
const fetchMock = vi.fn(async () => new Response('null', { status: 404 })) as typeof fetch;
|
||||
globalThis.fetch = fetchMock;
|
||||
await loadNote('path with spaces.md');
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'/api/notes/path%20with%20spaces.md',
|
||||
);
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/notes/path%20with%20spaces.md');
|
||||
});
|
||||
});
|
||||
|
||||
describe('saveNote', () => {
|
||||
it('sendet PUT mit Content im Body', async () => {
|
||||
const fetchMock = vi.fn(async () =>
|
||||
new Response(JSON.stringify({ id: 'x.md', content: 'Y', frontmatter: {}, lastModified: 'now' }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}),
|
||||
const fetchMock = vi.fn(
|
||||
async () =>
|
||||
new Response(
|
||||
JSON.stringify({ id: 'x.md', content: 'Y', frontmatter: {}, lastModified: 'now' }),
|
||||
{
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
},
|
||||
),
|
||||
) as typeof fetch;
|
||||
globalThis.fetch = fetchMock;
|
||||
await saveNote('x.md', 'Y');
|
||||
@@ -80,11 +90,12 @@ describe('notes-api Client', () => {
|
||||
|
||||
describe('triggerSync', () => {
|
||||
it('sendet POST an /api/sync und gibt ok zurueck', async () => {
|
||||
const fetchMock = vi.fn(async () =>
|
||||
new Response(JSON.stringify({ ok: true, message: 'Sync OK' }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}),
|
||||
const fetchMock = vi.fn(
|
||||
async () =>
|
||||
new Response(JSON.stringify({ ok: true, message: 'Sync OK' }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}),
|
||||
) as typeof fetch;
|
||||
globalThis.fetch = fetchMock;
|
||||
const result = await triggerSync();
|
||||
@@ -93,29 +104,26 @@ describe('notes-api Client', () => {
|
||||
});
|
||||
|
||||
it('gibt Fehler zurueck bei 500', async () => {
|
||||
globalThis.fetch = vi.fn(async () =>
|
||||
new Response('Fail', { status: 500 }),
|
||||
) as typeof fetch;
|
||||
globalThis.fetch = vi.fn(async () => new Response('Fail', { status: 500 })) as typeof fetch;
|
||||
await expect(triggerSync()).rejects.toThrow('HTTP 500');
|
||||
});
|
||||
});
|
||||
|
||||
describe('listNotes', () => {
|
||||
it('parst Notiz-Liste', async () => {
|
||||
globalThis.fetch = vi.fn(async () =>
|
||||
new Response(JSON.stringify({ notes: ['a.md', 'b.md'] }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}),
|
||||
globalThis.fetch = vi.fn(
|
||||
async () =>
|
||||
new Response(JSON.stringify({ notes: ['a.md', 'b.md'] }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}),
|
||||
) as typeof fetch;
|
||||
const notes = await listNotes();
|
||||
expect(notes).toEqual(['a.md', 'b.md']);
|
||||
});
|
||||
|
||||
it('gibt leeres Array bei Fehler', async () => {
|
||||
globalThis.fetch = vi.fn(async () =>
|
||||
new Response('Boom', { status: 500 }),
|
||||
) as typeof fetch;
|
||||
globalThis.fetch = vi.fn(async () => new Response('Boom', { status: 500 })) as typeof fetch;
|
||||
await expect(listNotes()).rejects.toThrow('HTTP 500');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user