-
Notifications
You must be signed in to change notification settings - Fork 143
/
analytics_test.go
65 lines (57 loc) · 1.43 KB
/
analytics_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
package mailgun_test
import (
"context"
"testing"
"github.com/mailgun/mailgun-go/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestListMetrics(t *testing.T) {
mg := mailgun.NewMailgun(testDomain, testKey)
mg.SetAPIBase(server.URL1())
start, _ := mailgun.NewRFC2822Time("Tue, 24 Sep 2024 00:00:00 +0000")
end, _ := mailgun.NewRFC2822Time("Tue, 24 Oct 2024 00:00:00 +0000")
opts := mailgun.MetricsOptions{
Start: start,
End: end,
Pagination: mailgun.MetricsPagination{
Limit: 10,
},
}
wantResp := mailgun.MetricsResponse{
Start: start,
End: end,
Resolution: "day",
Duration: "30d",
Dimensions: []string{"time"},
Items: []mailgun.MetricsItem{
{
Dimensions: []mailgun.MetricsDimension{{
Dimension: "time",
Value: "Tue, 24 Sep 2024 00:00:00 +0000",
DisplayValue: "Tue, 24 Sep 2024 00:00:00 +0000",
}},
Metrics: mailgun.Metrics{
SentCount: ptr(uint64(4)),
DeliveredCount: ptr(uint64(3)),
OpenedCount: ptr(uint64(2)),
FailedCount: ptr(uint64(1)),
},
},
},
Pagination: mailgun.MetricsPagination{
Sort: "",
Skip: 0,
Limit: 10,
Total: 1,
},
}
it, err := mg.ListMetrics(opts)
require.NoError(t, err)
var page mailgun.MetricsResponse
ctx := context.Background()
more := it.Next(ctx, &page)
require.Nil(t, it.Err())
assert.False(t, more)
assert.Equal(t, wantResp, page)
}