Initial commit: CraftDock as of 2026-11-01
The previous GitHub history was lost with the account (the local .git was missing its refs and most objects), so this repository starts from the existing code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
640e52c0c9
99 files changed
+12115
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { createPropertiesService } from '../../src/services/propertiesService.js';
|
||||
|
||||
const SAMPLE = `#Minecraft server properties
|
||||
#Mon Jul 18
|
||||
difficulty=easy
|
||||
pvp=true
|
||||
max-players=20`;
|
||||
|
||||
function makeFs(content) {
|
||||
const store = { value: content };
|
||||
return {
|
||||
store,
|
||||
readFile: vi.fn().mockImplementation(async () => store.value),
|
||||
writeFile: vi.fn().mockImplementation(async (_p, data) => { store.value = data; }),
|
||||
};
|
||||
}
|
||||
|
||||
describe('propertiesService', () => {
|
||||
it('parses key=value ignoring comments', () => {
|
||||
const svc = createPropertiesService({ mcDataPath: '/d' }, makeFs(SAMPLE));
|
||||
const obj = svc.parse(SAMPLE);
|
||||
expect(obj).toEqual({ difficulty: 'easy', pvp: 'true', 'max-players': '20' });
|
||||
});
|
||||
|
||||
it('serialize preserves comments and updates values', () => {
|
||||
const svc = createPropertiesService({ mcDataPath: '/d' }, makeFs(SAMPLE));
|
||||
const out = svc.serialize({ difficulty: 'hard', pvp: 'true', 'max-players': '20' }, SAMPLE);
|
||||
expect(out).toContain('#Minecraft server properties');
|
||||
expect(out).toContain('difficulty=hard');
|
||||
});
|
||||
|
||||
it('update merges patch and writes file', async () => {
|
||||
const fs = makeFs(SAMPLE);
|
||||
const svc = createPropertiesService({ mcDataPath: '/d' }, fs);
|
||||
const merged = await svc.update({ difficulty: 'hard' });
|
||||
expect(merged.difficulty).toBe('hard');
|
||||
expect(fs.writeFile).toHaveBeenCalled();
|
||||
expect(fs.store.value).toContain('difficulty=hard');
|
||||
});
|
||||
|
||||
it('update appends new keys not present originally', async () => {
|
||||
const fs = makeFs(SAMPLE);
|
||||
const svc = createPropertiesService({ mcDataPath: '/d' }, fs);
|
||||
await svc.update({ motd: 'Hello' });
|
||||
expect(fs.store.value).toContain('motd=Hello');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user