aboutsummaryrefslogtreecommitdiff
path: root/telegram/utils_test.go
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-11-30 03:41:22 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-11-30 03:41:22 +0300
commit7030ec0f1ba8eb97da2b17a19594dd2e4c568e1c (patch)
treea3cf11ec4cdc52844688db6ab5e3e443004d5b55 /telegram/utils_test.go
parent6332ea6d28ff850b46a2f7eff592c92ff2c38232 (diff)
Handle updates of newchat
Diffstat (limited to 'telegram/utils_test.go')
-rw-r--r--telegram/utils_test.go42
1 files changed, 42 insertions, 0 deletions
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)
+ }
+}