forked from nyaruka/courier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsender_test.go
81 lines (65 loc) · 2.05 KB
/
sender_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
package courier
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func testConfig() *Config {
config := NewConfig()
config.DB = "postgres://courier@localhost/courier_test?sslmode=disable"
config.Redis = "redis://localhost:6379/0"
return config
}
func TestSending(t *testing.T) {
assert := assert.New(t)
// create our backend and server
mb := NewMockBackend()
s := NewServer(testConfig(), mb)
// start everything
s.Start()
defer s.Stop()
// create and add a new outgoing message
xxChannel := NewMockChannel("53e5aafa-8155-449d-9009-fcb30d54bd26", "XX", "2020", "US", map[string]interface{}{})
dmChannel := NewMockChannel("e4bb1578-29da-4fa5-a214-9da19dd24230", "DM", "2020", "US", map[string]interface{}{})
msg := &mockMsg{
channel: xxChannel,
id: NewMsgID(101),
uuid: NilMsgUUID,
text: "test message",
urn: "tel:+250788383383",
}
mb.PushOutgoingMsg(msg)
// sleep a second, sender should take care of it in that time
time.Sleep(time.Second)
// message should have errored because we have registered handlers
assert.Equal(1, len(mb.msgStatuses))
assert.Equal(msg.ID(), mb.msgStatuses[0].ID())
assert.Equal(MsgErrored, mb.msgStatuses[0].Status())
assert.Equal(1, len(mb.msgStatuses[0].Logs()))
// clear our statuses
mb.msgStatuses = nil
// change our channel to our dummy channel
msg = &mockMsg{
channel: dmChannel,
id: NewMsgID(102),
uuid: NilMsgUUID,
text: "test message 2",
urn: "tel:+250788383383",
}
// send it
mb.PushOutgoingMsg(msg)
time.Sleep(time.Second)
// message should be marked as wired
assert.Equal(1, len(mb.msgStatuses))
assert.Equal(msg.ID(), mb.msgStatuses[0].ID())
assert.Equal(MsgSent, mb.msgStatuses[0].Status())
// clear our statuses
mb.msgStatuses = nil
// send the message again, should be skipped but again marked as wired
mb.PushOutgoingMsg(msg)
time.Sleep(time.Second)
// message should be marked as wired
assert.Equal(1, len(mb.msgStatuses))
assert.Equal(msg.ID(), mb.msgStatuses[0].ID())
assert.Equal(MsgWired, mb.msgStatuses[0].Status())
}