forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.e2e-spec.ts
69 lines (61 loc) 路 1.85 KB
/
app.e2e-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { readFileSync } from 'fs';
import * as request from 'supertest';
import { AppModule } from '../../src/app.module';
describe('E2E FileTest', () => {
let app: INestApplication;
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleRef.createNestApplication();
await app.init();
});
it('should allow for file uploads', async () => {
return request(app.getHttpServer())
.post('/file')
.attach('file', './package.json')
.field('name', 'test')
.expect(201)
.expect({
body: {
name: 'test',
},
file: readFileSync('./package.json').toString(),
});
});
it('should allow for file uploads that pass validation', async () => {
return request(app.getHttpServer())
.post('/file/pass-validation')
.attach('file', './package.json')
.field('name', 'test')
.expect(201)
.expect({
body: {
name: 'test',
},
file: readFileSync('./package.json').toString(),
});
});
it('should throw for file uploads that do not pass validation', async () => {
return request(app.getHttpServer())
.post('/file/fail-validation')
.attach('file', './package.json')
.field('name', 'test')
.expect(400);
});
it('should throw when file is required but no file is uploaded', async () => {
return request(app.getHttpServer())
.post('/file/fail-validation')
.expect(400);
});
it('should allow for optional file uploads with validation enabled (fixes #10017)', () => {
return request(app.getHttpServer())
.post('/file/pass-validation')
.expect(201);
});
afterAll(async () => {
await app.close();
});
});