| Total Complexity | 7 |
| Complexity/F | 1 |
| Lines of Code | 74 |
| Function Count | 7 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { expect, describe, it } from '@jest/globals'; |
||
| 2 | import Obj from '../objects.js'; |
||
| 3 | |||
| 4 | describe('Object test', () => { |
||
| 5 | const CountrySchema = { |
||
| 6 | name: String, |
||
| 7 | code: String, |
||
| 8 | active: Boolean, |
||
| 9 | }; |
||
| 10 | |||
| 11 | const addressSchema = { |
||
| 12 | street: String, |
||
| 13 | number: 'number', |
||
| 14 | postalCode: String, |
||
| 15 | city: String, |
||
| 16 | country: CountrySchema, |
||
| 17 | }; |
||
| 18 | |||
| 19 | const personSchema = { |
||
| 20 | name: String, |
||
| 21 | address: addressSchema |
||
|
|
|||
| 22 | }; |
||
| 23 | |||
| 24 | it('It should throw an exception for level 1', () => { |
||
| 25 | // deepcode ignore ExpectsArray: False error, it should allow an object |
||
| 26 | const Country = Obj({ schema: CountrySchema }) |
||
| 27 | expect(() => { |
||
| 28 | Country.create({ |
||
| 29 | name: 'Germany', |
||
| 30 | code: 'DE', |
||
| 31 | active: 'true', |
||
| 32 | }) |
||
| 33 | }).toThrowError('The field active should be a Boolean') |
||
| 34 | }); |
||
| 35 | |||
| 36 | it('It should throw an exception for level 2', () => { |
||
| 37 | // deepcode ignore ExpectsArray: False error, it should allow an object |
||
| 38 | const Address = Obj({ schema: addressSchema }) |
||
| 39 | expect(() => { |
||
| 40 | Address.create({ |
||
| 41 | street: 'Abc', |
||
| 42 | number: 42, |
||
| 43 | postalCode: '1234AB', |
||
| 44 | city: 'Example', |
||
| 45 | country: { |
||
| 46 | name: 'Germany', |
||
| 47 | code: 'DE', |
||
| 48 | active: 'true', |
||
| 49 | }, |
||
| 50 | }) |
||
| 51 | }).toThrowError('The field country.active should be a Boolean') |
||
| 52 | }); |
||
| 53 | |||
| 54 | it('It should throw an exception for level 3', () => { |
||
| 55 | // deepcode ignore ExpectsArray: False error, it should allow an object |
||
| 56 | const Person = Obj({ schema: personSchema }) |
||
| 57 | expect(() => { |
||
| 58 | Person.create({ |
||
| 59 | name: 'John', |
||
| 60 | address: { |
||
| 61 | street: 'Abc', |
||
| 62 | number: 42, |
||
| 63 | postalCode: '1234AB', |
||
| 64 | city: 'Example', |
||
| 65 | country: { |
||
| 66 | name: 'Germany', |
||
| 67 | code: 'DE', |
||
| 68 | active: 'true', |
||
| 69 | }, |
||
| 70 | }, |
||
| 71 | }) |
||
| 72 | }).toThrowError('The field address.country.active should be a Boolean') |
||
| 73 | }); |
||
| 74 | }); |
||
| 75 |