-
Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathmetrics_spec.rb
218 lines (212 loc) · 7.2 KB
/
metrics_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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
require 'spec_helper'
require 'mailgun'
vcr_opts = { cassette_name: 'metrics' }
describe Mailgun::Metrics, vcr: vcr_opts do
let(:metrics) { Mailgun::Metrics.new(Mailgun::Client.new(APIKEY, APIHOST, 'v1')) }
describe '#account_metrics' do
let(:options) do
{
resolution: 'hour',
metrics: [
'accepted_count',
'delivered_count',
'clicked_rate',
'opened_rate'
],
include_aggregates: true,
start: 'Tue, 26 Nov 2024 20:56:50 -0500',
duration: '1m',
filter: {
AND: [
{
attribute: 'domain',
comparator: '!=',
values: [
{
label: 'example.com',
value: 'example.com'
}
]
}
]
},
dimensions: ['time'],
end: 'Tue, 30 Nov 2024 20:56:50 -0500',
include_subaccounts: true
}
end
it 'responds with account metrics' do
expect(metrics.account_metrics(options)).to eq(
{
"start" => "Fri, 01 Nov 2024 01:00:00 +0000",
"end" => "Sun, 01 Dec 2024 01:00:00 +0000",
"resolution" => "hour",
"duration" => "1m",
"dimensions" => ["time"],
"pagination" => {
"sort" => "", "skip" => 0, "limit" => 1500, "total" => 3
},
"items" => [{
"dimensions" => [{
"dimension" => "time",
"value" => "Wed, 27 Nov 2024 12:00:00 +0000",
"display_value" => "Wed, 27 Nov 2024 12:00:00 +0000"
}],
"metrics" => {
"accepted_count" => 1, "delivered_count" => 1, "opened_rate" => "0.0000", "clicked_rate" => "0.0000"
}
},
{
"dimensions" => [{
"dimension" => "time",
"value" => "Wed, 27 Nov 2024 13:00:00 +0000",
"display_value" => "Wed, 27 Nov 2024 13:00:00 +0000"
}],
"metrics" => {
"accepted_count" => 1, "delivered_count" => 1, "opened_rate" => "0.0000", "clicked_rate" => "0.0000"
}
},
{
"dimensions" => [{
"dimension" => "time",
"value" => "Thu, 28 Nov 2024 15:00:00 +0000",
"display_value" => "Thu, 28 Nov 2024 15:00:00 +0000"
}],
"metrics" => {
"accepted_count" => 1, "delivered_count" => 1, "opened_rate" => "0.0000", "clicked_rate" => "0.0000"
}
}
],
"aggregates" => {
"metrics" => {
"accepted_count" => 3, "delivered_count" => 3, "opened_rate" => "0.0000", "clicked_rate" => "0.0000"
}
}
}
)
end
end
describe '#account_usage_metrics' do
let(:options) do
{
resolution: 'hour',
metrics: [
'email_preview_count',
'email_preview_failed_count',
'email_validation_bulk_count',
'email_validation_count',
'email_validation_list_count',
'email_validation_mailgun_count',
'email_validation_mailjet_count',
'email_validation_public_count',
'email_validation_single_count',
'email_validation_valid_count',
'link_validation_count',
'link_validation_failed_count',
'processed_count',
'seed_test_count'
],
include_aggregates: true,
start: 'Tue, 26 Nov 2024 20:56:50 -0500',
duration: '1m',
filter: {
AND: [
{
attribute: 'subaccount',
comparator: '!=',
values: [
{
label: '12345',
value: '12345'
}
]
}
]
},
dimensions: ['time'],
end: 'Tue, 28 Nov 2024 20:56:50 -0500',
include_subaccounts: true
}
end
it 'responds with account usage metrics' do
expect(metrics.account_usage_metrics(options)).to eq(
{
"start" => "Tue, 29 Oct 2024 01:00:00 +0000",
"end" => "Fri, 29 Nov 2024 01:00:00 +0000",
"resolution" => "hour",
"duration" => "1m",
"dimensions" => ["time"],
"pagination" => {
"sort" => "", "skip" => 0, "limit" => 1500, "total" => 2
},
"items" => [{
"dimensions" => [{
"dimension" => "time",
"value" => "Wed, 27 Nov 2024 00:00:00 +0000",
"display_value" => "Wed, 27 Nov 2024 00:00:00 +0000"
}],
"metrics" => {
"processed_count" => 2,
"email_validation_count" => 0,
"email_validation_public_count" => 0,
"email_validation_valid_count" => 0,
"email_validation_single_count" => 0,
"email_validation_bulk_count" => 0,
"email_validation_list_count" => 0,
"email_validation_mailgun_count" => 0,
"email_validation_mailjet_count" => 0,
"email_preview_count" => 0,
"email_preview_failed_count" => 0,
"link_validation_count" => 0,
"link_validation_failed_count" => 0,
"seed_test_count" => 0
}
},
{
"dimensions" => [{
"dimension" => "time",
"value" => "Thu, 28 Nov 2024 00:00:00 +0000",
"display_value" => "Thu, 28 Nov 2024 00:00:00 +0000"
}],
"metrics" => {
"processed_count" => 1,
"email_validation_count" => 0,
"email_validation_public_count" => 0,
"email_validation_valid_count" => 0,
"email_validation_single_count" => 0,
"email_validation_bulk_count" => 0,
"email_validation_list_count" => 0,
"email_validation_mailgun_count" => 0,
"email_validation_mailjet_count" => 0,
"email_preview_count" => 0,
"email_preview_failed_count" => 0,
"link_validation_count" => 0,
"link_validation_failed_count" => 0,
"seed_test_count" => 0
}
}
],
"aggregates" => {
"metrics" => {
"permanent_failed_count" => 0,
"processed_count" => 3,
"email_validation_count" => 0,
"email_validation_public_count" => 0,
"email_validation_valid_count" => 0,
"email_validation_single_count" => 0,
"email_validation_bulk_count" => 0,
"email_validation_list_count" => 0,
"email_validation_mailgun_count" => 0,
"email_validation_mailjet_count" => 0,
"email_preview_count" => 0,
"email_preview_failed_count" => 0,
"link_validation_count" => 0,
"link_validation_failed_count" => 0,
"seed_test_count" => 0
}
}
}
)
end
end
end