File size: 1,009 Bytes
1e92f2d |
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 |
package twiml
import (
"encoding/xml"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestResponse_UnmarshalXML(t *testing.T) {
const doc = `<Response><Say>hi</Say><Gather timeout="13"><Say>there</Say></Gather><Hangup></Hangup></Response>`
var r Response
err := xml.Unmarshal([]byte(doc), &r)
require.NoError(t, err)
assert.Equal(t, Response{Verbs: []Verb{
&Say{Content: "hi"},
&Gather{
TimeoutDur: 13 * time.Second,
Verbs: []GatherVerb{&Say{Content: "there"}},
// defaults should be set
FinishOnKey: "#",
Input: "dtmf",
Language: "en-US",
Method: "POST",
PartialResultCallbackMethod: "POST",
SpeechTimeoutDur: 13 * time.Second, // defaults to TimeoutDur
SpeechModel: "default",
},
&Hangup{},
}}, r)
data, err := xml.Marshal(r)
require.NoError(t, err)
assert.Equal(t, doc, string(data))
}
|