-
Notifications
You must be signed in to change notification settings - Fork 3
/
metrics_activities_exports_test.go
109 lines (100 loc) · 3.11 KB
/
metrics_activities_exports_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
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
package chartmogul
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/davecgh/go-spew/spew"
)
// Tests creation on an activity export.
func TestCreateActivitiesExport(t *testing.T) {
server := httptest.NewServer(
http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
t.Errorf("Unexpected method %v", r.Method)
}
if r.RequestURI != "/v/activities_export" {
t.Errorf("Unexpected URI %v", r.RequestURI)
}
w.WriteHeader(http.StatusOK)
//nolint
w.Write([]byte(`{
"id": "7f554dba-4a41-4cb2-9790-2045e4c3a5b1",
"status": "pending",
"file_url": null,
"params": {
"kind": "activities",
"params": {
"activity_type": "contraction",
"start_date": "2020-01-01",
"end_date": "2020-12-31"
}
},
"expires_at": null,
"created_at": "2021-07-12T14:46:56+00:00"
}`))
}))
defer server.Close()
SetURL(server.URL + "/v/%v")
var tested IApi = &API{
ApiKey: "token",
}
activitiesExport, err := tested.MetricsCreateActivitiesExport(&CreateMetricsActivitiesExportParam{
StartDate: "2020-01-01",
EndDate: "2020-12-31",
Type: "contraction",
})
if err != nil {
spew.Dump(err)
t.Fatal("Not expected to fail")
}
if activitiesExport.ID != "7f554dba-4a41-4cb2-9790-2045e4c3a5b1" || activitiesExport.Status != "pending" {
spew.Dump(activitiesExport)
t.Fatal("Unexpected result")
}
}
// Tests retrieval of an activity export
func TestRetrieveActivitiesExport(t *testing.T) {
server := httptest.NewServer(
http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
t.Errorf("Unexpected method %v", r.Method)
}
if r.RequestURI != "/v/activities_export/7f554dba-4a41-4cb2-9790-2045e4c3a5b1" {
t.Errorf("Unexpected URI %v", r.RequestURI)
}
w.WriteHeader(http.StatusOK)
//nolint
w.Write([]byte(`{
"id": "7f554dba-4a41-4cb2-9790-2045e4c3a5b1",
"status": "succeeded",
"file_url": "https://chartmogul-customer-export.s3.eu-west-1.amazonaws.com/activities-acme-corp-91e1ca88-d747-4e25-83d9-2b752033bdba.zip",
"params": {
"kind": "activities",
"params": {
"activity_type": "contraction",
"start_date": "2020-01-01",
"end_date": "2020-12-31"
}
},
"expires_at": "2021-07-19T14:46:58+00:00",
"created_at": "2021-07-12T14:46:56+00:00"
}`))
}))
defer server.Close()
SetURL(server.URL + "/v/%v")
var tested IApi = &API{
ApiKey: "token",
}
var activitiesExportID = "7f554dba-4a41-4cb2-9790-2045e4c3a5b1"
activitiesExport, err := tested.MetricsRetrieveActivitiesExport(activitiesExportID)
if err != nil {
spew.Dump(err)
t.Fatal("Not expected to fail")
}
if activitiesExport.ID != activitiesExportID || activitiesExport.Status != "succeeded" {
spew.Dump(activitiesExport)
t.Fatal("Unexpected result")
}
}