-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_test.go
102 lines (90 loc) · 2.24 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
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
package twiml
import (
"context"
"encoding/xml"
"reflect"
"testing"
)
func TestResponse_Render(t *testing.T) {
ctx := context.Background()
header := xml.Header[:len(xml.Header)-1]
response1 := &Response{
Verbs: []interface{}{
&Dial{
Verbs: []interface{}{
&Number{
Value: "810-730-3842",
},
},
},
&Say{
Value: "Failed to connect",
},
},
}
xml1 := header + `
<Response>
<Dial>
<Number>810-730-3842</Number>
</Dial>
<Say>Failed to connect</Say>
</Response>`
response2 := NewResponse().
Dial(NewDial().
Number(NewNumber("810-730-3842"))).
Say(NewSay("Failed to connect"))
xml2 := header + `
<Response>
<Dial>
<Number>810-730-3842</Number>
</Dial>
<Say>Failed to connect</Say>
</Response>`
response3 := NewResponse().
Gather(NewGather().
SetAction("%s").
SetMethod(Post).
SetTimeout(10).
SetInput("dtmf").
Say(AliceVoice.Say("Welcome to patch conferencing")).
Pause(1).
Say(AliceVoice.Say("Please enter your akkcess code, followed by the pound sign"))).
Say(AliceVoice.Say("We did not hear a selection")).
Pause(1).
Redirect(NewRedirect("%s").
SetMethod(Post))
xml3 := header + `
<Response>
<Gather input="dtmf" action="%s" method="POST" timeout="10">
<Say voice="alice">Welcome to patch conferencing</Say>
<Pause length="1"></Pause>
<Say voice="alice">Please enter your akkcess code, followed by the pound sign</Say>
</Gather>
<Say voice="alice">We did not hear a selection</Say>
<Pause length="1"></Pause>
<Redirect method="POST">%s</Redirect>
</Response>`
tests := []struct {
name string
response *Response
want string
wantErr error
}{
{name: "Test1", response: response1, want: xml1},
{name: "Test2", response: response2, want: xml2},
{name: "Test3", response: response3, want: xml3},
{name: "Test4", response: response1, want: xml1},
{name: "Test5", response: response1, want: xml1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.response.Render(ctx)
if err != nil {
t.Errorf("Response.Render() = %v, want %v", err, tt.wantErr)
}
if !reflect.DeepEqual(string(got), tt.want) {
t.Errorf("Response.Render() = %v, want %v", string(got), tt.want)
}
})
}
}