zendesk2 1.4.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/lib/zendesk2/attributes.rb +1 -1
- data/lib/zendesk2/{collection.rb → client/collection.rb} +22 -17
- data/lib/zendesk2/client/collections/categories.rb +2 -1
- data/lib/zendesk2/client/collections/forums.rb +2 -1
- data/lib/zendesk2/client/collections/groups.rb +4 -3
- data/lib/zendesk2/client/collections/help_center/articles.rb +2 -1
- data/lib/zendesk2/client/collections/help_center/categories.rb +2 -1
- data/lib/zendesk2/client/collections/help_center/sections.rb +2 -1
- data/lib/zendesk2/client/collections/memberships.rb +9 -7
- data/lib/zendesk2/client/collections/organizations.rb +3 -2
- data/lib/zendesk2/client/collections/ticket_audits.rb +5 -4
- data/lib/zendesk2/client/collections/ticket_comments.rb +4 -3
- data/lib/zendesk2/client/collections/ticket_fields.rb +3 -1
- data/lib/zendesk2/client/collections/tickets.rb +2 -1
- data/lib/zendesk2/client/collections/topic_comments.rb +2 -1
- data/lib/zendesk2/client/collections/topics.rb +2 -1
- data/lib/zendesk2/client/collections/user_fields.rb +3 -1
- data/lib/zendesk2/client/collections/user_identities.rb +3 -1
- data/lib/zendesk2/client/collections/users.rb +3 -2
- data/lib/zendesk2/client/help_center.rb +3 -0
- data/lib/zendesk2/client/mock.rb +7 -130
- data/lib/zendesk2/{model.rb → client/model.rb} +7 -3
- data/lib/zendesk2/client/models/audit_event.rb +2 -2
- data/lib/zendesk2/client/models/category.rb +8 -8
- data/lib/zendesk2/client/models/forum.rb +11 -16
- data/lib/zendesk2/client/models/group.rb +8 -13
- data/lib/zendesk2/client/models/help_center/article.rb +12 -16
- data/lib/zendesk2/client/models/help_center/category.rb +12 -16
- data/lib/zendesk2/client/models/help_center/section.rb +12 -16
- data/lib/zendesk2/client/models/membership.rb +10 -12
- data/lib/zendesk2/client/models/organization.rb +13 -20
- data/lib/zendesk2/client/models/ticket.rb +21 -19
- data/lib/zendesk2/client/models/ticket_audit.rb +3 -3
- data/lib/zendesk2/client/models/ticket_comment.rb +1 -1
- data/lib/zendesk2/client/models/ticket_comment_privacy_change.rb +1 -1
- data/lib/zendesk2/client/models/ticket_field.rb +5 -13
- data/lib/zendesk2/client/models/ticket_metric.rb +1 -1
- data/lib/zendesk2/client/models/ticket_voice_comment.rb +1 -1
- data/lib/zendesk2/client/models/topic.rb +9 -14
- data/lib/zendesk2/client/models/topic_comment.rb +14 -19
- data/lib/zendesk2/client/models/user.rb +25 -32
- data/lib/zendesk2/client/models/user_field.rb +10 -18
- data/lib/zendesk2/client/models/user_identity.rb +9 -18
- data/lib/zendesk2/client/real.rb +7 -8
- data/lib/zendesk2/client/request.rb +271 -0
- data/lib/zendesk2/client/requests/create_category.rb +19 -27
- data/lib/zendesk2/client/requests/create_forum.rb +23 -28
- data/lib/zendesk2/client/requests/create_group.rb +25 -29
- data/lib/zendesk2/client/requests/create_help_center_article.rb +54 -60
- data/lib/zendesk2/client/requests/create_help_center_category.rb +35 -47
- data/lib/zendesk2/client/requests/create_help_center_section.rb +49 -55
- data/lib/zendesk2/client/requests/create_membership.rb +42 -42
- data/lib/zendesk2/client/requests/create_organization.rb +30 -40
- data/lib/zendesk2/client/requests/create_ticket.rb +76 -85
- data/lib/zendesk2/client/requests/create_ticket_field.rb +36 -40
- data/lib/zendesk2/client/requests/create_topic.rb +23 -28
- data/lib/zendesk2/client/requests/create_topic_comment.rb +27 -31
- data/lib/zendesk2/client/requests/create_user.rb +51 -56
- data/lib/zendesk2/client/requests/create_user_field.rb +36 -40
- data/lib/zendesk2/client/requests/create_user_identity.rb +39 -44
- data/lib/zendesk2/client/requests/destroy_category.rb +8 -21
- data/lib/zendesk2/client/requests/destroy_forum.rb +8 -23
- data/lib/zendesk2/client/requests/destroy_group.rb +8 -21
- data/lib/zendesk2/client/requests/destroy_help_center_article.rb +8 -18
- data/lib/zendesk2/client/requests/destroy_help_center_category.rb +8 -18
- data/lib/zendesk2/client/requests/destroy_help_center_section.rb +10 -18
- data/lib/zendesk2/client/requests/destroy_membership.rb +8 -22
- data/lib/zendesk2/client/requests/destroy_organization.rb +8 -21
- data/lib/zendesk2/client/requests/destroy_ticket.rb +8 -21
- data/lib/zendesk2/client/requests/destroy_ticket_field.rb +8 -21
- data/lib/zendesk2/client/requests/destroy_topic.rb +8 -23
- data/lib/zendesk2/client/requests/destroy_topic_comment.rb +11 -24
- data/lib/zendesk2/client/requests/destroy_user.rb +17 -43
- data/lib/zendesk2/client/requests/destroy_user_field.rb +7 -22
- data/lib/zendesk2/client/requests/destroy_user_identity.rb +10 -25
- data/lib/zendesk2/client/requests/get_assignable_groups.rb +8 -16
- data/lib/zendesk2/client/requests/get_categories.rb +7 -15
- data/lib/zendesk2/client/requests/get_category.rb +11 -22
- data/lib/zendesk2/client/requests/get_ccd_tickets.rb +11 -18
- data/lib/zendesk2/client/requests/get_current_user.rb +6 -16
- data/lib/zendesk2/client/requests/get_forum.rb +11 -23
- data/lib/zendesk2/client/requests/get_forums.rb +7 -15
- data/lib/zendesk2/client/requests/get_group.rb +9 -23
- data/lib/zendesk2/client/requests/get_groups.rb +7 -15
- data/lib/zendesk2/client/requests/get_help_center_article.rb +13 -37
- data/lib/zendesk2/client/requests/get_help_center_articles.rb +6 -15
- data/lib/zendesk2/client/requests/get_help_center_categories.rb +6 -15
- data/lib/zendesk2/client/requests/get_help_center_category.rb +13 -37
- data/lib/zendesk2/client/requests/get_help_center_section.rb +14 -37
- data/lib/zendesk2/client/requests/get_help_center_sections.rb +6 -15
- data/lib/zendesk2/client/requests/get_membership.rb +9 -24
- data/lib/zendesk2/client/requests/get_organization.rb +9 -22
- data/lib/zendesk2/client/requests/get_organization_by_external_id.rb +11 -20
- data/lib/zendesk2/client/requests/get_organization_memberships.rb +10 -16
- data/lib/zendesk2/client/requests/get_organization_tickets.rb +14 -21
- data/lib/zendesk2/client/requests/get_organization_users.rb +12 -20
- data/lib/zendesk2/client/requests/get_organizations.rb +7 -16
- data/lib/zendesk2/client/requests/get_requested_tickets.rb +12 -18
- data/lib/zendesk2/client/requests/get_ticket.rb +9 -23
- data/lib/zendesk2/client/requests/get_ticket_audits.rb +12 -18
- data/lib/zendesk2/client/requests/get_ticket_comments.rb +10 -19
- data/lib/zendesk2/client/requests/get_ticket_field.rb +9 -22
- data/lib/zendesk2/client/requests/get_ticket_fields.rb +7 -15
- data/lib/zendesk2/client/requests/get_tickets.rb +7 -15
- data/lib/zendesk2/client/requests/get_topic.rb +8 -23
- data/lib/zendesk2/client/requests/get_topic_comment.rb +12 -28
- data/lib/zendesk2/client/requests/get_topic_comments.rb +13 -18
- data/lib/zendesk2/client/requests/get_topics.rb +6 -15
- data/lib/zendesk2/client/requests/get_user.rb +15 -28
- data/lib/zendesk2/client/requests/get_user_field.rb +9 -22
- data/lib/zendesk2/client/requests/get_user_identities.rb +11 -18
- data/lib/zendesk2/client/requests/get_user_identity.rb +11 -21
- data/lib/zendesk2/client/requests/get_user_memberships.rb +12 -18
- data/lib/zendesk2/client/requests/get_users.rb +7 -15
- data/lib/zendesk2/client/requests/mark_membership_default.rb +17 -28
- data/lib/zendesk2/client/requests/mark_user_identity_primary.rb +17 -30
- data/lib/zendesk2/client/requests/search.rb +30 -19
- data/lib/zendesk2/client/requests/search_help_center_articles.rb +22 -18
- data/lib/zendesk2/client/requests/search_organization.rb +40 -28
- data/lib/zendesk2/client/requests/search_user.rb +56 -44
- data/lib/zendesk2/client/requests/update_category.rb +14 -24
- data/lib/zendesk2/client/requests/update_forum.rb +13 -25
- data/lib/zendesk2/client/requests/update_group.rb +12 -24
- data/lib/zendesk2/client/requests/update_help_center_article.rb +17 -42
- data/lib/zendesk2/client/requests/update_help_center_category.rb +17 -42
- data/lib/zendesk2/client/requests/update_help_center_section.rb +17 -42
- data/lib/zendesk2/client/requests/update_organization.rb +23 -35
- data/lib/zendesk2/client/requests/update_ticket.rb +63 -63
- data/lib/zendesk2/client/requests/update_ticket_field.rb +12 -24
- data/lib/zendesk2/client/requests/update_topic.rb +11 -25
- data/lib/zendesk2/client/requests/update_user.rb +47 -62
- data/lib/zendesk2/client/requests/update_user_field.rb +11 -23
- data/lib/zendesk2/client/requests/update_user_identity.rb +20 -28
- data/lib/zendesk2/client.rb +52 -28
- data/lib/zendesk2/paged_collection.rb +9 -9
- data/lib/zendesk2/searchable.rb +1 -1
- data/lib/zendesk2/version.rb +1 -1
- data/lib/zendesk2.rb +1 -13
- data/spec/categories_spec.rb +132 -0
- data/spec/forums_spec.rb +132 -0
- data/spec/lib/paged_collection_spec.rb +2 -2
- data/spec/memberships_spec.rb +5 -9
- data/spec/organizations_spec.rb +176 -25
- data/spec/spec_helper.rb +2 -0
- data/spec/tickets_spec.rb +2 -2
- data/spec/topic_comments_spec.rb +2 -2
- data/spec/user_identities_spec.rb +9 -6
- data/spec/users_spec.rb +22 -21
- data/zendesk2.gemspec +1 -2
- metadata +7 -21
- data/lib/zendesk2/client/requests/update_topic_comment.rb +0 -37
data/lib/zendesk2/version.rb
CHANGED
data/lib/zendesk2.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require "zendesk2/version"
|
2
2
|
|
3
3
|
# dependencies
|
4
|
-
require 'addressable/uri'
|
5
4
|
require 'cistern'
|
6
5
|
require 'faraday'
|
7
6
|
require 'faraday_middleware'
|
8
7
|
require 'jwt'
|
8
|
+
require 'uri'
|
9
9
|
|
10
10
|
# stdlib
|
11
11
|
require 'forwardable'
|
@@ -24,16 +24,6 @@ module Zendesk2
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.paging_parameters(options={})
|
28
|
-
params = if url = options["url"]
|
29
|
-
Addressable::URI.parse(url).query_values
|
30
|
-
else
|
31
|
-
options
|
32
|
-
end
|
33
|
-
|
34
|
-
Cistern::Hash.slice(params, "page", "per_page")
|
35
|
-
end
|
36
|
-
|
37
27
|
def self.stringify_keys(hash)
|
38
28
|
hash.inject({}) { |r,(k,v)| r.merge(k.to_s => v) }
|
39
29
|
end
|
@@ -47,8 +37,6 @@ require 'zendesk2/attributes'
|
|
47
37
|
require 'zendesk2/error'
|
48
38
|
require 'zendesk2/searchable'
|
49
39
|
require 'zendesk2/logger'
|
50
|
-
require 'zendesk2/model'
|
51
|
-
require 'zendesk2/collection'
|
52
40
|
require 'zendesk2/paged_collection'
|
53
41
|
|
54
42
|
require 'zendesk2/client'
|
data/spec/categories_spec.rb
CHANGED
@@ -8,4 +8,136 @@ describe "categories" do
|
|
8
8
|
:create_params => lambda { { name: mock_uuid } },
|
9
9
|
:update_params => lambda { { name: mock_uuid } },
|
10
10
|
}
|
11
|
+
|
12
|
+
context "#create_category" do
|
13
|
+
it "should correctly respond" do
|
14
|
+
body = { "category" => {"name" => (name = mock_uuid)} }
|
15
|
+
|
16
|
+
response = client.create_category(body)
|
17
|
+
|
18
|
+
expect(response.status).to eq(201)
|
19
|
+
expect(response.env[:url].path).to eq("/api/v2/categories.json")
|
20
|
+
expect(response.env[:method]).to eq(:post)
|
21
|
+
expect(client.last_request).to match(body)
|
22
|
+
expect(response.env[:body]["category"]).to match(
|
23
|
+
a_hash_including(
|
24
|
+
"name" => name,
|
25
|
+
))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with a category" do
|
30
|
+
let!(:category) { client.categories.create!(name: mock_uuid) }
|
31
|
+
|
32
|
+
context "#destroy_category" do
|
33
|
+
it "should require a valid category" do
|
34
|
+
expect {
|
35
|
+
client.destroy_category(
|
36
|
+
"category" => {
|
37
|
+
"id" => 999999999,
|
38
|
+
}
|
39
|
+
)
|
40
|
+
}.to raise_error(Zendesk2::Error) { |e|
|
41
|
+
expect(e.response[:status]).to eq(404)
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should correctly respond" do
|
46
|
+
response = client.destroy_category(
|
47
|
+
"category" => {
|
48
|
+
"id" => category.id,
|
49
|
+
}
|
50
|
+
)
|
51
|
+
|
52
|
+
expect(response.status).to eq(200)
|
53
|
+
expect(response.env[:url].path).to eq("/api/v2/categories/#{category.id}.json")
|
54
|
+
expect(response.env[:method]).to eq(:delete)
|
55
|
+
expect(client.last_request).to eq(nil)
|
56
|
+
expect(response.env[:body]).to be_falsey
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "#get_categories" do
|
61
|
+
it "should correctly respond" do
|
62
|
+
response = client.get_categories
|
63
|
+
|
64
|
+
expect(response.status).to eq(200)
|
65
|
+
expect(response.env[:url].path).to eq("/api/v2/categories.json")
|
66
|
+
expect(response.env[:method]).to eq(:get)
|
67
|
+
expect(client.last_request).to eq(nil)
|
68
|
+
skip unless Zendesk2::Client.mocking?
|
69
|
+
expect(response.env[:body]["categories"]).to match([
|
70
|
+
a_hash_including(
|
71
|
+
"id" => category.id,
|
72
|
+
)])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "#get_category" do
|
77
|
+
it "should require a valid category" do
|
78
|
+
expect {
|
79
|
+
client.get_category(
|
80
|
+
"category" => {
|
81
|
+
"id" => 999999999,
|
82
|
+
}
|
83
|
+
)
|
84
|
+
}.to raise_error(Zendesk2::Error) { |e|
|
85
|
+
expect(e.response[:status]).to eq(404)
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should correctly respond" do
|
90
|
+
response = client.get_category(
|
91
|
+
"category" => {
|
92
|
+
"id" => category.id,
|
93
|
+
}
|
94
|
+
)
|
95
|
+
|
96
|
+
expect(response.status).to eq(200)
|
97
|
+
expect(response.env[:url].path).to eq("/api/v2/categories/#{category.id}.json")
|
98
|
+
expect(response.env[:method]).to eq(:get)
|
99
|
+
expect(client.last_request).to eq(nil)
|
100
|
+
expect(response.env[:body]["category"]).to match(
|
101
|
+
a_hash_including(
|
102
|
+
"id" => category.id,
|
103
|
+
"url" => response.env[:url].to_s,
|
104
|
+
))
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "#update_category" do
|
109
|
+
it "should require a valid category" do
|
110
|
+
expect {
|
111
|
+
client.update_category(
|
112
|
+
"category" => {
|
113
|
+
"id" => 999999999,
|
114
|
+
"name" => mock_uuid,
|
115
|
+
}
|
116
|
+
)
|
117
|
+
}.to raise_error(Zendesk2::Error) { |e|
|
118
|
+
expect(e.response[:status]).to eq(404)
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should correctly respond" do
|
123
|
+
response = client.update_category(
|
124
|
+
"category" => {
|
125
|
+
"id" => category.id,
|
126
|
+
"name" => (name = mock_uuid),
|
127
|
+
}
|
128
|
+
)
|
129
|
+
|
130
|
+
expect(response.status).to eq(200)
|
131
|
+
expect(response.env[:url].path).to eq("/api/v2/categories/#{category.id}.json")
|
132
|
+
expect(response.env[:method]).to eq(:put)
|
133
|
+
expect(client.last_request).to eq("category" => {"name" => name})
|
134
|
+
expect(response.env[:body]["category"]).to match(
|
135
|
+
a_hash_including(
|
136
|
+
"id" => category.id,
|
137
|
+
"url" => response.env[:url].to_s,
|
138
|
+
"name" => name,
|
139
|
+
))
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
11
143
|
end
|
data/spec/forums_spec.rb
CHANGED
@@ -9,4 +9,136 @@ describe "forums" do
|
|
9
9
|
:update_params => lambda { { name: mock_uuid } },
|
10
10
|
:delayed_destroy => true,
|
11
11
|
}
|
12
|
+
|
13
|
+
context "#create_forum" do
|
14
|
+
it "should correctly respond" do
|
15
|
+
body = { "forum" => {"name" => (name = mock_uuid)} }
|
16
|
+
|
17
|
+
response = client.create_forum(body)
|
18
|
+
|
19
|
+
expect(response.status).to eq(201)
|
20
|
+
expect(response.env[:url].path).to eq("/api/v2/forums.json")
|
21
|
+
expect(response.env[:method]).to eq(:post)
|
22
|
+
expect(client.last_request).to match(body)
|
23
|
+
expect(response.env[:body]["forum"]).to match(
|
24
|
+
a_hash_including(
|
25
|
+
"name" => name,
|
26
|
+
))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with a forum" do
|
31
|
+
let!(:forum) { client.forums.create!(name: mock_uuid) }
|
32
|
+
|
33
|
+
context "#destroy_forum" do
|
34
|
+
it "should require a valid forum" do
|
35
|
+
expect {
|
36
|
+
client.destroy_forum(
|
37
|
+
"forum" => {
|
38
|
+
"id" => 999999999,
|
39
|
+
}
|
40
|
+
)
|
41
|
+
}.to raise_error(Zendesk2::Error) { |e|
|
42
|
+
expect(e.response[:status]).to eq(404)
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should correctly respond" do
|
47
|
+
response = client.destroy_forum(
|
48
|
+
"forum" => {
|
49
|
+
"id" => forum.id,
|
50
|
+
}
|
51
|
+
)
|
52
|
+
|
53
|
+
expect(response.status).to eq(200)
|
54
|
+
expect(response.env[:url].path).to eq("/api/v2/forums/#{forum.id}.json")
|
55
|
+
expect(response.env[:method]).to eq(:delete)
|
56
|
+
expect(client.last_request).to eq(nil)
|
57
|
+
expect(response.env[:body]).to be_falsey
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "#get_forums" do
|
62
|
+
it "should correctly respond" do
|
63
|
+
response = client.get_forums
|
64
|
+
|
65
|
+
expect(response.status).to eq(200)
|
66
|
+
expect(response.env[:url].path).to eq("/api/v2/forums.json")
|
67
|
+
expect(response.env[:method]).to eq(:get)
|
68
|
+
expect(client.last_request).to eq(nil)
|
69
|
+
skip unless Zendesk2::Client.mocking?
|
70
|
+
expect(response.env[:body]["forums"]).to match([
|
71
|
+
a_hash_including(
|
72
|
+
"id" => forum.id,
|
73
|
+
)])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "#get_forum" do
|
78
|
+
it "should require a valid forum" do
|
79
|
+
expect {
|
80
|
+
client.get_forum(
|
81
|
+
"forum" => {
|
82
|
+
"id" => 999999999,
|
83
|
+
}
|
84
|
+
)
|
85
|
+
}.to raise_error(Zendesk2::Error) { |e|
|
86
|
+
expect(e.response[:status]).to eq(404)
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should correctly respond" do
|
91
|
+
response = client.get_forum(
|
92
|
+
"forum" => {
|
93
|
+
"id" => forum.id,
|
94
|
+
}
|
95
|
+
)
|
96
|
+
|
97
|
+
expect(response.status).to eq(200)
|
98
|
+
expect(response.env[:url].path).to eq("/api/v2/forums/#{forum.id}.json")
|
99
|
+
expect(response.env[:method]).to eq(:get)
|
100
|
+
expect(client.last_request).to eq(nil)
|
101
|
+
expect(response.env[:body]["forum"]).to match(
|
102
|
+
a_hash_including(
|
103
|
+
"id" => forum.id,
|
104
|
+
"url" => response.env[:url].to_s,
|
105
|
+
))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "#update_forum" do
|
110
|
+
it "should require a valid forum" do
|
111
|
+
expect {
|
112
|
+
client.update_forum(
|
113
|
+
"forum" => {
|
114
|
+
"id" => 999999999,
|
115
|
+
"name" => mock_uuid,
|
116
|
+
}
|
117
|
+
)
|
118
|
+
}.to raise_error(Zendesk2::Error) { |e|
|
119
|
+
expect(e.response[:status]).to eq(404)
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should correctly respond" do
|
124
|
+
response = client.update_forum(
|
125
|
+
"forum" => {
|
126
|
+
"id" => forum.id,
|
127
|
+
"name" => (name = mock_uuid),
|
128
|
+
}
|
129
|
+
)
|
130
|
+
|
131
|
+
expect(response.status).to eq(200)
|
132
|
+
expect(response.env[:url].path).to eq("/api/v2/forums/#{forum.id}.json")
|
133
|
+
expect(response.env[:method]).to eq(:put)
|
134
|
+
expect(client.last_request).to eq("forum" => {"name" => name})
|
135
|
+
expect(response.env[:body]["forum"]).to match(
|
136
|
+
a_hash_including(
|
137
|
+
"id" => forum.id,
|
138
|
+
"url" => response.env[:url].to_s,
|
139
|
+
"name" => name,
|
140
|
+
))
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
12
144
|
end
|
@@ -35,8 +35,8 @@ describe Zendesk2::PagedCollection, :mock_only do
|
|
35
35
|
|
36
36
|
found_records = client.organizations.search(name: "2_").each_entry.to_a
|
37
37
|
|
38
|
-
expect(
|
39
|
-
expect(
|
38
|
+
expect(found_records.size).to eq(matching_records.size)
|
39
|
+
expect(found_records).to match_array(matching_records)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/spec/memberships_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe "memberships" do
|
|
6
6
|
let(:organization) { client.organizations.create!(name: mock_uuid) }
|
7
7
|
|
8
8
|
include_examples "zendesk resource", {
|
9
|
-
:create_params => lambda { {organization_id: organization.id, user_id: user.id} },
|
9
|
+
:create_params => lambda { { organization_id: organization.id, user_id: user.id } },
|
10
10
|
:collection => lambda { client.memberships(user: user) },
|
11
11
|
:paged => false,
|
12
12
|
:update => false,
|
@@ -54,25 +54,21 @@ describe "memberships" do
|
|
54
54
|
describe "create_membership" do
|
55
55
|
it "should error when organization does not exist" do
|
56
56
|
expect {
|
57
|
-
client.create_membership("user_id" => user.identity, "organization_id" => 99)
|
57
|
+
client.create_membership("membership" => { "user_id" => user.identity, "organization_id" => 99 })
|
58
58
|
}.to raise_exception(Zendesk2::Error, /RecordInvalid/)
|
59
59
|
end
|
60
60
|
|
61
|
-
it "should error when missing parameters" do
|
62
|
-
expect { client.create_membership({}) }.to raise_exception(ArgumentError, "missing parameters: user_id, organization_id")
|
63
|
-
end
|
64
|
-
|
65
61
|
it "should error when creating a duplicate membership" do
|
66
|
-
client.create_membership("user_id" => user.identity, "organization_id" => organization.identity)
|
62
|
+
client.create_membership("membership" => { "user_id" => user.identity, "organization_id" => organization.identity })
|
67
63
|
|
68
64
|
expect {
|
69
|
-
client.create_membership("user_id" => user.identity, "organization_id" => organization.identity)
|
65
|
+
client.create_membership("membership" => { "user_id" => user.identity, "organization_id" => organization.identity })
|
70
66
|
}.to raise_exception(Zendesk2::Error, /RecordInvalid/)
|
71
67
|
end
|
72
68
|
|
73
69
|
it "should error when user does not exist" do
|
74
70
|
expect {
|
75
|
-
client.create_membership("user_id" => 99, "organization_id" => organization.identity)
|
71
|
+
client.create_membership("membership" => { "user_id" => 99, "organization_id" => organization.identity })
|
76
72
|
}.to raise_exception(Zendesk2::Error, /RecordNotFound/)
|
77
73
|
end
|
78
74
|
end
|
data/spec/organizations_spec.rb
CHANGED
@@ -13,33 +13,49 @@ describe "organizations" do
|
|
13
13
|
let(:organization) { client.organizations.create!(name: mock_uuid) }
|
14
14
|
|
15
15
|
it "should get #users" do
|
16
|
-
user = client.users.create(email: "#{mock_uuid}@example.org", name: mock_uuid, organization: organization)
|
16
|
+
user = client.users.create!(email: "#{mock_uuid}@example.org", name: mock_uuid, organization: organization)
|
17
17
|
expect(organization.users).to include user
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should get #tickets" do
|
21
|
-
user = client.users.create(email: "#{mock_uuid}@example.org", name: mock_uuid, organization: organization)
|
22
|
-
ticket = client.tickets.create(subject: "#{mock_uuid}@example.org", description: mock_uuid, requester: user)
|
21
|
+
user = client.users.create!(email: "#{mock_uuid}@example.org", name: mock_uuid, organization: organization)
|
22
|
+
ticket = client.tickets.create!(subject: "#{mock_uuid}@example.org", description: mock_uuid, requester: user)
|
23
23
|
expect(organization.tickets).to include ticket
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should hate non-unique names" do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
# create
|
28
|
+
expect {
|
29
|
+
client.organizations.create!(name: organization.name)
|
30
|
+
}.to raise_exception(Zendesk2::Error)
|
31
|
+
|
32
|
+
expect(
|
33
|
+
client.organizations.create(name: organization.name).errors
|
34
|
+
).to eq("name" => ["Name: has already been taken"])
|
35
|
+
|
36
|
+
expect(
|
37
|
+
client.organizations.create(name: organization.name.upcase).errors
|
38
|
+
).to eq("name" => ["Name: has already been taken"])
|
39
|
+
|
40
|
+
# update
|
41
|
+
model = client.organizations.create!(name: mock_uuid)
|
42
|
+
|
43
|
+
expect(
|
44
|
+
model.update(name: organization.name).errors
|
45
|
+
).to eq("name" => ["Name: has already been taken"])
|
46
|
+
|
47
|
+
expect(
|
48
|
+
model.update(name: organization.name.upcase).errors
|
49
|
+
).to eq("name" => ["Name: has already been taken"])
|
34
50
|
end
|
35
51
|
|
36
52
|
it "should update name" do
|
37
53
|
old_name = organization.name
|
38
|
-
proxy
|
39
|
-
new_name =
|
54
|
+
proxy = organization.dup
|
55
|
+
new_name = mock_uuid
|
40
56
|
|
41
57
|
expect {
|
42
|
-
proxy.
|
58
|
+
proxy.update!(name: new_name)
|
43
59
|
}.to change { organization.reload.name }.from(old_name).to(new_name)
|
44
60
|
end
|
45
61
|
|
@@ -50,30 +66,165 @@ describe "organizations" do
|
|
50
66
|
expect(client.organizations.find_by_external_id(external_id).first).to eq(organization)
|
51
67
|
end
|
52
68
|
end
|
69
|
+
end
|
53
70
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
71
|
+
describe "#create_organization" do
|
72
|
+
let(:client) { create_client }
|
73
|
+
|
74
|
+
it "should prevent duplicate external_ids" do
|
75
|
+
external_id = mock_uuid
|
76
|
+
|
77
|
+
client.create_organization("organization" => { "name" => mock_uuid, external_id: nil }) # fine
|
78
|
+
client.create_organization("organization" => { "name" => mock_uuid, external_id: nil }) # also fine
|
79
|
+
client.create_organization("organization" => { "name" => mock_uuid, external_id: external_id}) # it's cool
|
59
80
|
|
81
|
+
expect {
|
82
|
+
client.create_organization("organization" => {"name" => mock_uuid, external_id: external_id})
|
83
|
+
}.to raise_exception(Zendesk2::Error, /External has already been taken/)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should correctly respond" do
|
87
|
+
body = { "organization" => {"name" => (name = mock_uuid)} }
|
88
|
+
|
89
|
+
response = client.create_organization(body)
|
90
|
+
|
91
|
+
expect(response.status).to eq(201)
|
92
|
+
expect(response.env[:url].path).to eq("/api/v2/organizations.json")
|
93
|
+
expect(response.env[:method]).to eq(:post)
|
94
|
+
expect(client.last_request).to match(body)
|
95
|
+
expect(response.env[:body]["organization"]).to match(
|
96
|
+
a_hash_including(
|
97
|
+
"name" => name,
|
98
|
+
))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "with a organization" do
|
103
|
+
let(:client) { create_client }
|
104
|
+
let!(:organization) { client.organizations.create!(name: mock_uuid) }
|
105
|
+
|
106
|
+
describe "#destroy_organization" do
|
107
|
+
it "should require a valid organization" do
|
60
108
|
expect {
|
61
|
-
client.
|
62
|
-
|
109
|
+
client.destroy_organization(
|
110
|
+
"organization" => {
|
111
|
+
"id" => 999999999,
|
112
|
+
}
|
113
|
+
)
|
114
|
+
}.to raise_error(Zendesk2::Error) { |e|
|
115
|
+
expect(e.response[:status]).to eq(404)
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should correctly respond" do
|
120
|
+
response = client.destroy_organization(
|
121
|
+
"organization" => {
|
122
|
+
"id" => organization.id,
|
123
|
+
}
|
124
|
+
)
|
125
|
+
|
126
|
+
expect(response.status).to eq(200)
|
127
|
+
expect(response.env[:url].path).to eq("/api/v2/organizations/#{organization.id}.json")
|
128
|
+
expect(response.env[:method]).to eq(:delete)
|
129
|
+
expect(client.last_request).to eq(nil)
|
130
|
+
expect(response.env[:body]).to be_falsey
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "#get_organizations" do
|
135
|
+
it "should correctly respond" do
|
136
|
+
response = client.get_organizations
|
137
|
+
|
138
|
+
expect(response.status).to eq(200)
|
139
|
+
expect(response.env[:url].path).to eq("/api/v2/organizations.json")
|
140
|
+
expect(response.env[:method]).to eq(:get)
|
141
|
+
expect(client.last_request).to eq(nil)
|
142
|
+
skip unless Zendesk2::Client.mocking?
|
143
|
+
expect(response.env[:body]["organizations"]).to match([
|
144
|
+
a_hash_including(
|
145
|
+
"id" => organization.id,
|
146
|
+
)])
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "#get_organization" do
|
151
|
+
it "should require a valid organization" do
|
152
|
+
expect {
|
153
|
+
client.get_organization(
|
154
|
+
"organization" => {
|
155
|
+
"id" => 999999999,
|
156
|
+
}
|
157
|
+
)
|
158
|
+
}.to raise_error(Zendesk2::Error) { |e|
|
159
|
+
expect(e.response[:status]).to eq(404)
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should correctly respond" do
|
164
|
+
response = client.get_organization(
|
165
|
+
"organization" => {
|
166
|
+
"id" => organization.id,
|
167
|
+
}
|
168
|
+
)
|
169
|
+
|
170
|
+
expect(response.status).to eq(200)
|
171
|
+
expect(response.env[:url].path).to eq("/api/v2/organizations/#{organization.id}.json")
|
172
|
+
expect(response.env[:method]).to eq(:get)
|
173
|
+
expect(client.last_request).to eq(nil)
|
174
|
+
expect(response.env[:body]["organization"]).to match(
|
175
|
+
a_hash_including(
|
176
|
+
"id" => organization.id,
|
177
|
+
"url" => response.env[:url].to_s,
|
178
|
+
))
|
63
179
|
end
|
64
180
|
end
|
65
181
|
|
66
182
|
describe "#update_organization" do
|
183
|
+
it "should require a valid organization" do
|
184
|
+
expect {
|
185
|
+
client.update_organization(
|
186
|
+
"organization" => {
|
187
|
+
"id" => 999999999,
|
188
|
+
"name" => mock_uuid,
|
189
|
+
}
|
190
|
+
)
|
191
|
+
}.to raise_error(Zendesk2::Error) { |e|
|
192
|
+
expect(e.response[:status]).to eq(404)
|
193
|
+
}
|
194
|
+
end
|
195
|
+
|
67
196
|
it "should prevent duplicate external_ids" do
|
68
|
-
|
69
|
-
|
197
|
+
external_id = mock_uuid
|
198
|
+
|
199
|
+
organization = client.organizations.create!(name: mock_uuid)
|
200
|
+
another_organization = client.organizations.create!(name: mock_uuid)
|
70
201
|
|
71
|
-
client.update_organization("id" => organization.id, external_id: nil) # fine
|
72
|
-
client.update_organization("id" => another_organization.id, external_id:
|
202
|
+
client.update_organization("organization" => {"id" => organization.id, external_id: nil}) # fine
|
203
|
+
client.update_organization("organization" => {"id" => another_organization.id, external_id: external_id}) # also fine
|
73
204
|
|
74
205
|
expect {
|
75
|
-
client.update_organization("id" => organization.id, external_id:
|
206
|
+
client.update_organization("organization" => {"id" => organization.id, external_id: external_id})
|
76
207
|
}.to raise_exception(Zendesk2::Error, /External has already been taken/)
|
77
208
|
end
|
209
|
+
|
210
|
+
it "should correctly respond" do
|
211
|
+
response = client.update_organization(
|
212
|
+
"organization" => {
|
213
|
+
"id" => organization.id,
|
214
|
+
"name" => (name = mock_uuid),
|
215
|
+
}
|
216
|
+
)
|
217
|
+
|
218
|
+
expect(response.status).to eq(200)
|
219
|
+
expect(response.env[:url].path).to eq("/api/v2/organizations/#{organization.id}.json")
|
220
|
+
expect(response.env[:method]).to eq(:put)
|
221
|
+
expect(client.last_request).to eq("organization" => {"name" => name})
|
222
|
+
expect(response.env[:body]["organization"]).to match(
|
223
|
+
a_hash_including(
|
224
|
+
"id" => organization.id,
|
225
|
+
"url" => response.env[:url].to_s,
|
226
|
+
"name" => name,
|
227
|
+
))
|
228
|
+
end
|
78
229
|
end
|
79
230
|
end
|