Skip to content

Commit 0b2f69d

Browse files
committed
tests: move integration tests to its own folder
1 parent 6eb859f commit 0b2f69d

File tree

10 files changed

+191
-29
lines changed

10 files changed

+191
-29
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Editor configuration file
2+
# For Sublime Text install package `EditorConfig`
3+
root = true
4+
5+
[*]
6+
indent_style = tab
7+
indent_size = 4
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
13+
; Indentation override for all JS under lib directory
14+
[*.(yml|yaml)]
15+
indent_style = space
16+
indent_size = 2

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
sudo: false
22
language: go
3-
43
go:
54
- 1.9.x
65
- 1.8.x
@@ -23,6 +22,6 @@ script:
2322
- diff -u <(echo -n) <(gofmt -d -s .)
2423
- go generate -x ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code) # Check that go generate ./... produces a zero diff; clean up any changes afterwards.
2524
- go tool vet .
26-
- ls -la
27-
- go test ./pipedrive -api -covermode=count -coverprofile=coverage.out
28-
- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN
25+
- go test -v -race ./...
26+
# - go test ./pipedrive -api -covermode=count -coverprofile=coverage.out
27+
# - $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN

pipedrive/pipedrive.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ type Client struct {
5656
Authorizations *AuthorizationsService
5757
Stages *StagesService
5858
Webhooks *WebhooksService
59-
UserSettings *UserSettingsService
6059
UserConnections *UserConnectionsService
6160
GoalsService *GoalsService
6261
PipelinesService *PipelinesService
62+
UserSettings *UserSettingsService
6363
}
6464

6565
type service struct {
@@ -203,7 +203,7 @@ func (c *Client) SetOptions(options ...func(*Client) error) error {
203203
return nil
204204
}
205205

206-
func New(options *Config) *Client {
206+
func NewClient(options *Config) *Client {
207207
baseURL, _ := url.Parse(defaultBaseUrl)
208208

209209
c := &Client{
@@ -227,10 +227,10 @@ func New(options *Config) *Client {
227227
c.Authorizations = (*AuthorizationsService)(&c.common)
228228
c.Stages = (*StagesService)(&c.common)
229229
c.Webhooks = (*WebhooksService)(&c.common)
230-
c.UserSettings = (*UserSettingsService)(&c.common)
231230
c.UserConnections = (*UserConnectionsService)(&c.common)
232231
c.GoalsService = (*GoalsService)(&c.common)
233232
c.PipelinesService = (*PipelinesService)(&c.common)
233+
c.UserSettings = (*UserSettingsService)(&c.common)
234234

235235
return c
236236
}

pipedrive/users.go

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,39 +30,72 @@ type User struct {
3030
IsYou bool `json:"is_you"`
3131
}
3232

33-
type Users struct {
33+
type UsersResponse struct {
3434
Success bool `json:"success"`
3535
Error string `json:"error,omitempty"`
3636
ErrorInfo string `json:"error_info,omitempty"`
3737
Data []User `json:"data"`
3838
AdditionalData AdditionalData `json:"additional_data"`
3939
}
4040

41-
type SingleUser struct {
41+
type UserSingleResponse struct {
4242
Success bool `json:"success"`
4343
Data User `json:"data"`
4444
AdditionalData AdditionalData `json:"additional_data"`
4545
}
4646

47+
type UserFollowersResponse struct {
48+
Success bool `json:"success"`
49+
Data []int `json:"data"`
50+
AdditionalData AdditionalData `json:"additional_data"`
51+
}
52+
4753
type UsersFindByNameOptions struct {
4854
Term string `url:"term,omitempty"`
4955
SearchByEmail int `url:"search_by_email,omitempty"`
5056
}
5157

58+
type UsersUpdateUserDetailsOptions struct {
59+
ActiveFlag uint8 `url:"active_flag,omitempty"`
60+
}
61+
62+
type DeletePermissionSetAssignmentOptions struct {
63+
PermissionSetId uint `url:"permission_set_id,omitempty"`
64+
}
65+
5266
type DeleteRoleAssignmentOptions struct {
5367
RoleId uint `url:"role_id,omitempty"`
5468
}
5569

56-
// Returns data about all users within the company.
5770
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/Users/get_users
58-
func (s *UsersService) List() (*Users, *Response, error) {
71+
func (s *UsersService) List() (*UsersResponse, *Response, error) {
5972
req, err := s.client.NewRequest(http.MethodGet, "/users", nil, nil)
6073

6174
if err != nil {
6275
return nil, nil, err
6376
}
6477

65-
var record *Users
78+
var record *UsersResponse
79+
80+
resp, err := s.client.Do(req, &record)
81+
82+
if err != nil {
83+
return nil, resp, err
84+
}
85+
86+
return record, resp, nil
87+
}
88+
89+
// https://developers.pipedrive.com/docs/api/v1/#!/Users/get_users_id_followers
90+
func (s *UsersService) ListFollowers(id int) (*UserFollowersResponse, *Response, error) {
91+
uri := fmt.Sprintf("/users/%v/followers", id)
92+
req, err := s.client.NewRequest(http.MethodGet, uri, nil, nil)
93+
94+
if err != nil {
95+
return nil, nil, err
96+
}
97+
98+
var record *UserFollowersResponse
6699

67100
resp, err := s.client.Do(req, &record)
68101

@@ -73,16 +106,15 @@ func (s *UsersService) List() (*Users, *Response, error) {
73106
return record, resp, nil
74107
}
75108

76-
// Finds users by their name.
77109
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/Users/get_users_find
78-
func (s *UsersService) FindByName(opt *UsersFindByNameOptions) (*Users, *Response, error) {
110+
func (s *UsersService) FindByName(opt *UsersFindByNameOptions) (*UsersResponse, *Response, error) {
79111
req, err := s.client.NewRequest(http.MethodGet, "/users/find", opt, nil)
80112

81113
if err != nil {
82114
return nil, nil, err
83115
}
84116

85-
var record *Users
117+
var record *UsersResponse
86118

87119
resp, err := s.client.Do(req, &record)
88120

@@ -93,17 +125,16 @@ func (s *UsersService) FindByName(opt *UsersFindByNameOptions) (*Users, *Respons
93125
return record, resp, nil
94126
}
95127

96-
// Returns data about a specific user within the company
97128
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/Users/get_users_id
98-
func (s *UsersService) GetById(id int) (*SingleUser, *Response, error) {
129+
func (s *UsersService) GetById(id int) (*UserFollowersResponse, *Response, error) {
99130
uri := fmt.Sprintf("/users/%v", id)
100131
req, err := s.client.NewRequest(http.MethodGet, uri, nil, nil)
101132

102133
if err != nil {
103134
return nil, nil, err
104135
}
105136

106-
var record *SingleUser
137+
var record *UserFollowersResponse
107138

108139
resp, err := s.client.Do(req, &record)
109140

@@ -114,11 +145,46 @@ func (s *UsersService) GetById(id int) (*SingleUser, *Response, error) {
114145
return record, resp, nil
115146
}
116147

117-
// Delete a role assignment for a user.
148+
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/Users/put_users_id
149+
func (s *UsersService) UpdateUserDetails(id int, opt *UsersUpdateUserDetailsOptions) (*Response, error) {
150+
uri := fmt.Sprintf("/users/%v", id)
151+
req, err := s.client.NewRequest(http.MethodPut, uri, opt, nil)
152+
153+
if err != nil {
154+
return nil, err
155+
}
156+
157+
resp, err := s.client.Do(req, nil)
158+
159+
if err != nil {
160+
return resp, err
161+
}
162+
163+
return resp, nil
164+
}
165+
166+
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/Users/delete_users_id_permissionSetAssignments
167+
func (s *UsersService) DeletePermissionSetAssignment(id int, opt *DeletePermissionSetAssignmentOptions) (*Response, error) {
168+
uri := fmt.Sprintf("/users/%v/permissionSetAssignments", id)
169+
req, err := s.client.NewRequest(http.MethodDelete, uri, opt, nil)
170+
171+
if err != nil {
172+
return nil, err
173+
}
174+
175+
resp, err := s.client.Do(req, nil)
176+
177+
if err != nil {
178+
return resp, err
179+
}
180+
181+
return resp, nil
182+
}
183+
118184
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/Users/delete_users_id_roleAssignments
119185
func (s *UsersService) DeleteRoleAssignment(id int, opt *DeleteRoleAssignmentOptions) (*Response, error) {
120186
uri := fmt.Sprintf("/users/%v/roleAssignments", id)
121-
req, err := s.client.NewRequest(http.MethodDelete, uri, nil, nil)
187+
req, err := s.client.NewRequest(http.MethodDelete, uri, opt, nil)
122188

123189
if err != nil {
124190
return nil, err

pipedrive/webhooks.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ type Webhooks struct {
3434
Data []Webhook `json:"data,omitempty"`
3535
}
3636

37+
type SingleWebhook struct {
38+
Status string `json:"status,omitempty"`
39+
Success bool `json:"success,omitempty"`
40+
Data Webhook `json:"data,omitempty"`
41+
}
42+
3743
type WebhooksCreateOptions struct {
3844
SubscriptionUrl string `url:"subscription_url"`
3945
EventAction EventAction `url:"event_action"`
@@ -43,7 +49,6 @@ type WebhooksCreateOptions struct {
4349
HttpAuthPassword string `url:"http_auth_password"`
4450
}
4551

46-
// Returns data about all webhooks of a company.
4752
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/Webhooks/get_webhooks
4853
func (s *WebhooksService) List() (*Webhooks, *Response, error) {
4954
req, err := s.client.NewRequest(http.MethodGet, "/webhooks", nil, nil)
@@ -63,20 +68,15 @@ func (s *WebhooksService) List() (*Webhooks, *Response, error) {
6368
return record, resp, nil
6469
}
6570

66-
// Creates a new webhook and returns its details.
67-
// Note that specifying an event which triggers the webhook combines 2 parameters -
68-
// 'event_action' and 'event_object'.
69-
// E.g., use '*.*' for getting notifications about all events,
70-
// 'added.deal' for any newly added deals, 'deleted.persons' for any deleted persons, etc.
7171
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/Webhooks/post_webhooks
72-
func (s *WebhooksService) Create(opt *WebhooksCreateOptions) (*SingleStage, *Response, error) {
72+
func (s *WebhooksService) Create(opt *WebhooksCreateOptions) (*SingleWebhook, *Response, error) {
7373
req, err := s.client.NewRequest(http.MethodPost, "/webhooks", nil, opt)
7474

7575
if err != nil {
7676
return nil, nil, err
7777
}
7878

79-
var record *SingleStage
79+
var record *SingleWebhook
8080

8181
resp, err := s.client.Do(req, &record)
8282

@@ -87,7 +87,6 @@ func (s *WebhooksService) Create(opt *WebhooksCreateOptions) (*SingleStage, *Res
8787
return record, resp, nil
8888
}
8989

90-
// Deletes the specified webhook.
9190
// Pipedrive API docs: https://developers.pipedrive.com/docs/api/v1/#!/Webhooks/delete_webhooks_id
9291
func (s *WebhooksService) Delete(id int) (*Response, error) {
9392
uri := fmt.Sprintf("/webhooks/%v", id)

test/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# pipedrive-api tests
2+
3+
integration
4+
-----------
5+
6+
This will exercise the library against the live Pipedrive API and verify actual behaviour of the API.
7+
8+
Run tests using:
9+
10+
PIPEDRIVE_API_TOKEN=XXXXXX go test -v -tags=integration ./integration

test/integration/pipedrive_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package integration
2+
3+
import (
4+
"github.com/genert/pipedrive-api/pipedrive"
5+
"os"
6+
)
7+
8+
var (
9+
client *pipedrive.Client
10+
)
11+
12+
func init() {
13+
token := os.Getenv("PIPEDRIVE_API_TOKEN")
14+
15+
if token == "" {
16+
print("No API key found. Integration tests won't run!\n\n")
17+
os.Exit(1)
18+
} else {
19+
config := &pipedrive.Config{
20+
ApiKey: token,
21+
}
22+
23+
client = pipedrive.NewClient(config)
24+
}
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package integration
2+
3+
import "testing"
4+
5+
func TestUserConnectionsService_List(t *testing.T) {
6+
result, _, err := client.UserConnections.List()
7+
8+
if err != nil {
9+
t.Errorf("Could not get webhooks list: %v", err)
10+
}
11+
12+
if result.Success != true {
13+
t.Error("Got invalid result")
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package integration
2+
3+
import "testing"
4+
5+
func TestUserSettings_List(t *testing.T) {
6+
result, _, err := client.UserSettings.List()
7+
8+
if err != nil {
9+
t.Errorf("Could not get webhooks list: %v", err)
10+
}
11+
12+
if result.Success != true {
13+
t.Error("Got invalid result")
14+
}
15+
}

test/integration/webhooks_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package integration
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestWebhooksService_List(t *testing.T) {
8+
result, _, err := client.Webhooks.List()
9+
10+
if err != nil {
11+
t.Errorf("Could not get webhooks list: %v", err)
12+
}
13+
14+
if result.Success != true {
15+
t.Error("Got invalid result")
16+
}
17+
}

0 commit comments

Comments
 (0)