Skip to content
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ outport/
## 📚 Documentation

- **[CSV Writer Guide](docs/csv-writer.md)** - Examples and usage patterns for the CSV writer
- **[JSON Writer Guide](docs/json-writer.md)** - Examples and usage patterns for the JSON writer

## 🧪 Testing

Expand Down
25 changes: 18 additions & 7 deletions src/index.test.ts → __tests__/writers/WriterFactory.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
import { describe, it, expect } from 'vitest';
import { WriterFactory, ValidationError } from './index.js';
import { WriterFactory } from '../../src/writers/WriterFactory';
import { ValidationError } from '../../src/errors';

describe('WriterFactory', () => {
it('should export WriterFactory', () => {
it('should have create method', () => {
expect(WriterFactory).toBeDefined();
expect(typeof WriterFactory.create).toBe('function');
});

it('should throw ValidationError for unknown writer type', () => {
it('should create CsvWriter successfully', () => {
expect(() => {
WriterFactory.create({
type: 'unknown' as never,
type: 'csv',
mode: 'write',
file: 'test.csv',
});
}).toThrow(ValidationError);
}).not.toThrow();
});

it('should throw ValidationError for JSON writer (not yet implemented)', () => {
it('should create JsonWriter successfully', () => {
expect(() => {
WriterFactory.create({
type: 'json',
mode: 'write',
file: 'test.json',
});
}).toThrow('JSON writer not yet implemented');
}).not.toThrow();
});

it('should throw ValidationError for unknown writer type', () => {
expect(() => {
WriterFactory.create({
type: 'unknown' as never,
mode: 'write',
file: 'test.csv',
});
}).toThrow(ValidationError);
});
});
17 changes: 9 additions & 8 deletions __tests__/writers/csv/CsvWriter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ describe('CsvWriter', () => {
};

// Act & Assert
expect(() => new CsvWriter(options)).toThrow('Invalid writer type for CsvWriter');
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
expect(() => new CsvWriter(options as any)).toThrow('Invalid writer type for CsvWriter');
});

it('should throw error for empty file path', () => {
Expand Down Expand Up @@ -73,7 +74,7 @@ describe('CsvWriter', () => {
type: 'csv',
mode: 'write',
file: testFile,
csvConfig: {
config: {
delimiter: ',,',
},
};
Expand All @@ -88,7 +89,7 @@ describe('CsvWriter', () => {
type: 'csv',
mode: 'write',
file: testFile,
csvConfig: {
config: {
quote: '""',
},
};
Expand Down Expand Up @@ -127,7 +128,7 @@ describe('CsvWriter', () => {
type: 'csv',
mode: 'write',
file: testFile,
csvConfig: {
config: {
headers: ['ID', 'Name', 'Email'],
},
};
Expand All @@ -149,7 +150,7 @@ describe('CsvWriter', () => {
type: 'csv',
mode: 'write',
file: testFile,
csvConfig: {
config: {
columnMapping: {
id: 'User ID',
name: 'Full Name',
Expand All @@ -174,7 +175,7 @@ describe('CsvWriter', () => {
type: 'csv',
mode: 'write',
file: testFile,
csvConfig: {
config: {
includeKeys: ['name', 'email'],
},
};
Expand All @@ -195,7 +196,7 @@ describe('CsvWriter', () => {
type: 'csv',
mode: 'write',
file: testFile,
csvConfig: {
config: {
delimiter: '\t',
},
};
Expand All @@ -216,7 +217,7 @@ describe('CsvWriter', () => {
type: 'csv',
mode: 'write',
file: testFile,
csvConfig: {
config: {
includeUtf8Bom: true,
},
};
Expand Down
Loading