@@ -123,6 +123,83 @@ describe('classifyImage function', () => {
123123 expect ( outputs ) . toMatchObject ( expectedOutputs ) ;
124124 } , 120000 ) ;
125125
126+ it ( 'should classify Steamboat-willie.jpg with raw uint8 resize return responses (integration smoke test)' , async ( { expect, annotate} ) => {
127+ // This is a smoke test. You must have a running gRPC server at localhost:50051 for this to pass.
128+ // You may want to mock the gRPC client for true unit testing.
129+ const imagePath = __dirname + '/Steamboat-willie.jpg' ;
130+ const sdk = new ClassifierSdk ( {
131+ deploymentId : process . env . VITE_ATHENA_DEPLOYMENT_ID ,
132+ affiliate : process . env . VITE_ATHENA_AFFILIATE ,
133+ authentication : {
134+ issuerUrl : process . env . VITE_OAUTH_ISSUER ,
135+ clientId : process . env . VITE_ATHENA_CLIENT_ID ,
136+ clientSecret : process . env . VITE_ATHENA_CLIENT_SECRET ,
137+ scope : 'manage:classify'
138+ }
139+ } ) ;
140+
141+ const correlationId = randomUUID ( ) ;
142+
143+ annotate ( `Correlation IDs: ${ correlationId } ` ) ;
144+
145+ // Create a promise to wrap the event emitter event 'data'
146+ const promise = new Promise < ClassificationOutput [ ] > ( ( resolve , reject ) => {
147+ // Add a timeout to reject the promise if no data is received in 30 seconds
148+ const timeout = setTimeout ( ( ) => {
149+ reject ( new Error ( 'Timeout waiting for classification response' ) ) ;
150+ } , 30000 ) ;
151+
152+ sdk . on ( 'data' , ( data ) => {
153+ const byCorrelationId = data . outputs . filter ( o => o . correlationId === correlationId ) ;
154+ if ( byCorrelationId . length > 0 ) {
155+ clearTimeout ( timeout ) ;
156+ resolve ( byCorrelationId ) ;
157+ }
158+ } ) ;
159+ sdk . once ( 'error' , ( err ) => {
160+ clearTimeout ( timeout ) ;
161+ reject ( err ) ;
162+ } ) ;
163+ } ) ;
164+
165+ // This will fail if no server is running, but will exercise the code path.
166+ let error : any = undefined ;
167+
168+ await sdk . open ( ) ;
169+
170+ const imageStream = fs . createReadStream ( imagePath ) ;
171+ const options : ClassifyImageInput = {
172+ imageStream,
173+ correlationId,
174+ resize : true ,
175+ } ;
176+ try {
177+ await sdk . sendClassifyRequest ( options ) ;
178+ } catch ( err ) {
179+ error = err ;
180+ }
181+
182+ // Wait for classifier to process some data....
183+ const first = await promise ;
184+ sdk . close ( ) ;
185+
186+ expect ( first ) . toBeDefined ( ) ;
187+ expect ( first ) . toMatchObject ( [
188+ {
189+ correlationId,
190+ classifications : expect . arrayContaining ( [
191+ {
192+ label : expect . any ( String ) ,
193+ weight : expect . any ( Number )
194+ }
195+ ] )
196+ } as ClassificationOutput
197+ ] ) ;
198+
199+ // Accept either a successful call or a connection error (for CI/dev convenience)
200+ expect ( error ) . toBeUndefined ( ) ;
201+ } , 120000 ) ;
202+
126203 it ( 'should classify Steamboat-willie.jpg and return responses (integration smoke test)' , async ( { expect, annotate} ) => {
127204 // This is a smoke test. You must have a running gRPC server at localhost:50051 for this to pass.
128205 // You may want to mock the gRPC client for true unit testing.
@@ -170,7 +247,8 @@ describe('classifyImage function', () => {
170247 const imageStream = fs . createReadStream ( imagePath ) ;
171248 const options : ClassifyImageInput = {
172249 imageStream,
173- correlationId
250+ correlationId,
251+ format : ImageFormat . JPEG
174252 } ;
175253 try {
176254 await sdk . sendClassifyRequest ( options ) ;
0 commit comments