Skip to content

Commit

Permalink
Merge branch 'master' into fvilela/omnichannel
Browse files Browse the repository at this point in the history
  • Loading branch information
fbvilela committed Jun 28, 2024
2 parents 2bc0689 + 48e7438 commit 36342a0
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 56 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Adding support to the agent availabilities API endpoints

Adding multiple Gemfile and Gemfile.lock files for differen Ruby versions so that Snyk can scan the repo for vulnerabilities.

## v3.0.5

Adding CBP support to more endpoints. please see `cbp_support_spec.rb` for the complete list.
Expand Down
2 changes: 1 addition & 1 deletion lib/zendesk_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ZendeskAPI
VERSION = "3.0.5"
VERSION = "3.0.6"
end
4 changes: 4 additions & 0 deletions spec/core/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ def stub_json_request(verb, path_matcher, body = json, options = {})
c.default_cassette_options = { :record => :new_episodes, :decode_compressed_response => true, :serialize_with => :json, :preserve_exact_body_bytes => true }
c.hook_into :webmock
c.configure_rspec_metadata!

# In CI this doesn't matter, since we start by deleting all the cassettes.
# In development, this helps debugging.
c.allow_http_connections_when_no_cassette = true
end

include WebMock::API
1 change: 1 addition & 0 deletions spec/fixtures/zendesk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def find_or_create_user(role)

def topic
VCR.use_cassette('valid_topic') do
@topic ||= client.topics.fetch.find { |t| t.name == "Test Topic" }
@topic ||= client.topics.create(
:name => "Test Topic",
:description => "This is the body of a topic."
Expand Down
2 changes: 1 addition & 1 deletion spec/live/automation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe ZendeskAPI::Automation, :delete_after do
def valid_attributes
{
:title => "my test automation",
:title => "my test automation_ruby_sdk_test",
:conditions => {
:all => [{ :field => "status", :operator => "is", :value => "open" }]
},
Expand Down
4 changes: 2 additions & 2 deletions spec/live/brand_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

describe ZendeskAPI::Brand, :delete_after do
def valid_attributes
{ :name => "awesomesauce", :subdomain => "zendeskapi#{SecureRandom.hex(3)}" }
{ :name => "awesomesauce_ruby_sdk_test", :subdomain => "zendeskapi#{SecureRandom.hex(3)}" }
end

it_should_be_creatable
it_should_be_updatable :name
it_should_be_updatable :name, "awesomesauce_ruby_sdk_updated_name"
it_should_be_readable :brands

# Deleted brands are still findable by id, but in the index action
Expand Down
2 changes: 1 addition & 1 deletion spec/live/custom_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def valid_attributes
end

it_should_be_creatable
it_should_be_updatable :agent_label, 'New Agent Label'
it_should_be_updatable :agent_label, "ruby_sdk_test_agent_label_updated"
it_should_be_updatable :end_user_label, 'New End User Label'
it_should_be_updatable :description, 'New Description'
it_should_be_updatable :end_user_description, 'New End User Description'
Expand Down
6 changes: 3 additions & 3 deletions spec/live/dynamic_content/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
describe ZendeskAPI::DynamicContent::Item, :delete_after do
def valid_attributes
{
:name => "Snowboard Problem",
:name => "Dynamic Content Item name Ruby SDK test",
:default_locale_id => 1,
:content => "Snowboard Problem variant"
:content => "Ruby SDK test content"
}
end

it_should_be_readable :dynamic_content, :items, :create => true
it_should_be_creatable
it_should_be_updatable :name
it_should_be_updatable :name, 'Updated Dynamic Content Item name Ruby SDK test'
it_should_be_deletable
end
2 changes: 1 addition & 1 deletion spec/live/dynamic_content/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def valid_attributes
:locale_id => 2,
:active => true,
:default => false,
:content => 'Mon dieu!'
:content => 'Ruby SDK Test Variant Content'
}
end

Expand Down
2 changes: 1 addition & 1 deletion spec/live/identity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe ZendeskAPI::User::Identity, :delete_after do
def valid_attributes
{ :type => "email", :value => "abcdef@example.com" }
{ :type => "email", :value => "ruby_sdk_test@example.com" }
end

under current_user do
Expand Down
4 changes: 2 additions & 2 deletions spec/live/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

describe ZendeskAPI::Organization, :delete_after do
def valid_attributes
{ :name => "Awesome-O" }
{ :name => 'organization_name_ruby_sdk_test' }
end

it_should_be_creatable
it_should_be_updatable :name
it_should_be_updatable :name, 'organization_name_ruby_sdk_test_updated'
it_should_be_deletable
it_should_be_readable :organizations, :create => true

Expand Down
13 changes: 0 additions & 13 deletions spec/live/topic_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
require 'core/spec_helper'

RSpec.describe ZendeskAPI::Topic do
# Cleanup topics (:delete_after doesn't work here)
before :all do
VCR.configure do |c|
@previous_allow_http_connections = c.allow_http_connections_when_no_cassette?
c.allow_http_connections_when_no_cassette = true
end
client.topics.fetch!.reject { |t| t == @topic }.map(&:destroy!)
ensure
VCR.configure do |c|
c.allow_http_connections_when_no_cassette = @previous_allow_http_connections
end
end

def valid_attributes
{
:name => "My Topic",
Expand Down
6 changes: 3 additions & 3 deletions spec/live/user_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

describe ZendeskAPI::UserField, :delete_after do
def valid_attributes
{ :type => "text", :title => "Age", :key => "age" }
{ :type => "text", :title => "title_ruby_sdk_test", :key => 'ruby_sdk_test_key' }
end

it_should_be_creatable
it_should_be_updatable :title, "key"
it_should_be_deletable
it_should_be_creatable
it_should_be_updatable :title, "updated_title_ruby_sdk_test"
it_should_be_readable :user_fields, :create => true
end
53 changes: 25 additions & 28 deletions spec/macros/resource_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ def it_should_be_creatable(options = {})

before(:all) do
VCR.use_cassette("#{described_class.to_s}_create") do
@object = described_class.create(client, valid_attributes.merge(default_options))
@creatable_object = described_class.create!(client, valid_attributes.merge(default_options))
end
end

it "should have an id" do
expect(@object).to_not be_nil
expect(@object.send(:id)).to_not be_nil
expect(@creatable_object).to_not be_nil
expect(@creatable_object.send(:id)).to_not be_nil
end

it "should be findable", :unless => metadata[:not_findable] do
options = default_options
options.merge!(:id => @object.id) unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
expect(described_class.find(client, options)).to eq(@object)
options.merge!(:id => @creatable_object.id) unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
expect(described_class.find(client, options)).to eq(@creatable_object)
end

after(:all) do
return unless @object.id
return unless @creatable_object.id

VCR.use_cassette("#{described_class.to_s}_create_delete") do
@object.destroy
@creatable_object.destroy
end
end if metadata[:delete_after]
end
Expand All @@ -50,40 +50,38 @@ def it_should_be_updatable(attribute, value = "TESTDATA", extra = {})
context "update", :vcr do
before(:all) do
VCR.use_cassette("#{described_class.to_s}_update_create") do
@object = described_class.create(client, valid_attributes.merge(default_options))
@updatable_object = described_class.create!(client, valid_attributes.merge(default_options))
end
end

before(:each) do
@object.send("#{attribute}=", value)
extra.each { |k, v| @object.send("#{k}=", v) }
@updatable_object.public_send("#{attribute}=", value)
extra.each { |k, v| @updatable_object.public_send("#{k}=", v) }
end

it "should be savable" do
expect(@object.save).to be(true)
expect(@updatable_object.save).to be(true), "Expected object to save, but it failed with errors: #{@updatable_object.errors&.full_messages&.join(', ')}"
end

context "after save" do
before(:each) do
@object.save
@updatable_object.save
end

it "should keep attributes" do
expect(@object.send(attribute)).to eq(value)
expect(@updatable_object.send(attribute)).to eq(value)
end

it "should be findable", :unless => metadata[:not_findable] do
options = default_options
options.merge!(:id => @object.id) unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
expect(described_class.find(client, options)).to eq(@object)
options.merge!(:id => @updatable_object.id) unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
expect(described_class.find(client, options)).to eq(@updatable_object)
end
end

after(:all) do
return unless @object.id

VCR.use_cassette("#{described_class.to_s}_update_delete") do
@object.destroy
@updatable_object.destroy
end
end if metadata[:delete_after]
end
Expand All @@ -93,21 +91,20 @@ def it_should_be_deletable(options = {})
context "deletion", :vcr do
before(:all) do
if options[:object]
@object = options.delete(:object)
@deletable_object = options.delete(:object)
else
VCR.use_cassette("#{described_class.to_s}_delete_create") do
@object = described_class.create(client, valid_attributes.merge(default_options))
@deletable_object = described_class.create!(client, valid_attributes.merge(default_options))
end
end
end

it "should be destroyable" do |example|
expect(@object.destroy).to be(true)
expect(@object.destroyed?).to be(true)

expect(@deletable_object.destroy).to be(true)
expect(@deletable_object.destroyed?).to be(true)
if (!options.key?(:find) || options[:find]) && !example.metadata[:not_findable]
opts = default_options
opts.merge!(:id => @object.id) unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
opts.merge!(:id => @deletable_object.id) unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
obj = described_class.find(client, opts)

if options[:find]
Expand All @@ -129,13 +126,13 @@ def it_should_be_readable(*args)
context context_name, :vcr do
before(:all) do
VCR.use_cassette("#{described_class.to_s}_#{context_name}_create") do
@object = described_class.create!(client, valid_attributes.merge(default_options))
@readable_object = described_class.create!(client, valid_attributes.merge(default_options))
end
end if create

after(:all) do
VCR.use_cassette("#{described_class.to_s}_#{context_name}_delete") do
@object.destroy
@readable_object.destroy
end
end if create

Expand All @@ -148,7 +145,7 @@ def it_should_be_readable(*args)
object = nil

result.all do |o|
object = o if @object == o
object = o if @readable_object == o
end

expect(object).to_not be_nil
Expand All @@ -158,7 +155,7 @@ def it_should_be_readable(*args)
end
else
expect(result).to_not be_nil
expect(result).to eq(@object) if create
expect(result).to eq(@readable_object) if create
object = result
end

Expand Down

0 comments on commit 36342a0

Please sign in to comment.