-
Notifications
You must be signed in to change notification settings - Fork 0
/
history_test.go
48 lines (40 loc) · 1.2 KB
/
history_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
package cag
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
type fakeHistory struct{}
func (a *fakeHistory) Get() (HistoryResponse, int, error) {
return HistoryResponse{}, http.StatusOK, nil
}
func (a *fakeHistory) Check() error {
return nil
}
func TestNewHistory(t *testing.T) {
assert := assert.New(t)
client := &client{
apiKey: fakeAPIKey,
}
history := &HistoryData{}
client.NewHistory(history)
assert.Equal(client, history.Client)
assert.Equal(1, history.Page)
}
func TestGetHistory(t *testing.T) {
assert := assert.New(t)
client := NewFakeClient()
history := HistoryData{Client: client, Page: 1}
historyResponse, statusCode, err := history.Get()
assert.NoError(err, "failed to get history without an error")
assert.Equal(5, historyResponse.TotalPages, "alert response does not match")
assert.Equal(http.StatusFound, statusCode, "http status not correct")
}
func TestGetHistoryInvalid(t *testing.T) {
assert := assert.New(t)
client := NewFakeClient()
history := HistoryData{Client: client}
_, statusCode, err := history.Get()
assert.Error(err, "failed to get an error with invalid input")
assert.Equal(http.StatusBadRequest, statusCode, "http status not correct")
}