-
Notifications
You must be signed in to change notification settings - Fork 24
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 `Exposed` decorated fields
- Loading branch information
1 parent
58e733f
commit 7ed5f93
Showing
7 changed files
with
117 additions
and
4 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
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,56 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { NestFastifyApplication } from '@nestjs/platform-fastify'; | ||
import * as request from 'supertest'; | ||
import { createTestModule } from './helpers/create-test-module'; | ||
|
||
|
||
// https://github.com/dmitriy-nz/nestjs-form-data/issues/55 | ||
describe('Express - Exposed optional upload', () => { | ||
let app: INestApplication; | ||
|
||
beforeEach(async () => { | ||
app = await createTestModule(); | ||
}); | ||
|
||
it('Upload optional exposed field single file', () => { | ||
return request | ||
.default(app.getHttpServer()) | ||
.post('/optional-exposed-single') | ||
.expect(200) | ||
.expect({}); | ||
}); | ||
|
||
it('Upload optional exposed field array files', () => { | ||
return request | ||
.default(app.getHttpServer()) | ||
.post('/optional-exposed-array') | ||
.expect(200) | ||
.expect({}); | ||
}); | ||
}); | ||
|
||
describe('Fastify - Exposed optional upload', () => { | ||
let app: NestFastifyApplication; | ||
|
||
beforeEach(async () => { | ||
app = (await createTestModule({ | ||
fastify: true, | ||
})) as NestFastifyApplication; | ||
}); | ||
|
||
it('Upload optional exposed field single file', () => { | ||
return request | ||
.default(app.getHttpServer()) | ||
.post('/optional-exposed-single') | ||
.expect(200) | ||
.expect({}); | ||
}); | ||
|
||
it('Upload optional exposed field array files', () => { | ||
return request | ||
.default(app.getHttpServer()) | ||
.post('/optional-exposed-array') | ||
.expect(200) | ||
.expect({}); | ||
}); | ||
}); |
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
16 changes: 16 additions & 0 deletions
16
test/test-module/dto/UploadOptionalExposedFieldArrayFile.dto.ts
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,16 @@ | ||
import { MemoryStoredFile } from '../../../src/classes/storage'; | ||
import { HasMimeType, IsFiles, MaxFileSize, MinFileSize } from '../../../src/decorators'; | ||
import { IsOptional } from 'class-validator'; | ||
import { Expose } from 'class-transformer'; | ||
|
||
export class UploadOptionalExposedFieldArrayFileDto { | ||
|
||
@Expose() | ||
@IsFiles() | ||
@HasMimeType(['text/plain'], { each: true }) | ||
@MaxFileSize(5, { each: true }) | ||
@MinFileSize(3, { each: true }) | ||
@IsOptional() | ||
file?: MemoryStoredFile[]; | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
test/test-module/dto/UploadOptionalExposedFieldSingleFile.dto.ts
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,16 @@ | ||
import { MemoryStoredFile } from '../../../src/classes/storage'; | ||
import { HasMimeType, IsFile, MaxFileSize, MinFileSize } from '../../../src/decorators'; | ||
import { IsOptional } from 'class-validator'; | ||
import { Expose } from 'class-transformer'; | ||
|
||
export class UploadOptionalExposedFieldSingleFileDto { | ||
|
||
@Expose() | ||
@IsFile() | ||
@HasMimeType(['text/plain']) | ||
@MaxFileSize(5) | ||
@MinFileSize(3) | ||
@IsOptional() | ||
file?: MemoryStoredFile; | ||
|
||
} |