forked from Exayn/go-listmonk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransactional_service_test.go
45 lines (35 loc) · 1.39 KB
/
transactional_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
package listmonk
import (
"context"
"testing"
"github.com/stretchr/testify/suite"
)
type transactionalServiceTestSuite struct {
suite.Suite
}
func TestTransactionalService(t *testing.T) {
suite.Run(t, new(transactionalServiceTestSuite))
}
func (s *transactionalServiceTestSuite) TestPostTransactionalService() {
mockResponse := []byte(`{
"data": true,
}`)
mockClient := newMockClient(mockResponse)
service := &PostTransactionalService{
c: mockClient,
// set other fields if needed
}
service.TemplateId(1)
service.SubscriberIds([]uint{1, 2})
service.SubscriberEmails([]string{"test2", "test2"})
service.Data(map[string]string{"key1": "value1", "key2": "value2"})
service.Headers(map[string]string{"key1": "value1", "key2": "value2"})
err := service.Do(context.Background())
s.Nil(err)
s.Equal(mockClient.Calls[0].Arguments.Get(1).(*request).method, "POST")
s.Equal(mockClient.Calls[0].Arguments.Get(1).(*request).json["template_id"], uint(1))
s.Equal(mockClient.Calls[0].Arguments.Get(1).(*request).json["subscriber_ids"], "[1, 2]")
s.Equal(mockClient.Calls[0].Arguments.Get(1).(*request).json["subscriber_emails"], "[\"test2\", \"test2\"]")
s.Equal(mockClient.Calls[0].Arguments.Get(1).(*request).json["data"], "{\"key1\":\"value1\",\"key2\":\"value2\"}")
s.Equal(mockClient.Calls[0].Arguments.Get(1).(*request).json["headers"], "[{\"key1\": \"value1\"}, {\"key2\": \"value2\"}]")
}