github.com/twilio/twilio-go@v1.20.1/twiml/voice_response_test.go (about)

     1  package twiml_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"github.com/twilio/twilio-go/twiml"
     8  )
     9  
    10  func TestVoice_ZeroValueVerbList(t *testing.T) {
    11  	var verbs []twiml.Element
    12  	resp, _ := twiml.Voice(verbs)
    13  	assert.Equal(t,
    14  		`<?xml version="1.0" encoding="UTF-8"?><Response/>`,
    15  		resp)
    16  }
    17  
    18  func TestVoice_EmptyVerbList(t *testing.T) {
    19  	verbs := []twiml.Element{}
    20  	resp, _ := twiml.Voice(verbs)
    21  	assert.Equal(t,
    22  		`<?xml version="1.0" encoding="UTF-8"?><Response/>`,
    23  		resp)
    24  }
    25  
    26  func TestVoice_SayVerb(t *testing.T) {
    27  	say := twiml.VoiceSay{
    28  		Message: "Hello World!",
    29  	}
    30  	verbs := []twiml.Element{say}
    31  	resp, _ := twiml.Messages(verbs)
    32  	assert.Equal(t,
    33  		`<?xml version="1.0" encoding="UTF-8"?><Response><Say>Hello World!</Say></Response>`,
    34  		resp)
    35  }
    36  
    37  func TestVoice_SayVerbWithParams(t *testing.T) {
    38  	say := twiml.VoiceSay{
    39  		Message:  "Hello World!",
    40  		Voice:    "alice",
    41  		Loop:     "1",
    42  		Language: "en",
    43  	}
    44  	verbs := []twiml.Element{say}
    45  	resp, _ := twiml.Messages(verbs)
    46  	assert.Contains(t, resp, `voice="alice"`)
    47  	assert.Contains(t, resp, `loop="1"`)
    48  	assert.Contains(t, resp, `language="en"`)
    49  }
    50  
    51  func TestVoice_SayVerbWithOptionalAttributes(t *testing.T) {
    52  	optAttrs := map[string]string{"PlaybackURL": "https://demo.twilio.com"}
    53  	say := twiml.VoiceSay{
    54  		Message:            "Hello World!",
    55  		OptionalAttributes: optAttrs,
    56  	}
    57  	verbs := []twiml.Element{say}
    58  	resp, _ := twiml.Messages(verbs)
    59  	assert.Contains(t, resp, `playbackURL="https://demo.twilio.com"`)
    60  }
    61  
    62  func TestVoice_GatherVerbWithNestedPlayVerb(t *testing.T) {
    63  	play := twiml.VoicePlay{
    64  		Url: "https://demo.twilio.com",
    65  	}
    66  	gather := twiml.VoiceGather{
    67  		InnerElements: []twiml.Element{play},
    68  	}
    69  	verbs := []twiml.Element{gather}
    70  	resp, _ := twiml.Messages(verbs)
    71  	assert.Equal(t,
    72  		`<?xml version="1.0" encoding="UTF-8"?><Response><Gather><Play>https://demo.twilio.com</Play></Gather></Response>`,
    73  		resp)
    74  }