@@ -16,7 +16,7 @@ import { ServiceBroker } from "moleculer";
1616import APISchema from "../../services/api.service.js" ;
1717import GreeterSchema from "../../services/greeter.service.js" ;
1818{ { #dbService} }
19- import ProductsSchema from "../../services/products.service.js" ;
19+ import ProductsSchema , { ProductEntity } from "../../services/products.service.js" ;
2020{ { / d b S e r v i c e } }
2121
2222describe ( "Test HTTP API gateway" , ( ) => {
@@ -34,7 +34,7 @@ describe("Test HTTP API gateway", () => {
3434 await broker . start ( ) ;
3535
3636 // Add small delay for API service to register product's custom endpoints
37- await ( broker . Promise as any ) . delay ( 500 ) ;
37+ await new Promise ( resolve => setTimeout ( resolve , 500 ) ) ;
3838 } ) ;
3939 afterAll ( ( ) => broker . stop ( ) ) ;
4040
@@ -234,9 +234,9 @@ describe("Test Socket.IO API gateway", () => {
234234 * @param {Object } params
235235 * @returns
236236 */
237- function callAwait ( client : Socket , action : string , params ?: any ) {
237+ function callAwait < TResult = unknown > ( client : Socket , action : string , params ?: any ) : Promise < TResult > {
238238 return new Promise ( function ( resolve , reject ) {
239- client . emit ( "call" , action , params , function ( err : any , res : any ) {
239+ client . emit ( "call" , action , params , function ( err : any , res : TResult ) {
240240 if ( err ) return reject ( err ) ;
241241 resolve ( res ) ;
242242 } ) ;
@@ -292,11 +292,11 @@ describe("Test Socket.IO API gateway", () => {
292292 } ) ;
293293
294294 it ( "test 'products.create'" , async ( ) => {
295- const res = await callAwait ( client , "products.create" , {
295+ const res = await callAwait < ProductEntity > ( client , "products.create" , {
296296 name : "Super Phone" ,
297297 price : 123
298298 } ) ;
299- PHONE_ID = ( res as any ) . id ;
299+ PHONE_ID = res . id ;
300300
301301 expect ( res ) . toEqual ( {
302302 id : expect . any ( String ) ,
@@ -526,9 +526,9 @@ describe("Test GraphQL API gateway", () => {
526526 }
527527 }
528528 ` ;
529- const res = await request ( `http://localhost:${ port } /graphql` , query ) ;
529+ const res = await request < { createProduct : ProductEntity } > ( `http://localhost:${ port } /graphql` , query ) ;
530530
531- PHONE_ID = ( res as any ) . createProduct . id ;
531+ PHONE_ID = res . createProduct . id ;
532532
533533 expect ( res ) . toEqual ( {
534534 createProduct : {
0 commit comments