aboutsummaryrefslogtreecommitdiff
path: root/telegram/utils_test.go
diff options
context:
space:
mode:
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)
+ }
+}