|
| 1 | +import { validateCsvBlob } from '@utils/csv-ingestion/csvAlgorithm'; |
| 2 | + |
| 3 | +type TeamRow = { |
| 4 | + tableNumber: number; |
| 5 | + projectTitle: string; |
| 6 | + status: string; |
| 7 | + primaryTrack: string; |
| 8 | +}; |
| 9 | + |
| 10 | +function buildCsv(rows: TeamRow[]): string { |
| 11 | + const header = [ |
| 12 | + 'Table Number', |
| 13 | + 'Project Status', |
| 14 | + 'Project Title', |
| 15 | + 'Track #1 (Primary Track)', |
| 16 | + 'Track #2', |
| 17 | + 'Track #3', |
| 18 | + 'Opt-In Prizes', |
| 19 | + ].join(','); |
| 20 | + |
| 21 | + const lines = rows.map((row) => |
| 22 | + [ |
| 23 | + String(row.tableNumber), |
| 24 | + row.status, |
| 25 | + row.projectTitle, |
| 26 | + row.primaryTrack, |
| 27 | + '', |
| 28 | + '', |
| 29 | + '', |
| 30 | + ].join(',') |
| 31 | + ); |
| 32 | + |
| 33 | + return `${header}\n${lines.join('\n')}`; |
| 34 | +} |
| 35 | + |
| 36 | +describe('csvAlgorithm table assignment', () => { |
| 37 | + it('assigns the first hardware team to A1', async () => { |
| 38 | + const csv = buildCsv([ |
| 39 | + { |
| 40 | + tableNumber: 1, |
| 41 | + status: 'Submitted', |
| 42 | + projectTitle: 'Hardware Team', |
| 43 | + primaryTrack: 'Best Hardware Hack', |
| 44 | + }, |
| 45 | + { |
| 46 | + tableNumber: 2, |
| 47 | + status: 'Submitted', |
| 48 | + projectTitle: 'Other Team', |
| 49 | + primaryTrack: 'Best AI/ML Hack', |
| 50 | + }, |
| 51 | + ]); |
| 52 | + |
| 53 | + const res = await validateCsvBlob(new Blob([csv], { type: 'text/csv' })); |
| 54 | + |
| 55 | + expect(res.ok).toBe(true); |
| 56 | + expect(res.body).not.toBeNull(); |
| 57 | + |
| 58 | + const hardwareTeam = res.body?.find((t) => t.name === 'Hardware Team'); |
| 59 | + expect(hardwareTeam?.tableNumber).toBe('A1'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('starts floor 2 at I1 after floor 1 capacity is filled', async () => { |
| 63 | + // Floor 1: 8 rows * 13 seats = 104. Floor 2 starts at 105th team |
| 64 | + const rows: TeamRow[] = Array.from({ length: 105 }, (_, i) => ({ |
| 65 | + tableNumber: i + 1, |
| 66 | + status: 'Submitted', |
| 67 | + projectTitle: `Team ${i + 1}`, |
| 68 | + primaryTrack: 'Best AI/ML Hack', |
| 69 | + })); |
| 70 | + |
| 71 | + const csv = buildCsv(rows); |
| 72 | + const res = await validateCsvBlob(new Blob([csv], { type: 'text/csv' })); |
| 73 | + |
| 74 | + if (!res.ok) { |
| 75 | + console.error('Unexpected error:', res.error); |
| 76 | + } |
| 77 | + expect(res.ok).toBe(true); |
| 78 | + expect(res.body).not.toBeNull(); |
| 79 | + expect(res.body?.length).toBe(105); |
| 80 | + // Last team on floor 1 |
| 81 | + expect(res.body?.[103].tableNumber).toBe('H13'); |
| 82 | + // First team on floor 2 |
| 83 | + expect(res.body?.[104].tableNumber).toBe('I1'); |
| 84 | + }); |
| 85 | + |
| 86 | + it('returns a global warning when team count exceeds venue capacity', async () => { |
| 87 | + // Total capacity: 104 (F1) + 60 (F2) = 164 |
| 88 | + // We provide 167 teams to trigger WAIT-n overflow labels. |
| 89 | + const rows: TeamRow[] = Array.from({ length: 167 }, (_, i) => ({ |
| 90 | + tableNumber: i + 1, |
| 91 | + status: 'Submitted', |
| 92 | + projectTitle: `Team ${i + 1}`, |
| 93 | + primaryTrack: 'Best AI/ML Hack', |
| 94 | + })); |
| 95 | + |
| 96 | + const csv = buildCsv(rows); |
| 97 | + const res = await validateCsvBlob(new Blob([csv], { type: 'text/csv' })); |
| 98 | + |
| 99 | + // Capacity overflow is non-blocking and surfaced as a global warning. |
| 100 | + expect(res.ok).toBe(true); |
| 101 | + expect(res.error).toBeNull(); |
| 102 | + expect(res.report.errorRows).toBe(0); |
| 103 | + expect(res.report.warningRows).toBe(0); |
| 104 | + expect(res.report.globalWarnings).toBeDefined(); |
| 105 | + expect(res.report.globalWarnings?.[0]).toContain('Capacity Exceeded'); |
| 106 | + |
| 107 | + // Verify that even with overflow, data was processed. |
| 108 | + expect(res.body).toHaveLength(167); |
| 109 | + |
| 110 | + // Verify the last team got a WAIT label. |
| 111 | + const lastTeam = res.body?.[166]; |
| 112 | + expect(lastTeam?.tableNumber).toBe('WAIT-3'); |
| 113 | + }); |
| 114 | +}); |
0 commit comments