File size: 2,905 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
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
package harness

// PhoneAssertions is used to assert voice and SMS behavior.
type PhoneAssertions interface {

	// Device returns a TwilioDevice for the given number.
	//
	// It is safe to call multiple times for the same device.
	Device(number string) PhoneDevice

	// WaitAndAssert will fail the test if there are any unexpected messages received within the timeout interval.
	WaitAndAssert()
}

// A PhoneDevice immitates a device (i.e. a phone) for testing interactions.
type PhoneDevice interface {
	// SendSMS will send a message to GoAlert from the device.
	SendSMS(body string)

	// ExpectSMS will match against an SMS that matches ALL provided keywords (case-insensitive).
	// Each call to ExpectSMS results in the requirement that an additional SMS is received.
	ExpectSMS(keywords ...string) ExpectedSMS

	// RejectSMS will match against an SMS that matches ALL provided keywords (case-insensitive) and tell the server that delivery failed.
	RejectSMS(keywords ...string)

	// ExpectVoice will match against a voice call where the spoken text matches ALL provided keywords (case-insensitive).
	ExpectVoice(keywords ...string) ExpectedCall

	// RejectVoice will match against a voice call where the spoken text matches ALL provided keywords (case-insensitive) and tell the server that delivery failed.
	RejectVoice(keywords ...string)

	// IgnoreUnexpectedSMS will cause any extra SMS messages (after processing ExpectSMS calls) that match
	// ALL keywords (case-insensitive) to not fail the test.
	IgnoreUnexpectedSMS(keywords ...string)

	// IgnoreUnexpectedVoice will cause any extra voice calls (after processing ExpectVoice) that match
	// ALL keywords (case-insensitive) to not fail the test.
	IgnoreUnexpectedVoice(keywords ...string)
}

// ExpectedCall represents a phone call.
type ExpectedCall interface {
	// ThenPress imitates a user entering a key on the phone.
	ThenPress(digits string) ExpectedCall

	// ThenExpect asserts that the message matches ALL keywords (case-insensitive).
	//
	// Generally used as ThenPress().ThenExpect()
	ThenExpect(keywords ...string) ExpectedCall

	// Body will return the last full spoken message as text. Separate stanzas (e.g. multiple `<Say>`) are
	// separated by newline.
	Body() string

	// Hangup will hangup the active call.
	Hangup()
}

// ExpectedSMS represents an SMS message.
type ExpectedSMS interface {

	// ThenReply will respond with an SMS with the given body.
	ThenReply(body string) SMSReply

	// Body is the text of the SMS message.
	Body() string

	// From is the source number of the SMS message.
	From() string
}

// SMSReply represents a reply to a received SMS message.
type SMSReply interface {
	// ThenExpect will match against an SMS that matches ALL provided keywords (case-insensitive).
	// The message must be received AFTER the reply is sent or the assertion will fail.
	ThenExpect(keywords ...string) ExpectedSMS
}