2019-03-04 20:14:45 +03:00
|
|
|
import { processStatsFromVisits } 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',
|
2019-01-07 13:53:14 +03:00
|
|
|
cityName: 'Zaragoza',
|
2019-01-09 09:59:56 +03:00
|
|
|
latitude: '123.45',
|
|
|
|
longitude: '-543.21',
|
2018-08-25 00:38:37 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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',
|
2019-01-07 13:53:14 +03:00
|
|
|
cityName: 'New York',
|
2019-01-09 09:59:56 +03:00
|
|
|
latitude: '1029',
|
|
|
|
longitude: '6758',
|
2018-08-25 00:38:37 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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',
|
2019-01-07 13:53:14 +03:00
|
|
|
cityName: 'Zaragoza',
|
2019-01-09 09:59:56 +03:00
|
|
|
latitude: '123.45',
|
|
|
|
longitude: '-543.21',
|
2018-08-25 00:38:37 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2019-03-04 20:14:45 +03:00
|
|
|
describe('processStatsFromVisits', () => {
|
|
|
|
let stats;
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
stats = processStatsFromVisits({ id: 'id', visits });
|
|
|
|
});
|
|
|
|
|
2018-08-25 00:38:37 +03:00
|
|
|
it('properly parses OS stats', () => {
|
2019-03-04 20:14:45 +03:00
|
|
|
const { os } = stats;
|
|
|
|
|
|
|
|
expect(os).toEqual({
|
2018-08-26 00:39:27 +03:00
|
|
|
Linux: 3,
|
|
|
|
Windows: 1,
|
|
|
|
MacOS: 1,
|
2018-08-25 00:38:37 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('properly parses browser stats', () => {
|
2019-03-04 20:14:45 +03:00
|
|
|
const { browsers } = stats;
|
|
|
|
|
|
|
|
expect(browsers).toEqual({
|
2018-08-26 00:39:27 +03:00
|
|
|
Firefox: 2,
|
|
|
|
Chrome: 2,
|
|
|
|
Opera: 1,
|
2018-08-25 00:38:37 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('properly parses referrer stats', () => {
|
2019-03-04 20:14:45 +03:00
|
|
|
const { referrers } = stats;
|
|
|
|
|
|
|
|
expect(referrers).toEqual({
|
2020-03-06 22:42:22 +03:00
|
|
|
'Direct': 2,
|
2018-08-25 00:38:37 +03:00
|
|
|
'google.com': 2,
|
|
|
|
'm.facebook.com': 1,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('properly parses countries stats', () => {
|
2019-03-04 20:14:45 +03:00
|
|
|
const { countries } = stats;
|
|
|
|
|
|
|
|
expect(countries).toEqual({
|
2018-08-25 00:38:37 +03:00
|
|
|
'Spain': 3,
|
|
|
|
'United States': 1,
|
|
|
|
'Unknown': 1,
|
|
|
|
});
|
|
|
|
});
|
2019-01-07 13:53:14 +03:00
|
|
|
|
|
|
|
it('properly parses cities stats', () => {
|
2019-03-04 20:14:45 +03:00
|
|
|
const { cities } = stats;
|
|
|
|
|
|
|
|
expect(cities).toEqual({
|
2019-01-07 13:53:14 +03:00
|
|
|
'Zaragoza': 2,
|
|
|
|
'New York': 1,
|
|
|
|
'Unknown': 2,
|
|
|
|
});
|
|
|
|
});
|
2019-01-09 09:59:56 +03:00
|
|
|
|
|
|
|
it('properly parses cities stats with lat and long', () => {
|
2019-03-04 20:14:45 +03:00
|
|
|
const { citiesForMap } = stats;
|
2019-01-09 09:59:56 +03:00
|
|
|
const zaragozaLat = 123.45;
|
|
|
|
const zaragozaLong = -543.21;
|
|
|
|
const newYorkLat = 1029;
|
|
|
|
const newYorkLong = 6758;
|
|
|
|
|
2019-03-04 20:14:45 +03:00
|
|
|
expect(citiesForMap).toEqual({
|
2019-01-09 09:59:56 +03:00
|
|
|
'Zaragoza': {
|
|
|
|
cityName: 'Zaragoza',
|
|
|
|
count: 2,
|
|
|
|
latLong: [ zaragozaLat, zaragozaLong ],
|
|
|
|
},
|
|
|
|
'New York': {
|
|
|
|
cityName: 'New York',
|
|
|
|
count: 1,
|
|
|
|
latLong: [ newYorkLat, newYorkLong ],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-08-25 00:38:37 +03:00
|
|
|
});
|