From 7030ec0f1ba8eb97da2b17a19594dd2e4c568e1c Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Sat, 30 Nov 2019 02:41:22 +0200 Subject: Handle updates of newchat --- telegram/utils_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 telegram/utils_test.go (limited to 'telegram/utils_test.go') diff --git a/telegram/utils_test.go b/telegram/utils_test.go new file mode 100644 index 0000000..8b1b025 --- /dev/null +++ b/telegram/utils_test.go @@ -0,0 +1,42 @@ +package telegram + +import ( + "testing" + "time" + + "github.com/zelenin/go-tdlib/client" +) + +const testTimeFormat string = "15:03 02/01/2006" + +func TestOnlineStatus(t *testing.T) { + show, status := userStatusToText(client.UserStatus(&client.UserStatusOnline{})) + if show != "" || status != "Online" { + t.Errorf("Wrong online status: %v, %v", show, status) + } +} + +func TestOnlineRecently(t *testing.T) { + show, status := userStatusToText(client.UserStatus(&client.UserStatusRecently{})) + if show != "dnd" || status != "Last seen recently" { + t.Errorf("Wrong recently status: %v, %v", show, status) + } +} + +func TestOnlineOfflineAway(t *testing.T) { + timestamp := time.Now().Unix() - 3599 + time := time.Unix(timestamp, 0) + show, status := userStatusToText(client.UserStatus(&client.UserStatusOffline{WasOnline: int32(timestamp)})) + if show != "away" || status != "Last seen at "+time.Format(testTimeFormat) { + t.Errorf("Wrong away status: %v, %v", show, status) + } +} + +func TestOnlineOfflineXa(t *testing.T) { + timestamp := time.Now().Unix() - 3601 + time := time.Unix(timestamp, 0) + show, status := userStatusToText(client.UserStatus(&client.UserStatusOffline{WasOnline: int32(timestamp)})) + if show != "xa" || status != "Last seen at "+time.Format(testTimeFormat) { + t.Errorf("Wrong xa status: %v, %v", show, status) + } +} -- cgit v1.2.3