Passed
Pull Request — master (#25)
by Alejandro
06:29
created

VisitsParser.test.js ➔ ???   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 74
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 47
nc 1
dl 0
loc 74
rs 8.7345
c 0
b 0
f 0
nop 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A VisitsParser.test.js ➔ ... ➔ ??? 0 9 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import {
2
  processOsStats,
3
  processBrowserStats,
4
  processReferrersStats,
5
  processCountriesStats,
6
} from '../../../src/visits/services/VisitsParser';
7
8
describe('VisitsParser', () => {
9
  const visits = [
10
    {
11
      userAgent: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0',
12
      referer: 'https://google.com',
13
      visitLocation: {
14
        countryName: 'Spain',
15
      },
16
    },
17
    {
18
      userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0',
19
      referer: 'https://google.com',
20
      visitLocation: {
21
        countryName: 'United States',
22
      },
23
    },
24
    {
25
      userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
26
      visitLocation: {
27
        countryName: 'Spain',
28
      },
29
    },
30
    {
31
      userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
32
      referer: 'https://m.facebook.com',
33
      visitLocation: {
34
        countryName: 'Spain',
35
      },
36
    },
37
    {
38
      userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41',
39
    },
40
  ];
41
42
  describe('processOsStats', () => {
43
    it('properly parses OS stats', () => {
44
      expect(processOsStats(visits)).toEqual({
45
        Linux: 3,
46
        Windows: 1,
47
        MacOS: 1,
48
      });
49
    });
50
  });
51
52
  describe('processBrowserStats', () => {
53
    it('properly parses browser stats', () => {
54
      expect(processBrowserStats(visits)).toEqual({
55
        Firefox: 2,
56
        Chrome: 2,
57
        Opera: 1,
58
      });
59
    });
60
  });
61
62
  describe('processReferrersStats', () => {
63
    it('properly parses referrer stats', () => {
64
      expect(processReferrersStats(visits)).toEqual({
65
        'Unknown': 2,
66
        'google.com': 2,
67
        'm.facebook.com': 1,
68
      });
69
    });
70
  });
71
72
  describe('processCountriesStats', () => {
73
    it('properly parses countries stats', () => {
74
      expect(processCountriesStats(visits)).toEqual({
75
        'Spain': 3,
76
        'United States': 1,
77
        'Unknown': 1,
78
      });
79
    });
80
  });
81
});
82