nestjs

What is the proper way to unit test Service with NestJS/Elastic

我与影子孤独终老i 提交于 2020-08-02 07:57:37
问题 Im trying to unit test a Service that uses elastic search. I want to make sure I am using the right techniques. I am new user to many areas of this problem, so most of my attempts have been from reading other problems similar to this and trying out the ones that make sense in my use case. I believe I am missing a field within the createTestingModule. Also sometimes I see providers: [Service] and others components: [Service] . const module: TestingModule = await Test.createTestingModule({

nestjs to azure windows app service - web.config settings

耗尽温柔 提交于 2020-07-22 18:51:47
问题 I've been trying to deploy my nestjs api to azure since yesterday and have not been successful. At first I was trying to push it to a linux cloud service plan and was able to deploy it from vs code, see in the azure logs that the app was successfully started, but it would not return any data from my endpoints and after some digging, I kept seeing some container failures. I tried troubleshooting that for a while then decided I would try setting it up on a windows app service instead. Following

nestjs to azure windows app service - web.config settings

好久不见. 提交于 2020-07-22 18:51:06
问题 I've been trying to deploy my nestjs api to azure since yesterday and have not been successful. At first I was trying to push it to a linux cloud service plan and was able to deploy it from vs code, see in the azure logs that the app was successfully started, but it would not return any data from my endpoints and after some digging, I kept seeing some container failures. I tried troubleshooting that for a while then decided I would try setting it up on a windows app service instead. Following

SpyOn TypeORM repository to change the return value for unit testing NestJS

ε祈祈猫儿з 提交于 2020-07-17 06:21:14
问题 I would like to unittest corner cases for my TypeORM database calls. I have already mocked all my TypeORM repositories with valid data. But I would like to SpyOn the repository and change the return value form TypeORM. How do I do that? import {INestApplication} from '@nestjs/common'; import {Test} from '@nestjs/testing'; import {CommonModule} from '@src/common/common.module'; import {AuthService} from './auth.service'; import {Repository} from 'typeorm'; import {V3User} from '@src/database

SpyOn TypeORM repository to change the return value for unit testing NestJS

廉价感情. 提交于 2020-07-17 06:21:07
问题 I would like to unittest corner cases for my TypeORM database calls. I have already mocked all my TypeORM repositories with valid data. But I would like to SpyOn the repository and change the return value form TypeORM. How do I do that? import {INestApplication} from '@nestjs/common'; import {Test} from '@nestjs/testing'; import {CommonModule} from '@src/common/common.module'; import {AuthService} from './auth.service'; import {Repository} from 'typeorm'; import {V3User} from '@src/database

How to hash password before inserting?

笑着哭i 提交于 2020-07-09 19:15:13
问题 I am using Nest.Js with TypeORM and I want to hash my password before persisting into the DB. I tried using the event decorator @BeforeInsert() however it wasn't working for me but later I found that it was not working because I was taking an DTO as an input. user.controller.ts @Post() async create(@Body() data: CreateUserDto, @Res() res) { // if user already exist const isUserExist = await this.service.findByEmail(data.email); if (isUserExist) { throw new BadRequestException('Email already

testing private functions in typescript with jest

眉间皱痕 提交于 2020-07-09 06:19:10
问题 In the below code my test case was passed as expected but i am using stryker for mutation testing , handleError function is survived in mutation testing , so i want to kill the mutant by testing the handleError function is being called or not. need to help to test the private function. i tried spyOn but didn't work const orderBuilderSpy = jest.spyOn(orderBuilder, 'build') const handleError = jest.fn() expect(rderBuilderSpy).toHaveBeenCalledWith(handleError) // code written in nestJS

testing private functions in typescript with jest

房东的猫 提交于 2020-07-09 06:17:50
问题 In the below code my test case was passed as expected but i am using stryker for mutation testing , handleError function is survived in mutation testing , so i want to kill the mutant by testing the handleError function is being called or not. need to help to test the private function. i tried spyOn but didn't work const orderBuilderSpy = jest.spyOn(orderBuilder, 'build') const handleError = jest.fn() expect(rderBuilderSpy).toHaveBeenCalledWith(handleError) // code written in nestJS

testing private functions in typescript with jest

自古美人都是妖i 提交于 2020-07-09 06:17:11
问题 In the below code my test case was passed as expected but i am using stryker for mutation testing , handleError function is survived in mutation testing , so i want to kill the mutant by testing the handleError function is being called or not. need to help to test the private function. i tried spyOn but didn't work const orderBuilderSpy = jest.spyOn(orderBuilder, 'build') const handleError = jest.fn() expect(rderBuilderSpy).toHaveBeenCalledWith(handleError) // code written in nestJS

NestJS jwt-passport Authentication

我怕爱的太早我们不能终老 提交于 2020-07-06 20:26:25
问题 I want to implement a distributable authentication library to use it on several of my projects. The library should implement JWT authentication method. The code is as follows: jwt.strategy.ts: import {ExtractJwt, Strategy} from 'passport-jwt'; import {PassportStrategy} from '@nestjs/passport'; import {Injectable} from '@nestjs/common'; import {JwtPayload, User} from './interfaces'; import {ConfigService} from "./config.service"; @Injectable() export class JwtStrategy extends PassportStrategy