I have a controller in nestjs
as below
import * as dialogflow from \'dialogflow-fulfillment\';
import { Request, Response } from \'express\';
@Cont
In this case I'd suggest to write a facade (wrapper) around the library. The facade does not need to be unit tested since it simply propagates the parameters and does not contain logic (you could write a "facade test" instead which essentially tests the library code, I'd say an integration test is a better fit):
@Injectable()
export class WebHookClientFacade {
create(request, response) {
return new dialogflow.WebhookClient({ request, response });
}
}
And use the facade in your controller that is now testable:
constructor(private webHookClientBuilder: WebHookClientFacade) {}
@Post()
async fulfill(@Req() request: Request, @Res() response: Response) {
const agent = this.webHookClientBuilder.create(request, response);
}