Bahn: aisupport, Analyse-O2C-C2S, awesome-bahn-mcp-servers, beam-mcp,
Confluence_Bot, db-planet-mcp-server, O2C-Harness, project-audit,
Projekt-KIQ-HP, teamlandkarte-mcp
Dhive: Jury-Voting
Privat: CV, NoteGraph (NOTE: NoteGraph needs complete redo after consolidation)
Shared: AI-Orchestrator, OrgMyLife, power_skills_and_more
Shared/references: symphony (read-only)
Bahn repos remain available as independent remotes - this monorepo
pulls them in via subtree, the originals are untouched.
72 lines
2.8 KiB
TypeScript
72 lines
2.8 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { shouldAcceptScore, resolveConflict } from '../conflict.js';
|
|
import { Score } from '../../shared/types.js';
|
|
|
|
function makeScore(overrides: Partial<Score> = {}): Score {
|
|
return {
|
|
jurorId: 'finke',
|
|
teamId: 'dual',
|
|
criterionId: 'gesamtidee',
|
|
value: 7,
|
|
updatedAt: '2026-05-19T18:00:00.000Z',
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe('shouldAcceptScore', () => {
|
|
it('accepts when no existing score', () => {
|
|
const incoming = makeScore();
|
|
const result = shouldAcceptScore(incoming, undefined);
|
|
expect(result).toEqual({ accept: true });
|
|
});
|
|
|
|
it('accepts when incoming timestamp is newer', () => {
|
|
const existing = makeScore({ updatedAt: '2026-05-19T18:00:00.000Z' });
|
|
const incoming = makeScore({ updatedAt: '2026-05-19T18:01:00.000Z', value: 9 });
|
|
const result = shouldAcceptScore(incoming, existing);
|
|
expect(result).toEqual({ accept: true });
|
|
});
|
|
|
|
it('rejects when incoming timestamp is older', () => {
|
|
const existing = makeScore({ updatedAt: '2026-05-19T18:01:00.000Z' });
|
|
const incoming = makeScore({ updatedAt: '2026-05-19T18:00:00.000Z', value: 3 });
|
|
const result = shouldAcceptScore(incoming, existing);
|
|
expect(result).toEqual({ accept: false, reason: 'Newer score already exists' });
|
|
});
|
|
|
|
it('rejects when timestamps are equal', () => {
|
|
const existing = makeScore({ updatedAt: '2026-05-19T18:00:00.000Z' });
|
|
const incoming = makeScore({ updatedAt: '2026-05-19T18:00:00.000Z', value: 5 });
|
|
const result = shouldAcceptScore(incoming, existing);
|
|
expect(result).toEqual({ accept: false, reason: 'Newer score already exists' });
|
|
});
|
|
});
|
|
|
|
describe('resolveConflict', () => {
|
|
it('accepts when force is true regardless of timestamps', () => {
|
|
const existing = makeScore({ updatedAt: '2026-05-19T18:01:00.000Z' });
|
|
const incoming = makeScore({ updatedAt: '2026-05-19T18:00:00.000Z', value: 2 });
|
|
const result = resolveConflict(incoming, existing, true);
|
|
expect(result).toEqual({ accept: true });
|
|
});
|
|
|
|
it('delegates to shouldAcceptScore when force is false', () => {
|
|
const existing = makeScore({ updatedAt: '2026-05-19T18:01:00.000Z' });
|
|
const incoming = makeScore({ updatedAt: '2026-05-19T18:00:00.000Z', value: 2 });
|
|
const result = resolveConflict(incoming, existing, false);
|
|
expect(result).toEqual({ accept: false, reason: 'Newer score already exists' });
|
|
});
|
|
|
|
it('delegates to shouldAcceptScore when force is undefined', () => {
|
|
const incoming = makeScore();
|
|
const result = resolveConflict(incoming, undefined);
|
|
expect(result).toEqual({ accept: true });
|
|
});
|
|
|
|
it('accepts with force even when no existing score', () => {
|
|
const incoming = makeScore();
|
|
const result = resolveConflict(incoming, undefined, true);
|
|
expect(result).toEqual({ accept: true });
|
|
});
|
|
});
|