zendesk2 1.2.6 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zendesk2/client/requests/create_organization.rb +9 -3
- data/lib/zendesk2/client/requests/create_user.rb +6 -1
- data/lib/zendesk2/client/requests/update_organization.rb +11 -3
- data/lib/zendesk2/client/requests/update_user.rb +14 -3
- data/lib/zendesk2/version.rb +1 -1
- data/lib/zendesk2.rb +0 -4
- data/spec/categories_spec.rb +2 -2
- data/spec/forums_spec.rb +2 -2
- data/spec/groups_spec.rb +3 -3
- data/spec/help_center/articles_spec.rb +4 -4
- data/spec/help_center/categories_spec.rb +2 -2
- data/spec/help_center/sections_spec.rb +3 -3
- data/spec/memberships_spec.rb +7 -7
- data/spec/organizations_spec.rb +33 -8
- data/spec/support/data_helper.rb +13 -0
- data/spec/ticket_fields_spec.rb +2 -2
- data/spec/tickets_spec.rb +16 -16
- data/spec/topic_comments_spec.rb +5 -5
- data/spec/topics_spec.rb +3 -3
- data/spec/user_fields_spec.rb +2 -2
- data/spec/user_identities_spec.rb +3 -3
- data/spec/users_spec.rb +46 -20
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbedbdbd2cc1fb5d7181d274138df03c74caf78a
|
4
|
+
data.tar.gz: d1b795649c0ecc16cf9142bc7c527b9f9048c81c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93400647817f08b86d3322a4dc24282bd5b0ce04218cb8d3e782da177d84312f552ca85eeccb020ea5b71fa419dbc96bfb8ed4ed6ed32bef42d41f52ed912e20
|
7
|
+
data.tar.gz: 7864462a046770514e143cf51d0ba2af739c21c968e327523087445ab3af25a70e5d198fbb7bbf5ea7372bb35bcf21745887d812610be29ba61b00b83e0fbc79
|
@@ -10,7 +10,8 @@ class Zendesk2::Client
|
|
10
10
|
end # Real
|
11
11
|
|
12
12
|
class Mock
|
13
|
-
def create_organization(
|
13
|
+
def create_organization(_params={})
|
14
|
+
params = Cistern::Hash.stringify_keys(_params)
|
14
15
|
identity = self.class.new_id
|
15
16
|
|
16
17
|
record = {
|
@@ -20,15 +21,20 @@ class Zendesk2::Client
|
|
20
21
|
"updated_at" => Time.now.iso8601,
|
21
22
|
}.merge(params)
|
22
23
|
|
24
|
+
|
23
25
|
unless record["name"]
|
24
26
|
error!(:invalid, details: { "name" => [ { "description" => "Name cannot be blank" } ]})
|
25
27
|
end
|
26
28
|
|
27
|
-
if self.data[:organizations].values.find{|o| o["name"] == record["name"]}
|
29
|
+
if self.data[:organizations].values.find { |o| o["name"] == record["name"]}
|
28
30
|
error!(:invalid, details: {"name" => [ { "description" => "Name: has already been taken" } ]})
|
29
31
|
end
|
30
32
|
|
31
|
-
self.data[:organizations][
|
33
|
+
if record["external_id"] && self.data[:organizations].values.find { |o| o["external_id"] == record["external_id"] }
|
34
|
+
error!(:invalid, details: {"name" => [ { "description" => "External has already been taken" } ]})
|
35
|
+
end
|
36
|
+
|
37
|
+
self.data[:organizations][identity] = record
|
32
38
|
|
33
39
|
response(
|
34
40
|
:method => :post,
|
@@ -10,7 +10,8 @@ class Zendesk2::Client
|
|
10
10
|
end # Real
|
11
11
|
|
12
12
|
class Mock
|
13
|
-
def create_user(
|
13
|
+
def create_user(_params={})
|
14
|
+
params = Cistern::Hash.stringify_keys(_params)
|
14
15
|
user_id = self.class.new_id
|
15
16
|
path = "/users.json"
|
16
17
|
|
@@ -22,6 +23,10 @@ class Zendesk2::Client
|
|
22
23
|
"active" => true,
|
23
24
|
}.merge(params)
|
24
25
|
|
26
|
+
if record["external_id"] && self.data[:users].values.find { |o| o["external_id"] == record["external_id"] }
|
27
|
+
error!(:invalid, details: {"name" => [ { "description" => "External has already been taken" } ]})
|
28
|
+
end
|
29
|
+
|
25
30
|
if (email = record["email"]) && self.data[:identities].find{|k,i| i["type"] == "email" && i["value"] == email}
|
26
31
|
error!(:invalid, :details => {
|
27
32
|
"email" => [ {
|
@@ -13,15 +13,23 @@ class Zendesk2::Client
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
class Mock
|
16
|
-
def update_organization(
|
17
|
-
|
16
|
+
def update_organization(_params={})
|
17
|
+
params = Cistern::Hash.stringify_keys(_params)
|
18
|
+
id = params.delete("id")
|
18
19
|
|
19
20
|
organization = self.find!(:organizations, id)
|
20
21
|
|
21
|
-
|
22
|
+
other_organizations = self.data[:organizations].dup
|
23
|
+
other_organizations.delete(id)
|
24
|
+
|
25
|
+
if other_organizations.values.find { |o| o["name"] == params["name"] }
|
22
26
|
error!(:invalid, details: {"name" => [ { "description" => "Name: has already been taken" } ]})
|
23
27
|
end
|
24
28
|
|
29
|
+
if params["external_id"] && other_organizations.values.find { |o| o["external_id"] == params["external_id"] }
|
30
|
+
error!(:invalid, details: {"name" => [ { "description" => "External has already been taken" } ]})
|
31
|
+
end
|
32
|
+
|
25
33
|
body = organization.merge!(params)
|
26
34
|
|
27
35
|
response(
|
@@ -13,15 +13,25 @@ class Zendesk2::Client
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
class Mock
|
16
|
-
def update_user(
|
16
|
+
def update_user(_params={})
|
17
|
+
params = Cistern::Hash.stringify_keys(_params)
|
17
18
|
user_id = params.delete("id")
|
18
19
|
path = "/users/#{user_id}.json"
|
19
20
|
|
20
21
|
email = params["email"]
|
21
22
|
|
23
|
+
other_users = self.data[:users].dup
|
24
|
+
other_users.delete(user_id)
|
25
|
+
|
26
|
+
if params["external_id"] && other_users.values.find { |o| o["external_id"] == params["external_id"] }
|
27
|
+
error!(:invalid, details: {"name" => [ { "description" => "External has already been taken" } ]})
|
28
|
+
end
|
29
|
+
|
22
30
|
existing_identity = self.data[:identities].values.find { |i| i["type"] == "email" && i["value"] == email }
|
23
31
|
|
24
|
-
if
|
32
|
+
if !email
|
33
|
+
# nvm
|
34
|
+
elsif existing_identity && existing_identity["user_id"] != user_id
|
25
35
|
# email not allowed to conflict across users
|
26
36
|
error!(:invalid, details: { "email" => [ {
|
27
37
|
"description" => "Email #{params["email"]} is already being used by another user",
|
@@ -30,7 +40,7 @@ class Zendesk2::Client
|
|
30
40
|
# no-op email already used
|
31
41
|
else
|
32
42
|
# add a new identity
|
33
|
-
user_identity_id = self.class.new_id
|
43
|
+
user_identity_id = self.class.new_id
|
34
44
|
|
35
45
|
user_identity = {
|
36
46
|
"id" => user_identity_id,
|
@@ -48,6 +58,7 @@ class Zendesk2::Client
|
|
48
58
|
end
|
49
59
|
|
50
60
|
body = self.data[:users][user_id].merge!(params)
|
61
|
+
|
51
62
|
response(
|
52
63
|
:method => :put,
|
53
64
|
:path => path,
|
data/lib/zendesk2/version.rb
CHANGED
data/lib/zendesk2.rb
CHANGED
data/spec/categories_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe "categories" do
|
|
5
5
|
|
6
6
|
include_examples "zendesk resource", {
|
7
7
|
:collection => lambda { client.categories },
|
8
|
-
:create_params => lambda { { name:
|
9
|
-
:update_params => lambda { { name:
|
8
|
+
:create_params => lambda { { name: mock_uuid } },
|
9
|
+
:update_params => lambda { { name: mock_uuid } },
|
10
10
|
}
|
11
11
|
end
|
data/spec/forums_spec.rb
CHANGED
@@ -5,8 +5,8 @@ describe "forums" do
|
|
5
5
|
|
6
6
|
include_examples "zendesk resource", {
|
7
7
|
:collection => lambda { client.forums },
|
8
|
-
:create_params => lambda { { name:
|
9
|
-
:update_params => lambda { { name:
|
8
|
+
:create_params => lambda { { name: mock_uuid } },
|
9
|
+
:update_params => lambda { { name: mock_uuid } },
|
10
10
|
:delayed_destroy => true,
|
11
11
|
}
|
12
12
|
end
|
data/spec/groups_spec.rb
CHANGED
@@ -5,12 +5,12 @@ describe "groups" do
|
|
5
5
|
|
6
6
|
include_examples "zendesk resource", {
|
7
7
|
:collection => lambda { client.groups },
|
8
|
-
:create_params => lambda { { name:
|
9
|
-
:update_params => lambda { { name:
|
8
|
+
:create_params => lambda { { name: mock_uuid } },
|
9
|
+
:update_params => lambda { { name: mock_uuid } },
|
10
10
|
}
|
11
11
|
|
12
12
|
it "should list assignable groups" do
|
13
|
-
client.groups.create(name:
|
13
|
+
client.groups.create(name: mock_uuid) # assignable by default
|
14
14
|
|
15
15
|
expect(client.groups.assignable).to be_all{|g| !g.deleted}
|
16
16
|
end
|
@@ -3,10 +3,10 @@ require 'spec_helper'
|
|
3
3
|
describe "help_center/articles" do
|
4
4
|
let(:client) { create_client }
|
5
5
|
let!(:section) do
|
6
|
-
category = client.help_center_categories.create!(name:
|
6
|
+
category = client.help_center_categories.create!(name: mock_uuid,
|
7
7
|
locale: "en-us",
|
8
8
|
)
|
9
|
-
client.help_center_sections.create!(:name =>
|
9
|
+
client.help_center_sections.create!(:name => mock_uuid,
|
10
10
|
:locale => "en-us",
|
11
11
|
:category => category,
|
12
12
|
)
|
@@ -14,8 +14,8 @@ describe "help_center/articles" do
|
|
14
14
|
|
15
15
|
include_examples "zendesk resource", {
|
16
16
|
:collection => lambda { client.help_center_articles },
|
17
|
-
:create_params => lambda { { title:
|
18
|
-
:update_params => lambda { { title:
|
17
|
+
:create_params => lambda { { title: mock_uuid, locale: "en-us", section: section } },
|
18
|
+
:update_params => lambda { { title: mock_uuid } },
|
19
19
|
:search_params => lambda { Cistern::Hash.slice(create_params, :title) },
|
20
20
|
:search => true,
|
21
21
|
}
|
@@ -5,8 +5,8 @@ describe "help_center/categories" do
|
|
5
5
|
|
6
6
|
include_examples "zendesk resource", {
|
7
7
|
:collection => lambda { client.help_center_categories },
|
8
|
-
:create_params => lambda { { name:
|
9
|
-
:update_params => lambda { { name:
|
8
|
+
:create_params => lambda { { name: mock_uuid, locale: "en-us" } },
|
9
|
+
:update_params => lambda { { name: mock_uuid } },
|
10
10
|
:search => false,
|
11
11
|
}
|
12
12
|
end
|
@@ -3,15 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe "help_center/sections" do
|
4
4
|
let(:client) { create_client }
|
5
5
|
let!(:category) do
|
6
|
-
client.help_center_categories.create!(name:
|
6
|
+
client.help_center_categories.create!(name: mock_uuid,
|
7
7
|
locale: "en-us",
|
8
8
|
)
|
9
9
|
end
|
10
10
|
|
11
11
|
include_examples "zendesk resource", {
|
12
12
|
:collection => lambda { client.help_center_sections },
|
13
|
-
:create_params => lambda { { name:
|
14
|
-
:update_params => lambda { { name:
|
13
|
+
:create_params => lambda { { name: mock_uuid, locale: "en-us", category: category } },
|
14
|
+
:update_params => lambda { { name: mock_uuid } },
|
15
15
|
:search => false,
|
16
16
|
}
|
17
17
|
end
|
data/spec/memberships_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "memberships" do
|
4
4
|
let(:client) { create_client }
|
5
|
-
let(:user) { client.users.create!(email:
|
6
|
-
let(:organization) { client.organizations.create!(name:
|
5
|
+
let(:user) { client.users.create!(email: mock_email, name: mock_uuid, verified: true) }
|
6
|
+
let(:organization) { client.organizations.create!(name: mock_uuid) }
|
7
7
|
|
8
8
|
include_examples "zendesk resource", {
|
9
9
|
:create_params => lambda { {organization_id: organization.id, user_id: user.id} },
|
@@ -15,7 +15,7 @@ describe "memberships" do
|
|
15
15
|
|
16
16
|
it "should be marked as default" do
|
17
17
|
membership = client.memberships.create!(organization: organization, user: user)
|
18
|
-
another_organization = client.organizations.create!(name:
|
18
|
+
another_organization = client.organizations.create!(name: mock_uuid)
|
19
19
|
|
20
20
|
another_membership = client.memberships.create!(organization: another_organization, user: user)
|
21
21
|
|
@@ -28,8 +28,8 @@ describe "memberships" do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should get an organization's memberships" do
|
31
|
-
another_user = client.users.create!(email:
|
32
|
-
another_organization = client.organizations.create!(name:
|
31
|
+
another_user = client.users.create!(email: mock_email, name: mock_uuid, verified: true)
|
32
|
+
another_organization = client.organizations.create!(name: mock_uuid)
|
33
33
|
|
34
34
|
another_organization.memberships.create!(user: another_user)
|
35
35
|
another_organization.memberships.create!(user: user)
|
@@ -40,8 +40,8 @@ describe "memberships" do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should get an user's memberships" do
|
43
|
-
another_user = client.users.create!(email:
|
44
|
-
another_organization = client.organizations.create!(name:
|
43
|
+
another_user = client.users.create!(email: mock_email, name: mock_uuid, verified: true)
|
44
|
+
another_organization = client.organizations.create!(name: mock_uuid)
|
45
45
|
|
46
46
|
another_organization.memberships.create!(user: another_user)
|
47
47
|
user_membership = another_organization.memberships.create!(user: user)
|
data/spec/organizations_spec.rb
CHANGED
@@ -5,21 +5,21 @@ describe "organizations" do
|
|
5
5
|
|
6
6
|
include_examples "zendesk resource", {
|
7
7
|
:collection => lambda { client.organizations },
|
8
|
-
:create_params => lambda { { name:
|
9
|
-
:update_params => lambda { { name:
|
8
|
+
:create_params => lambda { { name: mock_uuid } },
|
9
|
+
:update_params => lambda { { name: mock_uuid } },
|
10
10
|
}
|
11
11
|
|
12
12
|
describe "with an organization" do
|
13
|
-
let(:organization) { client.organizations.create!(name:
|
13
|
+
let(:organization) { client.organizations.create!(name: mock_uuid) }
|
14
14
|
|
15
15
|
it "should get #users" do
|
16
|
-
user = client.users.create(email: "#{
|
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: "#{
|
22
|
-
ticket = client.tickets.create(subject: "#{
|
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
|
|
@@ -27,18 +27,43 @@ describe "organizations" do
|
|
27
27
|
expect { client.organizations.create!(name: organization.name) }.to raise_exception(Zendesk2::Error)
|
28
28
|
model = client.organizations.create(name: organization.name)
|
29
29
|
expect(model.errors).to eq({"name" => ["Name: has already been taken"]})
|
30
|
-
model = client.organizations.create(name:
|
30
|
+
model = client.organizations.create(name: mock_uuid)
|
31
31
|
model.name = organization.name
|
32
32
|
model.save
|
33
33
|
expect(model.errors).to eq({"name" => ["Name: has already been taken"]})
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should be able to find organizations by external id" do
|
37
|
-
external_id = organization.external_id =
|
37
|
+
external_id = organization.external_id = mock_uuid
|
38
38
|
organization.save!
|
39
39
|
|
40
40
|
expect(client.organizations.find_by_external_id(external_id).first).to eq(organization)
|
41
41
|
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#create_organization" do
|
45
|
+
it "should prevent duplicate external_ids" do
|
46
|
+
client.create_organization("name" => "a", external_id: nil) # fine
|
47
|
+
client.create_organization("name" => "b", external_id: nil) # also fine
|
48
|
+
client.create_organization("name" => "c", external_id: "1") # it's cool
|
49
|
+
|
50
|
+
expect {
|
51
|
+
client.create_organization("name" => "d", external_id: "1")
|
52
|
+
}.to raise_exception(Zendesk2::Error, /External has already been taken/)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#update_organization" do
|
57
|
+
it "should prevent duplicate external_ids" do
|
58
|
+
organization = client.organizations.create(name: "a")
|
59
|
+
another_organization = client.organizations.create(name: "b")
|
42
60
|
|
61
|
+
client.update_organization("id" => organization.id, external_id: nil) # fine
|
62
|
+
client.update_organization("id" => another_organization.id, external_id: "1") # also fine
|
63
|
+
|
64
|
+
expect {
|
65
|
+
client.update_organization("id" => organization.id, external_id: "1")
|
66
|
+
}.to raise_exception(Zendesk2::Error, /External has already been taken/)
|
67
|
+
end
|
43
68
|
end
|
44
69
|
end
|
data/spec/ticket_fields_spec.rb
CHANGED
@@ -5,8 +5,8 @@ describe "ticket_fields" do
|
|
5
5
|
|
6
6
|
include_examples "zendesk resource", {
|
7
7
|
:collection => lambda { client.ticket_fields },
|
8
|
-
:create_params => lambda { { title:
|
9
|
-
:update_params => lambda { { title:
|
8
|
+
:create_params => lambda { { title: mock_uuid, type: "text" } },
|
9
|
+
:update_params => lambda { { title: mock_uuid } },
|
10
10
|
:paged => false,
|
11
11
|
}
|
12
12
|
end
|
data/spec/tickets_spec.rb
CHANGED
@@ -6,24 +6,24 @@ describe "Zendesk2::Client" do
|
|
6
6
|
describe "tickets" do
|
7
7
|
include_examples "zendesk resource", {
|
8
8
|
:collection => lambda { client.tickets },
|
9
|
-
:create_params => lambda { {subject:
|
10
|
-
:update_params => lambda { {subject:
|
9
|
+
:create_params => lambda { {subject: mock_uuid, description: mock_uuid} },
|
10
|
+
:update_params => lambda { {subject: mock_uuid} },
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "#create_ticket" do
|
15
15
|
it "should require a description" do
|
16
16
|
expect {
|
17
|
-
client.create_ticket("subject" =>
|
17
|
+
client.create_ticket("subject" => mock_uuid)
|
18
18
|
}.to raise_exception(Zendesk2::Error, /Description: cannot be blank/)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "when creating a ticket" do
|
23
|
-
let!(:requester_email) { "#{
|
23
|
+
let!(:requester_email) { "#{mock_uuid}@example.org" }
|
24
24
|
|
25
25
|
it "should create requester" do
|
26
|
-
ticket = client.tickets.create!(subject:
|
26
|
+
ticket = client.tickets.create!(subject: mock_uuid, description: mock_uuid, requester: {name: "Josh Lane", email: requester_email})
|
27
27
|
if Zendesk2::Client.mocking? # this takes some time for realsies
|
28
28
|
requester = client.users.search(email: requester_email).first
|
29
29
|
expect(requester).not_to be_nil
|
@@ -36,24 +36,24 @@ describe "Zendesk2::Client" do
|
|
36
36
|
|
37
37
|
it "should require requester name" do
|
38
38
|
expect {
|
39
|
-
client.tickets.create!(subject:
|
39
|
+
client.tickets.create!(subject: mock_uuid, description: mock_uuid, requester: {email: requester_email})
|
40
40
|
}.to raise_exception(Zendesk2::Error, /Requester Name: .* too short/)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should require a description" do
|
44
44
|
expect {
|
45
|
-
client.tickets.create!(subject:
|
45
|
+
client.tickets.create!(subject: mock_uuid)
|
46
46
|
}.to raise_exception(ArgumentError, /description is required/)
|
47
47
|
|
48
48
|
expect {
|
49
|
-
client.tickets.create!(subject:
|
49
|
+
client.tickets.create!(subject: mock_uuid, description: "")
|
50
50
|
}.to raise_exception(ArgumentError, /description is required/)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should set priority" do
|
54
54
|
priority = "urgent"
|
55
55
|
|
56
|
-
ticket = client.tickets.create!(subject:
|
56
|
+
ticket = client.tickets.create!(subject: mock_uuid, description: mock_uuid, priority: priority)
|
57
57
|
|
58
58
|
expect(ticket.priority).to eq("urgent")
|
59
59
|
expect(client.tickets.get!(ticket.id).priority).to eq(priority)
|
@@ -61,7 +61,7 @@ describe "Zendesk2::Client" do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe "with a created ticket" do
|
64
|
-
let(:ticket) { client.tickets.create!(subject:
|
64
|
+
let(:ticket) { client.tickets.create!(subject: mock_uuid, description: mock_uuid) }
|
65
65
|
|
66
66
|
it "should get requester" do
|
67
67
|
expect(ticket.requester).to eq(client.users.current)
|
@@ -77,10 +77,10 @@ describe "Zendesk2::Client" do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
describe "ticket comments" do
|
80
|
-
let(:ticket) { client.tickets.create!(subject:
|
80
|
+
let(:ticket) { client.tickets.create!(subject: mock_uuid, description: mock_uuid) }
|
81
81
|
|
82
82
|
it "lists audits" do
|
83
|
-
body =
|
83
|
+
body = mock_uuid
|
84
84
|
ticket.comment(body)
|
85
85
|
|
86
86
|
audit = ticket.audits.last
|
@@ -99,7 +99,7 @@ describe "Zendesk2::Client" do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
it "lists comments" do
|
102
|
-
body =
|
102
|
+
body = mock_uuid
|
103
103
|
ticket.comment(body)
|
104
104
|
|
105
105
|
expect(ticket.comments.find{|c| c.body == body}).not_to be_nil
|
@@ -110,19 +110,19 @@ describe "Zendesk2::Client" do
|
|
110
110
|
let!(:ticket_field) { client.ticket_fields.create!(title: SecureRandom.hex(3), type: "text") }
|
111
111
|
|
112
112
|
it "should be based on ticket_fields" do
|
113
|
-
ticket = client.tickets.create!(subject:
|
113
|
+
ticket = client.tickets.create!(subject: mock_uuid, description: mock_uuid)
|
114
114
|
custom_field = ticket.custom_fields.find { |cf| cf["id"] == ticket_field.identity }
|
115
115
|
|
116
116
|
expect(custom_field).not_to be_nil
|
117
117
|
expect(custom_field["value"]).to be_nil
|
118
118
|
|
119
|
-
ticket = client.tickets.create!(subject:
|
119
|
+
ticket = client.tickets.create!(subject: mock_uuid, description: mock_uuid, custom_fields: [{"id" => ticket_field.identity, "value" => "jessicaspacekat"}])
|
120
120
|
custom_field = ticket.custom_fields.find { |cf| cf["id"] == ticket_field.identity }
|
121
121
|
|
122
122
|
expect(custom_field).not_to be_nil
|
123
123
|
expect(custom_field["value"]).to eq("jessicaspacekat")
|
124
124
|
|
125
|
-
ticket = client.tickets.create!(subject:
|
125
|
+
ticket = client.tickets.create!(subject: mock_uuid, description: mock_uuid, custom_fields: [{"id" => "-1", "value" => "fantasy"}])
|
126
126
|
expect(ticket.custom_fields).not_to include({"id" => -1, "value" => "fantasy"})
|
127
127
|
end
|
128
128
|
end
|
data/spec/topic_comments_spec.rb
CHANGED
@@ -2,14 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "topic_comments" do
|
4
4
|
let!(:client) { create_client }
|
5
|
-
let!(:user) { client.users.create!(email:
|
6
|
-
let!(:forum) { client.forums.create!(name:
|
7
|
-
let!(:topic) { client.topics.create!(title:
|
5
|
+
let!(:user) { client.users.create!(email: mock_email, name: mock_uuid, verified: true) }
|
6
|
+
let!(:forum) { client.forums.create!(name: mock_uuid) }
|
7
|
+
let!(:topic) { client.topics.create!(title: mock_uuid, body: mock_uuid, forum: forum) }
|
8
8
|
|
9
9
|
include_examples "zendesk resource",
|
10
10
|
{
|
11
|
-
:create_params => lambda { {body:
|
12
|
-
:update_params => lambda { {body:
|
11
|
+
:create_params => lambda { {body: mock_uuid, topic_id: topic.identity, user_id: user.identity} },
|
12
|
+
:update_params => lambda { {body: mock_uuid} },
|
13
13
|
:fetch_params => lambda { |tc| {"topic_id" => tc.topic_id, "id" => tc.identity} },
|
14
14
|
:collection => lambda { client.topic_comments(topic_id: topic.identity) },
|
15
15
|
}
|
data/spec/topics_spec.rb
CHANGED
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "topics" do
|
4
4
|
let(:client) { create_client }
|
5
|
-
let(:forum) { client.forums.create(name:
|
5
|
+
let(:forum) { client.forums.create(name: mock_uuid) }
|
6
6
|
|
7
7
|
include_examples "zendesk resource", {
|
8
8
|
:collection => lambda { client.topics },
|
9
|
-
:create_params => lambda { { title:
|
10
|
-
:update_params => lambda { { title:
|
9
|
+
:create_params => lambda { { title: mock_uuid, body: mock_uuid, forum_id: forum.id } },
|
10
|
+
:update_params => lambda { { title: mock_uuid, body: mock_uuid } },
|
11
11
|
}
|
12
12
|
end
|
data/spec/user_fields_spec.rb
CHANGED
@@ -5,8 +5,8 @@ describe "user_fields" do
|
|
5
5
|
|
6
6
|
include_examples "zendesk resource", {
|
7
7
|
:collection => lambda { client.user_fields },
|
8
|
-
:create_params => lambda { { title:
|
9
|
-
:update_params => lambda { { title:
|
8
|
+
:create_params => lambda { { title: mock_uuid, type: "text", key: "custom_#{SecureRandom.hex(3)}"} },
|
9
|
+
:update_params => lambda { { title: mock_uuid } },
|
10
10
|
:paged => false,
|
11
11
|
}
|
12
12
|
end
|
@@ -2,10 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "user_identities" do
|
4
4
|
let(:client) { create_client }
|
5
|
-
let(:user) { client.users.create(email:
|
5
|
+
let(:user) { client.users.create(email: mock_email, name: mock_uuid, verified: true) }
|
6
6
|
|
7
7
|
include_examples "zendesk resource", {
|
8
|
-
:create_params => lambda { { value: "ey+#{
|
8
|
+
:create_params => lambda { { value: "ey+#{mock_uuid}@example.org", type: "email", user_id: user.id } },
|
9
9
|
:update_params => lambda { { verified: true } },
|
10
10
|
:fetch_params => lambda { |uc| { "user_id" => uc.user_id, "id" => uc.id } },
|
11
11
|
:collection => lambda { client.user_identities(user_id: user.id) },
|
@@ -14,7 +14,7 @@ describe "user_identities" do
|
|
14
14
|
}
|
15
15
|
|
16
16
|
describe "#create_user_identity" do
|
17
|
-
let(:another_user) { client.users.create(email:
|
17
|
+
let(:another_user) { client.users.create(email: mock_email, name: mock_uuid, verified: true) }
|
18
18
|
|
19
19
|
it "should prevent duplicate identities across users" do
|
20
20
|
expect {
|
data/spec/users_spec.rb
CHANGED
@@ -5,8 +5,8 @@ describe "users" do
|
|
5
5
|
|
6
6
|
include_examples "zendesk resource", {
|
7
7
|
:collection => lambda { client.users },
|
8
|
-
:create_params => lambda { { email:
|
9
|
-
:update_params => lambda { { name:
|
8
|
+
:create_params => lambda { { email: mock_email, name: mock_uuid, verified: true } },
|
9
|
+
:update_params => lambda { { name: mock_uuid } },
|
10
10
|
}
|
11
11
|
|
12
12
|
it "should get current user" do
|
@@ -14,17 +14,43 @@ describe "users" do
|
|
14
14
|
expect(current_user.email).to eq(client.username)
|
15
15
|
end
|
16
16
|
|
17
|
+
describe "#create_user" do
|
18
|
+
it "should prevent duplicate external_ids" do
|
19
|
+
client.create_user(email: mock_email, name: "a", external_id: nil) # fine
|
20
|
+
client.create_user(email: mock_email, name: "b", external_id: nil) # also fine
|
21
|
+
client.create_user(email: mock_email, name: "c", external_id: "1") # it's cool
|
22
|
+
|
23
|
+
expect {
|
24
|
+
client.create_user(email: mock_email, name: "d", external_id: "1")
|
25
|
+
}.to raise_exception(Zendesk2::Error, /External has already been taken/)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#update_user" do
|
30
|
+
it "should prevent duplicate external_ids" do
|
31
|
+
user = client.users.create(email: mock_email, name: "a")
|
32
|
+
another_user = client.users.create(email: mock_email, name: "b")
|
33
|
+
|
34
|
+
client.update_user(id: user.id, external_id: nil) # fine
|
35
|
+
client.update_user(id: another_user.id, external_id: "1") # also fine
|
36
|
+
|
37
|
+
expect {
|
38
|
+
client.update_user("id" => user.id, external_id: "1")
|
39
|
+
}.to raise_exception(Zendesk2::Error, /External has already been taken/)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
17
43
|
describe "#search" do
|
18
44
|
it "should find a user based on details criteria with wildcards and by organization name", mock_only: true do
|
19
45
|
# detached user
|
20
|
-
client.users.create!(email:
|
46
|
+
client.users.create!(email: mock_email, name: mock_uuid)
|
21
47
|
|
22
48
|
# possible match
|
23
|
-
bad_org = client.organizations.create!(name:
|
24
|
-
client.users.create!(email:
|
49
|
+
bad_org = client.organizations.create!(name: mock_uuid)
|
50
|
+
client.users.create!(email: mock_email, name: mock_uuid, organization: bad_org)
|
25
51
|
|
26
|
-
org = client.organizations.create!(name:
|
27
|
-
user = client.users.create!(email:
|
52
|
+
org = client.organizations.create!(name: mock_uuid)
|
53
|
+
user = client.users.create!(email: mock_email, name: mock_uuid, organization: org, details: "anything_hello-something-michelle")
|
28
54
|
|
29
55
|
expect(client.users.search(details: "*michelle*", organization: org.name)).to contain_exactly(user)
|
30
56
|
expect(client.users.search(details: "*michelle*", organization: org.name[0..6])).to include(user)
|
@@ -32,10 +58,10 @@ describe "users" do
|
|
32
58
|
end
|
33
59
|
|
34
60
|
describe "#save" do
|
35
|
-
let!(:user) { client.users.create!(email:
|
61
|
+
let!(:user) { client.users.create!(email: mock_email, name: mock_uuid) }
|
36
62
|
|
37
63
|
it "should update organization" do
|
38
|
-
user.organization = organization = client.organizations.create!(name:
|
64
|
+
user.organization = organization = client.organizations.create!(name: mock_uuid)
|
39
65
|
|
40
66
|
user.save!
|
41
67
|
|
@@ -43,19 +69,19 @@ describe "users" do
|
|
43
69
|
end
|
44
70
|
|
45
71
|
it "should get requested tickets" do
|
46
|
-
ticket = client.tickets.create!(requester: user, subject:
|
72
|
+
ticket = client.tickets.create!(requester: user, subject: mock_uuid, description: mock_uuid)
|
47
73
|
|
48
74
|
expect(user.requested_tickets).to include ticket
|
49
75
|
end
|
50
76
|
|
51
77
|
it "should get ccd tickets", mock_only: true do
|
52
|
-
ticket = client.tickets.create!(collaborators: [user], subject:
|
78
|
+
ticket = client.tickets.create!(collaborators: [user], subject: mock_uuid, description: mock_uuid)
|
53
79
|
|
54
80
|
expect(user.ccd_tickets).to include ticket
|
55
81
|
end
|
56
82
|
|
57
83
|
it "cannot destroy a user with a ticket" do
|
58
|
-
client.tickets.create!(requester: user, subject:
|
84
|
+
client.tickets.create!(requester: user, subject: mock_uuid, description: mock_uuid)
|
59
85
|
|
60
86
|
expect(user.destroy).to be_falsey
|
61
87
|
|
@@ -74,7 +100,7 @@ describe "users" do
|
|
74
100
|
end
|
75
101
|
|
76
102
|
it "should create a new identity" do
|
77
|
-
email = "ey+#{
|
103
|
+
email = "ey+#{mock_uuid}@example.org"
|
78
104
|
|
79
105
|
new_identity = user.identities.create!(type: "email", value: email)
|
80
106
|
expect(new_identity.primary).to be_falsey
|
@@ -84,7 +110,7 @@ describe "users" do
|
|
84
110
|
end
|
85
111
|
|
86
112
|
it "should mark remaining identity as primary" do
|
87
|
-
email = "ey+#{
|
113
|
+
email = "ey+#{mock_uuid}@example.org"
|
88
114
|
|
89
115
|
initial_identity = user.identities.all.first
|
90
116
|
new_identity = user.identities.create!(type: "email", value: email)
|
@@ -98,7 +124,7 @@ describe "users" do
|
|
98
124
|
end
|
99
125
|
|
100
126
|
it "should not allow multiple primary identities" do
|
101
|
-
email = "ey+#{
|
127
|
+
email = "ey+#{mock_uuid}@example.org"
|
102
128
|
|
103
129
|
initial_identity = user.identities.all.first
|
104
130
|
new_identity = user.identities.create!(type: "email", value: email)
|
@@ -110,11 +136,11 @@ describe "users" do
|
|
110
136
|
end
|
111
137
|
|
112
138
|
it "should hate non-unique emails" do
|
113
|
-
email =
|
114
|
-
client.users.create!(email: email, name:
|
115
|
-
expect { client.users.create!(email: email, name:
|
139
|
+
email = mock_email
|
140
|
+
client.users.create!(email: email, name: mock_uuid)
|
141
|
+
expect { client.users.create!(email: email, name: mock_uuid) }.to raise_exception(Zendesk2::Error)
|
116
142
|
|
117
|
-
user = client.users.create(email: email, name:
|
143
|
+
user = client.users.create(email: email, name: mock_uuid)
|
118
144
|
|
119
145
|
expect(user.identity).to eq(nil)
|
120
146
|
expect(user.errors).to eq({"email" => ["Email: #{email} is already being used by another user"]})
|
@@ -124,7 +150,7 @@ describe "users" do
|
|
124
150
|
expect(user.identities.size).to eq(1)
|
125
151
|
|
126
152
|
original_email = user.email
|
127
|
-
user.email = (new_email =
|
153
|
+
user.email = (new_email = mock_email)
|
128
154
|
|
129
155
|
expect {
|
130
156
|
user.save!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zendesk2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -255,6 +255,7 @@ files:
|
|
255
255
|
- spec/shared/zendesk_resource.rb
|
256
256
|
- spec/spec_helper.rb
|
257
257
|
- spec/support/client_helper.rb
|
258
|
+
- spec/support/data_helper.rb
|
258
259
|
- spec/ticket_fields_spec.rb
|
259
260
|
- spec/tickets_spec.rb
|
260
261
|
- spec/topic_comments_spec.rb
|
@@ -299,6 +300,7 @@ test_files:
|
|
299
300
|
- spec/shared/zendesk_resource.rb
|
300
301
|
- spec/spec_helper.rb
|
301
302
|
- spec/support/client_helper.rb
|
303
|
+
- spec/support/data_helper.rb
|
302
304
|
- spec/ticket_fields_spec.rb
|
303
305
|
- spec/tickets_spec.rb
|
304
306
|
- spec/topic_comments_spec.rb
|