package twiml import ( "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestIterator(t *testing.T) { const doc = ` This is GoAlert with an alert notification. testing. To acknowledge, press 4. To close, press 6. To disable voice notifications to this number, press 1. To repeat this message, press star. ` i := NewIterator() err := i.SetResponse([]byte(doc)) require.NoError(t, err) assert.True(t, i.Next()) assert.Equal(t, &Say{Content: "\n\t\t\tThis is GoAlert with an alert notification. testing.\n\t\t"}, i.Verb()) assert.True(t, i.Next()) assert.Equal(t, &Say{Content: "\n\t\t\tTo acknowledge, press 4.\n\t\t"}, i.Verb()) assert.True(t, i.Next()) assert.Equal(t, &Say{Content: "\n\t\t\tTo close, press 6.\n\t\t"}, i.Verb()) assert.True(t, i.Next()) assert.Equal(t, &Say{Content: "\n\t\t\tTo disable voice notifications to this number, press 1.\n\t\t"}, i.Verb()) assert.True(t, i.Next()) assert.Equal(t, &Say{Content: "\n\t\t\tTo repeat this message, press star.\n\t\t"}, i.Verb()) assert.True(t, i.Next()) assert.Equal(t, &Gather{ Action: "http://127.0.0.1:39111/api/v2/twilio/call?msgBody=VGhpcyBpcyBHb0FsZXJ0IHdpdGggYW4gYWxlcnQgbm90aWZpY2F0aW9uLiB0ZXN0aW5nLg&msgID=62b6e835-e086-4cc2-9030-b0b230fdd2b2&msgSubjectID=1&type=alert", FinishOnKey: "#", Input: "dtmf", Language: "en-US", Method: "POST", NumDigitsCount: 1, PartialResultCallbackMethod: "POST", TimeoutDur: 10 * time.Second, SpeechTimeoutDur: 10 * time.Second, SpeechModel: "default", }, i.Verb()) assert.False(t, i.Next()) }