@@ -2,6 +2,7 @@ import { SnapProcessor } from '../src/processors/snapProcessor';
22import { AACTree } from '../src/core/treeStructure' ;
33import path from 'path' ;
44import fs from 'fs' ;
5+ import AdmZip from 'adm-zip' ;
56
67describe ( 'SnapProcessor' , ( ) => {
78 const exampleFile : string = path . join ( __dirname , 'assets/snap/example.spb' ) ;
@@ -62,11 +63,6 @@ describe('SnapProcessor', () => {
6263
6364 it ( 'should handle .sub.zip files by extracting and processing the embedded .sps file' , async ( ) => {
6465 const processor = new SnapProcessor ( ) ;
65- // Skip test if example .sub.zip file doesn't exist
66- if ( ! fs . existsSync ( exampleSubZipFile ) ) {
67- console . warn ( `Skipping .sub.zip test - file not found: ${ exampleSubZipFile } ` ) ;
68- return ;
69- }
7066 const tree : AACTree = await processor . loadIntoTree ( exampleSubZipFile ) ;
7167 expect ( tree ) . toBeTruthy ( ) ;
7268 const pageIds : string [ ] = Object . keys ( tree . pages ) ;
@@ -89,6 +85,26 @@ describe('SnapProcessor', () => {
8985 const processor = new SnapProcessor ( ) ;
9086 await expect ( processor . loadIntoTree ( '' ) ) . rejects . toThrow ( ) ;
9187 } ) ;
88+
89+ it ( 'should throw error for .sub.zip file without .sps file inside' , async ( ) => {
90+ const processor = new SnapProcessor ( ) ;
91+ const zip = new AdmZip ( ) ;
92+ zip . addFile ( 'not-an-sps.txt' , Buffer . from ( 'Not a pageset' ) ) ;
93+ const invalidSubZipPath = path . join ( __dirname , 'invalid.sub.zip' ) ;
94+ zip . writeZip ( invalidSubZipPath ) ;
95+
96+ await expect ( processor . loadIntoTree ( invalidSubZipPath ) ) . rejects . toThrow (
97+ 'No .sps file found in .sub.zip archive'
98+ ) ;
99+
100+ // Cleanup
101+ fs . unlinkSync ( invalidSubZipPath ) ;
102+ } ) ;
103+
104+ it ( 'should throw error for .sub.zip file that does not exist' , async ( ) => {
105+ const processor = new SnapProcessor ( ) ;
106+ await expect ( processor . loadIntoTree ( 'non-existent.sub.zip' ) ) . rejects . toThrow ( ) ;
107+ } ) ;
92108 } ) ;
93109
94110 describe ( 'Audio Options' , ( ) => {
0 commit comments