Skip to content

Commit

Permalink
fixed comments & npm audit fix
Browse files Browse the repository at this point in the history
  • Loading branch information
willemgovaerts committed Jan 5, 2023
1 parent 8efaa71 commit b641e58
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 951 deletions.
3 changes: 1 addition & 2 deletions __tests__/customValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from 'class-validator'

import { validationMetadatasToSchemas } from '../src'
import { IStorage } from '../src/options.js'

@ValidatorConstraint()
export class CustomTextLength implements ValidatorConstraintInterface {
Expand Down Expand Up @@ -35,7 +34,7 @@ class InvalidPost {
describe('custom validation classes', () => {
it('uses property type if no additional converter is supplied', () => {
const schemas = validationMetadatasToSchemas({
classValidatorMetadataStorage: (getMetadataStorage() as unknown) as IStorage,
classValidatorMetadataStorage: getMetadataStorage(),
})
expect(schemas.Post).toEqual({
properties: {
Expand Down
10 changes: 6 additions & 4 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
IsString,
Length,
MaxLength,
MetadataStorage,
MinLength,
ValidateNested,
} from 'class-validator'
import { ValidationMetadata } from 'class-validator/types/metadata/ValidationMetadata'
import { targetConstructorToSchema, validationMetadatasToSchemas } from '../src'
import { IStorage } from '../src/options'

class User {
@IsString() id: string
Expand Down Expand Up @@ -64,6 +64,7 @@ describe('classValidatorConverter', () => {
const emptyStorage: any = {
constraintMetadatas: new Map(),
validationMetadatas: new Map(),
getTargetValidatorConstraints: () => [],
}

expect(
Expand All @@ -87,13 +88,14 @@ describe('classValidatorConverter', () => {
validationTypeOptions: {},
}

const storage: Partial<IStorage> = {
const storage = ({
constraintMetadatas: new Map(),
validationMetadatas: new Map([[User, [customMetadata]]]),
}
getTargetValidatorConstraints: () => [],
} as unknown) as MetadataStorage

const schemas = validationMetadatasToSchemas({
classValidatorMetadataStorage: storage as any,
classValidatorMetadataStorage: storage,
})
expect(schemas.User.properties!.id).toEqual({ type: 'string' })
})
Expand Down
Loading

0 comments on commit b641e58

Please sign in to comment.