This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
forked from jazibjohar/intercom-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage_test.go
97 lines (90 loc) · 2.47 KB
/
message_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package intercom
import "testing"
func TestNewEmailMessage(t *testing.T) {
user := User{}
admin := Admin{}
message := NewEmailMessage(PERSONAL_TEMPLATE, admin, user, "subject", "body")
if message.MessageType != "email" {
t.Errorf("Message type was not email")
}
if message.Template != "personal" {
t.Errorf("Message template was not personal")
}
if message.From.Type != "admin" {
t.Errorf("Message from was not admin")
}
if message.To.Type != "user" {
t.Errorf("Message to was not user")
}
if message.Subject != "subject" {
t.Errorf("Message subject was not set")
}
if message.Body != "body" {
t.Errorf("Message body was not set")
}
}
func TestNewInAppMessage(t *testing.T) {
contact := Contact{}
admin := Admin{}
message := NewInAppMessage(admin, contact, "body")
if message.MessageType != "inapp" {
t.Errorf("Message type was not inapp")
}
if message.Template != "" {
t.Errorf("Message template was not empty, was %s", message.Template)
}
if message.From.Type != "admin" {
t.Errorf("Message from was not admin")
}
if message.To.Type != "contact" {
t.Errorf("Message to was not contact")
}
if message.Subject != "" {
t.Errorf("Message subject was not empty")
}
if message.Body != "body" {
t.Errorf("Message body was not set")
}
}
func TestNewUserMessage(t *testing.T) {
user := User{}
message := NewUserMessage(user, "body")
if message.MessageType != "inapp" {
t.Errorf("Message type was not inapp")
}
if message.Template != "" {
t.Errorf("Message template was not empty, was %s", message.Template)
}
if message.From.Type != "user" {
t.Errorf("Message from was not user")
}
if message.To.Type != "" {
t.Errorf("Message to was not empty")
}
if message.Subject != "" {
t.Errorf("Message subject was not empty")
}
if message.Body != "body" {
t.Errorf("Message body was not set")
}
}
func TestSaveMessage(t *testing.T) {
messageService := MessageService{Repository: TestMessageAPI{t: t}}
message := NewInAppMessage(Admin{}, User{}, "hi there")
resp, _ := messageService.Save(&message)
if resp.Owner.Type != "admin" {
t.Errorf("Owner was not admin")
}
}
type TestMessageAPI struct {
t *testing.T
}
func (t TestMessageAPI) save(message *MessageRequest) (MessageResponse, error) {
if message.MessageType != "inapp" {
t.t.Errorf("Message not inapp")
}
if message.To.Type != "user" {
t.t.Errorf("Message not sent to user")
}
return MessageResponse{MessageType: message.MessageType, Owner: message.From, Body: message.Body}, nil
}