@@ -35,79 +35,89 @@ describe("Test different types of input", () => {
3535 // don't provide an extension to see if we can detect MIME
3636 // type based on contents
3737 const filename = "receipt" ;
38- const input = new Base64Input ( {
38+ const inputSource = new Base64Input ( {
3939 inputString : b64String ,
4040 filename : filename ,
4141 } ) ;
42- await input . init ( ) ;
43- expect ( input . inputType ) . to . equals ( INPUT_TYPE_BASE64 ) ;
44- expect ( input . filename ) . to . equals ( filename ) ;
45- expect ( input . mimeType ) . to . equals ( "image/jpeg" ) ;
42+ await inputSource . init ( ) ;
43+ expect ( inputSource . inputType ) . to . equals ( INPUT_TYPE_BASE64 ) ;
44+ expect ( inputSource . filename ) . to . equals ( filename ) ;
45+ expect ( inputSource . mimeType ) . to . equals ( "image/jpeg" ) ;
46+ expect ( inputSource . isPdf ( ) ) . to . false ;
47+ expect ( await inputSource . getPageCount ( ) ) . to . equals ( 1 ) ;
4648 // we need to insert a newline very 76 chars to match the format
4749 // of the input file.
48- const expectedString = input . fileObject
50+ const expectedString = inputSource . fileObject
4951 . toString ( "base64" )
5052 . replace ( / ( .{ 76 } ) / gm, "$1\n" ) ;
5153 expect ( expectedString ) . to . eqls ( b64String ) ;
5254 } ) ;
5355
5456 it ( "should accept JPEG files from a path" , async ( ) => {
55- const input = new PathInput ( {
57+ const inputSource = new PathInput ( {
5658 inputPath : path . join ( __dirname , "../data/products/expense_receipts/default_sample.jpg" ) ,
5759 } ) ;
58- await input . init ( ) ;
60+ await inputSource . init ( ) ;
5961
6062 const expectedResult = await fs . promises . readFile (
6163 path . join ( __dirname , "../data/products/expense_receipts/default_sample.jpg" )
6264 ) ;
63- expect ( input . inputType ) . to . equals ( INPUT_TYPE_PATH ) ;
64- expect ( input . filename ) . to . equals ( "default_sample.jpg" ) ;
65- expect ( input . mimeType ) . to . equals ( "image/jpeg" ) ;
66- expect ( input . fileObject ) . to . eqls ( expectedResult ) ;
65+ expect ( inputSource . inputType ) . to . equals ( INPUT_TYPE_PATH ) ;
66+ expect ( inputSource . filename ) . to . equals ( "default_sample.jpg" ) ;
67+ expect ( inputSource . mimeType ) . to . equals ( "image/jpeg" ) ;
68+ expect ( inputSource . isPdf ( ) ) . to . false ;
69+ expect ( await inputSource . getPageCount ( ) ) . to . equals ( 1 ) ;
70+ expect ( inputSource . fileObject ) . to . eqls ( expectedResult ) ;
6771 } ) ;
6872
6973 it ( "should accept TIFF from a path" , async ( ) => {
70- const input = new PathInput ( {
74+ const inputSource = new PathInput ( {
7175 inputPath : path . join ( __dirname , "../data/file_types/receipt.tif" ) ,
7276 } ) ;
73- await input . init ( ) ;
77+ await inputSource . init ( ) ;
7478 const expectedResult = await fs . promises . readFile (
7579 path . join ( __dirname , "../data/file_types/receipt.tif" )
7680 ) ;
77- expect ( input . inputType ) . to . equals ( INPUT_TYPE_PATH ) ;
78- expect ( input . filename ) . to . equals ( "receipt.tif" ) ;
79- expect ( input . mimeType ) . to . equals ( "image/tiff" ) ;
80- expect ( input . fileObject ) . to . eqls ( expectedResult ) ;
81+ expect ( inputSource . inputType ) . to . equals ( INPUT_TYPE_PATH ) ;
82+ expect ( inputSource . filename ) . to . equals ( "receipt.tif" ) ;
83+ expect ( inputSource . mimeType ) . to . equals ( "image/tiff" ) ;
84+ expect ( inputSource . isPdf ( ) ) . to . false ;
85+ expect ( await inputSource . getPageCount ( ) ) . to . equals ( 1 ) ;
86+ expect ( inputSource . fileObject ) . to . eqls ( expectedResult ) ;
8187 } ) ;
8288
8389 it ( "should accept HEIC from a path" , async ( ) => {
84- const input = new PathInput ( {
90+ const inputSource = new PathInput ( {
8591 inputPath : path . join ( __dirname , "../data/file_types/receipt.heic" ) ,
8692 } ) ;
87- await input . init ( ) ;
93+ await inputSource . init ( ) ;
8894 const expectedResult = await fs . promises . readFile (
8995 path . join ( __dirname , "../data/file_types/receipt.heic" )
9096 ) ;
91- expect ( input . inputType ) . to . equals ( INPUT_TYPE_PATH ) ;
92- expect ( input . filename ) . to . equals ( "receipt.heic" ) ;
93- expect ( input . mimeType ) . to . equals ( "image/heic" ) ;
94- expect ( input . fileObject ) . to . eqls ( expectedResult ) ;
97+ expect ( inputSource . inputType ) . to . equals ( INPUT_TYPE_PATH ) ;
98+ expect ( inputSource . filename ) . to . equals ( "receipt.heic" ) ;
99+ expect ( inputSource . mimeType ) . to . equals ( "image/heic" ) ;
100+ expect ( inputSource . isPdf ( ) ) . to . false ;
101+ expect ( await inputSource . getPageCount ( ) ) . to . equals ( 1 ) ;
102+ expect ( inputSource . fileObject ) . to . eqls ( expectedResult ) ;
95103 } ) ;
96104
97105 it ( "should accept read streams" , async ( ) => {
98106 const filePath = path . join ( __dirname , "../data/products/expense_receipts/default_sample.jpg" ) ;
99107 const stream = fs . createReadStream ( filePath ) ;
100108 const filename = "default_sample.jpg" ;
101- const input = new StreamInput ( {
109+ const inputSource = new StreamInput ( {
102110 inputStream : stream ,
103111 filename : filename ,
104112 } ) ;
105- await input . init ( ) ;
106- expect ( input . inputType ) . to . equals ( INPUT_TYPE_STREAM ) ;
107- expect ( input . filename ) . to . equals ( filename ) ;
108- expect ( input . mimeType ) . to . equals ( "image/jpeg" ) ;
113+ await inputSource . init ( ) ;
114+ expect ( inputSource . inputType ) . to . equals ( INPUT_TYPE_STREAM ) ;
115+ expect ( inputSource . filename ) . to . equals ( filename ) ;
116+ expect ( inputSource . mimeType ) . to . equals ( "image/jpeg" ) ;
117+ expect ( inputSource . isPdf ( ) ) . to . false ;
118+ expect ( await inputSource . getPageCount ( ) ) . to . equals ( 1 ) ;
109119 const expectedResult = await fs . promises . readFile ( filePath ) ;
110- expect ( input . fileObject . toString ( ) ) . to . eqls ( expectedResult . toString ( ) ) ;
120+ expect ( inputSource . fileObject . toString ( ) ) . to . eqls ( expectedResult . toString ( ) ) ;
111121 } ) ;
112122
113123 it ( "should accept raw bytes" , async ( ) => {
@@ -116,16 +126,18 @@ describe("Test different types of input", () => {
116126 // don't provide an extension to see if we can detect MIME
117127 // type based on contents
118128 const filename = "receipt" ;
119- const input = new BytesInput ( {
129+ const inputSource = new BytesInput ( {
120130 inputBytes : inputBytes ,
121131 filename : filename ,
122132 } ) ;
123- await input . init ( ) ;
124- expect ( input . inputType ) . to . equal ( INPUT_TYPE_BYTES ) ;
125- expect ( input . filename ) . to . equal ( filename ) ;
126- expect ( input . mimeType ) . to . equal ( "image/jpeg" ) ;
133+ await inputSource . init ( ) ;
134+ expect ( inputSource . inputType ) . to . equal ( INPUT_TYPE_BYTES ) ;
135+ expect ( inputSource . filename ) . to . equal ( filename ) ;
136+ expect ( inputSource . mimeType ) . to . equal ( "image/jpeg" ) ;
137+ expect ( inputSource . isPdf ( ) ) . to . false ;
138+ expect ( await inputSource . getPageCount ( ) ) . to . equals ( 1 ) ;
127139 const expectedResult = await fs . promises . readFile ( filePath ) ;
128- expect ( Buffer . compare ( input . fileObject , expectedResult ) ) . to . equal ( 0 ) ;
140+ expect ( Buffer . compare ( inputSource . fileObject , expectedResult ) ) . to . equal ( 0 ) ;
129141 } ) ;
130142
131143 it ( "should accept a Buffer" , async ( ) => {
@@ -135,15 +147,16 @@ describe("Test different types of input", () => {
135147 path . join ( __dirname , "../data/products/invoices/invoice_10p.pdf" )
136148 )
137149 ) ;
138- const input = new BufferInput ( {
150+ const inputSource = new BufferInput ( {
139151 buffer : buffer ,
140152 filename : filename ,
141153 } ) ;
142- await input . init ( ) ;
143- expect ( input . inputType ) . to . equals ( INPUT_TYPE_BUFFER ) ;
144- expect ( input . filename ) . to . equals ( filename ) ;
145- expect ( input . isPdf ( ) ) . to . be . true ;
146- expect ( input . fileObject ) . to . be . instanceOf ( Buffer ) ;
154+ await inputSource . init ( ) ;
155+ expect ( inputSource . inputType ) . to . equals ( INPUT_TYPE_BUFFER ) ;
156+ expect ( inputSource . filename ) . to . equals ( filename ) ;
157+ expect ( inputSource . isPdf ( ) ) . to . be . true ;
158+ expect ( await inputSource . getPageCount ( ) ) . to . equals ( 10 ) ;
159+ expect ( inputSource . fileObject ) . to . be . instanceOf ( Buffer ) ;
147160 } ) ;
148161
149162
0 commit comments