Skip to content

Commit

Permalink
feat(nest): code style updates, remove redundant libs (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec authored and NathanWalker committed Jan 7, 2019
1 parent d49c859 commit 72f0ddf
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 55 deletions.
10 changes: 5 additions & 5 deletions src/app.nest/_files/e2e/app/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as request from 'supertest';
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { ApplicationModule } from '../../src/app.module';
import { AppService } from '../../src/app.service';
import { INestApplication } from '@nestjs/common';

describe('Application', () => {
let app: INestApplication;
let appService = { get: () => 'Hello world' };
let appService = { getHello: () => 'Hello world' };

beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [ApplicationModule]
imports: [ApplicationModule],
})
.overrideProvider(AppService)
.useValue(appService)
Expand All @@ -24,7 +24,7 @@ describe('Application', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect(appService.get());
.expect(appService.getHello());
});

afterAll(async () => {
Expand Down
26 changes: 13 additions & 13 deletions src/app.nest/_files/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { Test } from "@nestjs/testing";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";
import { Test } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';

describe("App controller", () => {
describe('AppController', () => {
let appController: AppController;
let appService: AppService;

beforeEach(async () => {
const module = await Test.createTestingModule({
const testingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService]
providers: [AppService],
}).compile();

appService = module.get<AppService>(AppService);
appController = module.get<AppController>(AppController);
appService = testingModule.get<AppService>(AppService);
appController = testingModule.get<AppController>(AppController);
});

describe("hello world", () => {
it("should get response", async () => {
const result = "Hello world";
jest.spyOn(appService, "get").mockImplementation(() => result);
describe('getHello', () => {
it('should return "Hello world" string', async () => {
const result = 'Hello world';
jest.spyOn(appService, 'getHello').mockImplementation(() => result);

expect(await appController.root()).toBe(result);
expect(await appController.getHello()).toBe(result);
});
});
});
8 changes: 4 additions & 4 deletions src/app.nest/_files/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Get, Controller } from "@nestjs/common";
import { AppService } from "./app.service";
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
root(): string {
return this.appService.get();
getHello(): string {
return this.appService.getHello();
}
}
8 changes: 4 additions & 4 deletions src/app.nest/_files/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Module } from "@nestjs/common";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
imports: [],
controllers: [AppController],
providers: [AppService]
providers: [AppService],
})
export class ApplicationModule {}
6 changes: 3 additions & 3 deletions src/app.nest/_files/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from "@nestjs/common";
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
get() {
return "Hello world!";
getHello(): string {
return 'Hello world!';
}
}
29 changes: 3 additions & 26 deletions src/app.nest/_files/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
import { NestFactory } from "@nestjs/core";
import { ApplicationModule } from "./app.module";

import * as helmet from "helmet";
// import * as csurf from "csurf";
import * as rateLimit from "express-rate-limit";
import * as compression from "compression";

declare const module: any;
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(ApplicationModule, { cors: true });

app.use(helmet());
//app.use(csurf());
app.use(
rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100 // limit each IP to 100 requests per windowMs
})
);
app.use(compression());

const app = await NestFactory.create(ApplicationModule);
await app.listen(9000);

if (module.hot) {
module.hot.accept();
module.hot.dispose(() => app.close());
}
}
bootstrap();

0 comments on commit 72f0ddf

Please sign in to comment.