| @@ -177,7 +177,7 @@ func TestReadEncryptMsg(t *testing.T) { | |||
| AssertEqual(t, m.Encrypt, "Dv3epMMhmmGU1o6lg71IfbpRrOYX1S8oZX3nwW0uBAHHMKx62T4KniS4efuf8fNHWf6gsF/YGaDraF6HhGOdKp8vbzluiIEsCnIveKN1pO+IUDOBBxzPAzQSFSYJ3OwVXWmBdBcC1S5guQrOxLysH+6UIWSor9cEef+94UAKTNw/MLB0zPfqK5TVoN1A0yobmP9OU8wtFJP0L1aKySPFGGbqBMfJkStRTrYLjIQfZ7pAIisB/g3c87w26r7LUz9hVh4ey3/T6cjQ8vKvgNKL3j8y4IwUdmnmTPrrdOsyA1pz69977xKHFtIptZYHKGD9dTW6PyPcKKTP6iOod6Agb8TI+is80auqHkjvUyvT/xPG8fxak/wI9BKzKndAnwxlcDG/8WElkHVl0TwxpsCb48ZxLEf4GFKaYaliC9xBVweKLNnqdbBmzwfe7GBNWC61h7KQYqwtZqMkZs3BBsStcQ==", "ToUserName failed") | |||
| } | |||
| func TestReadEventMsg(t *testing.T) { | |||
| func TestReadEventClick(t *testing.T) { | |||
| msg := `<xml><ToUserName><![CDATA[gh_f09231355c68]]></ToUserName> | |||
| <FromUserName><![CDATA[oUN420bxqFqlx0ZQHciUOesZO3PE]]></FromUserName> | |||
| <CreateTime>1493903506</CreateTime> | |||
| @@ -227,3 +227,65 @@ func TestAcceptLocationInfo(t *testing.T) { | |||
| AssertEqual(t, m.Latitude, -33.764935, "Expect -33.764935") | |||
| AssertEqual(t, m.Precision, 110.000000, "Expect 110.000000") | |||
| } | |||
| func TestReadEventFollow(t *testing.T) { | |||
| msg := `<xml> | |||
| <ToUserName><![CDATA[toUser]]></ToUserName> | |||
| <FromUserName><![CDATA[FromUser]]></FromUserName> | |||
| <CreateTime>123456789</CreateTime> | |||
| <MsgType><![CDATA[event]]></MsgType> | |||
| <Event><![CDATA[subscribe]]></Event> | |||
| </xml>` | |||
| m := ReadEventMsg(msg) | |||
| AssertEqual(t, m.Event, "subscribe", "Expect subscribe") | |||
| } | |||
| func TestReadEventScanNoFollow(t *testing.T) { | |||
| msg := `<xml><ToUserName><![CDATA[toUser]]></ToUserName> | |||
| <FromUserName><![CDATA[FromUser]]></FromUserName> | |||
| <CreateTime>123456789</CreateTime> | |||
| <MsgType><![CDATA[event]]></MsgType> | |||
| <Event><![CDATA[subscribe]]></Event> | |||
| <EventKey><![CDATA[qrscene_123123]]></EventKey> | |||
| <Ticket><![CDATA[TICKET]]></Ticket> | |||
| </xml>` | |||
| m := ReadEventMsg(msg) | |||
| AssertEqual(t, m.Event, "subscribe", "Expect subscribe") | |||
| AssertEqual(t, m.EventKey, "qrscene_123123", "Expect qrscene_123123") | |||
| AssertEqual(t, m.Ticket, "TICKET", "Expect TICKET") | |||
| } | |||
| func TestReadEventScanWithFollow(t *testing.T) { | |||
| msg := `<xml> | |||
| <ToUserName><![CDATA[toUser]]></ToUserName> | |||
| <FromUserName><![CDATA[FromUser]]></FromUserName> | |||
| <CreateTime>123456789</CreateTime> | |||
| <MsgType><![CDATA[event]]></MsgType> | |||
| <Event><![CDATA[SCAN]]></Event> | |||
| <EventKey><![CDATA[SCENE_VALUE]]></EventKey> | |||
| <Ticket><![CDATA[TICKET]]></Ticket> | |||
| </xml>` | |||
| m := ReadEventMsg(msg) | |||
| AssertEqual(t, m.Event, "SCAN", "Expect SCAN") | |||
| AssertEqual(t, m.EventKey, "SCENE_VALUE", "Expect SCENE_VALUE") | |||
| AssertEqual(t, m.Ticket, "TICKET", "Expect TICKET") | |||
| } | |||
| func TestReadEventView(t *testing.T) { | |||
| msg := `<xml> | |||
| <ToUserName><![CDATA[toUser]]></ToUserName> | |||
| <FromUserName><![CDATA[FromUser]]></FromUserName> | |||
| <CreateTime>123456789</CreateTime> | |||
| <MsgType><![CDATA[event]]></MsgType> | |||
| <Event><![CDATA[VIEW]]></Event> | |||
| <EventKey><![CDATA[www.qq.com]]></EventKey> | |||
| </xml>` | |||
| m := ReadEventMsg(msg) | |||
| AssertEqual(t, m.Event, "VIEW", "Expect VIEW") | |||
| AssertEqual(t, m.EventKey, "www.qq.com", "Expectwww.qq.com") | |||
| AssertEqual(t, m.Ticket, "", "Expect empty ") | |||
| } | |||