-
Notifications
You must be signed in to change notification settings - Fork 7
/
media_test.go
47 lines (38 loc) · 1.01 KB
/
media_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
package ankiconnect
import (
"net/http"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
)
func TestMediaManager_Retrieve(t *testing.T) {
retrieveMediaRequest := []byte(`{
"action": "retrieveMediaFile",
"version": 6,
"params": {
"filename": "_hello.txt"
}
}`)
retrieveMediaResult := []byte(`{
"result": "SGVsbG8sIHdvcmxkIQ==",
"error": null
}`)
t.Run("success", func(t *testing.T) {
defer httpmock.Reset()
registerVerifiedPayload(t,
retrieveMediaRequest,
retrieveMediaResult)
data, restErr := client.Media.RetrieveMediaFile("_hello.txt")
assert.Equal(t, "SGVsbG8sIHdvcmxkIQ==", *data)
assert.Nil(t, restErr)
})
t.Run("error", func(t *testing.T) {
defer httpmock.Reset()
registerErrorResponse(t)
data, restErr := client.Media.RetrieveMediaFile("_hello.txt")
assert.Nil(t, data)
assert.NotNil(t, restErr)
assert.Equal(t, http.StatusBadRequest, restErr.StatusCode)
assert.Equal(t, "some error message", restErr.Message)
})
}