github.com/rajatvaryani/mattermost-server@v5.11.1+incompatible/model/push_notification_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "strings" 8 "testing" 9 ) 10 11 func TestPushNotification(t *testing.T) { 12 msg := PushNotification{Platform: "test"} 13 json := msg.ToJson() 14 result := PushNotificationFromJson(strings.NewReader(json)) 15 16 if msg.Platform != result.Platform { 17 t.Fatal("Ids do not match") 18 } 19 } 20 21 func TestPushNotificationDeviceId(t *testing.T) { 22 23 msg := PushNotification{Platform: "test"} 24 25 msg.SetDeviceIdAndPlatform("android:12345") 26 if msg.Platform != "android" { 27 t.Fatal(msg.Platform) 28 } 29 if msg.DeviceId != "12345" { 30 t.Fatal(msg.DeviceId) 31 } 32 msg.Platform = "" 33 msg.DeviceId = "" 34 35 msg.SetDeviceIdAndPlatform("android:12:345") 36 if msg.Platform != "android" { 37 t.Fatal(msg.Platform) 38 } 39 if msg.DeviceId != "12:345" { 40 t.Fatal(msg.DeviceId) 41 } 42 msg.Platform = "" 43 msg.DeviceId = "" 44 45 msg.SetDeviceIdAndPlatform("android::12345") 46 if msg.Platform != "android" { 47 t.Fatal(msg.Platform) 48 } 49 if msg.DeviceId != ":12345" { 50 t.Fatal(msg.DeviceId) 51 } 52 msg.Platform = "" 53 msg.DeviceId = "" 54 55 msg.SetDeviceIdAndPlatform(":12345") 56 if msg.Platform != "" { 57 t.Fatal(msg.Platform) 58 } 59 if msg.DeviceId != "12345" { 60 t.Fatal(msg.DeviceId) 61 } 62 msg.Platform = "" 63 msg.DeviceId = "" 64 65 msg.SetDeviceIdAndPlatform("android:") 66 if msg.Platform != "android" { 67 t.Fatal(msg.Platform) 68 } 69 if msg.DeviceId != "" { 70 t.Fatal(msg.DeviceId) 71 } 72 msg.Platform = "" 73 msg.DeviceId = "" 74 75 msg.SetDeviceIdAndPlatform("") 76 if msg.Platform != "" { 77 t.Fatal(msg.Platform) 78 } 79 if msg.DeviceId != "" { 80 t.Fatal(msg.DeviceId) 81 } 82 msg.Platform = "" 83 msg.DeviceId = "" 84 85 msg.SetDeviceIdAndPlatform(":") 86 if msg.Platform != "" { 87 t.Fatal(msg.Platform) 88 } 89 if msg.DeviceId != "" { 90 t.Fatal(msg.DeviceId) 91 } 92 msg.Platform = "" 93 msg.DeviceId = "" 94 }