-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseven_spec.rb
61 lines (48 loc) · 1.52 KB
/
seven_spec.rb
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
require 'rails_helper'
RSpec.describe Channel::Driver::Sms::Seven do
it 'passes' do
channel = create_channel
stub_request(:get, url_to_mock)
.to_return(body: '100')
api = channel.driver_instance.new
expect(api.send(channel.options, {to: to, text: text})).to be true
end
it 'fails' do
channel = create_channel
stub_request(:get, url_to_mock)
.to_return(body: '305')
api = channel.driver_instance.new
expect { api.send(channel.options, {to: to, text: ''}) }.to raise_exception(RuntimeError)
end
private
def create_channel
FactoryBot.create(:channel,
options: {
adapter: 'sms/seven',
from: from,
api_key: api_key
},
created_by_id: 1,
updated_by_id: 1)
end
def url_to_mock
'https://gateway.seven.io/api/sms?' + URI.encode_www_form({
p: api_key,
text: text,
to: to,
from: from
})
end
def text
'Test'
end
def to
'+491716992343'
end
def from
'+491000000000'
end
def api_key
'HeJyJSAvBWDn5RwNfhQGKZI6poCLk7pUXjpxctipYHWGsjoHtWNDI3d4De8gkoVe'
end
end