1
bot/models/chat_background_test.go

106 lines
2.6 KiB
Go
Raw Permalink Normal View History

2024-05-20 17:07:43 +08:00
package models
import (
"encoding/json"
"testing"
)
func TestChatBackground_UnmarshalJSON_fill(t *testing.T) {
2024-10-21 16:44:53 +08:00
src := `{"type":{"type":"fill","fill":{"type":"solid","color":123},"dark_theme_dimming":2}}`
2024-05-20 17:07:43 +08:00
var cb ChatBackground
err := json.Unmarshal([]byte(src), &cb)
if err != nil {
t.Fatal(err)
}
2025-01-10 16:01:04 +08:00
if cb.Type.Type != ChatBackgroundTypeFill {
2024-05-20 17:07:43 +08:00
t.Fatal("invalid type")
}
2025-01-10 16:01:04 +08:00
if cb.Type.Fill == nil {
2024-05-20 17:07:43 +08:00
t.Fatal("invalid Fill")
}
2025-01-10 16:01:04 +08:00
if cb.Type.Fill.Fill.Type != BackgroundFillTypeSolid {
2024-05-20 17:07:43 +08:00
t.Fatal("invalid fill type")
}
2025-01-10 16:01:04 +08:00
if cb.Type.Fill.Fill.Solid.Color != 123 {
t.Fatalf("invalid color %d, expect 123", cb.Type.Fill.Fill.Solid.Color)
2024-05-20 17:07:43 +08:00
}
2025-01-10 16:01:04 +08:00
if cb.Type.Fill.DarkThemeDimming != 2 {
t.Fatalf("invalid dark theme dimming %d, expect 2", cb.Type.Fill.DarkThemeDimming)
2024-05-20 17:07:43 +08:00
}
}
func TestChatBackground_UnmarshalJSON_wallpaper(t *testing.T) {
2024-10-21 16:44:53 +08:00
src := `{"type":{"type":"wallpaper","document":{"file_name":"BG_1.jpg","mime_type":"image/jpeg",
"thumbnail":{"file_id":"test","file_unique_id":"test","file_size":4260,"width":156,"height":320},
"thumb":{"file_id":"test","file_unique_id":"test","file_size":4260,"width":156,"height":320},
"file_id":"test","file_unique_id":"test","file_size":299202},"dark_theme_dimming":0}}`
2024-05-20 17:07:43 +08:00
var cb ChatBackground
err := json.Unmarshal([]byte(src), &cb)
if err != nil {
t.Fatal(err)
}
2025-01-10 16:01:04 +08:00
if cb.Type.Type != ChatBackgroundTypeWallpaper {
2024-05-20 17:07:43 +08:00
t.Fatal("invalid type")
}
2025-01-10 16:01:04 +08:00
if cb.Type.Wallpaper == nil {
2024-05-20 17:07:43 +08:00
t.Fatal("invalid Wallpaper")
}
2025-01-10 16:01:04 +08:00
if cb.Type.Wallpaper.Document.FileID != "test" {
2024-05-20 17:07:43 +08:00
t.Fatal("invalid document file id")
}
}
func TestChatBackground_UnmarshalJSON_pattern(t *testing.T) {
2024-10-21 16:44:53 +08:00
src := `{"type":{"type":"pattern","document":{"file_id":"test","file_unique_id":"test","file_size":123,"file_path":"test"},"fill":{"type":"solid","solid":{"color":123}},"intensity":1,"is_inverted":true,"is_moving":true}}`
2024-05-20 17:07:43 +08:00
var cb ChatBackground
err := json.Unmarshal([]byte(src), &cb)
if err != nil {
t.Fatal(err)
}
2025-01-10 16:01:04 +08:00
if cb.Type.Type != ChatBackgroundTypePattern {
2024-05-20 17:07:43 +08:00
t.Fatal("invalid type")
}
2025-01-10 16:01:04 +08:00
if cb.Type.Pattern == nil {
2024-05-20 17:07:43 +08:00
t.Fatal("invalid Pattern")
}
2025-01-10 16:01:04 +08:00
if cb.Type.Pattern.Document.FileID != "test" {
2024-05-20 17:07:43 +08:00
t.Fatal("invalid document file id")
}
}
func TestChatBackground_UnmarshalJSON_chat_theme(t *testing.T) {
2024-10-21 16:44:53 +08:00
src := `{"type":{"type":"chat_theme","theme_name":"test"}}`
2024-05-20 17:07:43 +08:00
var cb ChatBackground
err := json.Unmarshal([]byte(src), &cb)
if err != nil {
t.Fatal(err)
}
2025-01-10 16:01:04 +08:00
if cb.Type.Type != ChatBackgroundTypeChatTheme {
2024-05-20 17:07:43 +08:00
t.Fatal("invalid type")
}
2025-01-10 16:01:04 +08:00
if cb.Type.Theme == nil {
2024-05-20 17:07:43 +08:00
t.Fatal("invalid Theme")
}
2025-01-10 16:01:04 +08:00
if cb.Type.Theme.ThemeName != "test" {
2024-05-20 17:07:43 +08:00
t.Fatal("invalid theme name")
}
}