This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
types_test.go
168 lines (154 loc) · 3.75 KB
/
types_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package dialogflow
import (
"reflect"
"testing"
)
func TestBasicCard_GetKey(t *testing.T) {
want := "basicCard"
b := BasicCard{}
if got := b.GetKey(); got != want {
t.Errorf("BasicCard.GetKey() = %v, want %v", got, want)
}
}
func TestCard_GetKey(t *testing.T) {
want := "card"
c := Card{}
if got := c.GetKey(); got != want {
t.Errorf("Card.GetKey() = %v, want %v", got, want)
}
}
func TestSimpleResponsesWrapper_GetKey(t *testing.T) {
want := "simpleResponses"
s := SimpleResponsesWrapper{}
if got := s.GetKey(); got != want {
t.Errorf("SimpleResponsesWrapper.GetKey() = %v, want %v", got, want)
}
}
func TestText_GetKey(t *testing.T) {
want := "text"
txt := Text{}
if got := txt.GetKey(); got != want {
t.Errorf("Text.GetKey() = %v, want %v", got, want)
}
}
func TestQuickReplies_GetKey(t *testing.T) {
want := "quickReplies"
q := QuickReplies{}
if got := q.GetKey(); got != want {
t.Errorf("QuickReplies.GetKey() = %v, want %v", got, want)
}
}
func TestImage_GetKey(t *testing.T) {
want := "image"
i := Image{}
if got := i.GetKey(); got != want {
t.Errorf("Image.GetKey() = %v, want %v", got, want)
}
}
func TestPayloadWrapper_GetKey(t *testing.T) {
want := "payload"
p := PayloadWrapper{}
if got := p.GetKey(); got != want {
t.Errorf("Payload.GetKey() = %v, want %v", got, want)
}
}
func TestSuggestions_GetKey(t *testing.T) {
want := "suggestions"
s := Suggestions{}
if got := s.GetKey(); got != want {
t.Errorf("Suggestions.GetKey() = %v, want %v", got, want)
}
}
func TestLinkOutSuggestion_GetKey(t *testing.T) {
want := "linkOutSuggestion"
l := LinkOutSuggestion{}
if got := l.GetKey(); got != want {
t.Errorf("LinkOutSuggestion.GetKey() = %v, want %v", got, want)
}
}
func TestListSelect_GetKey(t *testing.T) {
want := "listSelect"
l := ListSelect{}
if got := l.GetKey(); got != want {
t.Errorf("ListSelect.GetKey() = %v, want %v", got, want)
}
}
func TestCarouselSelect_GetKey(t *testing.T) {
want := "carouselSelect"
c := CarouselSelect{}
if got := c.GetKey(); got != want {
t.Errorf("CarouselSelect.GetKey() = %v, want %v", got, want)
}
}
func TestSingleSimpleResponse(t *testing.T) {
type args struct {
display string
speech string
}
tests := []struct {
name string
args args
want SimpleResponsesWrapper
}{
{
"same text and speech",
args{"hello world", "hello world"},
SimpleResponsesWrapper{
SimpleResponses: []SimpleResponse{
{DisplayText: "hello world", TextToSpeech: "hello world"},
},
},
},
{
"different text and speech",
args{"hello world", "hi"},
SimpleResponsesWrapper{
SimpleResponses: []SimpleResponse{
{DisplayText: "hello world", TextToSpeech: "hi"},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SingleSimpleResponse(tt.args.display, tt.args.speech); !reflect.DeepEqual(got, tt.want) {
t.Errorf("SingleSimpleResponse() = %v, want %v", got, tt.want)
}
})
}
}
func TestPayloadWrapper_MarshalJSON(t *testing.T) {
type fields struct {
Payload interface{}
}
type minimal struct {
Hello string `json:"hello"`
}
tests := []struct {
name string
fields fields
want []byte
wantErr bool
}{
{"should fail", fields{make(chan int)}, []byte(""), true},
{"should marshal", fields{minimal{"hi"}}, []byte(`{"hello":"hi"}`), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := PayloadWrapper{
Payload: tt.fields.Payload,
}
got, err := p.MarshalJSON()
if (err != nil) != tt.wantErr {
t.Errorf("PayloadWrapper.MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.wantErr {
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("PayloadWrapper.MarshalJSON() = %v, want %v", got, tt.want)
}
})
}
}