1+ import { describe , it , expect } from 'vitest' ;
2+ import { parseCSV } from '../lib/utils' ;
3+
4+ describe ( 'CSV Parsing Issue Reproduction' , ( ) => {
5+ it ( 'should handle the exact CSV format provided by user' , ( ) => {
6+ const csvContent = `"Timestamp","User","Model","Requests Used","Exceeds Monthly Quota","Total Monthly Quota"
7+ "2025-06-11T05:13:27.8766440Z","xyz","gpt-4.1-2025-04-14","1","False","Unlimited"
8+ "2025-06-11T05:09:40.8432110Z","xyz","gpt-4.1-2025-04-14","1","False","Unlimited"` ;
9+
10+ console . log ( 'Testing user CSV content:' ) ;
11+ console . log ( csvContent ) ;
12+ console . log ( '' ) ;
13+
14+ // This should parse without issues
15+ expect ( ( ) => parseCSV ( csvContent ) ) . not . toThrow ( ) ;
16+
17+ const result = parseCSV ( csvContent ) ;
18+ expect ( result ) . toHaveLength ( 2 ) ;
19+ expect ( result [ 0 ] . user ) . toBe ( 'xyz' ) ;
20+ expect ( result [ 0 ] . model ) . toBe ( 'gpt-4.1-2025-04-14' ) ;
21+ expect ( result [ 0 ] . requestsUsed ) . toBe ( 1 ) ;
22+ expect ( result [ 0 ] . exceedsQuota ) . toBe ( false ) ;
23+ expect ( result [ 0 ] . totalMonthlyQuota ) . toBe ( 'Unlimited' ) ;
24+ } ) ;
25+
26+ it ( 'should handle header with potential whitespace issues' , ( ) => {
27+ // Test with potential whitespace or encoding issues
28+ const csvWithExtraSpacing = `"Timestamp","User","Model","Requests Used","Exceeds Monthly Quota","Total Monthly Quota"
29+ "2025-06-11T05:13:27.8766440Z","xyz","gpt-4.1-2025-04-14","1","False","Unlimited"` ;
30+
31+ expect ( ( ) => parseCSV ( csvWithExtraSpacing ) ) . not . toThrow ( ) ;
32+
33+ const result = parseCSV ( csvWithExtraSpacing ) ;
34+ expect ( result ) . toHaveLength ( 1 ) ;
35+ expect ( result [ 0 ] . totalMonthlyQuota ) . toBe ( 'Unlimited' ) ;
36+ } ) ;
37+
38+ it ( 'should handle header without quotes' , ( ) => {
39+ const csvWithoutQuotes = `Timestamp,User,Model,Requests Used,Exceeds Monthly Quota,Total Monthly Quota
40+ 2025-06-11T05:13:27.8766440Z,xyz,gpt-4.1-2025-04-14,1,False,Unlimited` ;
41+
42+ expect ( ( ) => parseCSV ( csvWithoutQuotes ) ) . not . toThrow ( ) ;
43+ const result = parseCSV ( csvWithoutQuotes ) ;
44+ expect ( result ) . toHaveLength ( 1 ) ;
45+ } ) ;
46+
47+ it ( 'should handle data rows with trailing spaces' , ( ) => {
48+ const csvWithTrailingSpaceInData = `"Timestamp","User","Model","Requests Used","Exceeds Monthly Quota","Total Monthly Quota"
49+ "2025-06-11T05:13:27.8766440Z","xyz","gpt-4.1-2025-04-14","1","False","Unlimited" ` ;
50+
51+ expect ( ( ) => parseCSV ( csvWithTrailingSpaceInData ) ) . not . toThrow ( ) ;
52+ const result = parseCSV ( csvWithTrailingSpaceInData ) ;
53+ expect ( result ) . toHaveLength ( 1 ) ;
54+ expect ( result [ 0 ] . totalMonthlyQuota ) . toBe ( 'Unlimited' ) ;
55+ } ) ;
56+ } ) ;
0 commit comments