Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
CatService,
{
provide: getModelToken('Cat'),
// notice that only the functions we call from the model are mocked
useValue: {
new: jest.fn().mockResolvedValue(mockCat()),
constructor: jest.fn().mockResolvedValue(mockCat()),
find: jest.fn(),
findOne: jest.fn(),
update: jest.fn(),
create: jest.fn(),
remove: jest.fn(),
exec: jest.fn(),
},
},
],
}).compile();
service = module.get(CatService);
Module, MiddlewareConsumer, NestModule
} from '@nestjs/common';
import { AuthService } from './auth.service';
import { JwtStrategy } from './passport/jwt.strategy';
import { AuthController } from './auth.controller';
import { UserSchema } from '../users/schemas/user.schema';
import { EmailVerificationSchema } from '../auth/schemas/emailverification.schema';
import { ForgottenPasswordSchema } from './schemas/forgottenpassword.schema';
import { ConsentRegistrySchema } from './schemas/consentregistry.schema';
import { UsersService } from '../users/users.service';
import { JWTService } from './jwt.service';
import { MongooseModule } from '@nestjs/mongoose';
import { LoggerMiddleware } from '../common/middlewares/logger.middleware';
@Module({
imports: [MongooseModule.forFeature([
{ name: 'User', schema: UserSchema },
{ name: 'EmailVerification', schema: EmailVerificationSchema },
{ name: 'ForgottenPassword', schema: ForgottenPasswordSchema },
{ name: 'ConsentRegistry', schema: ConsentRegistrySchema }
])],
controllers: [AuthController],
providers: [AuthService, UsersService, JWTService, JwtStrategy],
})
export class AuthModule implements NestModule {
public configure(consumer: MiddlewareConsumer) {
consumer
.apply(LoggerMiddleware)
// .exclude(
// { path: 'example', method: RequestMethod.GET },
// )
.forRoutes(AuthController);
import { RoomsModule } from './rooms/rooms.module';
import { MongooseModule } from '@nestjs/mongoose';
import { CorsMiddleware } from './middlewares/cors.middleware';
import { AuthModule } from './auth/auth.module';
const getMongoUrl = () => {
if (process.env.MONGOUSER && process.env.MONGOPASSWORD) {
return `mongodb://${process.env.MONGOUSER}:${process.env.MONGOPASSWORD}@ds249839.mlab.com:49839/angular-nest-chat-app`;
} else {
return 'mongodb://localhost:27017/nest';
}
};
@Module({
imports: [MongooseModule.forRoot(getMongoUrl()),
UsersModule,
RoomsModule,
AuthModule
],
components: []
})
export class ApplicationModule {
// configure(consumer: MiddlewaresConsumer): void {
// consumer.apply(CorsMiddleware).forRoutes('*');
// }
}
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [
MongooseModule.forRoot(config.MONGO_URL),
ArticlesModule,
GraphQLModule.forRoot({
typePaths: ['./**/*.graphql'],
path: '/api/v2',
context: ({ req, res }: { req: Request; res: Response }) => ({
request: req
})
})
]
})
.overrideProvider(ArticlesSercice)
.useValue(articleService)
.compile();
app = await module.createNestApplication().init();
});
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
providers: [
UsersService,
{
provide: getModelToken('User'),
useValue: UserModel,
},
],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [
MongooseModule.forRoot(config.MONGO_URL),
HerosModule,
GraphQLModule.forRoot({
typePaths: ['./**/*.graphql'],
path: '/api/v2',
context: ({ req, res }: { req: Request; res: Response }) => ({
request: req
})
})
]
})
.overrideProvider(HerosService)
.useValue(heroService)
.overrideProvider(EmailService)
.useValue(emailService)
.compile();
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [
MongooseModule.forRoot(config.MONGO_URL),
CommentsModule,
GraphQLModule.forRoot({
typePaths: ['./**/*.graphql'],
path: '/api/v2',
context: ({ req, res }: { req: Request; res: Response }) => ({
request: req
})
})
]
})
.overrideProvider(CommentsService)
.useValue(commentsService)
.overrideProvider(ArticlesSercice)
.useValue({
findOneArticle() {
return { _id: '123' };
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [LinksModule]
})
.overrideProvider(getModelToken('Links'))
.useValue(mockRepository)
.compile();
linksService = module.get(LinksService);
});
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [TagsModule]
})
.overrideProvider(getModelToken('Tags'))
.useValue(mockRepository)
.overrideProvider(getModelToken('Articles'))
.useValue({})
.overrideProvider(ArticlesSercice)
.useValue({
aggregate() {
return [
{
_id: '123'
}
];
}
})
.compile();
tagsService = module.get(TagsService);
});
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [OptionsModule]
})
.overrideProvider(getModelToken('Options'))
.useValue(mockRepository)
.compile();
optionsService = module.get(OptionsService);
});