2018-08-25 00:55:53 +03:00
|
|
|
import {
|
|
|
|
processOsStats,
|
|
|
|
processBrowserStats,
|
|
|
|
processReferrersStats,
|
|
|
|
processCountriesStats,
|
|
|
|
} from '../../../src/visits/services/VisitsParser';
|
2018-08-25 00:38:37 +03:00
|
|
|
|
|
|
|
describe('VisitsParser', () => {
|
|
|
|
const visits = [
|
|
|
|
{
|
|
|
|
userAgent: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0',
|
|
|
|
referer: 'https://google.com',
|
|
|
|
visitLocation: {
|
|
|
|
countryName: 'Spain',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0',
|
|
|
|
referer: 'https://google.com',
|
|
|
|
visitLocation: {
|
|
|
|
countryName: 'United States',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
|
|
|
|
visitLocation: {
|
|
|
|
countryName: 'Spain',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
|
|
|
|
referer: 'https://m.facebook.com',
|
|
|
|
visitLocation: {
|
|
|
|
countryName: 'Spain',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
describe('processOsStats', () => {
|
|
|
|
it('properly parses OS stats', () => {
|
2018-08-25 00:55:53 +03:00
|
|
|
expect(processOsStats(visits)).toEqual({
|
2018-08-25 00:38:37 +03:00
|
|
|
'Linux': 3,
|
|
|
|
'Windows': 1,
|
|
|
|
'MacOS': 1,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('processBrowserStats', () => {
|
|
|
|
it('properly parses browser stats', () => {
|
2018-08-25 00:55:53 +03:00
|
|
|
expect(processBrowserStats(visits)).toEqual({
|
2018-08-25 00:38:37 +03:00
|
|
|
'Firefox': 2,
|
|
|
|
'Chrome': 2,
|
|
|
|
'Opera': 1,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('processReferrersStats', () => {
|
|
|
|
it('properly parses referrer stats', () => {
|
2018-08-25 00:55:53 +03:00
|
|
|
expect(processReferrersStats(visits)).toEqual({
|
2018-08-25 00:38:37 +03:00
|
|
|
'Unknown': 2,
|
|
|
|
'google.com': 2,
|
|
|
|
'm.facebook.com': 1,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('processCountriesStats', () => {
|
|
|
|
it('properly parses countries stats', () => {
|
2018-08-25 00:55:53 +03:00
|
|
|
expect(processCountriesStats(visits)).toEqual({
|
2018-08-25 00:38:37 +03:00
|
|
|
'Spain': 3,
|
|
|
|
'United States': 1,
|
|
|
|
'Unknown': 1,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|