|
1 | | -import * as sinon from 'sinon'; |
2 | 1 | import { expect } from 'chai'; |
| 2 | +import { Exclude, Expose } from 'class-transformer'; |
| 3 | +import { IsOptional, IsString } from 'class-validator'; |
3 | 4 | import { ArgumentMetadata } from '../../interfaces'; |
4 | | -import { IsString, IsOptional } from 'class-validator'; |
5 | 5 | import { ValidationPipe } from '../../pipes/validation.pipe'; |
6 | | -import { Exclude, Expose } from 'class-transformer'; |
7 | 6 |
|
8 | 7 | @Exclude() |
9 | 8 | class TestModelInternal { |
@@ -36,7 +35,7 @@ describe('ValidationPipe', () => { |
36 | 35 | metatype: TestModel, |
37 | 36 | data: '', |
38 | 37 | }; |
39 | | - const metadatainternal: ArgumentMetadata = { |
| 38 | + const transformMetadata: ArgumentMetadata = { |
40 | 39 | type: 'body', |
41 | 40 | metatype: TestModelInternal, |
42 | 41 | data: '', |
@@ -93,38 +92,38 @@ describe('ValidationPipe', () => { |
93 | 92 | }); |
94 | 93 | describe('when transformation is internal', () => { |
95 | 94 | it('should return a TestModel with internal property', async () => { |
96 | | - target = new ValidationPipe({ |
| 95 | + target = new ValidationPipe({ |
97 | 96 | transform: true, |
98 | | - transformOptions: { groups: ['internal'] } |
| 97 | + transformOptions: { groups: ['internal'] }, |
99 | 98 | }); |
100 | 99 | const testObj = { |
101 | 100 | prop1: 'value1', |
102 | 101 | prop2: 'value2', |
103 | | - propInternal: 'value3' |
| 102 | + propInternal: 'value3', |
104 | 103 | }; |
105 | 104 | expect( |
106 | | - await target.transform(testObj, metadatainternal) |
107 | | - ).to.have.property('propInternal'); |
| 105 | + await target.transform(testObj, transformMetadata), |
| 106 | + ).to.have.property('propInternal'); |
108 | 107 | }); |
109 | 108 | }); |
110 | 109 | describe('when transformation is external', () => { |
111 | 110 | it('should return a TestModel without internal property', async () => { |
112 | | - target = new ValidationPipe({ |
| 111 | + target = new ValidationPipe({ |
113 | 112 | transform: true, |
114 | | - transformOptions: { groups: ['external'] } |
| 113 | + transformOptions: { groups: ['external'] }, |
115 | 114 | }); |
116 | 115 | const testObj = { |
117 | 116 | prop1: 'value1', |
118 | 117 | prop2: 'value2', |
119 | | - propInternal: 'value3' |
| 118 | + propInternal: 'value3', |
120 | 119 | }; |
121 | 120 | expect( |
122 | | - await target.transform(testObj, metadatainternal) |
| 121 | + await target.transform(testObj, transformMetadata), |
123 | 122 | ).to.not.have.property('propInternal'); |
124 | 123 | }); |
125 | 124 | }); |
126 | 125 | }); |
127 | | - describe("when validation doesn't transform", () => { |
| 126 | + describe('when validation doesn\'t transform', () => { |
128 | 127 | describe('when validation strips', () => { |
129 | 128 | it('should return a plain object without extra properties', async () => { |
130 | 129 | target = new ValidationPipe({ transform: false, whitelist: true }); |
|
0 commit comments