package main

import (
	"github.com/matryer/is"
	"testing"
)

func TestParseExtranalIdNumber(t *testing.T) {
	is := is.New(t)

	//ExtranalID check, type Number
	data := `2020-06-10T13:15:47+00:00	-	{\x22et\x22:1,\x22url\x22:\x22https://test.test.xsolla1.com/\x22,\x22eid\x22:5555,\x22exv\x22:\x22{\x5C\x22userID\x5C\x22:12345,\x5C\x22merchantId\x5C\x22:98765,\x5C\x22addParam\x5C\x22:\x5C\x22qwerty\x5C\x22}\x22,\x22ident\x22:{\x22t\x22:\x22\xD0\x90\xD0\xB2\xD1\x82\xD0\xBE\xD1\x81\xD1\x82\xD0\xB0\xD1\x82\xD1\x8C\xD0\xB8 \xD0\xBF\xD0\xBE \xD0\xBC\xD0\xB0\xD1\x82\xD0\xB5\xD0\xBC\xD0\xB0\xD1\x82\xD0\xB8\xD0\xBA\xD0\xB5\x22,\x22pc\x22:\x22utf-8\x22,\x22tz\x22:300,\x22wcw\x22:1680,\x22wch\x22:472,\x22plt\x22:null,\x22la\x22:\x22en-gb\x22,\x22j\x22:0,\x22clid\x22:\x221590450218815708139\x22,\x22cid\x22:1002,\x22vid\x22:\x221591794008822220422\x22,\x22c\x22:1,\x22sw\x22:1680,\x22sh\x22:1050,\x22sc\x22:24}}	Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36	127187982623965711	1591794947.093`
	result, err := processInput(data)
	is.NoErr(err)
	// без HitId
	success := `2020-06-10	2020-06-10 13:15:47	1002	1590450218815708139	127187982623965711	5555			1591794008822220422		1	https://test.test.xsolla1.com/		Автостатьи по математике				utf-8		300	1		en-gb				24	1050	1680	472	1680	Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36										Chrome	83		Mac OS X	10	14	6												direct	1591794947093								{"userID":12345,"merchantId":98765,"addParam":"qwerty"}`
	is.Equal(result[19:503], success)
}

func TestParseExtranalIdString(t *testing.T) {
	is := is.New(t)

	//ExtranalID check, type String
	data := `2020-06-10T13:15:48+00:00	-	{\x22eid\x22:\x22qwerty\x22,\x22exv\x22:\x22{\x5C\x22x\x5C\x22:\x5C\x22777\x5C\x22,\x5C\x22y\x5C\x22:321}\x22,\x22et\x22:2,\x22referer\x22:\x22https://test.test.xsolla1.com/\x22,\x22url\x22:\x22https://google.com\x22,\x22ident\x22:{\x22t\x22:\x22\xD0\x90\xD0\xB2\xD1\x82\xD0\xBE\xD1\x81\xD1\x82\xD0\xB0\xD1\x82\xD1\x8C\xD0\xB8 \xD0\xBF\xD0\xBE \xD0\xBC\xD0\xB0\xD1\x82\xD0\xB5\xD0\xBC\xD0\xB0\xD1\x82\xD0\xB8\xD0\xBA\xD0\xB5\x22,\x22pc\x22:\x22utf-8\x22,\x22tz\x22:300,\x22wcw\x22:1680,\x22wch\x22:472,\x22plt\x22:129,\x22la\x22:\x22en-gb\x22,\x22j\x22:0,\x22clid\x22:\x221590450218815708139\x22,\x22cid\x22:1002,\x22vid\x22:\x221591794008822220422\x22,\x22c\x22:1,\x22sw\x22:1680,\x22sh\x22:1050,\x22sc\x22:24}}	Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36	127187982623965711	1591794948.347`
	result, err := processInput(data)
	is.NoErr(err)
	// без HitId
	success := `2020-06-10	2020-06-10 13:15:48	1002	1590450218815708139	127187982623965711	qwerty			1591794008822220422		2	https://google.com	https://test.test.xsolla1.com/	Автостатьи по математике				utf-8		300	1	129	en-gb				24	1050	1680	472	1680	Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36										Chrome	83		Mac OS X	10	14	6												external	1591794948347								{"x":"777","y":321}`
	is.Equal(result[19:492], success)
}

func TestParseGoogleID(t *testing.T) {
	is := is.New(t)

	//google id check
	data := `2018-09-20T19:10:56+03:00	88.206.29.75, 35.186.204.162	{\x22eid\x22:\x2265989\x22,\x22et\x22:\x221\x22,\x22referer\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22url\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22ident\x22:{\x22t\x22:\x22Publisher Account\x22,\x22pc\x22:\x22utf-8\x22,\x22tz\x22:\x22300\x22,\x22wcw\x22:\x221326\x22,\x22wch\x22:\x22785\x22,\x22plt\x22:\x22null\x22,\x22lcp\x22:\x220\x22,\x22la\x22:\x22ru-ru\x22,\x22j\x22:\x220\x22,\x22clid\x22:\x221537415344881801599\x22,\x22cid\x22:\x221004\x22,\x22vid\x22:\x221537443533806528107\x22,\x22c\x22:\x221\x22,\x22sw\x22:\x222560\x22,\x22sh\x22:\x221080\x22,\x22sc\x22:\x2224\x22,\x22gaid\x22:\x22E\xEF\xBF\xBD:]\xEF\xBF\xBD\x5Cf\x5Cu001e\x5Cu0014\x5Cu000b\xEF\xBF\xBD\x5Cu001c0H\xEF\xBF\xBD}[\x22}}	Wallarm attack-rechecker (v1.x)	38001210149568523	1537459856.530`
	result, err := processInput(data)
	is.NoErr(err)
	// без HitId
	success := "2018-09-20	2018-09-20 19:10:56		1537415344881801599	38001210149568523	65989			1537443533806528107	88.206.29.75		https://publisher.xsolla.com/65989/projects/36323	https://publisher.xsolla.com/65989/projects/36323	Publisher Account				utf-8					ru-ru									Wallarm attack-rechecker (v1.x)										Other			Other						Russia	RU	Chelyabinsk	55.1540000000	61.4291000000						1537459856530	"
	is.Equal(result[19:405], success)
}

func TestParseElementValue(t *testing.T) {
	is := is.New(t)

	//google id check
	data := `2018-09-20T19:10:56+03:00	88.206.29.75, 35.186.204.162	{\x22eid\x22:\x2265989\x22,\x22ev\x22:\x22enabled\x22,\x22et\x22:\x221\x22,\x22referer\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22url\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22ident\x22:{\x22t\x22:\x22Publisher Account\x22,\x22pc\x22:\x22utf-8\x22,\x22tz\x22:\x22300\x22,\x22wcw\x22:\x221326\x22,\x22wch\x22:\x22785\x22,\x22plt\x22:\x22null\x22,\x22lcp\x22:\x220\x22,\x22la\x22:\x22ru-ru\x22,\x22j\x22:\x220\x22,\x22clid\x22:\x221537415344881801599\x22,\x22cid\x22:\x221004\x22,\x22vid\x22:\x221537443533806528107\x22,\x22c\x22:\x221\x22,\x22sw\x22:\x222560\x22,\x22sh\x22:\x221080\x22,\x22sc\x22:\x2224\x22,\x22gaid\x22:\x22E\xEF\xBF\xBD:]\xEF\xBF\xBD\x5Cf\x5Cu001e\x5Cu0014\x5Cu000b\xEF\xBF\xBD\x5Cu001c0H\xEF\xBF\xBD}[\x22}}	Wallarm attack-rechecker (v1.x)	38001210149568523	1537459856.530`
	result, err := processInput(data)
	is.NoErr(err)
	// без HitId
	success := "2018-09-20	2018-09-20 19:10:56		1537415344881801599	38001210149568523	65989			1537443533806528107	88.206.29.75		https://publisher.xsolla.com/65989/projects/36323	https://publisher.xsolla.com/65989/projects/36323	Publisher Account				utf-8					ru-ru									Wallarm attack-rechecker (v1.x)										Other			Other						Russia	RU	Chelyabinsk	55.1540000000	61.4291000000						1537459856530	enabled"
	is.Equal(result[19:412], success)

	//google id check
	data = `2018-09-20T19:10:56+03:00	88.206.29.75, 35.186.204.162	{\x22eid\x22:\x2265989\x22,\x22ev\x22:null,\x22et\x22:\x221\x22,\x22referer\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22url\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22ident\x22:{\x22t\x22:\x22Publisher Account\x22,\x22pc\x22:\x22utf-8\x22,\x22tz\x22:\x22300\x22,\x22wcw\x22:\x221326\x22,\x22wch\x22:\x22785\x22,\x22plt\x22:\x22null\x22,\x22lcp\x22:\x220\x22,\x22la\x22:\x22ru-ru\x22,\x22j\x22:\x220\x22,\x22clid\x22:\x221537415344881801599\x22,\x22cid\x22:\x221004\x22,\x22vid\x22:\x221537443533806528107\x22,\x22c\x22:\x221\x22,\x22sw\x22:\x222560\x22,\x22sh\x22:\x221080\x22,\x22sc\x22:\x2224\x22,\x22gaid\x22:\x22E\xEF\xBF\xBD:]\xEF\xBF\xBD\x5Cf\x5Cu001e\x5Cu0014\x5Cu000b\xEF\xBF\xBD\x5Cu001c0H\xEF\xBF\xBD}[\x22}}	Wallarm attack-rechecker (v1.x)	38001210149568523	1537459856.530`
	result, err = processInput(data)
	is.NoErr(err)
	// без HitId
	success = "2018-09-20	2018-09-20 19:10:56		1537415344881801599	38001210149568523	65989			1537443533806528107	88.206.29.75		https://publisher.xsolla.com/65989/projects/36323	https://publisher.xsolla.com/65989/projects/36323	Publisher Account				utf-8					ru-ru									Wallarm attack-rechecker (v1.x)										Other			Other						Russia	RU	Chelyabinsk	55.1540000000	61.4291000000						1537459856530	"
	is.Equal(result[19:405], success)
}

func TestPaystationVisit(t *testing.T) {
	is := is.New(t)
	//google id check
	data := `2018-09-20T19:10:56+03:00	88.206.29.75, 35.186.204.162	{\x22eid\x22:\x2265989\x22,\x22et\x22:\x221\x22,\x22referer\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22url\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22ident\x22:{\x22t\x22:\x22Publisher Account\x22,\x22pv\x22:\x221\x22,\x22pc\x22:\x22utf-8\x22,\x22tz\x22:\x22300\x22,\x22wcw\x22:\x221326\x22,\x22wch\x22:\x22785\x22,\x22plt\x22:\x22null\x22,\x22lcp\x22:\x220\x22,\x22la\x22:\x22ru-ru\x22,\x22j\x22:\x220\x22,\x22clid\x22:\x221537415344881801599\x22,\x22cid\x22:\x221004\x22,\x22vid\x22:\x221537443533806528107\x22,\x22c\x22:\x221\x22,\x22sw\x22:\x222560\x22,\x22sh\x22:\x221080\x22,\x22sc\x22:\x2224\x22,\x22gaid\x22:\x22E\xEF\xBF\xBD:]\xEF\xBF\xBD\x5Cf\x5Cu001e\x5Cu0014\x5Cu000b\xEF\xBF\xBD\x5Cu001c0H\xEF\xBF\xBD}[\x22}}	Wallarm attack-rechecker (v1.x)	38001210149568523	1537459856.530`
	result, err := processInput(data)
	is.NoErr(err)
	// без HitId
	success := "2018-09-20	2018-09-20 19:10:56		1537415344881801599	38001210149568523	65989			1537443533806528107	88.206.29.75		https://publisher.xsolla.com/65989/projects/36323	https://publisher.xsolla.com/65989/projects/36323	Publisher Account				utf-8					ru-ru									Wallarm attack-rechecker (v1.x)										Other			Other						Russia	RU	Chelyabinsk	55.1540000000	61.4291000000						1537459856530		1	"
	is.Equal(result[19:408], success)
}

func TestCorpsiteVisit(t *testing.T) {
	is := is.New(t)
	//google id check
	data := `2018-09-20T19:10:56+03:00	88.206.29.75, 35.186.204.162	{\x22eid\x22:\x2265989\x22,\x22et\x22:\x221\x22,\x22referer\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22url\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22ident\x22:{\x22t\x22:\x22Publisher Account\x22,\x22cv\x22:\x221\x22,\x22pc\x22:\x22utf-8\x22,\x22tz\x22:\x22300\x22,\x22wcw\x22:\x221326\x22,\x22wch\x22:\x22785\x22,\x22plt\x22:\x22null\x22,\x22lcp\x22:\x220\x22,\x22la\x22:\x22ru-ru\x22,\x22j\x22:\x220\x22,\x22clid\x22:\x221537415344881801599\x22,\x22cid\x22:\x221004\x22,\x22vid\x22:\x221537443533806528107\x22,\x22c\x22:\x221\x22,\x22sw\x22:\x222560\x22,\x22sh\x22:\x221080\x22,\x22sc\x22:\x2224\x22,\x22gaid\x22:\x22E\xEF\xBF\xBD:]\xEF\xBF\xBD\x5Cf\x5Cu001e\x5Cu0014\x5Cu000b\xEF\xBF\xBD\x5Cu001c0H\xEF\xBF\xBD}[\x22}}	Wallarm attack-rechecker (v1.x)	38001210149568523	1537459856.530`
	result, err := processInput(data)
	is.NoErr(err)
	// без HitId
	success := "2018-09-20	2018-09-20 19:10:56		1537415344881801599	38001210149568523	65989			1537443533806528107	88.206.29.75		https://publisher.xsolla.com/65989/projects/36323	https://publisher.xsolla.com/65989/projects/36323	Publisher Account				utf-8					ru-ru									Wallarm attack-rechecker (v1.x)										Other			Other						Russia	RU	Chelyabinsk	55.1540000000	61.4291000000						1537459856530			1"
	is.Equal(result[19:408], success)
}

func TestPublisherAccountVisit(t *testing.T) {
	is := is.New(t)
	//google id check
	data := `2018-09-20T19:10:56+03:00	88.206.29.75, 35.186.204.162	{\x22eid\x22:\x2265989\x22,\x22et\x22:\x221\x22,\x22referer\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22url\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22ident\x22:{\x22t\x22:\x22Publisher Account\x22,\x22pav\x22:\x221\x22,\x22pc\x22:\x22utf-8\x22,\x22tz\x22:\x22300\x22,\x22wcw\x22:\x221326\x22,\x22wch\x22:\x22785\x22,\x22plt\x22:\x22null\x22,\x22lcp\x22:\x220\x22,\x22la\x22:\x22ru-ru\x22,\x22j\x22:\x220\x22,\x22clid\x22:\x221537415344881801599\x22,\x22cid\x22:\x221004\x22,\x22vid\x22:\x221537443533806528107\x22,\x22c\x22:\x221\x22,\x22sw\x22:\x222560\x22,\x22sh\x22:\x221080\x22,\x22sc\x22:\x2224\x22,\x22gaid\x22:\x22E\xEF\xBF\xBD:]\xEF\xBF\xBD\x5Cf\x5Cu001e\x5Cu0014\x5Cu000b\xEF\xBF\xBD\x5Cu001c0H\xEF\xBF\xBD}[\x22}}	Wallarm attack-rechecker (v1.x)	38001210149568523	1537459856.530`
	result, err := processInput(data)
	is.NoErr(err)
	// без HitId
	success := "2018-09-20	2018-09-20 19:10:56		1537415344881801599	38001210149568523	65989			1537443533806528107	88.206.29.75		https://publisher.xsolla.com/65989/projects/36323	https://publisher.xsolla.com/65989/projects/36323	Publisher Account				utf-8					ru-ru									Wallarm attack-rechecker (v1.x)										Other			Other						Russia	RU	Chelyabinsk	55.1540000000	61.4291000000						1537459856530				1		"
	is.Equal(result[19:411], success)
}

func TestDevelopersVisit(t *testing.T) {
	is := is.New(t)
	//google id check
	data := `2018-09-20T19:10:56+03:00	88.206.29.75, 35.186.204.162	{\x22eid\x22:\x2265989\x22,\x22et\x22:\x221\x22,\x22referer\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22url\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22ident\x22:{\x22t\x22:\x22Publisher Account\x22,\x22dv\x22:\x221\x22,\x22pc\x22:\x22utf-8\x22,\x22tz\x22:\x22300\x22,\x22wcw\x22:\x221326\x22,\x22wch\x22:\x22785\x22,\x22plt\x22:\x22null\x22,\x22lcp\x22:\x220\x22,\x22la\x22:\x22ru-ru\x22,\x22j\x22:\x220\x22,\x22clid\x22:\x221537415344881801599\x22,\x22cid\x22:\x221004\x22,\x22vid\x22:\x221537443533806528107\x22,\x22c\x22:\x221\x22,\x22sw\x22:\x222560\x22,\x22sh\x22:\x221080\x22,\x22sc\x22:\x2224\x22,\x22gaid\x22:\x22E\xEF\xBF\xBD:]\xEF\xBF\xBD\x5Cf\x5Cu001e\x5Cu0014\x5Cu000b\xEF\xBF\xBD\x5Cu001c0H\xEF\xBF\xBD}[\x22}}	Wallarm attack-rechecker (v1.x)	38001210149568523	1537459856.530`
	result, err := processInput(data)
	is.NoErr(err)
	// без HitId
	success := "2018-09-20	2018-09-20 19:10:56		1537415344881801599	38001210149568523	65989			1537443533806528107	88.206.29.75		https://publisher.xsolla.com/65989/projects/36323	https://publisher.xsolla.com/65989/projects/36323	Publisher Account				utf-8					ru-ru									Wallarm attack-rechecker (v1.x)										Other			Other						Russia	RU	Chelyabinsk	55.1540000000	61.4291000000						1537459856530					1	"
	is.Equal(result[19:411], success)
}

func TestFirstVisitedProduct(t *testing.T) {
	is := is.New(t)
	//google id check
	data := `2018-09-20T19:10:56+03:00	88.206.29.75, 35.186.204.162	{\x22eid\x22:\x2265989\x22,\x22et\x22:\x221\x22,\x22referer\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22url\x22:\x22https://publisher.xsolla.com/65989/projects/36323\x22,\x22ident\x22:{\x22t\x22:\x22Publisher Account\x22,\x22fvp\x22:\x221\x22,\x22pc\x22:\x22utf-8\x22,\x22tz\x22:\x22300\x22,\x22wcw\x22:\x221326\x22,\x22wch\x22:\x22785\x22,\x22plt\x22:\x22null\x22,\x22lcp\x22:\x220\x22,\x22la\x22:\x22ru-ru\x22,\x22j\x22:\x220\x22,\x22clid\x22:\x221537415344881801599\x22,\x22cid\x22:\x221004\x22,\x22vid\x22:\x221537443533806528107\x22,\x22c\x22:\x221\x22,\x22sw\x22:\x222560\x22,\x22sh\x22:\x221080\x22,\x22sc\x22:\x2224\x22,\x22gaid\x22:\x22E\xEF\xBF\xBD:]\xEF\xBF\xBD\x5Cf\x5Cu001e\x5Cu0014\x5Cu000b\xEF\xBF\xBD\x5Cu001c0H\xEF\xBF\xBD}[\x22}}	Wallarm attack-rechecker (v1.x)	38001210149568523	1537459856.530`
	result, err := processInput(data)
	is.NoErr(err)
	// без HitId
	success := "2018-09-20	2018-09-20 19:10:56		1537415344881801599	38001210149568523	65989			1537443533806528107	88.206.29.75		https://publisher.xsolla.com/65989/projects/36323	https://publisher.xsolla.com/65989/projects/36323	Publisher Account				utf-8					ru-ru									Wallarm attack-rechecker (v1.x)										Other			Other						Russia	RU	Chelyabinsk	55.1540000000	61.4291000000						1537459856530						1"
	is.Equal(result[19:411], success)
}
