Initiales Projekt-Skelett appRobotFileservice
Ausgelagertes Programm-/File-Handling (vormals GCode.receiveFC im appRobotDriver, ToDo_4 / ToDo_6b). Express-Service mit .gcode + .json-Storage, aktivem Programm + Cursor, Teaching (FPoint) und Playback. Speicherung in Grad, driver-nativ (Radian) zum Driver. Konzept/API unter doc/draft_filehandeling*.md. Tests: jest (13 gruen). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
50
test/fileStore.test.js
Normal file
50
test/fileStore.test.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const fsp = require('fs/promises');
|
||||
const cfg = require('../src/config');
|
||||
const store = require('../src/store/fileStore');
|
||||
|
||||
let tmp;
|
||||
beforeAll(async () => {
|
||||
tmp = await fsp.mkdtemp(path.join(os.tmpdir(), 'fsvc-store-'));
|
||||
cfg.storageDir = tmp; // Storage-Verzeichnis für den Test umbiegen
|
||||
});
|
||||
afterAll(async () => {
|
||||
await fsp.rm(tmp, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('write + read + list + remove', async () => {
|
||||
await store.write('demo_a', {
|
||||
name: 'Demo A',
|
||||
lines: ['G90 G1 x0 y0 z0 a0 b0 c0 e0 f1000 ;1'],
|
||||
});
|
||||
expect(await store.exists('demo_a')).toBe(true);
|
||||
|
||||
const prog = await store.read('demo_a');
|
||||
expect(prog.name).toBe('Demo A');
|
||||
expect(prog.lines).toHaveLength(1);
|
||||
expect(prog.meta.angleUnit).toBe('deg');
|
||||
expect(prog.meta.createdAt).toBeTruthy();
|
||||
|
||||
const ls = await store.list();
|
||||
expect(ls.find((p) => p.id === 'demo_a')).toBeTruthy();
|
||||
|
||||
await store.remove('demo_a');
|
||||
expect(await store.exists('demo_a')).toBe(false);
|
||||
});
|
||||
|
||||
test('read von unbekanntem Programm → PROGRAM_NOT_FOUND', async () => {
|
||||
await expect(store.read('gibtsnicht')).rejects.toMatchObject({ code: 'PROGRAM_NOT_FOUND' });
|
||||
});
|
||||
|
||||
test('slugify entfernt Pfade & Sonderzeichen', () => {
|
||||
expect(store.slugify('../etc/passwd')).toBe('etc_passwd');
|
||||
expect(store.slugify('Demo C!')).toBe('demo_c');
|
||||
expect(store.slugify(' Mehr Worte ')).toBe('mehr_worte');
|
||||
});
|
||||
|
||||
test('assertValidId lehnt Pfad-Trenner ab', () => {
|
||||
expect(() => store.assertValidId('a/b')).toThrow();
|
||||
expect(() => store.assertValidId('..')).toThrow();
|
||||
expect(store.assertValidId('ok_123')).toBe('ok_123');
|
||||
});
|
||||
Reference in New Issue
Block a user