-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
227 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,3 @@ | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# storybook | ||
storybook-static |
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
"rules": { | ||
"@typescript-eslint/ban-types": "off" | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
test/decorators/httpCode.decorator.spec.ts → lib/decorators/httpCode.decorator.spec.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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import 'reflect-metadata'; | ||
import { HttpCode, HTTP_CODE_TOKEN } from '../../lib/decorators'; | ||
import { HttpCode, HTTP_CODE_TOKEN } from './httpCode.decorator'; | ||
|
||
class Test { | ||
@HttpCode(201) | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
public create(): void {} | ||
} | ||
|
||
it('HttpCode decorator should be set.', () => | ||
it('Should set the HttpCode decorator.', () => | ||
expect(Reflect.getMetadata(HTTP_CODE_TOKEN, Test, 'create')).toStrictEqual(201)); |
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
4 changes: 2 additions & 2 deletions
4
test/decorators/setHeader.decorator.spec.ts → lib/decorators/setHeader.decorator.spec.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
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,60 @@ | ||
import 'reflect-metadata'; | ||
import { Expose } from 'class-transformer'; | ||
import { IsNotEmpty } from 'class-validator'; | ||
import { validateObject } from './classValidator'; | ||
import * as lp from './loadPackage'; | ||
|
||
describe('validateObject', () => { | ||
it('Should return the value if "class-validator" is not being used.', async () => { | ||
const spy = jest | ||
.spyOn(lp, 'loadPackage') | ||
.mockImplementation((name: string) => (name === 'class-validator' ? false : require(name))); | ||
|
||
class Dto { | ||
@IsNotEmpty() | ||
public email!: string; | ||
} | ||
|
||
const result = await validateObject(Dto, { secondaryEmail: '[email protected]' }); | ||
|
||
expect(result).toHaveProperty('secondaryEmail', '[email protected]'); | ||
|
||
spy.mockRestore(); | ||
}); | ||
|
||
it('Should return the value if "class-transformer" is not being used.', async () => { | ||
const spy = jest | ||
.spyOn(lp, 'loadPackage') | ||
.mockImplementation((name: string) => (name === 'class-transformer' ? false : require(name))); | ||
|
||
class Dto { | ||
@IsNotEmpty() | ||
public email!: string; | ||
} | ||
|
||
const result = await validateObject(Dto, { secondaryEmail: '[email protected]' }); | ||
|
||
expect(result).toHaveProperty('secondaryEmail', '[email protected]'); | ||
|
||
spy.mockRestore(); | ||
}); | ||
|
||
it('Should return only exposed properties.', async () => { | ||
class Dto { | ||
@Expose() | ||
@IsNotEmpty() | ||
public email!: string; | ||
} | ||
|
||
const result = await validateObject( | ||
Dto, | ||
{ email: '[email protected]', secondaryEmail: '[email protected]' }, | ||
{ | ||
transformOptions: { excludeExtraneousValues: true } | ||
} | ||
); | ||
|
||
expect(result).toHaveProperty('email', '[email protected]'); | ||
expect(result).not.toHaveProperty('secondaryEmail', '[email protected]'); | ||
}); | ||
}); |
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,8 @@ | ||
import { loadPackage } from './loadPackage'; | ||
|
||
describe('loadPackage', () => { | ||
it('Should load a package correctly.', () => expect(loadPackage('class-validator')).not.toEqual(false)); | ||
|
||
it('Should return false for a non existing package.', () => | ||
expect(loadPackage('a-package-that-does-not-exist')).toEqual(false)); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,2 @@ | ||
export * from './parseBoolean.pipe'; | ||
export * from './parseNumber.pipe'; | ||
export * from './validation.pipe'; | ||
export * from './validateEnum.pipe'; | ||
export * from './parseDate.pipe'; | ||
export * from './validators'; | ||
export * from './parsers'; |
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,3 @@ | ||
export * from './parseBoolean.pipe'; | ||
export * from './parseNumber.pipe'; | ||
export * from './parseDate.pipe'; |
2 changes: 1 addition & 1 deletion
2
test/pipes/parseBoolean.pipe.spec.ts → lib/pipes/parsers/parseBoolean.pipe.spec.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
6 changes: 3 additions & 3 deletions
6
lib/pipes/parseBoolean.pipe.ts → lib/pipes/parsers/parseBoolean.pipe.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
2 changes: 1 addition & 1 deletion
2
test/pipes/parseDate.pipe.spec.ts → lib/pipes/parsers/parseDate.pipe.spec.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
6 changes: 3 additions & 3 deletions
6
lib/pipes/parseDate.pipe.ts → lib/pipes/parsers/parseDate.pipe.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
2 changes: 1 addition & 1 deletion
2
test/pipes/parseNumber.pipe.spec.ts → lib/pipes/parsers/parseNumber.pipe.spec.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
6 changes: 3 additions & 3 deletions
6
lib/pipes/parseNumber.pipe.ts → lib/pipes/parsers/parseNumber.pipe.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
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,2 @@ | ||
export * from './validation.pipe'; | ||
export * from './validateEnum.pipe'; |
2 changes: 1 addition & 1 deletion
2
test/pipes/validateEnum.pipe.spec.ts → ...ipes/validators/validateEnum.pipe.spec.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
6 changes: 3 additions & 3 deletions
6
lib/pipes/validateEnum.pipe.ts → lib/pipes/validators/validateEnum.pipe.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
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,9 @@ | ||
import { ValidationPipe } from './validation.pipe'; | ||
|
||
describe('ValidationPipe', () => { | ||
it('Should return the value as is when there is no meta type defined.', () => | ||
expect(ValidationPipe()({ firstName: 'Uncle', lastName: 'Bob' })).toMatchObject({ | ||
firstName: 'Uncle', | ||
lastName: 'Bob' | ||
})); | ||
}); |
4 changes: 2 additions & 2 deletions
4
lib/pipes/validation.pipe.ts → lib/pipes/validators/validation.pipe.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
Oops, something went wrong.