import { Client , credentials , Server } from '@grpc/grpc-js' ; import { expect } from '@loopback/testlab' ; import { createGRPCRecommendationServer } from '../..' ; import { loadRecommendationService } from '../../recommendation-grpc' ; const data = require ( '../../../data/recommendations.json' ) ; describe ( 'recommender' , ( ) => { let server ; let port ; before ( 'starting server' , async ( ) => { const result = await createGRPCRecommendationServer ( ) ; server = result . server ; port = result . port ; server . start ( ) ; } ) ; after ( 'stopping server' , async ( ) => { if ( server ) { server . forceShutdown ( ) ; } } ) ; let client ; before ( ( ) => { const RecommendationService = loadRecommendationService ( ) as unknown as typeof Client ; client = new RecommendationService ( `localhost:${ port }` , credentials . createInsecure ( ) ) ; } ) ; it ( 'returns product recommendations for user002' , done => { client . recommend ( { userId : 'user002' } , ( err , result ) => { if ( err ) return done ( err ) ; expect ( result ) . to . eql ( { products : data [ 'user002' ] } ) ; done ( ) ; } ) ; } ) ; it ( 'returns product recommendations for other users' , done => { client . recommend ( { userId : 'user004' } , ( err , result ) => { if ( err ) return done ( err ) ; expect ( result ) . to . eql ( { products : data [ 'user001' ] } ) ; done ( ) ; } ) ; } ) ; } ) ;