-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_test.go
71 lines (55 loc) · 1.87 KB
/
response_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
package ghome
import (
"testing"
"google.golang.org/api/dialogflow/v2"
)
func TestResponseCard(t *testing.T) {
resp := NewResponse()
resp.WriteCard(&dialogflow.GoogleCloudDialogflowV2IntentMessageCard{
Title: "Hello Gopher",
Subtitle: "Nice day",
ImageUri: "https://golang.org/doc/gopher/frontpage.png",
Buttons: []*dialogflow.GoogleCloudDialogflowV2IntentMessageCardButton{
{
Text: "Learn more about Go",
Postback: "https://golang.org",
},
},
})
if resp.FulfillmentMessages[0].Card.Title != "Hello Gopher" {
t.Errorf("Expected 'Hello Gopher' got %s", resp.FulfillmentMessages[0].Card.Title)
}
if resp.FulfillmentMessages[0].Card.ImageUri != "https://golang.org/doc/gopher/frontpage.png" {
t.Errorf("Expected 'https://golang.org/doc/gopher/frontpage.png' got %s", resp.FulfillmentMessages[0].Card.ImageUri)
}
}
func TestResponseWriteFollowupEventInput(t *testing.T) {
resp := NewResponse()
err := resp.WriteFollowupEventInput("Test", "en", map[string]interface{}{
"hello": "world",
})
if err != nil {
t.Errorf("Expected nil got error: %v", err)
}
if resp.FollowupEventInput.Name != "Test" {
t.Errorf("Expected: 'Test' got %s", resp.FollowupEventInput.Name)
}
if string(resp.FollowupEventInput.Parameters) != `{"hello":"world"}` {
t.Errorf("Expected: '{\"hello\":\"world\"}' got %s", resp.FollowupEventInput.Parameters)
}
}
func TestResponseWriteOutputContext(t *testing.T) {
resp := NewResponse()
err := resp.WriteOutputContext("Test", 0, map[string]interface{}{
"hello": "world",
})
if err != nil {
t.Errorf("Expected nil got error: %v", err)
}
if resp.OutputContexts[0].Name != "Test" {
t.Errorf("Expected: 'Test' got %s", resp.OutputContexts[0].Name)
}
if string(resp.OutputContexts[0].Parameters) != `{"hello":"world"}` {
t.Errorf("Expected: '{\"hello\":\"world\"}' got %s", resp.OutputContexts[0].Parameters)
}
}