forked from adlio/trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook_test.go
96 lines (78 loc) · 2.18 KB
/
webhook_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
88
89
90
91
92
93
94
95
96
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT license.
// Details in the LICENSE file.
package trello
import (
"testing"
)
func TestCreateWebhook(t *testing.T) {
client := testClient()
server := mockResponse("webhooks", "webhook-create.json")
defer server.Close()
client.BaseURL = server.URL
wh := Webhook{IDModel: "test", Description: "Webhook name", CallbackURL: "http://example.com/test"}
err := client.CreateWebhook(&wh)
if err != nil {
t.Error(err)
}
if wh.ID != "57f1c02b618bc5da74ad3874" {
t.Errorf("Unexpected resultant Webhook ID: '%s'.", wh.ID)
}
if wh.Active != true {
t.Error("Expected resulting webhook to be active.")
}
if wh.Description == "webhook name" {
t.Errorf("Webhook description should have been retrieved from the server. Got '%s'.", wh.Description)
}
}
func TestGetWebhook(t *testing.T) {
client := testClient()
server := mockResponse("webhooks", "webhook.json")
defer server.Close()
client.BaseURL = server.URL
webhook, err := client.GetWebhook("webhookID", Defaults())
if err != nil {
t.Error(err)
}
if webhook.ID != "57f1c02b618bc5da74ad3874" {
t.Errorf("Incorrect webhook.ID: '%s'.", webhook.ID)
}
if webhook.Active != true {
t.Error("Webhook should be active.")
}
if webhook.CallbackURL != "http://example.com/uvbhswuv" {
t.Errorf("Webhook has incorrect callback URL: '%s'.", webhook.CallbackURL)
}
}
func TestGetWebhooks(t *testing.T) {
token := testToken(t)
server := mockResponse("webhooks", "webhooks.json")
defer server.Close()
token.client.BaseURL = server.URL
webhooks, err := token.GetWebhooks(Defaults())
if err != nil {
t.Error(err)
}
if len(webhooks) != 2 {
t.Errorf("Expected 2 webhooks. Got %d", len(webhooks))
}
}
func TestDeleteWebhook(t *testing.T) {
c := testClient()
server := mockResponse("webhooks", "deleted.json")
defer server.Close()
c.BaseURL = server.URL
webhook := Webhook{
ID: "57f1c02b618bc5da74ad3874",
Description: "Test Web Hook",
IDModel: "57f039fbc0f98772398d289d",
CallbackURL: "http://example.com/uvbhswuv",
Active: true,
}
webhook.client = c
err := webhook.Delete(Defaults())
if err != nil {
t.Error(err)
}
}