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.go38
1 files changed, 27 insertions, 11 deletions
diff --git a/telegram/utils_test.go b/telegram/utils_test.go
index 7371f7f..69124fc 100644
--- a/telegram/utils_test.go
+++ b/telegram/utils_test.go
@@ -5,6 +5,7 @@ import (
"time"
"dev.narayana.im/narayana/telegabber/config"
+ "dev.narayana.im/narayana/telegabber/persistence"
"github.com/zelenin/go-tdlib/client"
)
@@ -12,24 +13,30 @@ import (
const testTimeFormat string = "15:04 02/01/2006"
func TestOnlineStatus(t *testing.T) {
- show, status := userStatusToText(client.UserStatus(&client.UserStatusOnline{}))
+ show, status := (&Client{}).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{}))
+ show, status := (&Client{}).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)}))
- trueStatus := "Last seen at " + time.Format(testTimeFormat)
+ location, _ := time.LoadLocation("Europe/Berlin")
+ timestamp := time.Now().In(location).Unix() - 3599
+ tm := time.Unix(timestamp, 0).In(location)
+ c := &Client{
+ Session: &persistence.Session{
+ Timezone: "+01:00",
+ },
+ }
+ show, status := c.userStatusToText(client.UserStatus(&client.UserStatusOffline{WasOnline: int32(timestamp)}))
+ trueStatus := "Last seen at " + tm.Format(testTimeFormat)
if show != "away" || status != trueStatus {
t.Errorf("Wrong away status: %v, %v, should be %v", show, status, trueStatus)
}
@@ -37,9 +44,12 @@ func TestOnlineOfflineAway(t *testing.T) {
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)}))
- trueStatus := "Last seen at " + time.Format(testTimeFormat)
+ tm := time.Unix(timestamp, 0).UTC()
+ c := &Client{
+ Session: &persistence.Session{},
+ }
+ show, status := c.userStatusToText(client.UserStatus(&client.UserStatusOffline{WasOnline: int32(timestamp)}))
+ trueStatus := "Last seen at " + tm.Format(testTimeFormat)
if show != "xa" || status != trueStatus {
t.Errorf("Wrong xa status: %v, %v, should be %v", show, status, trueStatus)
}
@@ -88,7 +98,10 @@ func TestFormatMessageOnelinePreview(t *testing.T) {
},
}
- text := (&Client{}).formatMessage(0, 0, false, &message)
+ c := &Client{
+ Session: &persistence.Session{},
+ }
+ text := c.formatMessage(0, 0, false, &message)
if text != "42 | | 10 Jan 2008 21:20:00 | tist" {
t.Errorf("Wrong oneline preview message formatting: %v", text)
}
@@ -105,7 +118,10 @@ func TestFormatMessageMultilinePreview(t *testing.T) {
},
}
- text := (&Client{}).formatMessage(0, 0, false, &message)
+ c := &Client{
+ Session: &persistence.Session{},
+ }
+ text := c.formatMessage(0, 0, false, &message)
if text != "42 | | 10 Jan 2008 21:20:00 | tist\nziz" {
t.Errorf("Wrong multiline preview message formatting: %v", text)
}