@@ -7,7 +7,9 @@ import assert from 'assert';
77import path from 'node:path' ;
88
99import {
10- type InternalValueRepresentation ,
10+ ERROR_TYPEGUARD ,
11+ type InternalValidValueRepresentation ,
12+ InvalidValue ,
1113 type JayveeServices ,
1214 type TransformDefinition ,
1315 createJayveeServices ,
@@ -33,6 +35,10 @@ import { type Table, type TableColumn } from '../types/io-types/table';
3335
3436import { type PortDetails , TransformExecutor } from './transform-executor' ;
3537
38+ function expectNoErrorsInColumn ( column : TableColumn ) {
39+ expect ( column . values . every ( ( value ) => ERROR_TYPEGUARD ( value ) ) ) ;
40+ }
41+
3642describe ( 'Validation of TransformExecutor' , ( ) => {
3743 let parse : (
3844 input : string ,
@@ -72,10 +78,7 @@ describe('Validation of TransformExecutor', () => {
7278 input : string ,
7379 inputTable : Table ,
7480 columnNames : string [ ] ,
75- ) : Promise < {
76- resultingColumn : TableColumn < InternalValueRepresentation > ;
77- rowsToDelete : number [ ] ;
78- } > {
81+ ) : Promise < TableColumn < InternalValidValueRepresentation > > {
7982 const document = await parse ( input , { validation : true } ) ;
8083 expectNoParserAndLexerErrors ( document ) ;
8184
@@ -147,15 +150,15 @@ describe('Validation of TransformExecutor', () => {
147150 transformColumnNames ,
148151 ) ;
149152
150- expect ( result . rowsToDelete ) . toHaveLength ( 0 ) ;
151- expect ( result . resultingColumn . valueType ) . toEqual (
153+ expectNoErrorsInColumn ( result ) ;
154+ expect ( result . valueType ) . toEqual (
152155 services . ValueTypeProvider . Primitives . Integer ,
153156 ) ;
154- expect ( result . resultingColumn . values ) . toHaveLength ( 1 ) ;
155- expect ( result . resultingColumn . values ) . toEqual ( expect . arrayContaining ( [ 21 ] ) ) ;
157+ expect ( result . values ) . toHaveLength ( 1 ) ;
158+ expect ( result . values ) . toEqual ( expect . arrayContaining ( [ 21 ] ) ) ;
156159 } ) ;
157160
158- it ( 'should diagnose no error on invalid value representation' , async ( ) => {
161+ it ( 'should evaluate InvalidValue on invalid value representation' , async ( ) => {
159162 const text = readJvTestAsset (
160163 'transform-executor/invalid-input-output-type-transform.jv' ,
161164 ) ;
@@ -187,12 +190,13 @@ describe('Validation of TransformExecutor', () => {
187190 transformColumnNames ,
188191 ) ;
189192
190- expect ( result . rowsToDelete ) . toHaveLength ( 1 ) ;
191- expect ( result . rowsToDelete ) . toEqual ( expect . arrayContaining ( [ 0 ] ) ) ;
192- expect ( result . resultingColumn . valueType ) . toEqual (
193+ expect ( result . valueType ) . toEqual (
193194 services . ValueTypeProvider . Primitives . Text ,
194195 ) ;
195- expect ( result . resultingColumn . values ) . toHaveLength ( 0 ) ;
196+ expect ( result . values ) . toHaveLength ( 1 ) ;
197+ const [ value ] = result . values ;
198+ assert ( value !== undefined ) ;
199+ expect ( value ) . toBeInstanceOf ( InvalidValue ) ;
196200 } ) ;
197201
198202 it ( 'should diagnose no error on valid value' , async ( ) => {
@@ -234,14 +238,12 @@ describe('Validation of TransformExecutor', () => {
234238 transformColumnNames ,
235239 ) ;
236240
237- expect ( result . rowsToDelete ) . toHaveLength ( 0 ) ;
238- expect ( result . resultingColumn . valueType ) . toEqual (
241+ expectNoErrorsInColumn ( result ) ;
242+ expect ( result . valueType ) . toEqual (
239243 services . ValueTypeProvider . Primitives . Integer ,
240244 ) ;
241- expect ( result . resultingColumn . values ) . toHaveLength ( 1 ) ;
242- expect ( result . resultingColumn . values ) . toEqual (
243- expect . arrayContaining ( [ 106 ] ) ,
244- ) ;
245+ expect ( result . values ) . toHaveLength ( 1 ) ;
246+ expect ( result . values ) . toEqual ( expect . arrayContaining ( [ 106 ] ) ) ;
245247 } ) ;
246248
247249 it ( 'should diagnose error on empty columns map' , async ( ) => {
@@ -287,7 +289,7 @@ describe('Validation of TransformExecutor', () => {
287289 }
288290 } ) ;
289291
290- it ( 'should diagnose no error on invalid column type' , async ( ) => {
292+ it ( 'should evaluate InvalidValue on invalid column type' , async ( ) => {
291293 const text = readJvTestAsset (
292294 'transform-executor/valid-decimal-integer-transform.jv' ,
293295 ) ;
@@ -319,14 +321,16 @@ describe('Validation of TransformExecutor', () => {
319321 transformColumnNames ,
320322 ) ;
321323
322- expect ( result . rowsToDelete ) . toHaveLength ( 1 ) ;
323- expect ( result . resultingColumn . valueType ) . toEqual (
324+ expect ( result . valueType ) . toEqual (
324325 services . ValueTypeProvider . Primitives . Integer ,
325326 ) ;
326- expect ( result . resultingColumn . values ) . toHaveLength ( 0 ) ;
327+ expect ( result . values ) . toHaveLength ( 1 ) ;
328+ const [ value ] = result . values ;
329+ assert ( value !== undefined ) ;
330+ expect ( value ) . toBeInstanceOf ( InvalidValue ) ;
327331 } ) ;
328332
329- it ( 'should diagnose no error on invalid row value' , async ( ) => {
333+ it ( 'should evaluate InvalidValue on invalid row value' , async ( ) => {
330334 const text = readJvTestAsset (
331335 'transform-executor/valid-decimal-integer-transform.jv' ,
332336 ) ;
@@ -358,15 +362,19 @@ describe('Validation of TransformExecutor', () => {
358362 transformColumnNames ,
359363 ) ;
360364
361- expect ( result . rowsToDelete ) . toHaveLength ( 1 ) ;
362- expect ( result . resultingColumn . valueType ) . toEqual (
365+ expect ( result . valueType ) . toEqual (
363366 services . ValueTypeProvider . Primitives . Integer ,
364367 ) ;
365- expect ( result . resultingColumn . values ) . toHaveLength ( 1 ) ;
366- expect ( result . resultingColumn . values ) . toEqual ( expect . arrayContaining ( [ 21 ] ) ) ;
368+ expect ( result . values ) . toHaveLength ( 2 ) ;
369+ const [ a , b ] = result . values ;
370+ assert ( a !== undefined ) ;
371+ assert ( b !== undefined ) ;
372+ expect ( a ) . toBeInstanceOf ( InvalidValue ) ;
373+ expect ( b ) . toBe ( 21 ) ;
374+ expect ( result . values ) . toEqual ( expect . arrayContaining ( [ 21 ] ) ) ;
367375 } ) ;
368376
369- it ( 'should diagnose no error on expression evaluation error ' , async ( ) => {
377+ it ( 'should evaluate InvalidValue on an erroneous expression ' , async ( ) => {
370378 const text = readJvTestAsset (
371379 'transform-executor/invalid-expression-evaluation-error.jv' ,
372380 ) ;
@@ -405,10 +413,12 @@ describe('Validation of TransformExecutor', () => {
405413 transformColumnNames ,
406414 ) ;
407415
408- expect ( result . rowsToDelete ) . toHaveLength ( 1 ) ;
409- expect ( result . resultingColumn . valueType ) . toEqual (
416+ expect ( result . valueType ) . toEqual (
410417 services . ValueTypeProvider . Primitives . Decimal ,
411418 ) ;
412- expect ( result . resultingColumn . values ) . toHaveLength ( 0 ) ;
419+ expect ( result . values ) . toHaveLength ( 1 ) ;
420+ const [ value ] = result . values ;
421+ assert ( value !== undefined ) ;
422+ expect ( value ) . toBeInstanceOf ( InvalidValue ) ;
413423 } ) ;
414424} ) ;
0 commit comments