refactor(api): extract buildSessionsCsv shared by worker + admin exports
This commit is contained in:
34
apps/api/test/csv.test.ts
Normal file
34
apps/api/test/csv.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { buildSessionsCsv, type SessionCsvRow } from '../src/lib/csv';
|
||||
|
||||
const row: SessionCsvRow = {
|
||||
id: 7,
|
||||
activityName: 'Frezen',
|
||||
userName: 'Jan',
|
||||
insoleType: 'Kurk',
|
||||
pairCount: 2,
|
||||
startTime: new Date('2026-06-17T08:00:00Z'),
|
||||
endTime: new Date('2026-06-17T08:01:30Z'),
|
||||
durationSeconds: 90,
|
||||
pausedSeconds: 0,
|
||||
};
|
||||
|
||||
describe('buildSessionsCsv', () => {
|
||||
it('omits the Worker column by default (legacy header)', () => {
|
||||
const lines = buildSessionsCsv([row]).split('\n');
|
||||
expect(lines[0]).toBe(
|
||||
'"ID","Task","Insole Type","No. of Insoles","Date","Total Duration","Paused Duration","Start Time","End Time"',
|
||||
);
|
||||
expect(lines[1]).toContain('"Frezen"');
|
||||
expect(lines[1]).toContain('"00:01:30"');
|
||||
expect(lines[1]).not.toContain('"Jan"');
|
||||
});
|
||||
|
||||
it('prepends a Worker column when includeWorker is true', () => {
|
||||
const lines = buildSessionsCsv([row], { includeWorker: true }).split('\n');
|
||||
expect(lines[0]).toBe(
|
||||
'"Worker","ID","Task","Insole Type","No. of Insoles","Date","Total Duration","Paused Duration","Start Time","End Time"',
|
||||
);
|
||||
expect(lines[1].startsWith('"Jan"')).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user