Passed
Pull Request — master (#158)
by Pieter Epeüs
03:12
created

src/__tests__/validate-sub-objects.spec.js   A

Complexity

Total Complexity 7
Complexity/F 1

Size

Lines of Code 74
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 52
mnd 0
bc 0
fnc 7
dl 0
loc 74
rs 10
bpm 0
cpm 1
noi 16
c 0
b 0
f 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
0 ignored issues
show
introduced by
Insert ,
Loading history...
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 })
0 ignored issues
show
introduced by
Insert ;
Loading history...
27
        expect(() => {
28
            Country.create({
29
                    name: 'Germany',
0 ignored issues
show
introduced by
Expected indentation of 16 spaces but found 20.
Loading history...
introduced by
Delete ····
Loading history...
30
                    code: 'DE',
0 ignored issues
show
introduced by
Expected indentation of 16 spaces but found 20.
Loading history...
introduced by
Delete ····
Loading history...
31
                    active: 'true',
0 ignored issues
show
introduced by
Expected indentation of 16 spaces but found 20.
Loading history...
introduced by
Replace ···················· with ················
Loading history...
32
            })
0 ignored issues
show
introduced by
Insert ;
Loading history...
33
        }).toThrowError('The field active should be a Boolean')
0 ignored issues
show
introduced by
Insert ;
Loading history...
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 })
0 ignored issues
show
introduced by
Insert ;
Loading history...
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
            })
0 ignored issues
show
introduced by
Insert ;
Loading history...
51
        }).toThrowError('The field country.active should be a Boolean')
0 ignored issues
show
introduced by
Insert ;
Loading history...
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 })
0 ignored issues
show
introduced by
Insert ;
Loading history...
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
            })
0 ignored issues
show
introduced by
Insert ;
Loading history...
72
        }).toThrowError('The field address.country.active should be a Boolean')
0 ignored issues
show
introduced by
Insert ;
Loading history...
73
    });
74
});
75