Skip to content

Commit 758201c

Browse files
Merge branch 'master' into patch-1
2 parents ee8b112 + 205d737 commit 758201c

84 files changed

Lines changed: 2381 additions & 1657 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/package-lock.json

Lines changed: 55 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/graphql/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
"start:prod": "node dist/main.js"
1010
},
1111
"dependencies": {
12-
"@nestjs/common": "6.0.3",
13-
"@nestjs/core": "6.0.3",
14-
"@nestjs/graphql": "6.0.3",
12+
"@nestjs/common": "6.0.5",
13+
"@nestjs/core": "6.0.5",
14+
"@nestjs/graphql": "6.0.5",
1515
"apollo-server-express": "2.4.8",
16-
"graphql": "14.2.0",
16+
"graphql": "14.2.1",
1717
"graphql-tools": "4.0.4",
1818
"reflect-metadata": "0.1.13",
1919
"rxjs": "6.4.0",
2020
"subscriptions-transport-ws": "0.9.16",
21-
"typescript": "3.3.4000",
21+
"typescript": "3.4.3",
2222
"ws": "6.2.1"
2323
},
2424
"devDependencies": {
2525
"@types/node": "7.10.5",
2626
"ts-node": "8.0.3",
27-
"tslint": "5.14.0"
27+
"tslint": "5.15.0"
2828
}
2929
}

integration/hello-world/e2e/interceptors.spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,34 @@ export class TransformInterceptor {
2828
}
2929
}
3030

31+
@Injectable()
32+
export class StatusInterceptor {
33+
constructor(private statusCode: number) {}
34+
35+
intercept(context: ExecutionContext, next: CallHandler) {
36+
const ctx = context.switchToHttp();
37+
const res = ctx.getResponse();
38+
res.status(this.statusCode);
39+
return next.handle().pipe(map(data => ({ data })));
40+
}
41+
}
42+
43+
@Injectable()
44+
export class HeaderInterceptor {
45+
constructor(private headers: object) {}
46+
47+
intercept(context: ExecutionContext, next: CallHandler) {
48+
const ctx = context.switchToHttp();
49+
const res = ctx.getResponse();
50+
for (const key in this.headers) {
51+
if (this.headers.hasOwnProperty(key)) {
52+
res.header(key, this.headers[key]);
53+
}
54+
}
55+
return next.handle().pipe(map(data => ({ data })));
56+
}
57+
}
58+
3159
function createTestModule(interceptor) {
3260
return Test.createTestingModule({
3361
imports: [ApplicationModule],
@@ -87,6 +115,33 @@ describe('Interceptors', () => {
87115
.expect(200, { data: 'Hello world!' });
88116
});
89117

118+
it(`should modify response status`, async () => {
119+
app = (await createTestModule(
120+
new StatusInterceptor(400),
121+
)).createNestApplication();
122+
123+
await app.init();
124+
return request(app.getHttpServer())
125+
.get('/hello')
126+
.expect(400, { data: 'Hello world!' });
127+
});
128+
129+
it(`should modify Authorization header`, async () => {
130+
const customHeaders = {
131+
Authorization: 'jwt',
132+
};
133+
134+
app = (await createTestModule(
135+
new HeaderInterceptor(customHeaders),
136+
)).createNestApplication();
137+
138+
await app.init();
139+
return request(app.getHttpServer())
140+
.get('/hello')
141+
.expect(200)
142+
.expect('Authorization', 'jwt');
143+
});
144+
90145
afterEach(async () => {
91146
await app.close();
92147
});

0 commit comments

Comments
 (0)