Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fbvilela committed Jun 13, 2024
1 parent 951ccdc commit 0a13e99
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 43 deletions.
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
2 changes: 1 addition & 1 deletion spec/fixtures/zendesk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def find_or_create_user(role)

def topic
VCR.use_cassette('valid_topic') do
@topic ||= client.topics.create(
@topic ||= client.topics.create!(
:name => "Test Topic",
:description => "This is the body of a topic."
)
Expand Down
8 changes: 7 additions & 1 deletion spec/live/automation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
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" }]
},
:actions => [{ :field => "status", :value => "solved" }]
}
end

# before(:all) do
# VCR.use_cassette("Automations_Cleanup") do
# client.automations.fetch.map(&:destroy)
# end
# end

it_should_be_readable :automations
it_should_be_readable :automations, :active

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 => 'Mon dieu!!'
}
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
6 changes: 6 additions & 0 deletions spec/live/organization_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ def valid_attributes
it_should_be_updatable :title, "key"
it_should_be_deletable
it_should_be_readable :organization_fields, :create => true

# it 'should have been cleaned up' do
# VCR.use_cassette("OrganizationField_Cleanup") do
# expect(client.organization_fields.fetch).to be_empty
# end
# end
end
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
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.send("#{attribute}=", value)
extra.each { |k, v| @updatable_object.send("#{k}=", v) }
end

it "should be savable" do
expect(@object.save).to be(true)
expect(@updatable_object.save!).to be(true)
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 0a13e99

Please sign in to comment.