Fix existing tests
This commit is contained in:
parent
3618dadd81
commit
bf00e98628
|
@ -45,11 +45,14 @@ func TestSessionGetAbsent(t *testing.T) {
|
|||
|
||||
func TestSessionToMap(t *testing.T) {
|
||||
session := Session{
|
||||
Timezone: "klsf",
|
||||
Timezone: "klsf",
|
||||
RawMessages: true,
|
||||
}
|
||||
m := session.ToMap()
|
||||
sample := map[string]string{
|
||||
"timezone": "klsf",
|
||||
"timezone": "klsf",
|
||||
"keeponline": "false",
|
||||
"rawmessages": "true",
|
||||
}
|
||||
if !reflect.DeepEqual(m, sample) {
|
||||
t.Errorf("Map does not match the sample: %v", m)
|
||||
|
|
|
@ -13,15 +13,18 @@ import (
|
|||
const testTimeFormat string = "15:04 02/01/2006"
|
||||
|
||||
func TestOnlineStatus(t *testing.T) {
|
||||
show, status := (&Client{}).userStatusToText(client.UserStatus(&client.UserStatusOnline{}))
|
||||
if show != "" || status != "Online" {
|
||||
c := Client{
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOnlineRecently(t *testing.T) {
|
||||
show, status := (&Client{}).userStatusToText(client.UserStatus(&client.UserStatusRecently{}))
|
||||
if show != "dnd" || status != "Last seen recently" {
|
||||
show, status, presenceType := (&Client{}).userStatusToText(client.UserStatus(&client.UserStatusRecently{}), 0)
|
||||
if show != "dnd" || status != "Last seen recently" || presenceType != "" {
|
||||
t.Errorf("Wrong recently status: %v, %v", show, status)
|
||||
}
|
||||
}
|
||||
|
@ -35,9 +38,9 @@ func TestOnlineOfflineAway(t *testing.T) {
|
|||
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)
|
||||
if show != "away" || status != trueStatus {
|
||||
if show != "away" || status != trueStatus || presenceType != "" {
|
||||
t.Errorf("Wrong away status: %v, %v, should be %v", show, status, trueStatus)
|
||||
}
|
||||
}
|
||||
|
@ -48,9 +51,9 @@ func TestOnlineOfflineXa(t *testing.T) {
|
|||
c := &Client{
|
||||
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)
|
||||
if show != "xa" || status != trueStatus {
|
||||
if show != "xa" || status != trueStatus || presenceType != "" {
|
||||
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) {
|
||||
file := client.File{
|
||||
Size: 23899,
|
||||
Local: &client.LocalFile{
|
||||
Path: "c:/Documents and Settings/blabla.jpg",
|
||||
},
|
||||
Remote: &client.RemoteFile{
|
||||
Id: "tist",
|
||||
UniqueId: "tist",
|
||||
},
|
||||
}
|
||||
c := Client{
|
||||
|
@ -154,7 +160,7 @@ func TestMessageToTextSticker(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
text := (&Client{}).messageToText(&sticker)
|
||||
text := (&Client{}).messageToText(&sticker, false)
|
||||
if text != "💩" {
|
||||
t.Errorf("Not poop")
|
||||
}
|
||||
|
@ -164,7 +170,7 @@ func TestMessageToTextGroup(t *testing.T) {
|
|||
group := client.Message{
|
||||
Content: &client.MessageBasicGroupChatCreate{},
|
||||
}
|
||||
text := (&Client{}).messageToText(&group)
|
||||
text := (&Client{}).messageToText(&group, false)
|
||||
if text != "has created chat" {
|
||||
t.Errorf("Who created the group?")
|
||||
}
|
||||
|
@ -174,7 +180,7 @@ func TestMessageToTextSupergroup(t *testing.T) {
|
|||
supergroup := client.Message{
|
||||
Content: &client.MessageSupergroupChatCreate{},
|
||||
}
|
||||
text := (&Client{}).messageToText(&supergroup)
|
||||
text := (&Client{}).messageToText(&supergroup, false)
|
||||
if text != "has created chat" {
|
||||
t.Errorf("Who created the supergroup?")
|
||||
}
|
||||
|
@ -184,7 +190,7 @@ func TestMessageChatJoin(t *testing.T) {
|
|||
join := client.Message{
|
||||
Content: &client.MessageChatJoinByLink{},
|
||||
}
|
||||
text := (&Client{}).messageToText(&join)
|
||||
text := (&Client{}).messageToText(&join, false)
|
||||
if text != "joined chat via invite link" {
|
||||
t.Errorf("Non-joined")
|
||||
}
|
||||
|
@ -194,7 +200,7 @@ func TestMessageChatAddNoMembers(t *testing.T) {
|
|||
add := client.Message{
|
||||
Content: &client.MessageChatAddMembers{},
|
||||
}
|
||||
text := (&Client{}).messageToText(&add)
|
||||
text := (&Client{}).messageToText(&add, false)
|
||||
if text != "invited " {
|
||||
t.Errorf("Invited someone anyway")
|
||||
}
|
||||
|
@ -206,7 +212,7 @@ func TestMessageChatChangeTitle(t *testing.T) {
|
|||
Title: "Anime",
|
||||
},
|
||||
}
|
||||
text := (&Client{}).messageToText(&title)
|
||||
text := (&Client{}).messageToText(&title, false)
|
||||
if text != "chat title set to: Anime" {
|
||||
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/" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
t.Errorf("Wrong voice label")
|
||||
}
|
||||
|
@ -315,7 +321,7 @@ func TestMessageVideoNote(t *testing.T) {
|
|||
videoNote := client.Message{
|
||||
Content: &client.MessageVideoNote{},
|
||||
}
|
||||
text := (&Client{}).messageToText(&videoNote)
|
||||
text := (&Client{}).messageToText(&videoNote, false)
|
||||
if text != "" {
|
||||
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" {
|
||||
t.Errorf("Wrong animation label")
|
||||
}
|
||||
|
@ -339,7 +345,7 @@ func TestMessageUnknown(t *testing.T) {
|
|||
unknown := client.Message{
|
||||
Content: &client.MessageExpiredPhoto{},
|
||||
}
|
||||
text := (&Client{}).messageToText(&unknown)
|
||||
text := (&Client{}).messageToText(&unknown, false)
|
||||
if text != "unknown message (messageExpiredPhoto)" {
|
||||
t.Errorf("Wrong label for unknown message")
|
||||
}
|
||||
|
@ -426,6 +432,11 @@ func TestContentToFilenameAudio(t *testing.T) {
|
|||
audio := client.MessageAudio{
|
||||
Audio: &client.Audio{
|
||||
FileName: "swine.mp3",
|
||||
Audio: &client.File{
|
||||
Local: &client.LocalFile{
|
||||
Path: "C:/WINNT/swine.mp3",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
_, filename := (&Client{}).contentToFilename(&audio)
|
||||
|
@ -438,6 +449,11 @@ func TestContentToFilenameVideo(t *testing.T) {
|
|||
video := client.MessageVideo{
|
||||
Video: &client.Video{
|
||||
FileName: "swine.3gp",
|
||||
Video: &client.File{
|
||||
Local: &client.LocalFile{
|
||||
Path: "C:/Document and Settings/Svinarchuk-PC/swine.3gp",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
_, filename := (&Client{}).contentToFilename(&video)
|
||||
|
@ -450,6 +466,11 @@ func TestContentToFilenameDocument(t *testing.T) {
|
|||
document := client.MessageDocument{
|
||||
Document: &client.Document{
|
||||
FileName: "swine.doc",
|
||||
Document: &client.File{
|
||||
Local: &client.LocalFile{
|
||||
Path: "D:/My Documents/swine.doc",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
_, filename := (&Client{}).contentToFilename(&document)
|
||||
|
@ -477,7 +498,7 @@ func TestMessageToPrefix1(t *testing.T) {
|
|||
},
|
||||
}
|
||||
prefix := (&Client{}).messageToPrefix(&message, "")
|
||||
if prefix != "➡ 42 | fwd: anonymous (ziz)" {
|
||||
if prefix != "➡ 42 | fwd: ziz" {
|
||||
t.Errorf("Wrong prefix: %v", prefix)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue