Code Duplication    Length = 47-50 lines in 7 locations

src/__tests__/validation-error.unit.js 1 location

@@ 1-50 (lines=50) @@
1
import { expect, describe, it } from '@jest/globals';
2
import { ValidationError } from '../index.js';
3
4
describe('Validation Error test', () => {
5
    it('It should create a validation error', () => {
6
        const error = new ValidationError({
7
            value: 'test',
8
            type: String,
9
            message: 'Example text',
10
        });
11
12
        expect(error instanceof ValidationError).toEqual(true);
13
        expect(error instanceof TypeError).toEqual(true);
14
        expect(error instanceof Error).toEqual(true);
15
        expect(error.name).toEqual('ValidationError');
16
        expect(error.message).toEqual('Example text');
17
        expect(error.value).toEqual('test');
18
        expect(error.status).toEqual(400);
19
        expect(error.type).toEqual(String);
20
        expect(error.date.constructor).toEqual(Date);
21
        expect(error.stack.includes('ValidationError: Example text')).toEqual(
22
            true
23
        );
24
    });
25
26
    it('It should handle invalid error values', () => {
27
        const error = new ValidationError({
28
            value: 'test',
29
            type: 'string',
30
            message: 'Example text',
31
        });
32
33
        expect(error instanceof ValidationError).toEqual(true);
34
        expect(error instanceof Error).toEqual(true);
35
        expect(error.name).toEqual('ValidationError');
36
        expect(error.message).toEqual('Invalid error');
37
        expect(error.value.errors[0][0]).toEqual('type?');
38
        expect(error.value.values.message).toEqual('Invalid error');
39
        expect(error.value.values.name).toEqual('ValidationError');
40
        expect(error.value.values.status).toEqual(400);
41
        expect(error.value.values.type).toEqual(Error);
42
        expect(error.value.values.value).toEqual('test');
43
        expect(error.status).toEqual(500);
44
        expect(error.type).toEqual(Error);
45
        expect(error.date.constructor).toEqual(Date);
46
        expect(error.stack.includes('ValidationError: Invalid error')).toEqual(
47
            true
48
        );
49
    });
50
});
51

src/__tests__/not-implemented-error.unit.js 1 location

@@ 1-50 (lines=50) @@
1
import { expect, describe, it } from '@jest/globals';
2
import { NotImplementedError } from '../index.js';
3
4
describe('Not Implemented Error test', () => {
5
    it('It should create a not implemented error', () => {
6
        const error = new NotImplementedError({
7
            value: 'test',
8
            type: String,
9
            message: 'Example text',
10
        });
11
12
        expect(error instanceof NotImplementedError).toEqual(true);
13
        expect(error instanceof RangeError).toEqual(true);
14
        expect(error instanceof Error).toEqual(true);
15
        expect(error.name).toEqual('NotImplementedError');
16
        expect(error.message).toEqual('Example text');
17
        expect(error.value).toEqual('test');
18
        expect(error.status).toEqual(405);
19
        expect(error.type).toEqual(String);
20
        expect(error.date.constructor).toEqual(Date);
21
        expect(
22
            error.stack.includes('NotImplementedError: Example text')
23
        ).toEqual(true);
24
    });
25
26
    it('It should handle invalid error values', () => {
27
        const error = new NotImplementedError({
28
            value: 'test',
29
            type: 'string',
30
            message: 'Example text',
31
        });
32
33
        expect(error instanceof NotImplementedError).toEqual(true);
34
        expect(error instanceof Error).toEqual(true);
35
        expect(error.name).toEqual('NotImplementedError');
36
        expect(error.message).toEqual('Invalid error');
37
        expect(error.value.errors[0][0]).toEqual('type?');
38
        expect(error.value.values.message).toEqual('Invalid error');
39
        expect(error.value.values.name).toEqual('NotImplementedError');
40
        expect(error.value.values.status).toEqual(405);
41
        expect(error.value.values.type).toEqual(Error);
42
        expect(error.value.values.value).toEqual('test');
43
        expect(error.status).toEqual(500);
44
        expect(error.type).toEqual(Error);
45
        expect(error.date.constructor).toEqual(Date);
46
        expect(
47
            error.stack.includes('NotImplementedError: Invalid error')
48
        ).toEqual(true);
49
    });
50
});
51

src/__tests__/not-found-error.unit.js 1 location

@@ 1-50 (lines=50) @@
1
import { expect, describe, it } from '@jest/globals';
2
import { NotFoundError } from '../index.js';
3
4
describe('Not Found Error test', () => {
5
    it('It should create a not found error', () => {
6
        const error = new NotFoundError({
7
            value: 'test',
8
            type: String,
9
            message: 'Example text',
10
        });
11
12
        expect(error instanceof NotFoundError).toEqual(true);
13
        expect(error instanceof RangeError).toEqual(true);
14
        expect(error instanceof Error).toEqual(true);
15
        expect(error.name).toEqual('NotFoundError');
16
        expect(error.message).toEqual('Example text');
17
        expect(error.value).toEqual('test');
18
        expect(error.status).toEqual(404);
19
        expect(error.type).toEqual(String);
20
        expect(error.date.constructor).toEqual(Date);
21
        expect(error.stack.includes('NotFoundError: Example text')).toEqual(
22
            true
23
        );
24
    });
25
26
    it('It should handle invalid error values', () => {
27
        const error = new NotFoundError({
28
            value: 'test',
29
            type: 'string',
30
            message: 'Example text',
31
        });
32
33
        expect(error instanceof NotFoundError).toEqual(true);
34
        expect(error instanceof Error).toEqual(true);
35
        expect(error.name).toEqual('NotFoundError');
36
        expect(error.message).toEqual('Invalid error');
37
        expect(error.value.errors[0][0]).toEqual('type?');
38
        expect(error.value.values.message).toEqual('Invalid error');
39
        expect(error.value.values.name).toEqual('NotFoundError');
40
        expect(error.value.values.status).toEqual(404);
41
        expect(error.value.values.type).toEqual(Error);
42
        expect(error.value.values.value).toEqual('test');
43
        expect(error.status).toEqual(500);
44
        expect(error.type).toEqual(Error);
45
        expect(error.date.constructor).toEqual(Date);
46
        expect(error.stack.includes('NotFoundError: Invalid error')).toEqual(
47
            true
48
        );
49
    });
50
});
51

src/__tests__/authentication-error.unit.js 1 location

@@ 1-50 (lines=50) @@
1
import { expect, describe, it } from '@jest/globals';
2
import { AuthenticationError } from '../index.js';
3
4
describe('Authentication Error test', () => {
5
    it('It should create a authentication error', () => {
6
        const error = new AuthenticationError({
7
            value: 'test',
8
            type: String,
9
            message: 'Example text',
10
        });
11
12
        expect(error instanceof AuthenticationError).toEqual(true);
13
        expect(error instanceof TypeError).toEqual(true);
14
        expect(error instanceof Error).toEqual(true);
15
        expect(error.name).toEqual('AuthenticationError');
16
        expect(error.message).toEqual('Example text');
17
        expect(error.value).toEqual('test');
18
        expect(error.status).toEqual(401);
19
        expect(error.type).toEqual(String);
20
        expect(error.date.constructor).toEqual(Date);
21
        expect(
22
            error.stack.includes('AuthenticationError: Example text')
23
        ).toEqual(true);
24
    });
25
26
    it('It should handle invalid error values', () => {
27
        const error = new AuthenticationError({
28
            value: 'test',
29
            type: 'string',
30
            message: 'Example text',
31
        });
32
33
        expect(error instanceof AuthenticationError).toEqual(true);
34
        expect(error instanceof Error).toEqual(true);
35
        expect(error.name).toEqual('AuthenticationError');
36
        expect(error.message).toEqual('Invalid error');
37
        expect(error.value.errors[0][0]).toEqual('type?');
38
        expect(error.value.values.message).toEqual('Invalid error');
39
        expect(error.value.values.name).toEqual('AuthenticationError');
40
        expect(error.value.values.status).toEqual(401);
41
        expect(error.value.values.type).toEqual(Error);
42
        expect(error.value.values.value).toEqual('test');
43
        expect(error.status).toEqual(500);
44
        expect(error.type).toEqual(Error);
45
        expect(error.date.constructor).toEqual(Date);
46
        expect(
47
            error.stack.includes('AuthenticationError: Invalid error')
48
        ).toEqual(true);
49
    });
50
});
51

src/__tests__/app-error.unit.js 1 location

@@ 1-49 (lines=49) @@
1
import { expect, describe, it } from '@jest/globals';
2
import { AppError } from '../index.js';
3
4
describe('App Error test', () => {
5
    it('It should create a app error', () => {
6
        const error = new AppError({
7
            value: 'test',
8
            type: String,
9
            message: 'Example text',
10
            me: AppError,
11
        });
12
13
        expect(error instanceof AppError).toEqual(true);
14
        expect(error instanceof Error).toEqual(true);
15
        expect(error.name).toEqual('AppError');
16
        expect(error.message).toEqual('Example text');
17
        expect(error.value).toEqual('test');
18
        expect(error.status).toEqual(500);
19
        expect(error.type).toEqual(String);
20
        expect(error.date.constructor).toEqual(Date);
21
        expect(error.stack.includes('AppError: Example text')).toEqual(true);
22
        expect(error.me).toEqual(AppError);
23
    });
24
25
    it('It should handle invalid error values', () => {
26
        const error = new AppError({
27
            value: 'test',
28
            type: 'string',
29
            message: 'Example text',
30
            me: AppError,
31
        });
32
33
        expect(error instanceof AppError).toEqual(true);
34
        expect(error instanceof Error).toEqual(true);
35
        expect(error.name).toEqual('AppError');
36
        expect(error.message).toEqual('Invalid error');
37
        expect(error.value.errors[0][0]).toEqual('type?');
38
        expect(error.value.values.message).toEqual('Invalid error');
39
        expect(error.value.values.name).toEqual('AppError');
40
        expect(error.value.values.status).toEqual(500);
41
        expect(error.value.values.type).toEqual(Error);
42
        expect(error.value.values.value).toEqual('test');
43
        expect(error.status).toEqual(500);
44
        expect(error.type).toEqual(Error);
45
        expect(error.date.constructor).toEqual(Date);
46
        expect(error.stack.includes('AppError: Invalid error')).toEqual(true);
47
        expect(error.me).toEqual(AppError);
48
    });
49
});
50

src/__tests__/timeout-error.unit.js 1 location

@@ 1-49 (lines=49) @@
1
import { expect, describe, it } from '@jest/globals';
2
import { TimeoutError } from '../index.js';
3
4
describe('Timeout Error test', () => {
5
    it('It should create a timeout error', () => {
6
        const error = new TimeoutError({
7
            value: 'test',
8
            type: String,
9
            message: 'Example text',
10
        });
11
12
        expect(error instanceof TimeoutError).toEqual(true);
13
        expect(error instanceof Error).toEqual(true);
14
        expect(error.name).toEqual('TimeoutError');
15
        expect(error.message).toEqual('Example text');
16
        expect(error.value).toEqual('test');
17
        expect(error.status).toEqual(408);
18
        expect(error.type).toEqual(String);
19
        expect(error.date.constructor).toEqual(Date);
20
        expect(error.stack.includes('TimeoutError: Example text')).toEqual(
21
            true
22
        );
23
    });
24
25
    it('It should handle invalid error values', () => {
26
        const error = new TimeoutError({
27
            value: 'test',
28
            type: 'string',
29
            message: 'Example text',
30
        });
31
32
        expect(error instanceof TimeoutError).toEqual(true);
33
        expect(error instanceof Error).toEqual(true);
34
        expect(error.name).toEqual('TimeoutError');
35
        expect(error.message).toEqual('Invalid error');
36
        expect(error.value.errors[0][0]).toEqual('type?');
37
        expect(error.value.values.message).toEqual('Invalid error');
38
        expect(error.value.values.name).toEqual('TimeoutError');
39
        expect(error.value.values.status).toEqual(408);
40
        expect(error.value.values.type).toEqual(Error);
41
        expect(error.value.values.value).toEqual('test');
42
        expect(error.status).toEqual(500);
43
        expect(error.type).toEqual(Error);
44
        expect(error.date.constructor).toEqual(Date);
45
        expect(error.stack.includes('TimeoutError: Invalid error')).toEqual(
46
            true
47
        );
48
    });
49
});
50

src/__tests__/server-error.unit.js 1 location

@@ 1-47 (lines=47) @@
1
import { expect, describe, it } from '@jest/globals';
2
import { ServerError } from '../index.js';
3
4
describe('Server Error test', () => {
5
    it('It should create a server error', () => {
6
        const error = new ServerError({
7
            value: 'test',
8
            type: String,
9
            message: 'Example text',
10
        });
11
12
        expect(error instanceof ServerError).toEqual(true);
13
        expect(error instanceof Error).toEqual(true);
14
        expect(error.name).toEqual('ServerError');
15
        expect(error.message).toEqual('Example text');
16
        expect(error.value).toEqual('test');
17
        expect(error.status).toEqual(500);
18
        expect(error.type).toEqual(String);
19
        expect(error.date.constructor).toEqual(Date);
20
        expect(error.stack.includes('ServerError: Example text')).toEqual(true);
21
    });
22
23
    it('It should handle invalid error values', () => {
24
        const error = new ServerError({
25
            value: 'test',
26
            type: 'string',
27
            message: 'Example text',
28
        });
29
30
        expect(error instanceof ServerError).toEqual(true);
31
        expect(error instanceof Error).toEqual(true);
32
        expect(error.name).toEqual('ServerError');
33
        expect(error.message).toEqual('Invalid error');
34
        expect(error.value.errors[0][0]).toEqual('type?');
35
        expect(error.value.values.message).toEqual('Invalid error');
36
        expect(error.value.values.name).toEqual('ServerError');
37
        expect(error.value.values.status).toEqual(500);
38
        expect(error.value.values.type).toEqual(Error);
39
        expect(error.value.values.value).toEqual('test');
40
        expect(error.status).toEqual(500);
41
        expect(error.type).toEqual(Error);
42
        expect(error.date.constructor).toEqual(Date);
43
        expect(error.stack.includes('ServerError: Invalid error')).toEqual(
44
            true
45
        );
46
    });
47
});
48