Skip to content

Commit 12aa576

Browse files
chore(): resolve merge conflicts
2 parents 2c7f76d + cb37ecb commit 12aa576

232 files changed

Lines changed: 4236 additions & 58784 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

integration/graphql-code-first/e2e/pipes.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('GraphQL Pipes', () => {
3333
code: 'INTERNAL_SERVER_ERROR',
3434
exception: {
3535
message: 'Bad Request Exception',
36+
name: 'BadRequestException',
3637
response: {
3738
message: [
3839
'description must be longer than or equal to 30 characters',
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import {
2+
Controller,
3+
Get,
4+
INestApplication,
5+
MiddlewareConsumer,
6+
Module,
7+
} from '@nestjs/common';
8+
import { RouterModule } from '@nestjs/core';
9+
import { Test } from '@nestjs/testing';
10+
import * as request from 'supertest';
11+
import { ApplicationModule } from '../src/app.module';
12+
13+
const RETURN_VALUE = 'test';
14+
const SCOPED_VALUE = 'test_scoped';
15+
16+
@Controller()
17+
class TestController {
18+
@Get('test')
19+
test() {
20+
return RETURN_VALUE;
21+
}
22+
23+
@Get('test2')
24+
test2() {
25+
return RETURN_VALUE;
26+
}
27+
}
28+
29+
@Module({
30+
imports: [ApplicationModule],
31+
controllers: [TestController],
32+
})
33+
class TestModule {
34+
configure(consumer: MiddlewareConsumer) {
35+
consumer
36+
.apply((req, res, next) => res.send(SCOPED_VALUE))
37+
.forRoutes(TestController);
38+
}
39+
}
40+
41+
describe('RouterModule with Middleware functions', () => {
42+
let app: INestApplication;
43+
44+
beforeEach(async () => {
45+
app = (
46+
await Test.createTestingModule({
47+
imports: [
48+
TestModule,
49+
RouterModule.register([
50+
{
51+
path: '/module-path/',
52+
module: TestModule,
53+
},
54+
]),
55+
],
56+
}).compile()
57+
).createNestApplication();
58+
59+
await app.init();
60+
});
61+
62+
it(`forRoutes(TestController) - /test`, () => {
63+
return request(app.getHttpServer())
64+
.get('/module-path/test')
65+
.expect(200, SCOPED_VALUE);
66+
});
67+
68+
it(`forRoutes(TestController) - /test2`, () => {
69+
return request(app.getHttpServer())
70+
.get('/module-path/test2')
71+
.expect(200, SCOPED_VALUE);
72+
});
73+
74+
afterEach(async () => {
75+
await app.close();
76+
});
77+
});
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { Controller, Get, INestApplication, Module } from '@nestjs/common';
2+
import { RouterModule, Routes } from '@nestjs/core';
3+
import { Test } from '@nestjs/testing';
4+
import * as request from 'supertest';
5+
6+
describe('RouterModule', () => {
7+
let app: INestApplication;
8+
9+
abstract class BaseController {
10+
@Get()
11+
getName() {
12+
return this.constructor.name;
13+
}
14+
}
15+
16+
@Controller('/parent-controller')
17+
class ParentController extends BaseController {}
18+
@Controller('/child-controller')
19+
class ChildController extends BaseController {}
20+
@Controller('no-slash-controller')
21+
class NoSlashController extends BaseController {}
22+
23+
class UnknownController {}
24+
@Module({ controllers: [ParentController] })
25+
class ParentModule {}
26+
27+
@Module({ controllers: [ChildController] })
28+
class ChildModule {}
29+
30+
@Module({})
31+
class AuthModule {}
32+
@Module({})
33+
class PaymentsModule {}
34+
35+
@Module({ controllers: [NoSlashController] })
36+
class NoSlashModule {}
37+
38+
const routes1: Routes = [
39+
{
40+
path: 'parent',
41+
module: ParentModule,
42+
children: [
43+
{
44+
path: 'child',
45+
module: ChildModule,
46+
},
47+
],
48+
},
49+
];
50+
const routes2: Routes = [
51+
{ path: 'v1', children: [AuthModule, PaymentsModule, NoSlashModule] },
52+
];
53+
54+
@Module({
55+
imports: [ParentModule, ChildModule, RouterModule.register(routes1)],
56+
})
57+
class MainModule {}
58+
59+
@Module({
60+
imports: [
61+
AuthModule,
62+
PaymentsModule,
63+
NoSlashModule,
64+
RouterModule.register(routes2),
65+
],
66+
})
67+
class AppModule {}
68+
69+
before(async () => {
70+
const moduleRef = await Test.createTestingModule({
71+
imports: [MainModule, AppModule],
72+
}).compile();
73+
74+
app = moduleRef.createNestApplication();
75+
await app.init();
76+
});
77+
78+
it('should hit the "ParentController"', async () => {
79+
return request(app.getHttpServer())
80+
.get('/parent/parent-controller')
81+
.expect(200, 'ParentController');
82+
});
83+
84+
it('should hit the "ChildController"', async () => {
85+
return request(app.getHttpServer())
86+
.get('/parent/child/child-controller')
87+
.expect(200, 'ChildController');
88+
});
89+
90+
it('should hit the "NoSlashController"', async () => {
91+
return request(app.getHttpServer())
92+
.get('/v1/no-slash-controller')
93+
.expect(200, 'NoSlashController');
94+
});
95+
96+
afterEach(async () => {
97+
await app.close();
98+
});
99+
});
Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BeforeApplicationShutdown, Injectable } from '@nestjs/common';
1+
import { BeforeApplicationShutdown, Injectable, Module } from '@nestjs/common';
22
import { Test } from '@nestjs/testing';
33
import { expect } from 'chai';
44
import * as Sinon from 'sinon';
@@ -19,35 +19,46 @@ describe('BeforeApplicationShutdown', () => {
1919
const instance = module.get(TestInjectable);
2020
expect(instance.beforeApplicationShutdown.called).to.be.true;
2121
});
22-
/*
23-
it('should not stop the server once beforeApplicationShutdown has been called', async () => {
24-
let resolve;
25-
const promise = new Promise(r => (resolve = r));
26-
const module = await Test.createTestingModule({
27-
providers: [
28-
{
29-
provide: 'Test',
30-
useValue: {
31-
beforeApplicationShutdown: () => promise,
32-
},
33-
},
34-
],
35-
}).compile();
36-
Sinon.stub(module, 'dispose' as any);
37-
const app = module.createNestApplication();
3822

39-
app.close();
23+
it('should sort modules by distance (topological sort) - DESC order', async () => {
24+
@Injectable()
25+
class BB implements BeforeApplicationShutdown {
26+
public field: string;
27+
async beforeApplicationShutdown() {
28+
this.field = 'b-field';
29+
}
30+
}
4031

41-
expect(((module as any).dispose as Sinon.SinonSpy).called, 'dispose').to.be
42-
.false;
32+
@Module({
33+
providers: [BB],
34+
exports: [BB],
35+
})
36+
class B {}
4337

44-
resolve();
38+
@Injectable()
39+
class AA implements BeforeApplicationShutdown {
40+
public field: string;
41+
constructor(private bb: BB) {}
4542

46-
setTimeout(
47-
() =>
48-
expect(((module as any).dispose as Sinon.SinonSpy).called, 'dispose').to
49-
.be.true,
50-
0,
51-
);
52-
});*/
43+
async beforeApplicationShutdown() {
44+
this.field = this.bb.field + '_a-field';
45+
}
46+
}
47+
@Module({
48+
imports: [B],
49+
providers: [AA],
50+
})
51+
class A {}
52+
53+
const module = await Test.createTestingModule({
54+
imports: [A],
55+
}).compile();
56+
57+
const app = module.createNestApplication();
58+
await app.init();
59+
await app.close();
60+
61+
const instance = module.get(AA);
62+
expect(instance.field).to.equal('b-field_a-field');
63+
});
5364
});

integration/hooks/e2e/on-app-boostrap.spec.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { Injectable, Module, OnApplicationBootstrap } from '@nestjs/common';
12
import { Test } from '@nestjs/testing';
23
import { expect } from 'chai';
34
import * as Sinon from 'sinon';
4-
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
55

66
@Injectable()
77
class TestInjectable implements OnApplicationBootstrap {
@@ -41,4 +41,45 @@ describe('OnApplicationBootstrap', () => {
4141
const app = module.createNestApplication();
4242
await app.init().then(obj => expect(obj).to.not.be.undefined);
4343
});
44+
45+
it('should sort modules by distance (topological sort) - DESC order', async () => {
46+
@Injectable()
47+
class BB implements OnApplicationBootstrap {
48+
public field: string;
49+
async onApplicationBootstrap() {
50+
this.field = 'b-field';
51+
}
52+
}
53+
54+
@Module({
55+
providers: [BB],
56+
exports: [BB],
57+
})
58+
class B {}
59+
60+
@Injectable()
61+
class AA implements OnApplicationBootstrap {
62+
public field: string;
63+
constructor(private bb: BB) {}
64+
65+
async onApplicationBootstrap() {
66+
this.field = this.bb.field + '_a-field';
67+
}
68+
}
69+
@Module({
70+
imports: [B],
71+
providers: [AA],
72+
})
73+
class A {}
74+
75+
const module = await Test.createTestingModule({
76+
imports: [A],
77+
}).compile();
78+
79+
const app = module.createNestApplication();
80+
await app.init();
81+
82+
const instance = module.get(AA);
83+
expect(instance.field).to.equal('b-field_a-field');
84+
});
4485
});

integration/hooks/e2e/on-app-shutdown.spec.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, OnApplicationShutdown } from '@nestjs/common';
1+
import { Injectable, Module, OnApplicationShutdown } from '@nestjs/common';
22
import { Test } from '@nestjs/testing';
33
import { expect } from 'chai';
44
import * as Sinon from 'sinon';
@@ -19,4 +19,46 @@ describe('OnApplicationShutdown', () => {
1919
const instance = module.get(TestInjectable);
2020
expect(instance.onApplicationShutdown.called).to.be.true;
2121
});
22+
23+
it('should sort modules by distance (topological sort) - DESC order', async () => {
24+
@Injectable()
25+
class BB implements OnApplicationShutdown {
26+
public field: string;
27+
async onApplicationShutdown() {
28+
this.field = 'b-field';
29+
}
30+
}
31+
32+
@Module({
33+
providers: [BB],
34+
exports: [BB],
35+
})
36+
class B {}
37+
38+
@Injectable()
39+
class AA implements OnApplicationShutdown {
40+
public field: string;
41+
constructor(private bb: BB) {}
42+
43+
async onApplicationShutdown() {
44+
this.field = this.bb.field + '_a-field';
45+
}
46+
}
47+
@Module({
48+
imports: [B],
49+
providers: [AA],
50+
})
51+
class A {}
52+
53+
const module = await Test.createTestingModule({
54+
imports: [A],
55+
}).compile();
56+
57+
const app = module.createNestApplication();
58+
await app.init();
59+
await app.close();
60+
61+
const instance = module.get(AA);
62+
expect(instance.field).to.equal('b-field_a-field');
63+
});
2264
});

0 commit comments

Comments
 (0)