forked from Exayn/go-listmonk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia_service_test.go
87 lines (71 loc) · 2.03 KB
/
media_service_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
package listmonk
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/suite"
)
type mediaServiceTestSuite struct {
suite.Suite
}
func TestMediaService(t *testing.T) {
suite.Run(t, new(mediaServiceTestSuite))
}
func (s *mediaServiceTestSuite) TestGetMedia() {
mockResponse := []byte(`{
"data": [
{
"id": 1,
"uuid": "ec7b45ce-1408-4e5c-924e-965326a20287",
"filename": "Media file",
"created_at": "2020-04-08T22:43:45.080058+01:00",
"thumb_url": "/uploads/image_thumb.jpg",
"uri": "/uploads/image.jpg"
}
]
}`)
mockClient := newMockClient(mockResponse)
service := &GetMediaService{
c: mockClient,
}
result, err := service.Do(context.Background())
s.Nil(err)
s.Equal(uint(1), result[0].Id)
s.Equal("Media file", result[0].Filename)
s.Equal("ec7b45ce-1408-4e5c-924e-965326a20287", result[0].Uuid)
s.Equal(mockClient.Calls[0].Arguments.Get(1).(*request).method, "GET")
}
func (s *mediaServiceTestSuite) TestCreateCampaign() {
mockResponse := []byte(`{
"data": {
"id": 1,
"uuid": "ec7b45ce-1408-4e5c-924e-965326a20287",
"filename": "Media file",
"created_at": "2020-04-08T22:43:45.080058+01:00",
"thumb_url": "/uploads/image_thumb.jpg",
"uri": "/uploads/image.jpg"
}
}`)
mockClient := newMockClient(mockResponse)
service := &CreateMediaService{
c: mockClient,
}
result, err := service.File([]byte("file")).Do(context.Background())
s.Nil(err)
s.Equal(uint(1), result.Id)
s.Equal("Media file", result.Filename)
s.Equal("ec7b45ce-1408-4e5c-924e-965326a20287", result.Uuid)
s.Equal(mockClient.Calls[0].Arguments.Get(1).(*request).method, "POST")
}
func (s *mediaServiceTestSuite) TestDeleteMedia() {
mockResponse := []byte(`{}`)
mockClient := newMockClient(mockResponse)
service := &DeleteMediaService{
c: mockClient,
id: 1,
}
err := service.Do(context.Background())
s.Nil(err)
s.Equal(mockClient.Calls[0].Arguments.Get(1).(*request).method, "DELETE")
s.Equal(mockClient.Calls[0].Arguments.Get(1).(*request).endpoint, fmt.Sprintf("/media/%d", 1))
}