-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added test cases for `enableImplicitConversion` field in the `class-validator` transform options - Modified `IsFile` validator to handle `enableImplicitConversion` param - Some other test cases were improved
- Loading branch information
1 parent
7dec6bf
commit 58e733f
Showing
9 changed files
with
157 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.npmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { NestFastifyApplication } from '@nestjs/platform-fastify'; | ||
import * as request from 'supertest'; | ||
import path from 'path'; | ||
import { createTestModule } from './helpers/create-test-module'; | ||
|
||
describe('Express - transform enableImplicitConversion', () => { | ||
let app: INestApplication; | ||
|
||
beforeEach(async () => { | ||
app = await createTestModule({}, { | ||
transform: true, transformOptions: { | ||
enableImplicitConversion: true, | ||
}, | ||
}); | ||
}); | ||
|
||
it('Valid files upload - array dto - array files', () => { | ||
return request | ||
.default(app.getHttpServer()) | ||
.post('/array-files') | ||
.attach('files', path.resolve(__dirname, 'test-files', 'file.txt')) | ||
.attach('files', path.resolve(__dirname, 'test-files', 'file.txt')) | ||
.expect(200) | ||
.expect([ | ||
{ filename: 'file.txt', mimetype: 'text/plain' }, | ||
{ filename: 'file.txt', mimetype: 'text/plain' }, | ||
]); | ||
}); | ||
|
||
it('Valid files upload - array dto - single file', () => { | ||
return request | ||
.default(app.getHttpServer()) | ||
.post('/array-files') | ||
.attach('files', path.resolve(__dirname, 'test-files', 'file.txt')) | ||
.expect(200) | ||
.expect([{ filename: 'file.txt', mimetype: 'text/plain' }]); | ||
}); | ||
|
||
it('Valid file upload - single dto - single file', () => { | ||
return request | ||
.default(app.getHttpServer()) | ||
.post('/single-file') | ||
.attach('file', path.resolve(__dirname, 'test-files', 'file.txt')) | ||
.expect(200) | ||
.expect({ filename: 'file.txt', mimetype: 'text/plain' }); | ||
}); | ||
|
||
it('Invalid file upload - single dto - array file', () => { | ||
return request | ||
.default(app.getHttpServer()) | ||
.post('/single-file') | ||
.attach('file', path.resolve(__dirname, 'test-files', 'file.txt')) | ||
.attach('file', path.resolve(__dirname, 'test-files', 'file.txt')) | ||
.expect(400); | ||
}); | ||
}); | ||
|
||
describe('Fastify - transform enableImplicitConversion', () => { | ||
let app: NestFastifyApplication; | ||
|
||
beforeEach(async () => { | ||
app = (await createTestModule({ | ||
fastify: true, | ||
}, { | ||
transform: true, transformOptions: { | ||
enableImplicitConversion: true, | ||
}, | ||
})) as NestFastifyApplication; | ||
}); | ||
|
||
it('Valid files upload - array dto - array files', () => { | ||
return request | ||
.default(app.getHttpServer()) | ||
.post('/array-files') | ||
.attach('files', path.resolve(__dirname, 'test-files', 'file.txt')) | ||
.attach('files', path.resolve(__dirname, 'test-files', 'file.txt')) | ||
.expect(200) | ||
.expect([ | ||
{ filename: 'file.txt', mimetype: 'text/plain' }, | ||
{ filename: 'file.txt', mimetype: 'text/plain' }, | ||
]); | ||
}); | ||
|
||
it('Valid files upload - array dto - single file', () => { | ||
return request | ||
.default(app.getHttpServer()) | ||
.post('/array-files') | ||
.attach('files', path.resolve(__dirname, 'test-files', 'file.txt')) | ||
.expect(200) | ||
.expect([{ filename: 'file.txt', mimetype: 'text/plain' }]); | ||
}); | ||
|
||
it('Valid file upload - single dto - single file', () => { | ||
return request | ||
.default(app.getHttpServer()) | ||
.post('/single-file') | ||
.attach('file', path.resolve(__dirname, 'test-files', 'file.txt')) | ||
.expect(200) | ||
.expect({ filename: 'file.txt', mimetype: 'text/plain' }); | ||
}); | ||
|
||
it('Invalid file upload - single dto - array file', () => { | ||
return request | ||
.default(app.getHttpServer()) | ||
.post('/single-file') | ||
.attach('file', path.resolve(__dirname, 'test-files', 'file.txt')) | ||
.attach('file', path.resolve(__dirname, 'test-files', 'file.txt')) | ||
.expect(400); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters