|
| 1 | +import AdmZip from 'adm-zip'; |
| 2 | +import { BaseProcessor } from '../../src/core/baseProcessor'; |
| 3 | +import { BaseValidator } from '../../src/validation/baseValidator'; |
| 4 | +import { ValidationResult } from '../../src/validation/validationTypes'; |
| 5 | + |
| 6 | +class TestProcessor extends BaseProcessor { |
| 7 | + async extractTexts(): Promise<string[]> { |
| 8 | + return []; |
| 9 | + } |
| 10 | + |
| 11 | + async loadIntoTree(): Promise<any> { |
| 12 | + return {}; |
| 13 | + } |
| 14 | + |
| 15 | + async processTexts(): Promise<Buffer> { |
| 16 | + return Buffer.from([]); |
| 17 | + } |
| 18 | + |
| 19 | + async saveFromTree(): Promise<void> { |
| 20 | + return; |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +class TestValidator extends BaseValidator { |
| 25 | + async validate(_content: any, _filename: string, _filesize: number): Promise<ValidationResult> { |
| 26 | + return this.buildResult('file', 0, 'test'); |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +describe('base defaults', () => { |
| 31 | + it('BaseProcessor provides a default zipAdapter', async () => { |
| 32 | + const processor = new TestProcessor(); |
| 33 | + const zip = new AdmZip(); |
| 34 | + zip.addFile('hello.txt', Buffer.from('hello', 'utf8')); |
| 35 | + const adapter = await (processor as any).options.zipAdapter(zip.toBuffer()); |
| 36 | + |
| 37 | + expect(adapter.listFiles()).toContain('hello.txt'); |
| 38 | + const contents = await adapter.readFile('hello.txt'); |
| 39 | + expect(Buffer.from(contents).toString('utf8')).toBe('hello'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('BaseValidator provides a default zipAdapter', async () => { |
| 43 | + const validator = new TestValidator(); |
| 44 | + const zip = new AdmZip(); |
| 45 | + zip.addFile('world.txt', Buffer.from('world', 'utf8')); |
| 46 | + const adapter = await (validator as any)._options.zipAdapter(zip.toBuffer()); |
| 47 | + |
| 48 | + expect(adapter.listFiles()).toContain('world.txt'); |
| 49 | + const contents = await adapter.readFile('world.txt'); |
| 50 | + expect(Buffer.from(contents).toString('utf8')).toBe('world'); |
| 51 | + }); |
| 52 | +}); |
0 commit comments