Fix existing tests

This commit is contained in:
Bohdan Horbeshko 2022-02-09 11:32:55 -05:00
parent 3618dadd81
commit bf00e98628
2 changed files with 52 additions and 28 deletions

View file

@ -46,10 +46,13 @@ func TestSessionGetAbsent(t *testing.T) {
func TestSessionToMap(t *testing.T) { func TestSessionToMap(t *testing.T) {
session := Session{ session := Session{
Timezone: "klsf", Timezone: "klsf",
RawMessages: true,
} }
m := session.ToMap() m := session.ToMap()
sample := map[string]string{ sample := map[string]string{
"timezone": "klsf", "timezone": "klsf",
"keeponline": "false",
"rawmessages": "true",
} }
if !reflect.DeepEqual(m, sample) { if !reflect.DeepEqual(m, sample) {
t.Errorf("Map does not match the sample: %v", m) t.Errorf("Map does not match the sample: %v", m)

View file

@ -13,15 +13,18 @@ import (
const testTimeFormat string = "15:04 02/01/2006" const testTimeFormat string = "15:04 02/01/2006"
func TestOnlineStatus(t *testing.T) { func TestOnlineStatus(t *testing.T) {
show, status := (&Client{}).userStatusToText(client.UserStatus(&client.UserStatusOnline{})) c := Client{
if show != "" || status != "Online" { DelayedStatuses: make(map[int64]*DelayedStatus),
}
show, status, presenceType := (&c).userStatusToText(client.UserStatus(&client.UserStatusOnline{}), 0)
if show != "" || status != "Online" || presenceType != "" {
t.Errorf("Wrong online status: %v, %v", show, status) t.Errorf("Wrong online status: %v, %v", show, status)
} }
} }
func TestOnlineRecently(t *testing.T) { func TestOnlineRecently(t *testing.T) {
show, status := (&Client{}).userStatusToText(client.UserStatus(&client.UserStatusRecently{})) show, status, presenceType := (&Client{}).userStatusToText(client.UserStatus(&client.UserStatusRecently{}), 0)
if show != "dnd" || status != "Last seen recently" { if show != "dnd" || status != "Last seen recently" || presenceType != "" {
t.Errorf("Wrong recently status: %v, %v", show, status) t.Errorf("Wrong recently status: %v, %v", show, status)
} }
} }
@ -35,9 +38,9 @@ func TestOnlineOfflineAway(t *testing.T) {
Timezone: "+01:00", Timezone: "+01:00",
}, },
} }
show, status := c.userStatusToText(client.UserStatus(&client.UserStatusOffline{WasOnline: int32(timestamp)})) show, status, presenceType := c.userStatusToText(client.UserStatus(&client.UserStatusOffline{WasOnline: int32(timestamp)}), 0)
trueStatus := "Last seen at " + tm.Format(testTimeFormat) trueStatus := "Last seen at " + tm.Format(testTimeFormat)
if show != "away" || status != trueStatus { if show != "away" || status != trueStatus || presenceType != "" {
t.Errorf("Wrong away status: %v, %v, should be %v", show, status, trueStatus) t.Errorf("Wrong away status: %v, %v, should be %v", show, status, trueStatus)
} }
} }
@ -48,9 +51,9 @@ func TestOnlineOfflineXa(t *testing.T) {
c := &Client{ c := &Client{
Session: &persistence.Session{}, Session: &persistence.Session{},
} }
show, status := c.userStatusToText(client.UserStatus(&client.UserStatusOffline{WasOnline: int32(timestamp)})) show, status, presenceType := c.userStatusToText(client.UserStatus(&client.UserStatusOffline{WasOnline: int32(timestamp)}), 0)
trueStatus := "Last seen at " + tm.Format(testTimeFormat) trueStatus := "Last seen at " + tm.Format(testTimeFormat)
if show != "xa" || status != trueStatus { if show != "xa" || status != trueStatus || presenceType != "" {
t.Errorf("Wrong xa status: %v, %v, should be %v", show, status, trueStatus) t.Errorf("Wrong xa status: %v, %v, should be %v", show, status, trueStatus)
} }
} }
@ -130,8 +133,11 @@ func TestFormatMessageMultilinePreview(t *testing.T) {
func TestFormatContent(t *testing.T) { func TestFormatContent(t *testing.T) {
file := client.File{ file := client.File{
Size: 23899, Size: 23899,
Local: &client.LocalFile{
Path: "c:/Documents and Settings/blabla.jpg",
},
Remote: &client.RemoteFile{ Remote: &client.RemoteFile{
Id: "tist", UniqueId: "tist",
}, },
} }
c := Client{ c := Client{
@ -154,7 +160,7 @@ func TestMessageToTextSticker(t *testing.T) {
}, },
}, },
} }
text := (&Client{}).messageToText(&sticker) text := (&Client{}).messageToText(&sticker, false)
if text != "💩" { if text != "💩" {
t.Errorf("Not poop") t.Errorf("Not poop")
} }
@ -164,7 +170,7 @@ func TestMessageToTextGroup(t *testing.T) {
group := client.Message{ group := client.Message{
Content: &client.MessageBasicGroupChatCreate{}, Content: &client.MessageBasicGroupChatCreate{},
} }
text := (&Client{}).messageToText(&group) text := (&Client{}).messageToText(&group, false)
if text != "has created chat" { if text != "has created chat" {
t.Errorf("Who created the group?") t.Errorf("Who created the group?")
} }
@ -174,7 +180,7 @@ func TestMessageToTextSupergroup(t *testing.T) {
supergroup := client.Message{ supergroup := client.Message{
Content: &client.MessageSupergroupChatCreate{}, Content: &client.MessageSupergroupChatCreate{},
} }
text := (&Client{}).messageToText(&supergroup) text := (&Client{}).messageToText(&supergroup, false)
if text != "has created chat" { if text != "has created chat" {
t.Errorf("Who created the supergroup?") t.Errorf("Who created the supergroup?")
} }
@ -184,7 +190,7 @@ func TestMessageChatJoin(t *testing.T) {
join := client.Message{ join := client.Message{
Content: &client.MessageChatJoinByLink{}, Content: &client.MessageChatJoinByLink{},
} }
text := (&Client{}).messageToText(&join) text := (&Client{}).messageToText(&join, false)
if text != "joined chat via invite link" { if text != "joined chat via invite link" {
t.Errorf("Non-joined") t.Errorf("Non-joined")
} }
@ -194,7 +200,7 @@ func TestMessageChatAddNoMembers(t *testing.T) {
add := client.Message{ add := client.Message{
Content: &client.MessageChatAddMembers{}, Content: &client.MessageChatAddMembers{},
} }
text := (&Client{}).messageToText(&add) text := (&Client{}).messageToText(&add, false)
if text != "invited " { if text != "invited " {
t.Errorf("Invited someone anyway") t.Errorf("Invited someone anyway")
} }
@ -206,7 +212,7 @@ func TestMessageChatChangeTitle(t *testing.T) {
Title: "Anime", Title: "Anime",
}, },
} }
text := (&Client{}).messageToText(&title) text := (&Client{}).messageToText(&title, false)
if text != "chat title set to: Anime" { if text != "chat title set to: Anime" {
t.Errorf("How to patch KDE2 for FreeBSD?") t.Errorf("How to patch KDE2 for FreeBSD?")
} }
@ -221,7 +227,7 @@ func TestMessageLocation(t *testing.T) {
}, },
}, },
} }
text := (&Client{}).messageToText(&location) text := (&Client{}).messageToText(&location, false)
if text != "coordinates: 50.8,42.0167 | https://www.google.com/maps/search/50.8,42.0167/" { if text != "coordinates: 50.8,42.0167 | https://www.google.com/maps/search/50.8,42.0167/" {
t.Errorf("Excuse me, I'm lost") t.Errorf("Excuse me, I'm lost")
} }
@ -235,7 +241,7 @@ func TestMessagePhoto(t *testing.T) {
}, },
}, },
} }
text := (&Client{}).messageToText(&photo) text := (&Client{}).messageToText(&photo, false)
if text != "tist" { if text != "tist" {
t.Errorf("Wrong photo label") t.Errorf("Wrong photo label")
} }
@ -249,7 +255,7 @@ func TestMessageAudio(t *testing.T) {
}, },
}, },
} }
text := (&Client{}).messageToText(&audio) text := (&Client{}).messageToText(&audio, false)
if text != "tist" { if text != "tist" {
t.Errorf("Wrong audio label") t.Errorf("Wrong audio label")
} }
@ -263,7 +269,7 @@ func TestMessageVideo(t *testing.T) {
}, },
}, },
} }
text := (&Client{}).messageToText(&video) text := (&Client{}).messageToText(&video, false)
if text != "tist" { if text != "tist" {
t.Errorf("Wrong video label") t.Errorf("Wrong video label")
} }
@ -277,7 +283,7 @@ func TestMessageDocument(t *testing.T) {
}, },
}, },
} }
text := (&Client{}).messageToText(&document) text := (&Client{}).messageToText(&document, false)
if text != "tist" { if text != "tist" {
t.Errorf("Wrong document label") t.Errorf("Wrong document label")
} }
@ -291,7 +297,7 @@ func TestMessageText(t *testing.T) {
}, },
}, },
} }
text := (&Client{}).messageToText(&textMessage) text := (&Client{}).messageToText(&textMessage, false)
if text != "tist" { if text != "tist" {
t.Errorf("Wrong text message") t.Errorf("Wrong text message")
} }
@ -305,7 +311,7 @@ func TestMessageVoice(t *testing.T) {
}, },
}, },
} }
text := (&Client{}).messageToText(&voice) text := (&Client{}).messageToText(&voice, false)
if text != "tist" { if text != "tist" {
t.Errorf("Wrong voice label") t.Errorf("Wrong voice label")
} }
@ -315,7 +321,7 @@ func TestMessageVideoNote(t *testing.T) {
videoNote := client.Message{ videoNote := client.Message{
Content: &client.MessageVideoNote{}, Content: &client.MessageVideoNote{},
} }
text := (&Client{}).messageToText(&videoNote) text := (&Client{}).messageToText(&videoNote, false)
if text != "" { if text != "" {
t.Errorf("Wrong video note label") t.Errorf("Wrong video note label")
} }
@ -329,7 +335,7 @@ func TestMessageAnimation(t *testing.T) {
}, },
}, },
} }
text := (&Client{}).messageToText(&animation) text := (&Client{}).messageToText(&animation, false)
if text != "tist" { if text != "tist" {
t.Errorf("Wrong animation label") t.Errorf("Wrong animation label")
} }
@ -339,7 +345,7 @@ func TestMessageUnknown(t *testing.T) {
unknown := client.Message{ unknown := client.Message{
Content: &client.MessageExpiredPhoto{}, Content: &client.MessageExpiredPhoto{},
} }
text := (&Client{}).messageToText(&unknown) text := (&Client{}).messageToText(&unknown, false)
if text != "unknown message (messageExpiredPhoto)" { if text != "unknown message (messageExpiredPhoto)" {
t.Errorf("Wrong label for unknown message") t.Errorf("Wrong label for unknown message")
} }
@ -426,6 +432,11 @@ func TestContentToFilenameAudio(t *testing.T) {
audio := client.MessageAudio{ audio := client.MessageAudio{
Audio: &client.Audio{ Audio: &client.Audio{
FileName: "swine.mp3", FileName: "swine.mp3",
Audio: &client.File{
Local: &client.LocalFile{
Path: "C:/WINNT/swine.mp3",
},
},
}, },
} }
_, filename := (&Client{}).contentToFilename(&audio) _, filename := (&Client{}).contentToFilename(&audio)
@ -438,6 +449,11 @@ func TestContentToFilenameVideo(t *testing.T) {
video := client.MessageVideo{ video := client.MessageVideo{
Video: &client.Video{ Video: &client.Video{
FileName: "swine.3gp", FileName: "swine.3gp",
Video: &client.File{
Local: &client.LocalFile{
Path: "C:/Document and Settings/Svinarchuk-PC/swine.3gp",
},
},
}, },
} }
_, filename := (&Client{}).contentToFilename(&video) _, filename := (&Client{}).contentToFilename(&video)
@ -450,6 +466,11 @@ func TestContentToFilenameDocument(t *testing.T) {
document := client.MessageDocument{ document := client.MessageDocument{
Document: &client.Document{ Document: &client.Document{
FileName: "swine.doc", FileName: "swine.doc",
Document: &client.File{
Local: &client.LocalFile{
Path: "D:/My Documents/swine.doc",
},
},
}, },
} }
_, filename := (&Client{}).contentToFilename(&document) _, filename := (&Client{}).contentToFilename(&document)
@ -477,7 +498,7 @@ func TestMessageToPrefix1(t *testing.T) {
}, },
} }
prefix := (&Client{}).messageToPrefix(&message, "") prefix := (&Client{}).messageToPrefix(&message, "")
if prefix != "➡ 42 | fwd: anonymous (ziz)" { if prefix != "➡ 42 | fwd: ziz" {
t.Errorf("Wrong prefix: %v", prefix) t.Errorf("Wrong prefix: %v", prefix)
} }
} }