zendesk2 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/lib/zendesk2/client/models/ticket.rb +1 -0
- data/lib/zendesk2/client/requests/create_ticket.rb +15 -2
- data/lib/zendesk2/client/requests/create_user.rb +1 -1
- data/lib/zendesk2/client.rb +16 -15
- data/lib/zendesk2/model.rb +7 -2
- data/lib/zendesk2/version.rb +1 -1
- data/spec/groups_spec.rb +1 -1
- data/spec/memberships_spec.rb +7 -7
- data/spec/organizations_spec.rb +5 -5
- data/spec/shared/zendesk_resource.rb +12 -12
- data/spec/tickets_spec.rb +41 -18
- data/spec/users_spec.rb +38 -38
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34ebab53477c20ee6c21506a5997b9c3ee42f3bf
|
4
|
+
data.tar.gz: a8ecb162208217ad57b67e1264105228cc48d210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b4afc752900f25a9fc7de4d150882b959cc291ec6ff4035ea075632082fe2108d5a8555177eb6eaa4e55e7036b16cabf64a20be2ba812e8098a58ce2a9183f1
|
7
|
+
data.tar.gz: 56993610a6ce3779a6f5fd7e3eca9f5621621021db9a7eb49a4339a95b989fb95d62ca5fd6400beb6b0f92c305117ee301f3dd3c54a6b0d6b8b628421f337104
|
data/Gemfile
CHANGED
@@ -11,8 +11,14 @@ class Zendesk2::Client
|
|
11
11
|
|
12
12
|
class Mock
|
13
13
|
def create_ticket(params={})
|
14
|
+
params = Cistern::Hash.stringify_keys(params)
|
15
|
+
|
14
16
|
identity = self.class.new_id
|
15
17
|
|
18
|
+
if params["description"].nil? || params["description"] == ""
|
19
|
+
error!(:invalid, :details => {"base" => [{"description" => "Description: cannot be blank"}]})
|
20
|
+
end
|
21
|
+
|
16
22
|
if requester = params.delete('requester')
|
17
23
|
if !requester['name'] || requester['name'].size < 1
|
18
24
|
response(
|
@@ -40,10 +46,17 @@ class Zendesk2::Client
|
|
40
46
|
params['requester_id'] = user_id
|
41
47
|
end
|
42
48
|
|
43
|
-
|
49
|
+
requested_custom_fields = (params.delete("custom_fields") || [])
|
50
|
+
|
51
|
+
custom_fields = requested_custom_fields.map do |cf|
|
52
|
+
field_id = cf["id"].to_i
|
53
|
+
if self.data[:ticket_fields][field_id]
|
54
|
+
{"id" => field_id, "value" => cf["value"] }
|
55
|
+
end
|
56
|
+
end.compact
|
44
57
|
|
45
58
|
self.data[:ticket_fields].each do |field_id, field|
|
46
|
-
|
59
|
+
requested_custom_fields.find { |cf| cf["id"] == field_id } ||
|
47
60
|
custom_fields << {"id" => field_id, "value" => nil }
|
48
61
|
end
|
49
62
|
|
@@ -25,7 +25,7 @@ class Zendesk2::Client
|
|
25
25
|
if (email = record["email"]) && self.data[:identities].find{|k,i| i["type"] == "email" && i["value"] == email}
|
26
26
|
error!(:invalid, :details => {
|
27
27
|
"email" => [ {
|
28
|
-
"description" => "Email #{email} is already being used by another user"
|
28
|
+
"description" => "Email: #{email} is already being used by another user"
|
29
29
|
}]})
|
30
30
|
else
|
31
31
|
user_identity_id = self.class.new_id # ugh
|
data/lib/zendesk2/client.rb
CHANGED
@@ -129,15 +129,14 @@ class Zendesk2::Client < Cistern::Service
|
|
129
129
|
raise ArgumentError, "missing parameters: #{missing.join(", ")}"
|
130
130
|
end
|
131
131
|
end
|
132
|
-
end
|
133
132
|
|
134
|
-
|
135
|
-
include Shared
|
133
|
+
private
|
136
134
|
|
137
|
-
|
135
|
+
def zendesk_url(options)
|
136
|
+
options[:url] || Zendesk2.defaults[:url] || form_zendesk_url(options)
|
137
|
+
end
|
138
138
|
|
139
|
-
def
|
140
|
-
url = options[:url] || Zendesk2.defaults[:url] || begin
|
139
|
+
def form_zendesk_url(options)
|
141
140
|
host = options[:host]
|
142
141
|
subdomain = options[:subdomain] || Zendesk2.defaults[:subdomain]
|
143
142
|
|
@@ -146,8 +145,17 @@ class Zendesk2::Client < Cistern::Service
|
|
146
145
|
port = options[:port] || (scheme == "https" ? 443 : 80)
|
147
146
|
|
148
147
|
"#{scheme}://#{host}:#{port}"
|
149
|
-
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
class Real
|
152
|
+
include Shared
|
150
153
|
|
154
|
+
attr_accessor :username, :url, :token, :logger, :jwt_token
|
155
|
+
|
156
|
+
def initialize(options={})
|
157
|
+
options[:subdomain] ||= "mock"
|
158
|
+
url = zendesk_url(options)
|
151
159
|
@url = URI.parse(url).to_s
|
152
160
|
|
153
161
|
@logger = options[:logger] || Logger.new(nil)
|
@@ -235,14 +243,7 @@ class Zendesk2::Client < Cistern::Service
|
|
235
243
|
end
|
236
244
|
|
237
245
|
def initialize(options={})
|
238
|
-
url = options
|
239
|
-
host = options[:host]
|
240
|
-
host ||= "#{options[:subdomain] || "mock"}.zendesk.com"
|
241
|
-
scheme = options[:scheme] || "https"
|
242
|
-
port = options[:port] || (scheme == "https" ? 443 : 80)
|
243
|
-
|
244
|
-
"#{scheme}://#{host}:#{port}"
|
245
|
-
end
|
246
|
+
url = zendesk_url(options)
|
246
247
|
|
247
248
|
@url = url
|
248
249
|
@path = URI.parse(url).path
|
data/lib/zendesk2/model.rb
CHANGED
@@ -12,8 +12,8 @@ class Zendesk2::Model < Cistern::Model
|
|
12
12
|
# @return [Zendesk2::Model] self, regardless of success
|
13
13
|
def save
|
14
14
|
save!
|
15
|
-
rescue Zendesk2::Error =>
|
16
|
-
self.errors =
|
15
|
+
rescue Zendesk2::Error => exception
|
16
|
+
self.errors = exception.response[:body]["details"].inject({}){|r,(k,v)| r.merge(k => v.map{|e| e["type"] || e["description"]})} rescue nil
|
17
17
|
self
|
18
18
|
end
|
19
19
|
|
@@ -26,4 +26,9 @@ class Zendesk2::Model < Cistern::Model
|
|
26
26
|
rescue Zendesk2::Error
|
27
27
|
false
|
28
28
|
end
|
29
|
+
|
30
|
+
# re-define Cistern::Attributes#missing_attributes to require non-blank
|
31
|
+
def missing_attributes(args)
|
32
|
+
([:connection] | args).select{|arg| val = send("#{arg}"); val.nil? || val == "" }
|
33
|
+
end
|
29
34
|
end
|
data/lib/zendesk2/version.rb
CHANGED
data/spec/groups_spec.rb
CHANGED
@@ -12,6 +12,6 @@ describe "groups" do
|
|
12
12
|
it "should list assignable groups" do
|
13
13
|
client.groups.create(name: Zendesk2.uuid) # assignable by default
|
14
14
|
|
15
|
-
client.groups.assignable.
|
15
|
+
expect(client.groups.assignable).to be_all{|g| !g.deleted}
|
16
16
|
end
|
17
17
|
end
|
data/spec/memberships_spec.rb
CHANGED
@@ -19,12 +19,12 @@ describe "memberships" do
|
|
19
19
|
|
20
20
|
another_membership = client.memberships.create!(organization: another_organization, user: user)
|
21
21
|
|
22
|
-
membership.default.
|
23
|
-
another_membership.default.
|
22
|
+
expect(membership.default).to be_falsey # for some reason
|
23
|
+
expect(another_membership.default).to be_falsey
|
24
24
|
|
25
25
|
expect { another_membership.default! }.to change { another_membership.reload.default }.from(false).to(true)
|
26
26
|
|
27
|
-
membership.reload.default.
|
27
|
+
expect(membership.reload.default).to be_falsey
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should get an organization's memberships" do
|
@@ -35,8 +35,8 @@ describe "memberships" do
|
|
35
35
|
another_organization.memberships.create!(user: user)
|
36
36
|
organization.memberships.create!(user: another_user)
|
37
37
|
|
38
|
-
organization.memberships.size.
|
39
|
-
another_organization.memberships.size.
|
38
|
+
expect(organization.memberships.size).to eq(1)
|
39
|
+
expect(another_organization.memberships.size).to eq(2)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should get an user's memberships" do
|
@@ -47,8 +47,8 @@ describe "memberships" do
|
|
47
47
|
user_membership = another_organization.memberships.create!(user: user)
|
48
48
|
organization.memberships.create!(user: another_user)
|
49
49
|
|
50
|
-
user.memberships.to_a.
|
51
|
-
another_user.memberships.size.
|
50
|
+
expect(user.memberships.to_a).to eq([user_membership])
|
51
|
+
expect(another_user.memberships.size).to eq(2)
|
52
52
|
end
|
53
53
|
|
54
54
|
describe "create_membership" do
|
data/spec/organizations_spec.rb
CHANGED
@@ -13,19 +13,19 @@ describe "organizations" do
|
|
13
13
|
let(:organization) { client.organizations.create(name: Zendesk2.uuid) }
|
14
14
|
it "should get #users" do
|
15
15
|
user = client.users.create(email: "#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid, organization: organization)
|
16
|
-
organization.users.
|
16
|
+
expect(organization.users).to include user
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should get #tickets" do
|
20
20
|
user = client.users.create(email: "#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid, organization: organization)
|
21
21
|
ticket = client.tickets.create(subject: "#{Zendesk2.uuid}@example.org", description: Zendesk2.uuid, requester: user)
|
22
|
-
organization.tickets.
|
22
|
+
expect(organization.tickets).to include ticket
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should hate non-unique names" do
|
26
|
-
|
26
|
+
expect { client.organizations.create!(name: organization.name) }.to raise_exception(Zendesk2::Error)
|
27
27
|
model = client.organizations.create(name: organization.name)
|
28
|
-
model.errors.
|
28
|
+
expect(model.errors).to eq({"name" => ["Name has already been taken"]})
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should be able to find organizations by external id" do
|
@@ -34,7 +34,7 @@ describe "organizations" do
|
|
34
34
|
o.external_id = external_id
|
35
35
|
o.save
|
36
36
|
found = client.organizations.find_by_external_id(external_id).first
|
37
|
-
found.
|
37
|
+
expect(found).to be === o
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
@@ -10,12 +10,12 @@ shared_examples "zendesk resource" do |options={}|
|
|
10
10
|
|
11
11
|
it "should be created" do
|
12
12
|
@record = collection.create!(create_params)
|
13
|
-
record.identity.
|
13
|
+
expect(record.identity).not_to be_nil
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should be fetched" do
|
17
17
|
@record = collection.create!(create_params)
|
18
|
-
collection.get!(fetch_params.call(record)).
|
18
|
+
expect(collection.get!(fetch_params.call(record))).to eq(record)
|
19
19
|
end
|
20
20
|
|
21
21
|
if options.fetch(:paged, true)
|
@@ -27,27 +27,27 @@ shared_examples "zendesk resource" do |options={}|
|
|
27
27
|
after(:each) { @resources.each { |r| r.destroy } }
|
28
28
|
|
29
29
|
it "should retrieve first page" do
|
30
|
-
collection.all("per_page" => "1").size.
|
30
|
+
expect(collection.all("per_page" => "1").size).to eq(1)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should retrieve next page" do
|
34
34
|
first_page = collection.all("per_page" => 1)
|
35
35
|
second_page = collection.all("per_page" => 1).next_page
|
36
|
-
second_page.
|
36
|
+
expect(second_page).not_to eq(first_page)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should retreive previous page" do
|
40
40
|
first_page = collection.all("per_page" => "1")
|
41
41
|
previous_to_second_page = collection.all("per_page" => 1).next_page.previous_page
|
42
|
-
previous_to_second_page.
|
42
|
+
expect(previous_to_second_page).to eq(first_page)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
else
|
46
46
|
context "paging" do
|
47
47
|
it "should not be present" do
|
48
|
-
collection.class.attributes.
|
49
|
-
collection.class.attributes.
|
50
|
-
collection.class.attributes.
|
48
|
+
expect(collection.class.attributes).not_to have_key(:next_page_link)
|
49
|
+
expect(collection.class.attributes).not_to have_key(:previous_page_link)
|
50
|
+
expect(collection.class.attributes).to have_key(:count)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -57,17 +57,17 @@ shared_examples "zendesk resource" do |options={}|
|
|
57
57
|
@record = collection.create!(create_params)
|
58
58
|
record.merge_attributes(update_params)
|
59
59
|
record.save
|
60
|
-
update_params.each {|k,v| record.send(k).
|
60
|
+
update_params.each {|k,v| expect(record.send(k)).to eq(v)}
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should be destroyed" do
|
65
65
|
@record = collection.create!(create_params)
|
66
|
-
record.identity.
|
66
|
+
expect(record.identity).not_to be_nil
|
67
67
|
record.destroy
|
68
68
|
|
69
69
|
if !options.fetch(:delayed_destroy, false) && !Zendesk2::Client.mocking?
|
70
|
-
record.
|
70
|
+
expect(record).to be_destroyed
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -75,7 +75,7 @@ shared_examples "zendesk resource" do |options={}|
|
|
75
75
|
# Search index takes 2-3 minutes according to the docs
|
76
76
|
it "should search" do
|
77
77
|
@record = collection.create!(create_params)
|
78
|
-
collection.search(create_params).
|
78
|
+
expect(collection.search(create_params)).to include(record)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
data/spec/tickets_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "Zendesk2::Client" do
|
4
4
|
let(:client) { create_client }
|
5
5
|
|
6
6
|
include_examples "zendesk resource", {
|
@@ -9,6 +9,14 @@ describe "tickets" do
|
|
9
9
|
:update_params => lambda { {subject: Zendesk2.uuid} },
|
10
10
|
}
|
11
11
|
|
12
|
+
describe "#create_ticket" do
|
13
|
+
it "should require a description" do
|
14
|
+
expect {
|
15
|
+
client.create_ticket("subject" => Zendesk2.uuid)
|
16
|
+
}.to raise_exception(Zendesk2::Error, /Description: cannot be blank/)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
12
20
|
describe "when creating a ticket" do
|
13
21
|
let!(:requester_email) { "#{Zendesk2.uuid}@example.org" }
|
14
22
|
|
@@ -16,11 +24,11 @@ describe "tickets" do
|
|
16
24
|
ticket = client.tickets.create!(subject: Zendesk2.uuid, description: Zendesk2.uuid, requester: {name: "Josh Lane", email: requester_email})
|
17
25
|
if Zendesk2::Client.mocking? # this takes some time for realsies
|
18
26
|
requester = client.users.search(email: requester_email).first
|
19
|
-
requester.
|
27
|
+
expect(requester).not_to be_nil
|
20
28
|
|
21
|
-
ticket.reload.requester.
|
29
|
+
expect(ticket.reload.requester).to eq(requester)
|
22
30
|
else
|
23
|
-
ticket.reload.requester.
|
31
|
+
expect(ticket.reload.requester).not_to be_nil
|
24
32
|
end
|
25
33
|
end
|
26
34
|
|
@@ -29,22 +37,32 @@ describe "tickets" do
|
|
29
37
|
client.tickets.create!(subject: Zendesk2.uuid, description: Zendesk2.uuid, requester: {email: requester_email})
|
30
38
|
}.to raise_exception(Zendesk2::Error, /Requester Name: .* too short/)
|
31
39
|
end
|
40
|
+
|
41
|
+
it "should require a description" do
|
42
|
+
expect {
|
43
|
+
client.tickets.create!(subject: Zendesk2.uuid)
|
44
|
+
}.to raise_exception(ArgumentError, /description is required/)
|
45
|
+
|
46
|
+
expect {
|
47
|
+
client.tickets.create!(subject: Zendesk2.uuid, description: "")
|
48
|
+
}.to raise_exception(ArgumentError, /description is required/)
|
49
|
+
end
|
32
50
|
end
|
33
51
|
|
34
52
|
describe "with a created ticket" do
|
35
53
|
let(:ticket) { client.tickets.create!(subject: Zendesk2.uuid, description: Zendesk2.uuid) }
|
36
54
|
it "should get requester" do
|
37
|
-
ticket.requester.
|
55
|
+
expect(ticket.requester).to eq(client.users.current)
|
38
56
|
end
|
39
57
|
|
40
58
|
it "should get submitter" do
|
41
|
-
ticket.submitter.
|
59
|
+
expect(ticket.submitter).to eq(client.users.current)
|
42
60
|
end
|
43
61
|
|
44
62
|
it "should have empty custom fields by default" do
|
45
63
|
pending if !Zendesk2::Client.mocking?
|
46
64
|
|
47
|
-
ticket.custom_fields.
|
65
|
+
expect(ticket.custom_fields).to eq([])
|
48
66
|
end
|
49
67
|
end
|
50
68
|
|
@@ -56,38 +74,43 @@ describe "tickets" do
|
|
56
74
|
ticket.comment(body)
|
57
75
|
|
58
76
|
audit = ticket.audits.last
|
59
|
-
audit.ticket.
|
77
|
+
expect(audit.ticket).to eq(ticket)
|
60
78
|
|
61
79
|
events = audit.events
|
62
|
-
events.size.
|
80
|
+
expect(events.size).to eq(1)
|
63
81
|
|
64
82
|
event = events.first
|
65
|
-
event.body.
|
66
|
-
event.
|
67
|
-
event.ticket_audit.
|
83
|
+
expect(event.body).to eq(body)
|
84
|
+
expect(event).to be_a(Zendesk2::Client::TicketComment)
|
85
|
+
expect(event.ticket_audit).to eq(audit)
|
68
86
|
end
|
69
87
|
|
70
88
|
it "lists comments" do
|
71
89
|
body = Zendesk2.uuid
|
72
90
|
ticket.comment(body)
|
73
91
|
|
74
|
-
ticket.comments.find{|c| c.body == body}.
|
92
|
+
expect(ticket.comments.find{|c| c.body == body}).not_to be_nil
|
75
93
|
end
|
76
94
|
end
|
77
95
|
|
78
96
|
describe "custom fields" do
|
79
|
-
let!(:ticket_field) { client.ticket_fields.create!(title:
|
97
|
+
let!(:ticket_field) { client.ticket_fields.create!(title: SecureRandom.hex(3), type: "text") }
|
80
98
|
|
81
99
|
it "should be based on ticket_fields" do
|
82
100
|
ticket = client.tickets.create!(subject: Zendesk2.uuid, description: Zendesk2.uuid)
|
83
101
|
custom_field = ticket.custom_fields.find { |cf| cf["id"] == ticket_field.identity }
|
84
|
-
|
85
|
-
custom_field
|
102
|
+
|
103
|
+
expect(custom_field).not_to be_nil
|
104
|
+
expect(custom_field["value"]).to be_nil
|
86
105
|
|
87
106
|
ticket = client.tickets.create!(subject: Zendesk2.uuid, description: Zendesk2.uuid, custom_fields: [{"id" => ticket_field.identity, "value" => "jessicaspacekat"}])
|
88
107
|
custom_field = ticket.custom_fields.find { |cf| cf["id"] == ticket_field.identity }
|
89
|
-
|
90
|
-
custom_field
|
108
|
+
|
109
|
+
expect(custom_field).not_to be_nil
|
110
|
+
expect(custom_field["value"]).to eq("jessicaspacekat")
|
111
|
+
|
112
|
+
ticket = client.tickets.create!(subject: Zendesk2.uuid, description: Zendesk2.uuid, custom_fields: [{"id" => "-1", "value" => "fantasy"}])
|
113
|
+
expect(ticket.custom_fields).not_to include({"id" => -1, "value" => "fantasy"})
|
91
114
|
end
|
92
115
|
end
|
93
116
|
end
|
data/spec/users_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe "users" do
|
|
11
11
|
|
12
12
|
it "should get current user" do
|
13
13
|
current_user = client.users.current
|
14
|
-
current_user.email.
|
14
|
+
expect(current_user.email).to eq(client.username)
|
15
15
|
end
|
16
16
|
|
17
17
|
describe do
|
@@ -24,49 +24,49 @@ describe "users" do
|
|
24
24
|
it "should update organization" do
|
25
25
|
organization = client.organizations.create(name: Zendesk2.uuid)
|
26
26
|
user.organization= organization
|
27
|
-
user.save.
|
28
|
-
user.organization.
|
27
|
+
expect(user.save).to be_truthy
|
28
|
+
expect(user.organization).to eq(organization)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should get requested tickets" do
|
32
32
|
ticket = client.tickets.create(requester: user, subject: Zendesk2.uuid, description: Zendesk2.uuid)
|
33
33
|
|
34
|
-
user.requested_tickets.
|
34
|
+
expect(user.requested_tickets).to include ticket
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should get ccd tickets" do
|
38
38
|
ticket = client.tickets.create(collaborators: [user], subject: Zendesk2.uuid, description: Zendesk2.uuid)
|
39
39
|
|
40
|
-
user.ccd_tickets.
|
40
|
+
expect(user.ccd_tickets).to include ticket
|
41
41
|
end
|
42
42
|
|
43
43
|
it "cannot destroy a user with a ticket" do
|
44
44
|
client.tickets.create(requester: user, subject: Zendesk2.uuid, description: Zendesk2.uuid)
|
45
45
|
|
46
|
-
user.destroy.
|
46
|
+
expect(user.destroy).to be_falsey
|
47
47
|
|
48
|
-
user.
|
48
|
+
expect(user).not_to be_destroyed
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should list identities" do
|
52
52
|
identities = user.identities.all
|
53
|
-
identities.size.
|
53
|
+
expect(identities.size).to eq(1)
|
54
54
|
|
55
55
|
identity = identities.first
|
56
|
-
identity.primary.
|
57
|
-
identity.verified.
|
58
|
-
identity.type.
|
59
|
-
identity.value.
|
56
|
+
expect(identity.primary).to be_truthy
|
57
|
+
expect(identity.verified).to be_falsey
|
58
|
+
expect(identity.type).to eq("email")
|
59
|
+
expect(identity.value).to eq(user.email)
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should create a new identity" do
|
63
63
|
email = "ey+#{Zendesk2.uuid}@example.org"
|
64
64
|
|
65
65
|
new_identity = user.identities.create!(type: "email", value: email)
|
66
|
-
new_identity.primary.
|
67
|
-
new_identity.verified.
|
68
|
-
new_identity.type.
|
69
|
-
new_identity.value.
|
66
|
+
expect(new_identity.primary).to be_falsey
|
67
|
+
expect(new_identity.verified).to be_falsey
|
68
|
+
expect(new_identity.type).to eq("email")
|
69
|
+
expect(new_identity.value).to eq(email)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should mark remaining identity as primary" do
|
@@ -77,10 +77,10 @@ describe "users" do
|
|
77
77
|
|
78
78
|
initial_identity.destroy
|
79
79
|
|
80
|
-
new_identity.reload.primary.
|
80
|
+
expect(new_identity.reload.primary).to be_falsey
|
81
81
|
|
82
82
|
new_identity.primary!
|
83
|
-
new_identity.reload.primary.
|
83
|
+
expect(new_identity.reload.primary).to be_truthy
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should not allow multiple primary identities" do
|
@@ -89,19 +89,19 @@ describe "users" do
|
|
89
89
|
initial_identity = user.identities.all.first
|
90
90
|
new_identity = user.identities.create!(type: "email", value: email)
|
91
91
|
new_identity.primary!
|
92
|
-
new_identity.primary.
|
93
|
-
new_identity.reload.primary.
|
92
|
+
expect(new_identity.primary).to be_truthy
|
93
|
+
expect(new_identity.reload.primary).to be_truthy
|
94
94
|
|
95
|
-
initial_identity.reload.primary.
|
95
|
+
expect(initial_identity.reload.primary).to be_falsey
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should hate non-unique emails" do
|
99
99
|
email = "zendesk2+#{Zendesk2.uuid}@example.org"
|
100
100
|
client.users.create(email: email, name: Zendesk2.uuid)
|
101
|
-
|
101
|
+
expect { client.users.create!(email: email, name: Zendesk2.uuid) }.to raise_exception(Zendesk2::Error)
|
102
102
|
user = client.users.create(email: email, name: Zendesk2.uuid)
|
103
|
-
user.identity.
|
104
|
-
user.errors.
|
103
|
+
expect(user.identity).to be_falsey
|
104
|
+
expect(user.errors).to eq({"email" => ["Email: #{email} is already being used by another user"]})
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should create another identity when updating email" do
|
@@ -109,36 +109,36 @@ describe "users" do
|
|
109
109
|
user.email = (new_email = "zendesk2+#{Zendesk2.uuid}@example.org")
|
110
110
|
user.save!
|
111
111
|
|
112
|
-
(identities = user.identities.all).size.
|
112
|
+
expect((identities = user.identities.all).size).to eq(2)
|
113
113
|
new_identity = identities.find{|i| i.value == new_email}
|
114
|
-
new_identity.
|
114
|
+
expect(new_identity).not_to be_nil
|
115
115
|
|
116
|
-
new_identity.primary.
|
116
|
+
expect(new_identity.primary).to be_falsey
|
117
117
|
|
118
118
|
original_identity = identities.find{|i| i.value == original_email}
|
119
|
-
original_identity.
|
119
|
+
expect(original_identity).not_to be_nil
|
120
120
|
|
121
|
-
original_identity.primary.
|
121
|
+
expect(original_identity.primary).to be_truthy
|
122
122
|
|
123
|
-
user.reload.email.
|
123
|
+
expect(user.reload.email).to eq(original_email)
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should form 'legacy' login url" do
|
127
127
|
return_to = "http://engineyard.com"
|
128
128
|
uri = Addressable::URI.parse(user.login_url(Time.now.to_s, return_to: return_to, token: "in-case-you-dont-have-it-in ~/.zendesk2 (aka ci)"))
|
129
|
-
uri.query_values["return_to"].
|
130
|
-
uri.query_values["name"].
|
131
|
-
uri.query_values["email"].
|
132
|
-
uri.query_values["hash"].
|
129
|
+
expect(uri.query_values["return_to"]).to eq(return_to)
|
130
|
+
expect(uri.query_values["name"]).to eq user.name
|
131
|
+
expect(uri.query_values["email"]).to eq user.email
|
132
|
+
expect(uri.query_values["hash"]).not_to be_nil
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should form jwt login url" do
|
136
136
|
return_to = "http://engineyard.com"
|
137
137
|
uri = Addressable::URI.parse(user.jwt_login_url(return_to: return_to, jwt_token: "in-case-you-dont-have-it-in ~/.zendesk2 (aka ci)"))
|
138
|
-
uri.query_values["return_to"].
|
139
|
-
uri.query_values["name"].
|
140
|
-
uri.query_values["email"].
|
141
|
-
uri.query_values["jwt"].
|
138
|
+
expect(uri.query_values["return_to"]).to eq(return_to)
|
139
|
+
expect(uri.query_values["name"]).to be_nil
|
140
|
+
expect(uri.query_values["email"]).to be_nil
|
141
|
+
expect(uri.query_values["jwt"]).not_to be_nil
|
142
142
|
|
143
143
|
#TODO: try JWT.decode
|
144
144
|
end
|
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: 0.5.
|
4
|
+
version: 0.5.2
|
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-
|
11
|
+
date: 2014-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|