Passed
Push — main ( 737de9...a57663 )
by Pieter Epeüs
01:31 queued 11s
created

src/__tests__/authentication-error.unit.js   A

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 50
Function Count 3

Duplication

Duplicated Lines 50
Ratio 100 %

Importance

Changes 0
Metric Value
wmc 3
eloc 41
mnd 0
bc 0
fnc 3
dl 50
loc 50
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1 View Code Duplication
import { expect, describe, it } from '@jest/globals';
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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