mirror of https://github.com/ghostfolio/ghostfolio
2 changed files with 67 additions and 1 deletions
@ -0,0 +1,49 @@ |
|||||
|
import { plainToInstance } from 'class-transformer'; |
||||
|
import { validateSync } from 'class-validator'; |
||||
|
|
||||
|
import { CountryDto } from './country.dto'; |
||||
|
|
||||
|
describe('CountryDto', () => { |
||||
|
const getInvalidProperties = (country: object) => { |
||||
|
return validateSync(plainToInstance(CountryDto, country), { |
||||
|
forbidNonWhitelisted: true, |
||||
|
whitelist: true |
||||
|
}).map(({ property }) => { |
||||
|
return property; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
it('Accepts a country with a code and a weight', () => { |
||||
|
expect(getInvalidProperties({ code: 'US', weight: 1 })).toEqual([]); |
||||
|
}); |
||||
|
|
||||
|
it('Accepts a country of an export', () => { |
||||
|
expect( |
||||
|
getInvalidProperties({ |
||||
|
code: 'US', |
||||
|
continent: 'North America', |
||||
|
name: 'United States', |
||||
|
weight: 1 |
||||
|
}) |
||||
|
).toEqual([]); |
||||
|
}); |
||||
|
|
||||
|
it('Rejects a continent and a name which are not strings', () => { |
||||
|
expect( |
||||
|
getInvalidProperties({ code: 'US', continent: 1, name: 2, weight: 1 }) |
||||
|
).toEqual(['continent', 'name']); |
||||
|
}); |
||||
|
|
||||
|
it('Rejects an invalid code and a weight out of range', () => { |
||||
|
expect(getInvalidProperties({ code: 'USA', weight: 1.5 })).toEqual([ |
||||
|
'code', |
||||
|
'weight' |
||||
|
]); |
||||
|
}); |
||||
|
|
||||
|
it('Rejects an unknown property', () => { |
||||
|
expect( |
||||
|
getInvalidProperties({ code: 'US', other: 'value', weight: 1 }) |
||||
|
).toEqual(['other']); |
||||
|
}); |
||||
|
}); |
||||
Loading…
Reference in new issue