Skip to content

Commit

Permalink
chore(): resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Feb 4, 2021
2 parents d381e14 + a86f2ae commit 29ca9e1
Show file tree
Hide file tree
Showing 211 changed files with 4,365 additions and 24,030 deletions.
1 change: 1 addition & 0 deletions integration/graphql-code-first/e2e/pipes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('GraphQL Pipes', () => {
code: 'INTERNAL_SERVER_ERROR',
exception: {
message: 'Bad Request Exception',
name: 'BadRequestException',
response: {
message: [
'description must be longer than or equal to 30 characters',
Expand Down
77 changes: 77 additions & 0 deletions integration/hello-world/e2e/router-module-middleware.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {
Controller,
Get,
INestApplication,
MiddlewareConsumer,
Module,
} from '@nestjs/common';
import { RouterModule } from '@nestjs/core';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { ApplicationModule } from '../src/app.module';

const RETURN_VALUE = 'test';
const SCOPED_VALUE = 'test_scoped';

@Controller()
class TestController {
@Get('test')
test() {
return RETURN_VALUE;
}

@Get('test2')
test2() {
return RETURN_VALUE;
}
}

@Module({
imports: [ApplicationModule],
controllers: [TestController],
})
class TestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply((req, res, next) => res.send(SCOPED_VALUE))
.forRoutes(TestController);
}
}

describe('RouterModule with Middleware functions', () => {
let app: INestApplication;

beforeEach(async () => {
app = (
await Test.createTestingModule({
imports: [
TestModule,
RouterModule.register([
{
path: '/module-path/',
module: TestModule,
},
]),
],
}).compile()
).createNestApplication();

await app.init();
});

it(`forRoutes(TestController) - /test`, () => {
return request(app.getHttpServer())
.get('/module-path/test')
.expect(200, SCOPED_VALUE);
});

it(`forRoutes(TestController) - /test2`, () => {
return request(app.getHttpServer())
.get('/module-path/test2')
.expect(200, SCOPED_VALUE);
});

afterEach(async () => {
await app.close();
});
});
99 changes: 99 additions & 0 deletions integration/hello-world/e2e/router-module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Controller, Get, INestApplication, Module } from '@nestjs/common';
import { RouterModule, Routes } from '@nestjs/core';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';

describe('RouterModule', () => {
let app: INestApplication;

abstract class BaseController {
@Get()
getName() {
return this.constructor.name;
}
}

@Controller('/parent-controller')
class ParentController extends BaseController {}
@Controller('/child-controller')
class ChildController extends BaseController {}
@Controller('no-slash-controller')
class NoSlashController extends BaseController {}

class UnknownController {}
@Module({ controllers: [ParentController] })
class ParentModule {}

@Module({ controllers: [ChildController] })
class ChildModule {}

@Module({})
class AuthModule {}
@Module({})
class PaymentsModule {}

@Module({ controllers: [NoSlashController] })
class NoSlashModule {}

const routes1: Routes = [
{
path: 'parent',
module: ParentModule,
children: [
{
path: 'child',
module: ChildModule,
},
],
},
];
const routes2: Routes = [
{ path: 'v1', children: [AuthModule, PaymentsModule, NoSlashModule] },
];

@Module({
imports: [ParentModule, ChildModule, RouterModule.register(routes1)],
})
class MainModule {}

@Module({
imports: [
AuthModule,
PaymentsModule,
NoSlashModule,
RouterModule.register(routes2),
],
})
class AppModule {}

before(async () => {
const moduleRef = await Test.createTestingModule({
imports: [MainModule, AppModule],
}).compile();

app = moduleRef.createNestApplication();
await app.init();
});

it('should hit the "ParentController"', async () => {
return request(app.getHttpServer())
.get('/parent/parent-controller')
.expect(200, 'ParentController');
});

it('should hit the "ChildController"', async () => {
return request(app.getHttpServer())
.get('/parent/child/child-controller')
.expect(200, 'ChildController');
});

it('should hit the "NoSlashController"', async () => {
return request(app.getHttpServer())
.get('/v1/no-slash-controller')
.expect(200, 'NoSlashController');
});

afterEach(async () => {
await app.close();
});
});
67 changes: 39 additions & 28 deletions integration/hooks/e2e/before-app-shutdown.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BeforeApplicationShutdown, Injectable } from '@nestjs/common';
import { BeforeApplicationShutdown, Injectable, Module } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import * as Sinon from 'sinon';
Expand All @@ -19,35 +19,46 @@ describe('BeforeApplicationShutdown', () => {
const instance = module.get(TestInjectable);
expect(instance.beforeApplicationShutdown.called).to.be.true;
});
/*
it('should not stop the server once beforeApplicationShutdown has been called', async () => {
let resolve;
const promise = new Promise(r => (resolve = r));
const module = await Test.createTestingModule({
providers: [
{
provide: 'Test',
useValue: {
beforeApplicationShutdown: () => promise,
},
},
],
}).compile();
Sinon.stub(module, 'dispose' as any);
const app = module.createNestApplication();

app.close();
it('should sort modules by distance (topological sort) - DESC order', async () => {
@Injectable()
class BB implements BeforeApplicationShutdown {
public field: string;
async beforeApplicationShutdown() {
this.field = 'b-field';
}
}

expect(((module as any).dispose as Sinon.SinonSpy).called, 'dispose').to.be
.false;
@Module({
providers: [BB],
exports: [BB],
})
class B {}

resolve();
@Injectable()
class AA implements BeforeApplicationShutdown {
public field: string;
constructor(private bb: BB) {}

setTimeout(
() =>
expect(((module as any).dispose as Sinon.SinonSpy).called, 'dispose').to
.be.true,
0,
);
});*/
async beforeApplicationShutdown() {
this.field = this.bb.field + '_a-field';
}
}
@Module({
imports: [B],
providers: [AA],
})
class A {}

const module = await Test.createTestingModule({
imports: [A],
}).compile();

const app = module.createNestApplication();
await app.init();
await app.close();

const instance = module.get(AA);
expect(instance.field).to.equal('b-field_a-field');
});
});
43 changes: 42 additions & 1 deletion integration/hooks/e2e/on-app-boostrap.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable, Module, OnApplicationBootstrap } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import * as Sinon from 'sinon';
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';

@Injectable()
class TestInjectable implements OnApplicationBootstrap {
Expand Down Expand Up @@ -41,4 +41,45 @@ describe('OnApplicationBootstrap', () => {
const app = module.createNestApplication();
await app.init().then(obj => expect(obj).to.not.be.undefined);
});

it('should sort modules by distance (topological sort) - DESC order', async () => {
@Injectable()
class BB implements OnApplicationBootstrap {
public field: string;
async onApplicationBootstrap() {
this.field = 'b-field';
}
}

@Module({
providers: [BB],
exports: [BB],
})
class B {}

@Injectable()
class AA implements OnApplicationBootstrap {
public field: string;
constructor(private bb: BB) {}

async onApplicationBootstrap() {
this.field = this.bb.field + '_a-field';
}
}
@Module({
imports: [B],
providers: [AA],
})
class A {}

const module = await Test.createTestingModule({
imports: [A],
}).compile();

const app = module.createNestApplication();
await app.init();

const instance = module.get(AA);
expect(instance.field).to.equal('b-field_a-field');
});
});
44 changes: 43 additions & 1 deletion integration/hooks/e2e/on-app-shutdown.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, OnApplicationShutdown } from '@nestjs/common';
import { Injectable, Module, OnApplicationShutdown } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import * as Sinon from 'sinon';
Expand All @@ -19,4 +19,46 @@ describe('OnApplicationShutdown', () => {
const instance = module.get(TestInjectable);
expect(instance.onApplicationShutdown.called).to.be.true;
});

it('should sort modules by distance (topological sort) - DESC order', async () => {
@Injectable()
class BB implements OnApplicationShutdown {
public field: string;
async onApplicationShutdown() {
this.field = 'b-field';
}
}

@Module({
providers: [BB],
exports: [BB],
})
class B {}

@Injectable()
class AA implements OnApplicationShutdown {
public field: string;
constructor(private bb: BB) {}

async onApplicationShutdown() {
this.field = this.bb.field + '_a-field';
}
}
@Module({
imports: [B],
providers: [AA],
})
class A {}

const module = await Test.createTestingModule({
imports: [A],
}).compile();

const app = module.createNestApplication();
await app.init();
await app.close();

const instance = module.get(AA);
expect(instance.field).to.equal('b-field_a-field');
});
});
Loading

0 comments on commit 29ca9e1

Please sign in to comment.