forked from mailgun/mailgun-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
suppressions_spec.rb
executable file
·126 lines (98 loc) · 3.34 KB
/
suppressions_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
require 'spec_helper'
require 'mailgun'
require 'mailgun/suppressions'
vcr_opts = { :cassette_name => 'suppressions' }
describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts do
before(:all) do
@mg_obj = Mailgun::Client.new(APIKEY)
@suppress = Mailgun::Suppressions.new(@mg_obj, TESTDOMAIN)
@addresses = ['test1@example.com', 'test2@example.org', 'test3@example.net', 'test4@example.info']
end
it 'can batch-add bounces' do
bounces = []
@addresses.each do |addr|
bounces.push({
:address => addr,
:code => 500,
:error => 'integration testing',
})
end
response, nested = @suppress.create_bounces bounces
response.to_h!
expect(response.code).to eq(200)
expect(response.body['message']).to eq('4 addresses have been added to the bounces table')
expect(nested.length).to eq(0)
end
it 'raises ParameterError if no bounce[:address] is present' do
bounces = []
bounces.push({
:code => 500,
:error => 'integration testing',
})
expect { @suppress.create_bounces bounces }.to raise_error(Mailgun::ParameterError)
end
it 'removes a single bounce address' do
@addresses.each do |addr|
response = @suppress.delete_bounce addr
response.to_h!
expect(response.code).to eq(200)
expect(response.body['message']).to eq('Bounced address has been removed')
end
end
it 'can batch-add unsubscribes' do
unsubscribes = []
@addresses.each do |addr|
unsubscribes.push({
:address => addr,
:tag => 'integration',
})
end
response, nested = @suppress.create_unsubscribes unsubscribes
response.to_h!
expect(response.code).to eq(200)
expect(response.body['message']).to eq('4 addresses have been added to the unsubscribes table')
expect(nested.length).to eq(0)
end
it 'raises ParameterError if no unsubscribe[:address] is present' do
unsubscribes = []
unsubscribes.push({
:tag => 'integration',
})
expect { @suppress.create_unsubscribes unsubscribes }.to raise_error(Mailgun::ParameterError)
end
it 'removes a single unsubscribe address' do
@addresses.each do |addr|
response = @suppress.delete_unsubscribe addr
response.to_h!
expect(response.code).to eq(200)
expect(response.body['message']).to eq('Unsubscribe event has been removed')
end
end
it 'can batch-add complaints' do
complaints = []
@addresses.each do |addr|
complaints.push :address => addr
end
response, nested = @suppress.create_complaints complaints
response.to_h!
expect(response.code).to eq(200)
expect(response.body['message']).to eq('4 complaint addresses have been added to the complaints table')
expect(nested.length).to eq(0)
end
it 'raises ParameterError if no complaint[:address] is present' do
complaints = []
complaints.push({
:tag => 'integration',
})
expect { @suppress.create_complaints complaints }.to raise_error(Mailgun::ParameterError)
end
it 'removes a single complaint address' do
@addresses.each do |addr|
response = @suppress.delete_complaint addr
response.to_h!
expect(response.code).to eq(200)
expect(response.body['message']).to eq('Spam complaint has been removed')
end
end
# TODO: Add tests for pagination support.
end