Erzwinge innere Stimmigkeit in loadSession statt nur Typprüfung

Stapelzähler wird beim Laden immer aus den zugeordneten Einträgen neu
berechnet statt aus dem gespeicherten Wert übernommen. Zusätzlich wird
verworfen (null): Einträge mit unbekannter Stapelkennung, doppelte
Eintragsnummern, doppelte Stapelkennungen und ein nextEntryId, der nicht
größer als jede vorhandene Eintragsnummer ist.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
vchuser
2026-07-28 16:08:39 +02:00
co-authored by Claude Opus 5
parent 5fea22a8c1
commit 5966aab6b6
2 changed files with 83 additions and 0 deletions
+58
View File
@@ -108,6 +108,64 @@ test('Eintrag ohne Spec liefert null', () => {
assert.equal(loadSession(store), null);
});
test('Stapelzaehler wird beim Laden aus den Eintraegen neu berechnet', () => {
const store = fakeStore();
store.setItem('ram-sortierhilfe:session', JSON.stringify({
stacks: [{ id: 'A', count: 5, spec: emptySpec() }],
entries: [{ entryId: 1, stackId: 'A', spec: emptySpec(), source: 'barcode' }],
nextEntryId: 2,
}));
const wieder = loadSession(store);
assert.notEqual(wieder, null);
assert.equal(wieder.stacks[0].count, 1);
});
test('Eintrag mit unbekannter Stapelkennung liefert null', () => {
const store = fakeStore();
store.setItem('ram-sortierhilfe:session', JSON.stringify({
stacks: [],
entries: [{ entryId: 1, stackId: 'Z', spec: emptySpec(), source: 'barcode' }],
nextEntryId: 2,
}));
assert.equal(loadSession(store), null);
});
test('doppelte Eintragsnummern liefert null', () => {
const store = fakeStore();
store.setItem('ram-sortierhilfe:session', JSON.stringify({
stacks: [{ id: 'A', count: 2, spec: emptySpec() }],
entries: [
{ entryId: 1, stackId: 'A', spec: emptySpec(), source: 'barcode' },
{ entryId: 1, stackId: 'A', spec: emptySpec(), source: 'barcode' },
],
nextEntryId: 2,
}));
assert.equal(loadSession(store), null);
});
test('doppelte Stapelkennungen liefert null', () => {
const store = fakeStore();
store.setItem('ram-sortierhilfe:session', JSON.stringify({
stacks: [
{ id: 'A', count: 0, spec: emptySpec() },
{ id: 'A', count: 0, spec: emptySpec() },
],
entries: [],
nextEntryId: 1,
}));
assert.equal(loadSession(store), null);
});
test('nextEntryId nicht groesser als vorhandene Eintragsnummer liefert null', () => {
const store = fakeStore();
store.setItem('ram-sortierhilfe:session', JSON.stringify({
stacks: [{ id: 'A', count: 1, spec: emptySpec() }],
entries: [{ entryId: 5, stackId: 'A', spec: emptySpec(), source: 'barcode' }],
nextEntryId: 5,
}));
assert.equal(loadSession(store), null);
});
test('nach Sichern und Laden funktioniert Weiterarbeiten weiterhin', () => {
const store = fakeStore();
const session = createSession();