feat(data): settings.moderatorsPerDay in load/save JSON
This commit is contained in:
1 parent
7bda92a0a3
commit
a825a63961
2 files changed
+58
-3
No files matched your search
+48
-1
@@ -1,5 +1,5 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { addHistoryEntries, removeHistoryEntry } from '../js/data.js';
|
||||
import { addHistoryEntries, removeHistoryEntry, loadFromJSON, saveToJSON } from '../js/data.js';
|
||||
|
||||
function makeState(history = []) {
|
||||
return {
|
||||
@@ -76,4 +76,51 @@ function makeState(history = []) {
|
||||
assert.equal(state.history.length, 1, 'no change when employeeId not found');
|
||||
}
|
||||
|
||||
// loadFromJSON: missing settings → default {moderatorsPerDay: 1}
|
||||
{
|
||||
const json = JSON.stringify({
|
||||
employees: [],
|
||||
calendar: { holidays: [], companyClosures: [] },
|
||||
history: []
|
||||
});
|
||||
const loaded = loadFromJSON(json);
|
||||
assert.deepEqual(loaded.settings, { moderatorsPerDay: 1 }, 'default settings when missing');
|
||||
}
|
||||
|
||||
// loadFromJSON: present settings preserved, moderatorsPerDay clamped to [1,5]
|
||||
{
|
||||
const json = JSON.stringify({
|
||||
employees: [], calendar: { holidays: [], companyClosures: [] }, history: [],
|
||||
settings: { moderatorsPerDay: 3 }
|
||||
});
|
||||
const loaded = loadFromJSON(json);
|
||||
assert.equal(loaded.settings.moderatorsPerDay, 3, 'preserved value');
|
||||
}
|
||||
|
||||
// loadFromJSON: invalid moderatorsPerDay (string, out of range) → fallback to 1
|
||||
{
|
||||
const tooHigh = loadFromJSON(JSON.stringify({
|
||||
employees: [], calendar: { holidays: [], companyClosures: [] }, history: [],
|
||||
settings: { moderatorsPerDay: 99 }
|
||||
}));
|
||||
assert.equal(tooHigh.settings.moderatorsPerDay, 1, 'out of range falls back to 1');
|
||||
|
||||
const wrongType = loadFromJSON(JSON.stringify({
|
||||
employees: [], calendar: { holidays: [], companyClosures: [] }, history: [],
|
||||
settings: { moderatorsPerDay: 'two' }
|
||||
}));
|
||||
assert.equal(wrongType.settings.moderatorsPerDay, 1, 'wrong type falls back to 1');
|
||||
}
|
||||
|
||||
// saveToJSON: settings are serialized
|
||||
{
|
||||
const state = {
|
||||
employees: [], calendar: { holidays: [], companyClosures: [] }, history: [],
|
||||
settings: { moderatorsPerDay: 2 }
|
||||
};
|
||||
const json = saveToJSON(state);
|
||||
const parsed = JSON.parse(json);
|
||||
assert.deepEqual(parsed.settings, { moderatorsPerDay: 2 }, 'settings round-trip');
|
||||
}
|
||||
|
||||
console.log('All data tests passed.');
|
||||
Reference in new issue
Block a user