-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathactivity_test.go
56 lines (40 loc) · 1.27 KB
/
activity_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
package mailersend_test
import (
"bytes"
"context"
"fmt"
"io"
"net/http"
"testing"
"time"
"github.com/mailersend/mailersend-go"
"github.com/stretchr/testify/assert"
)
func TestCanCreateActivityOptions(t *testing.T) {
from := time.Now().Unix()
to := time.Now().Add(-24 * time.Hour).Unix()
options := mailersend.ActivityOptions{DateFrom: from, DateTo: to}
assert.Equal(t, 0, options.Limit)
assert.Equal(t, from, options.DateFrom)
assert.Equal(t, to, options.DateTo)
}
func TestCanMockActivity(t *testing.T) {
ms := mailersend.NewMailersend(testKey)
from := time.Now().Unix()
to := time.Now().Add(-24 * time.Hour).Unix()
client := NewTestClient(func(req *http.Request) *http.Response {
// Test request parameters
assert.Equal(t, req.URL.String(), fmt.Sprintf("https://api.mailersend.com/v1/activity/domain-id?date_from=%v&date_to=%v", from, to))
return &http.Response{
StatusCode: http.StatusAccepted,
Body: io.NopCloser(bytes.NewBufferString(`OK`)),
}
})
ctx := context.TODO()
ms.SetClient(client)
options := &mailersend.ActivityOptions{DomainID: "domain-id", DateFrom: from, DateTo: to}
_, _, _ = ms.Activity.List(ctx, options)
assert.Equal(t, 0, options.Limit)
assert.Equal(t, from, options.DateFrom)
assert.Equal(t, to, options.DateTo)
}