Total Complexity | 7 |
Complexity/F | 1 |
Lines of Code | 78 |
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 ("true")'); |
||
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( |
||
52 | 'The field country.active should be a Boolean ("true")' |
||
53 | ); |
||
54 | }); |
||
55 | |||
56 | it('It should throw an exception for level 3', () => { |
||
57 | // deepcode ignore ExpectsArray: False error, it should allow an object |
||
58 | const Person = Obj({ schema: personSchema }); |
||
59 | expect(() => { |
||
60 | Person.create({ |
||
61 | name: 'John', |
||
62 | address: { |
||
63 | street: 'Abc', |
||
64 | number: 42, |
||
65 | postalCode: '1234AB', |
||
66 | city: 'Example', |
||
67 | country: { |
||
68 | name: 'Germany', |
||
69 | code: 'DE', |
||
70 | active: 'true', |
||
71 | }, |
||
72 | }, |
||
73 | }); |
||
74 | }).toThrowError( |
||
75 | 'The field address.country.active should be a Boolean ("true")' |
||
76 | ); |
||
77 | }); |
||
78 | }); |
||
79 |