generated from include-davis/Next.js-App-Router-Starter
-
Notifications
You must be signed in to change notification settings - Fork 2
CSV ingestion fixes #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
CSV ingestion fixes #354
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
50debe1
CSV ingestion test
ReehalS 5427484
Linter fixes
ReehalS 18d4e40
Add error handling for csv validation
ReehalS bf10b19
Add error handling to uploading of valid teams
ReehalS 0aa4b3d
unify the memberLine to once per map
ReehalS e7dab80
update chosen trck naming and lint fixes
ReehalS 22c98c3
Lint fixes
ReehalS cf8f114
Suggested fixes
ReehalS e2feb6b
remove duplicate teamMemberLines
ReehalS 6f1bd0e
Add tests and improvements
ReehalS f2732ca
update to remove serialization toJson errors
ReehalS e306260
Implement redundancies and remove `Any` usage
ReehalS dd041bc
Merge branch 'main' into 349-csv-ingestion-fixes
ReehalS 7d045cb
Add duplicate talble number error catch
ReehalS a328746
remove rowIndexToOutputIndex map
ReehalS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # **.mjs | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { | ||
| matchCanonicalTrack, | ||
| sortTracks, | ||
| } from '@utils/csv-ingestion/csvAlgorithm'; | ||
|
|
||
| describe('csvAlgorithm track matching', () => { | ||
| it('matches tracks case-insensitively to canonical names', () => { | ||
| expect(matchCanonicalTrack('best hardware hack')).toBe( | ||
| 'Best Hardware Hack' | ||
| ); | ||
| expect(matchCanonicalTrack('Best hardware hack')).toBe( | ||
| 'Best Hardware Hack' | ||
| ); | ||
| }); | ||
|
|
||
| it('does not attempt to correct spelling', () => { | ||
| expect(matchCanonicalTrack('Best Hardwre Hack')).toBeNull(); | ||
| expect(matchCanonicalTrack('Best Assistive Technlogy')).toBeNull(); | ||
| }); | ||
|
|
||
| it('ingests all opt-in tracks and does not cap length', () => { | ||
| const tracks = sortTracks( | ||
| 'best hardware hack', | ||
| '', | ||
| '', | ||
| 'Best Use of Gemini API; Best Use of MongoDB Atlas, Best Use of Vectara | Best Use of Auth0' | ||
| ); | ||
|
|
||
| expect(tracks).toEqual([ | ||
| 'Best Hardware Hack', | ||
| 'Best Use of Gemini API', | ||
| 'Best Use of MongoDB Atlas', | ||
| 'Best Use of Vectara', | ||
| 'Best Use of Auth0', | ||
| ]); | ||
| }); | ||
|
|
||
| it('filters out excluded tracks', () => { | ||
| const tracks = sortTracks( | ||
| 'Best Hack for Social Good', | ||
| "Hacker's Choice Award", | ||
| '', | ||
| 'Best Hack for Social Good, Best Hardware Hack' | ||
| ); | ||
|
|
||
| expect(tracks).toEqual(['Best Hardware Hack']); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { validateCsvBlob } from '@utils/csv-ingestion/csvAlgorithm'; | ||
|
|
||
| describe('csvAlgorithm validation', () => { | ||
| it("silently ignores 'N/A' without warnings", async () => { | ||
| const csv = | ||
| 'Table Number,Project Status,Project Title,Track #1 (Primary Track),Track #2,Track #3,Opt-In Prizes\n' + | ||
| '12,Submitted (Gallery/Visible),Test Project,Best Beginner Hack,N/A,,\n'; | ||
|
|
||
| const blob = new Blob([csv], { type: 'text/csv' }); | ||
| const res = await validateCsvBlob(blob); | ||
|
|
||
| expect(res.ok).toBe(true); | ||
| expect(res.report.errorRows).toBe(0); | ||
| expect(res.report.warningRows).toBe(0); | ||
| expect(res.report.issues).toEqual([]); | ||
| }); | ||
|
|
||
| it('treats duplicate tracks as warnings (non-blocking)', async () => { | ||
| const csv = | ||
| 'Table Number,Project Status,Project Title,Track #1 (Primary Track),Track #2,Track #3,Opt-In Prizes\n' + | ||
| '87,Submitted (Gallery/Visible),PartyPal,Best UI/UX Design,Best UI/UX Design,,\n'; | ||
|
|
||
| const blob = new Blob([csv], { type: 'text/csv' }); | ||
| const res = await validateCsvBlob(blob); | ||
|
|
||
| expect(res.ok).toBe(true); | ||
| expect(res.report.errorRows).toBe(0); | ||
| expect(res.report.warningRows).toBe(1); | ||
| expect(res.report.issues[0].severity).toBe('warning'); | ||
| expect(res.report.issues[0].duplicateTracks).toEqual(['Best UI/UX Design']); | ||
| }); | ||
|
|
||
| it('detects duplicate teamNumbers as errors', async () => { | ||
| const csv = | ||
| 'Table Number,Project Status,Project Title,Track #1 (Primary Track),Track #2,Track #3,Opt-In Prizes\n' + | ||
| '42,Submitted (Gallery/Visible),Project A,Best Hardware Hack,,,\n' + | ||
| '42,Submitted (Gallery/Visible),Project B,Best UI/UX Design,,,\n'; | ||
|
|
||
| const blob = new Blob([csv], { type: 'text/csv' }); | ||
| const res = await validateCsvBlob(blob); | ||
|
|
||
| // Should have 1 error issue: second row with same teamNumber is flagged | ||
| expect(res.ok).toBe(false); | ||
| expect(res.report.errorRows).toBe(1); | ||
| expect(res.report.issues.length).toBe(1); | ||
| expect(res.report.issues[0].severity).toBe('error'); | ||
| expect(res.report.issues[0].duplicateTeamNumber).toBe(42); | ||
| expect(res.report.issues[0].teamNumber).toBe(42); | ||
| }); | ||
|
|
||
| it('detects multiple duplicate teamNumbers', async () => { | ||
| const csv = | ||
| 'Table Number,Project Status,Project Title,Track #1 (Primary Track),Track #2,Track #3,Opt-In Prizes\n' + | ||
| '10,Submitted (Gallery/Visible),Project A,Best Hardware Hack,,,\n' + | ||
| '10,Submitted (Gallery/Visible),Project B,Best UI/UX Design,,,\n' + | ||
| '20,Submitted (Gallery/Visible),Project C,Best Beginner Hack,,,\n' + | ||
| '20,Submitted (Gallery/Visible),Project D,Best Use of AWS,,,\n'; | ||
|
|
||
| const blob = new Blob([csv], { type: 'text/csv' }); | ||
| const res = await validateCsvBlob(blob); | ||
|
|
||
| expect(res.ok).toBe(false); | ||
| expect(res.report.errorRows).toBe(2); | ||
| expect(res.report.issues.length).toBe(2); | ||
|
|
||
| // Both should be errors with duplicateTeamNumber set | ||
| const duplicateIssues = res.report.issues.filter( | ||
| (i) => i.duplicateTeamNumber !== undefined | ||
| ); | ||
| expect(duplicateIssues.length).toBe(2); | ||
| expect(duplicateIssues[0].duplicateTeamNumber).toBe(10); | ||
| expect(duplicateIssues[1].duplicateTeamNumber).toBe(20); | ||
| }); | ||
|
|
||
| it('does not flag unique teamNumbers as duplicates', async () => { | ||
| const csv = | ||
| 'Table Number,Project Status,Project Title,Track #1 (Primary Track),Track #2,Track #3,Opt-In Prizes\n' + | ||
| '10,Submitted (Gallery/Visible),Project A,Best Hardware Hack,,,\n' + | ||
| '11,Submitted (Gallery/Visible),Project B,Best UI/UX Design,,,\n' + | ||
| '12,Submitted (Gallery/Visible),Project C,Best Beginner Hack,,,\n'; | ||
|
|
||
| const blob = new Blob([csv], { type: 'text/csv' }); | ||
| const res = await validateCsvBlob(blob); | ||
|
|
||
| expect(res.ok).toBe(true); | ||
| expect(res.report.errorRows).toBe(0); | ||
| expect(res.report.warningRows).toBe(0); | ||
| expect(res.report.issues).toEqual([]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { db } from '../../jest.setup'; | ||
| import checkTeamsPopulated from '@actions/logic/checkTeamsPopulated'; | ||
| import * as mongoClient from '@utils/mongodb/mongoClient.mjs'; | ||
|
|
||
| beforeEach(async () => { | ||
| await db.collection('teams').deleteMany({}); | ||
| }); | ||
|
|
||
| describe('checkTeamsPopulated', () => { | ||
| it('should return populated false and count 0 when no teams exist', async () => { | ||
| const result = await checkTeamsPopulated(); | ||
| expect(result.ok).toBe(true); | ||
| expect(result.populated).toBe(false); | ||
| expect(result.count).toBe(0); | ||
| expect(result.error).toBe(null); | ||
| }); | ||
|
|
||
| it('should return populated true and correct count when teams exist', async () => { | ||
| await db.collection('teams').insertMany( | ||
| [ | ||
| { | ||
| name: 'Team 1', | ||
| teamNumber: 1, | ||
| tableNumber: 1, | ||
| tracks: ['Best Hardware Hack'], | ||
| active: true, | ||
| }, | ||
| { | ||
| name: 'Team 2', | ||
| teamNumber: 2, | ||
| tableNumber: 2, | ||
| tracks: ['Data Science/Machine Learning'], | ||
| active: true, | ||
| }, | ||
| { | ||
| name: 'Team 3', | ||
| teamNumber: 3, | ||
| tableNumber: 3, | ||
| tracks: ['Beginner'], | ||
| active: false, | ||
| }, | ||
| ], | ||
| { bypassDocumentValidation: true } | ||
| ); | ||
|
|
||
| const result = await checkTeamsPopulated(); | ||
| expect(result.ok).toBe(true); | ||
| expect(result.populated).toBe(true); | ||
| expect(result.count).toBe(3); | ||
| expect(result.error).toBe(null); | ||
| }); | ||
|
|
||
| it('should return populated true and count 1 when exactly one team exists', async () => { | ||
| await db.collection('teams').insertOne( | ||
| { | ||
| name: 'Solo Team', | ||
| teamNumber: 1, | ||
| tableNumber: 1, | ||
| tracks: ['Best Hardware Hack'], | ||
| active: true, | ||
| }, | ||
| { bypassDocumentValidation: true } | ||
| ); | ||
|
|
||
| const result = await checkTeamsPopulated(); | ||
| expect(result.ok).toBe(true); | ||
| expect(result.populated).toBe(true); | ||
| expect(result.count).toBe(1); | ||
| expect(result.error).toBe(null); | ||
| }); | ||
|
|
||
| it('should handle database errors gracefully', async () => { | ||
| // Mock the getDatabase to throw an error | ||
| const mockGetDatabase = jest | ||
| .spyOn(mongoClient, 'getDatabase') | ||
| .mockRejectedValue(new Error('Database connection failed')); | ||
|
|
||
| const result = await checkTeamsPopulated(); | ||
|
|
||
| expect(result.ok).toBe(false); | ||
| expect(result.populated).toBe(false); | ||
| expect(result.count).toBe(0); | ||
| expect(result.error).toBe('Database connection failed'); | ||
|
|
||
| // Restore the mock | ||
| mockGetDatabase.mockRestore(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.