Fix auto-correctable rubocop offenses in test suite

This commit is contained in:
Ryan Lue 2019-04-15 09:41:17 +08:00
parent e907c13cbe
commit 2ac28bf906
119 changed files with 1406 additions and 1532 deletions

View file

@ -6,41 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 36
# Cop supports --auto-correct.
# Configuration parameters: EnabledMethods.
Capybara/FeatureMethods:
Exclude:
- 'spec/system/basic/authentication_spec.rb'
- 'spec/system/basic/redirects_spec.rb'
- 'spec/system/basic/richtext_spec.rb'
- 'spec/system/js/q_unit_spec.rb'
- 'spec/system/setup/auto_wizard_spec.rb'
- 'spec/system/setup/mail_accounts_spec.rb'
- 'spec/system/setup/system_spec.rb'
- 'spec/system/ticket/create_spec.rb'
- 'spec/system/ticket/update_spec.rb'
# Offense count: 39
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'spec/factories/job.rb'
- 'spec/factories/postmaster_filter.rb'
- 'spec/factories/ticket.rb'
- 'spec/factories/ticket/article.rb'
- 'spec/lib/sequencer/unit/import/zendesk/sub_sequence/base_examples.rb'
- 'spec/models/calendar_spec.rb'
- 'spec/models/channel/email_parser_spec.rb'
- 'spec/models/cti/caller_id_spec.rb'
- 'spec/models/job_spec.rb'
- 'spec/models/recent_view_spec.rb'
- 'spec/models/role_spec.rb'
- 'spec/models/ticket_spec.rb'
- 'spec/models/trigger_spec.rb'
- 'spec/requests/ticket_spec.rb'
# Offense count: 43
Lint/UselessAssignment:
Enabled: false
@ -53,7 +18,7 @@ Lint/UselessAssignment:
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 1969
Max: 1987
# Offense count: 16
RSpec/AnyInstance:
@ -84,48 +49,6 @@ RSpec/BeforeAfterAll:
RSpec/ContextWording:
Enabled: false
# Offense count: 1
RSpec/DescribeClass:
Exclude:
- 'spec/scripts/websocket_server_spec.rb'
# Offense count: 207
# Cop supports --auto-correct.
# Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Enabled: false
# Offense count: 15
# Cop supports --auto-correct.
RSpec/EmptyLineAfterFinalLet:
Exclude:
- 'spec/db/migrate/issue_1905_exchange_login_from_remote_id_spec.rb'
- 'spec/db/migrate/issue_2541_fix_notification_email_without_body_spec.rb'
- 'spec/lib/import/zendesk/object_attribute/base_examples.rb'
- 'spec/models/cti/log_spec.rb'
- 'spec/models/object_manager/attribute/validation/future_past_spec.rb'
- 'spec/models/object_manager/attribute/validation/required_spec.rb'
- 'spec/models/ticket_spec.rb'
- 'spec/models/user_spec.rb'
- 'spec/requests/integration/twitter_webhook_spec.rb'
# Offense count: 25
# Cop supports --auto-correct.
RSpec/EmptyLineAfterHook:
Exclude:
- 'spec/lib/notification_factory/slack_spec.rb'
- 'spec/lib/notification_factory_spec.rb'
- 'spec/models/role_spec.rb'
- 'spec/models/ticket_spec.rb'
- 'spec/models/trigger_spec.rb'
- 'spec/models/user_spec.rb'
# Offense count: 34
# Cop supports --auto-correct.
RSpec/EmptyLineAfterSubject:
Enabled: false
# Offense count: 540
# Configuration parameters: Max.
RSpec/ExampleLength:
@ -144,13 +67,6 @@ RSpec/ExpectActual:
- 'spec/requests/user/organization_spec.rb'
- 'spec/requests/user_spec.rb'
# Offense count: 99
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: method_call, block
RSpec/ExpectChange:
Enabled: false
# Offense count: 3
RSpec/ExpectInHook:
Exclude:
@ -175,20 +91,6 @@ RSpec/FilePath:
- 'spec/db/migrate/issue_2541_fix_notification_email_without_body_spec.rb'
- 'spec/lib/import/base_factory_spec.rb'
# Offense count: 30
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, each, example
RSpec/HookArgument:
Enabled: false
# Offense count: 4
# Cop supports --auto-correct.
RSpec/HooksBeforeExamples:
Exclude:
- 'spec/models/concerns/has_groups_examples.rb'
- 'spec/models/trigger_spec.rb'
# Offense count: 60
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
@ -205,36 +107,6 @@ RSpec/InstanceVariable:
- 'spec/requests/ticket/article_attachments_spec.rb'
- 'spec/requests/user_spec.rb'
# Offense count: 2
RSpec/IteratedExpectation:
Exclude:
- 'spec/jobs/update_cti_logs_by_caller_job_spec.rb'
# Offense count: 10
# Cop supports --auto-correct.
RSpec/LeadingSubject:
Exclude:
- 'spec/lib/notification_factory/slack_spec.rb'
- 'spec/models/object_manager/attribute/validation/backend_spec.rb'
- 'spec/models/object_manager/attribute/validation/future_past_spec.rb'
- 'spec/models/object_manager/attribute/validation/required_spec.rb'
- 'spec/models/role_spec.rb'
- 'spec/models/ticket/article_spec.rb'
- 'spec/models/trigger_spec.rb'
- 'spec/models/user_spec.rb'
# Offense count: 15
# Cop supports --auto-correct.
RSpec/LetBeforeExamples:
Exclude:
- 'spec/lib/import/otrs/article/attachment_factory_spec.rb'
- 'spec/lib/import/otrs/dynamic_field_factory_spec.rb'
- 'spec/lib/import/otrs/dynamic_field_spec.rb'
- 'spec/lib/ldap/group_spec.rb'
- 'spec/lib/ldap/user_spec.rb'
- 'spec/lib/ldap_spec.rb'
- 'spec/models/user_spec.rb'
# Offense count: 34
RSpec/LetSetup:
Enabled: false
@ -274,40 +146,6 @@ RSpec/NamedSubject:
RSpec/NestedGroups:
Max: 8
# Offense count: 28
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: not_to, to_not
RSpec/NotToNot:
Exclude:
- 'spec/db/migrate/object_manager_attribute_date_remove_future_past_spec.rb'
- 'spec/lib/import/otrs/user_factory_spec.rb'
- 'spec/lib/migration_job/ldap_samaccountname_to_uid_spec.rb'
- 'spec/lib/report/ticket_generic_time_spec.rb'
- 'spec/lib/stats_spec.rb'
- 'spec/models/object_manager/attribute/validation_spec.rb'
- 'spec/models/object_manager/attribute_spec.rb'
- 'spec/requests/integration/idoit_spec.rb'
- 'spec/requests/integration/twilio_sms_spec.rb'
- 'spec/requests/integration/user_device_spec.rb'
- 'spec/requests/search_spec.rb'
- 'spec/requests/text_module_spec.rb'
- 'spec/requests/ticket/article_spec.rb'
# Offense count: 81
# Cop supports --auto-correct.
# Configuration parameters: Strict, EnforcedStyle.
# SupportedStyles: inflected, explicit
RSpec/PredicateMatcher:
Exclude:
- 'spec/lib/password_hash_spec.rb'
- 'spec/models/trigger/sms_spec.rb'
- 'spec/requests/api_auth_on_behalf_of_spec.rb'
- 'spec/requests/api_auth_spec.rb'
- 'spec/requests/integration/monitoring_spec.rb'
- 'spec/requests/organization_spec.rb'
- 'spec/requests/user_spec.rb'
# Offense count: 12
RSpec/RepeatedDescription:
Exclude:
@ -315,11 +153,6 @@ RSpec/RepeatedDescription:
- 'spec/requests/form_spec.rb'
- 'spec/requests/ticket_spec.rb'
# Offense count: 2
RSpec/RepeatedExample:
Exclude:
- 'spec/models/translation_spec.rb'
# Offense count: 3
RSpec/ScatteredLet:
Exclude:
@ -347,16 +180,3 @@ RSpec/SubjectStub:
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Enabled: false
# Offense count: 2
RSpec/VoidExpect:
Exclude:
- 'spec/lib/ldap/group_spec.rb'
- 'spec/lib/ldap/user_spec.rb'
# Offense count: 741
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: numeric, symbolic
Rails/HttpStatus:
Enabled: false

View file

@ -5,7 +5,7 @@ RSpec.describe Issue1219ZhtwLocaleTypo, type: :db_migration do
let(:translation) { create(:translation, locale: premigrate_locale) }
let(:user) { create(:user, preferences: { locale: premigrate_locale }) }
before(:each) do
before do
Locale.find_by(name: 'Chinese (Tradi.) (正體中文)')&.destroy
stub_const("#{described_class}::CURRENT_VERSION", version)
end

View file

@ -44,6 +44,7 @@ RSpec.describe Issue1905ExchangeLoginFromRemoteId, type: :db_migration do
context 'blank config' do
let(:config) { nil }
it_behaves_like 'irrelevant config'
end
@ -53,6 +54,7 @@ RSpec.describe Issue1905ExchangeLoginFromRemoteId, type: :db_migration do
some: 'config'
}
end
it_behaves_like 'irrelevant config'
end
@ -64,6 +66,7 @@ RSpec.describe Issue1905ExchangeLoginFromRemoteId, type: :db_migration do
}
}
end
it_behaves_like 'irrelevant config'
end
@ -76,6 +79,7 @@ RSpec.describe Issue1905ExchangeLoginFromRemoteId, type: :db_migration do
}
}
end
it_behaves_like 'irrelevant config'
end
end

View file

@ -16,9 +16,7 @@ RSpec.describe Issue1977RemoveInvalidUserForeignKeys, type: :db_migration do
expect do
migrate
end.to change {
OnlineNotification.count
}.by(-1)
end.to change(OnlineNotification, :count).by(-1)
end
it 'cleans up RecentView#created_by_id', db_strategy: :reset do
@ -30,9 +28,7 @@ RSpec.describe Issue1977RemoveInvalidUserForeignKeys, type: :db_migration do
expect do
migrate
end.to change {
RecentView.count
}.by(-1)
end.to change(RecentView, :count).by(-1)
end
it 'cleans up Avatar#o_id', db_strategy: :reset do
@ -44,9 +40,7 @@ RSpec.describe Issue1977RemoveInvalidUserForeignKeys, type: :db_migration do
expect do
migrate
end.to change {
Avatar.count
}.by(-1)
end.to change(Avatar, :count).by(-1)
end
end

View file

@ -1,23 +1,20 @@
require 'rails_helper'
RSpec.describe AddCountryAttributeToUsers, type: :db_migration do
context 'AddCountryAttributeToUsers migration' do
def country_attribute
ObjectManager::Attribute.find_by(object_lookup_id: ObjectLookup.by_name('User'), name: 'country')
end
it 'preserves the existing country attribute' do
expect { migrate }
.not_to(change { country_attribute.present? })
.not_to change { ObjectManager::Attribute.find_by(object_lookup_id: ObjectLookup.by_name('User'), name: 'country') }
end
it 'adds the country attribute when it is not present' do
country_attribute.delete
expect { migrate }
.to change { country_attribute.present? }
.from( false ).to( true )
context 'when country attribute is not present' do
before { ObjectManager::Attribute.find_by(object_lookup_id: ObjectLookup.by_name('User'), name: 'country').delete }
it 'adds the country attribute when it is not present' do
expect { migrate }
.to change { ObjectManager::Attribute.exists?(object_lookup_id: ObjectLookup.by_name('User'), name: 'country') }
.from(false).to(true)
end
end
end
end

View file

@ -38,6 +38,7 @@ RSpec.describe Issue2541FixNotificationEmailWithoutBody, type: :db_migration do
context 'when migrating Jobs' do
subject(:job) { create(:job) }
let(:type) { 'notification.email' }
it "updates empty perform['notification.email']['body'] attribute" do
@ -48,6 +49,7 @@ RSpec.describe Issue2541FixNotificationEmailWithoutBody, type: :db_migration do
describe 'scheduler management' do
let(:scheduler) { Scheduler.find_by(method: 'Job.run') }
before { scheduler.update!(active: false) }
it "re-enables 'Job.run' Scheduler" do

View file

@ -19,7 +19,7 @@ RSpec.describe ObjectManagerAttributeDateRemoveFuturePast, type: :db_migration d
migrate
expect(subject.data_option).to_not include(:past, :future)
expect(subject.data_option).not_to include(:past, :future)
end
context 'when incomplete data_option is given' do

View file

@ -14,7 +14,7 @@ RSpec.describe UpdateCtiLogsByCallerJob, type: :job do
it 'updates Cti::Logs from that number with "preferences" => {}' do
described_class.perform_now(phone)
log_prefs.each { |p| expect(p).to be_empty }
expect(log_prefs).to all(be_empty)
end
end
@ -24,7 +24,7 @@ RSpec.describe UpdateCtiLogsByCallerJob, type: :job do
it 'updates Cti::Logs from that number with valid "preferences" hash' do
described_class.perform_now(phone)
log_prefs.each { |p| expect(p).to include('from' => a_kind_of(Array)) }
expect(log_prefs).to all(include('from' => a_kind_of(Array)))
end
end
end

View file

@ -3,30 +3,30 @@ require 'rails_helper'
RSpec.describe ApplicationHandleInfo do
describe '.use' do
it 'requires a block' do
expect { ApplicationHandleInfo.use('foo') }
expect { described_class.use('foo') }
.to raise_error(ArgumentError)
end
context 'for a given starting ApplicationHandleInfo' do
before { ApplicationHandleInfo.current = 'foo' }
before { described_class.current = 'foo' }
it 'runs the block using the given ApplicationHandleInfo' do
ApplicationHandleInfo.use('bar') do
expect(ApplicationHandleInfo.current).to eq('bar')
described_class.use('bar') do
expect(described_class.current).to eq('bar')
end
end
it 'resets ApplicationHandleInfo to its original value' do
ApplicationHandleInfo.use('bar') {}
described_class.use('bar') {}
expect(ApplicationHandleInfo.current).to eq('foo')
expect(described_class.current).to eq('foo')
end
context 'when an error is raised in the given block' do
it 'does not rescue the error, and still resets ApplicationHandleInfo' do
expect { ApplicationHandleInfo.use('bar') { raise } }
expect { described_class.use('bar') { raise } }
.to raise_error(StandardError)
.and not_change { ApplicationHandleInfo.current }
.and not_change { described_class.current }
end
end
end

View file

@ -5,14 +5,14 @@ RSpec.describe Cache do
before { allow(Rails.cache).to receive(:read) }
it 'wraps Rails.cache.read' do
Cache.get('foo')
described_class.get('foo')
expect(Rails.cache).to have_received(:read).with('foo')
end
context 'with a non-string argument' do
it 'passes a string' do
Cache.get(:foo)
described_class.get(:foo)
expect(Rails.cache).to have_received(:read).with('foo')
end
@ -21,25 +21,25 @@ RSpec.describe Cache do
describe '.write' do
it 'stores string values' do
expect { Cache.write('123', 'some value') }
.to change { Cache.get('123') }.to('some value')
expect { described_class.write('123', 'some value') }
.to change { described_class.get('123') }.to('some value')
end
it 'stores hash values' do
expect { Cache.write('123', { key: 'some value' }) }
.to change { Cache.get('123') }.to({ key: 'some value' })
expect { described_class.write('123', { key: 'some value' }) }
.to change { described_class.get('123') }.to({ key: 'some value' })
end
it 'overwrites previous values' do
Cache.write('123', 'some value')
described_class.write('123', 'some value')
expect { Cache.write('123', { key: 'some value' }) }
.to change { Cache.get('123') }.to({ key: 'some value' })
expect { described_class.write('123', { key: 'some value' }) }
.to change { described_class.get('123') }.to({ key: 'some value' })
end
it 'stores hash values with non-ASCII content' do
expect { Cache.write('123', { key: 'some valueöäüß' }) }
.to change { Cache.get('123') }.to({ key: 'some valueöäüß' })
expect { described_class.write('123', { key: 'some valueöäüß' }) }
.to change { described_class.get('123') }.to({ key: 'some valueöäüß' })
end
context 'when expiring' do
@ -51,58 +51,58 @@ RSpec.describe Cache do
end
it 'defaults to expires_in: 7.days' do
Cache.write('123', 'some value')
described_class.write('123', 'some value')
expect { travel 7.days - 1.second }.not_to change { Cache.get('123') }
expect { travel 2.seconds }.to change { Cache.get('123') }.to(nil)
expect { travel 7.days - 1.second }.not_to change { described_class.get('123') }
expect { travel 2.seconds }.to change { described_class.get('123') }.to(nil)
end
it 'accepts a custom :expires_in option' do
Cache.write('123', 'some value', expires_in: 3.seconds)
described_class.write('123', 'some value', expires_in: 3.seconds)
expect { travel 4.seconds }.to change { Cache.get('123') }.to(nil)
expect { travel 4.seconds }.to change { described_class.get('123') }.to(nil)
end
end
end
describe '.delete' do
it 'deletes stored values' do
Cache.write('123', 'some value')
described_class.write('123', 'some value')
expect { Cache.delete('123') }
.to change { Cache.get('123') }.to(nil)
expect { described_class.delete('123') }
.to change { described_class.get('123') }.to(nil)
end
it 'is idempotent' do
Cache.write('123', 'some value')
Cache.delete('123')
described_class.write('123', 'some value')
described_class.delete('123')
expect { Cache.delete('123') }.not_to raise_error
expect { described_class.delete('123') }.not_to raise_error
end
end
describe '.clear' do
it 'deletes all stored values' do
Cache.write('123', 'some value')
Cache.write('456', 'some value')
described_class.write('123', 'some value')
described_class.write('456', 'some value')
expect { Cache.clear }
.to change { Cache.get('123') }.to(nil)
.and change { Cache.get('456') }.to(nil)
expect { described_class.clear }
.to change { described_class.get('123') }.to(nil)
.and change { described_class.get('456') }.to(nil)
end
it 'is idempotent' do
Cache.write('123', 'some value')
Cache.clear
described_class.write('123', 'some value')
described_class.clear
expect { Cache.clear }.not_to raise_error
expect { described_class.clear }.not_to raise_error
end
context 'when cache directory is not present on disk' do
before { FileUtils.rm_rf(Rails.cache.cache_path) }
it 'does not raise an error' do
expect { Cache.clear }.not_to raise_error
expect { described_class.clear }.not_to raise_error
end
end
end

View file

@ -25,8 +25,8 @@ RSpec.describe String do
end
it 'does not break on non-unicode strings' do
expect(String.new("\xC2\xA92011 Z ", encoding: 'ASCII-8BIT').strip)
.to eq(String.new("\xC2\xA92011 Z", encoding: 'ASCII-8BIT'))
expect(described_class.new("\xC2\xA92011 Z ", encoding: 'ASCII-8BIT').strip)
.to eq(described_class.new("\xC2\xA92011 Z", encoding: 'ASCII-8BIT'))
end
end
end
@ -56,9 +56,9 @@ RSpec.describe String do
end
it 'does not break on invalid-unicode strings (in place)' do
str = String.new("\xC2\xA92011 Z ", encoding: 'ASCII-8BIT')
str = described_class.new("\xC2\xA92011 Z ", encoding: 'ASCII-8BIT')
expect(str.strip!)
.to be(str).and eq(String.new("\xC2\xA92011 Z", encoding: 'ASCII-8BIT'))
.to be(str).and eq(described_class.new("\xC2\xA92011 Z", encoding: 'ASCII-8BIT'))
end
end
end
@ -1844,7 +1844,7 @@ RSpec.describe String do
end
context 'which are incorrectly set to other, technically valid encodings' do
let(:subject) { String.new('ö', encoding: 'tis-620') }
let(:subject) { described_class.new('ö', encoding: 'tis-620') }
it 'sets input encoding to UTF-8 instead of attempting conversion' do
expect(subject.utf8_encode).to eq(subject.dup.force_encoding('utf-8'))

View file

@ -4,8 +4,8 @@ require 'rails_helper'
RSpec.describe HtmlSanitizer do
describe '.replace_inline_images' do
let(:body) { HtmlSanitizer.replace_inline_images(html).first }
let(:inline_attachments) { HtmlSanitizer.replace_inline_images(html).last }
let(:body) { described_class.replace_inline_images(html).first }
let(:inline_attachments) { described_class.replace_inline_images(html).last }
context 'for image at absolute path' do
let(:html) { '<img src="/some_one.png" style="width: 181px; height: 125px" alt="abc">' }
@ -142,7 +142,7 @@ RSpec.describe HtmlSanitizer do
context 'for image at absolute path' do
context 'with src attr last' do
it 'add max-width: 100% rule to style attr' do
expect(HtmlSanitizer.dynamic_image_size(<<~HTML.chomp)).to match(Regexp.new(<<~REGEX.chomp))
expect(described_class.dynamic_image_size(<<~HTML.chomp)).to match(Regexp.new(<<~REGEX.chomp))
<img style="width: 181px; height: 125px" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/...">
HTML
<img style="max-width:100%;width: 181px;max-height: 125px;" src="data:image.+?">
@ -152,7 +152,7 @@ RSpec.describe HtmlSanitizer do
context 'with src attr first' do
it 'add max-width: 100% rule to style attr' do
expect(HtmlSanitizer.dynamic_image_size(<<~HTML.chomp)).to match(Regexp.new(<<~REGEX.chomp))
expect(described_class.dynamic_image_size(<<~HTML.chomp)).to match(Regexp.new(<<~REGEX.chomp))
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/..." style="width: 181px; height: 125px" alt="abc">
HTML
<img src="data:image.+?" style="max-width:100%;width: 181px;max-height: 125px;" alt="abc">
@ -164,7 +164,7 @@ RSpec.describe HtmlSanitizer do
context 'for base64-encoded inline images' do
context 'with src attr last' do
it 'add max-width: 100% rule to style attr' do
expect(HtmlSanitizer.dynamic_image_size(<<~HTML.chomp)).to match(Regexp.new(<<~REGEX.chomp))
expect(described_class.dynamic_image_size(<<~HTML.chomp)).to match(Regexp.new(<<~REGEX.chomp))
<img src="/some_one.png" style="width: 181px; height: 125px" alt="abc">
HTML
<img src="/some_one.png" style="max-width:100%;width: 181px;max-height: 125px;" alt="abc">
@ -174,7 +174,7 @@ RSpec.describe HtmlSanitizer do
context 'with src attr first' do
it 'add max-width: 100% rule to style attr' do
expect(HtmlSanitizer.dynamic_image_size(<<~HTML.chomp)).to match(Regexp.new(<<~REGEX.chomp))
expect(described_class.dynamic_image_size(<<~HTML.chomp)).to match(Regexp.new(<<~REGEX.chomp))
<img src="/some_one.png" alt="abc">
HTML
<img src="/some_one.png" alt="abc" style="max-width:100%;">
@ -190,14 +190,14 @@ RSpec.describe HtmlSanitizer do
before { allow(Timeout).to receive(:timeout).and_raise(Timeout::Error) }
it 'returns a timeout error message for the user' do
expect(HtmlSanitizer.strict(+'<img src="/some_one.png">', true))
expect(described_class.strict(+'<img src="/some_one.png">', true))
.to match(HtmlSanitizer::UNPROCESSABLE_HTML_MSG)
end
end
context 'with href links that contain square brackets' do
it 'correctly URL encodes them' do
expect(HtmlSanitizer.strict(+'<a href="https://example.com/?foo=bar&baz[x]=y">example</a>', true))
expect(described_class.strict(+'<a href="https://example.com/?foo=bar&baz[x]=y">example</a>', true))
.to eq('<a href="https://example.com/?foo=bar&amp;baz%5Bx%5D=y" rel="nofollow noreferrer noopener" target="_blank" title="https://example.com/?foo=bar&amp;baz[x]=y">example</a>')
end
end
@ -208,7 +208,7 @@ RSpec.describe HtmlSanitizer do
before { allow(Timeout).to receive(:timeout).and_raise(Timeout::Error) }
it 'returns a timeout error message for the user' do
expect(HtmlSanitizer.cleanup(+'<img src="/some_one.png">'))
expect(described_class.cleanup(+'<img src="/some_one.png">'))
.to match(HtmlSanitizer::UNPROCESSABLE_HTML_MSG)
end
end

View file

@ -2,13 +2,13 @@ require 'rails_helper'
require 'lib/import/import_factory_examples'
RSpec.describe Import::OTRS::Article::AttachmentFactory do
it_behaves_like 'Import factory'
def load_attachment_json(file)
json_fixture("import/otrs/article/attachment/#{file}")
let(:start_import) do
described_class.import(
attachments: attachments,
local_article: local_article
)
end
let(:local_article) { instance_double(Ticket::Article, ticket_id: 1337, id: 42) }
let(:attachments) do
[
load_attachment_json('default'),
@ -16,11 +16,11 @@ RSpec.describe Import::OTRS::Article::AttachmentFactory do
load_attachment_json('default')
]
end
let(:start_import) do
described_class.import(
attachments: attachments,
local_article: local_article
)
let(:local_article) { instance_double(Ticket::Article, ticket_id: 1337, id: 42) }
def load_attachment_json(file)
json_fixture("import/otrs/article/attachment/#{file}")
end
def import_expectations
@ -34,6 +34,8 @@ RSpec.describe Import::OTRS::Article::AttachmentFactory do
expect(local_article).to receive(:attachments).and_return(article_attachments)
end
it_behaves_like 'Import factory'
it 'imports' do
article_attachment_expectations([])
import_expectations

View file

@ -32,18 +32,18 @@ RSpec.describe Import::OTRS::ArticleCustomer do
end
it 'creates customers with special encoding in name' do
expect { described_class.new(load_article_json('customer_special_chars')) }.to change { User.count }.by(1)
expect { described_class.new(load_article_json('customer_special_chars')) }.to change(User, :count).by(1)
expect(User.last.login).to eq('user.hernandez@example.com')
end
it 'creates customers with special from email syntax' do
expect { described_class.new(load_article_json('from_bracket_email_syntax')) }.to change { User.count }.by(1)
expect { described_class.new(load_article_json('from_bracket_email_syntax')) }.to change(User, :count).by(1)
expect(User.last.login).to eq('user@example.com')
end
it 'converts emails to downcase' do
Setting.set('import_mode', true)
expect { described_class.new(load_article_json('from_capital_case')) }.to change { User.count }.by(1)
expect { described_class.new(load_article_json('from_capital_case')) }.to change(User, :count).by(1)
expect(User.last.email).to eq('user@example.com')
expect(User.last.login).to eq('user@example.com')
end

View file

@ -104,7 +104,7 @@ RSpec.describe Import::OTRS::CustomerUser do
}
end
before(:each) do
before do
travel_to DateTime.current
end

View file

@ -3,10 +3,10 @@ require 'lib/import/factory_examples'
require 'lib/import/otrs/dynamic_field_examples'
RSpec.describe Import::OTRS::DynamicFieldFactory do
it_behaves_like 'Import::Factory'
let(:start_import_test) { described_class.import(object_structure) }
let(:object_structure) { [load_dynamic_field_json('text/default')] }
let(:start_import_test) { described_class.import(object_structure) }
it_behaves_like 'Import::Factory'
it 'responds to skip_field?' do
expect(described_class).to respond_to('skip_field?')

View file

@ -2,10 +2,10 @@ require 'rails_helper'
require 'lib/import/otrs/dynamic_field_examples'
RSpec.describe Import::OTRS::DynamicField do
it_behaves_like 'Import::OTRS::DynamicField'
let(:start_import_test) { described_class.new(object_structure) }
let(:object_structure) { load_dynamic_field_json('text/default') }
let(:start_import_test) { described_class.new(object_structure) }
it_behaves_like 'Import::OTRS::DynamicField'
it 'requires an implementation of init_callback' do
expect(ObjectManager::Attribute).to receive(:get).and_return(false)

View file

@ -7,7 +7,7 @@ RSpec.describe Import::OTRS::UserFactory do
it 'skips root@localhost' do
root_data = json_fixture('import/otrs/user/default')
expect(Import::OTRS::User).to_not receive(:new)
expect(Import::OTRS::User).not_to receive(:new)
described_class.import([root_data])
end

View file

@ -19,6 +19,7 @@ RSpec.shared_examples Import::Zendesk::ObjectAttribute::Base do
describe 'exception handling' do
let(:error_text) { Faker::Lorem.sentence }
it 'extends ObjectManager Attribute exception message' do
expect(ObjectManager::Attribute).to receive(:add).and_raise(RuntimeError, error_text)

View file

@ -5,6 +5,11 @@ require 'ldap/group'
RSpec.describe Ldap::Group do
# required as 'let' to perform test based
# expectations and reuse it in 'let' instance
# as additional parameter
let(:mocked_ldap) { double() }
context '.uid_attribute' do
it 'responds to .uid_attribute' do
@ -16,17 +21,12 @@ RSpec.describe Ldap::Group do
end
end
# required as 'let' to perform test based
# expectations and reuse it in 'let' instance
# as additional parameter
let(:mocked_ldap) { double() }
context 'initialization config parameters' do
it 'reuses given Ldap instance if given' do
config = {}
expect(Ldap).not_to receive(:new).with(config)
instance = described_class.new(config, ldap: mocked_ldap)
described_class.new(config, ldap: mocked_ldap)
end
it 'takes optional filter' do
@ -55,7 +55,8 @@ RSpec.describe Ldap::Group do
it 'creates own Ldap instance if none given' do
expect(Ldap).to receive(:new)
expect(described_class.new())
described_class.new
end
end

View file

@ -6,6 +6,8 @@ require 'tcr/net/ldap'
RSpec.describe Ldap::User do
let(:mocked_ldap) { double() }
context '.uid_attribute' do
it 'responds to .uid_attribute' do
@ -32,13 +34,12 @@ RSpec.describe Ldap::User do
# required as 'let' to perform test based
# expectations and reuse it in 'let' instance
# as additional parameter
let(:mocked_ldap) { double() }
context 'initialization config parameters' do
it 'reuses given Ldap instance if given' do
expect(Ldap).not_to receive(:new)
instance = described_class.new(ldap: mocked_ldap)
described_class.new(ldap: mocked_ldap)
end
it 'takes optional filter' do
@ -67,7 +68,8 @@ RSpec.describe Ldap::User do
it 'creates own Ldap instance if none given' do
expect(Ldap).to receive(:new)
expect(described_class.new())
described_class.new()
end
end

View file

@ -233,13 +233,13 @@ RSpec.describe Ldap do
context '#search' do
let(:base) { 'DC=domain,DC=tld' }
let(:filter) { '(objectClass=user)' }
it 'responds to #search' do
expect(instance).to respond_to(:search)
end
let(:filter) { '(objectClass=user)' }
let(:base) { 'DC=domain,DC=tld' }
it 'performs search for a filter, base and scope and yields of returned entries' do
scope = Net::LDAP::SearchScope_BaseObject
@ -309,12 +309,12 @@ RSpec.describe Ldap do
context '#entries?' do
let(:filter) { '(objectClass=user)' }
it 'responds to #entries?' do
expect(instance).to respond_to(:entries?)
end
let(:filter) { '(objectClass=user)' }
it 'returns true if entries are present' do
params = {

View file

@ -6,12 +6,12 @@ RSpec.describe Mail::Encodings do
# Then, upstream was fixed, whereas our patch broke.)
describe '.value_decode' do
it 'decodes us-ascii encoded strings' do
expect(Mail::Encodings.value_decode('=?us-ascii?Q?Test?='))
expect(described_class.value_decode('=?us-ascii?Q?Test?='))
.to eql('Test')
end
it 'decodes utf-8 encoded strings' do
expect(Mail::Encodings.value_decode('=?UTF-8?Q? Personal=C3=A4nderung?='))
expect(described_class.value_decode('=?UTF-8?Q? Personal=C3=A4nderung?='))
.to eql(' Personaländerung')
end
end

View file

@ -3,14 +3,14 @@ require 'rails_helper'
RSpec.describe MigrationJob::LdapSamaccountnameToUid do
it 'performs no changes if no LDAP config present' do
expect(Setting).to_not receive(:set)
expect(Setting).not_to receive(:set)
expect(Import::Ldap).to receive(:config).and_return(nil)
described_class.new.perform
end
it 'performs no changes if uid attributes equals' do
expect(Setting).to_not receive(:set)
expect(Setting).not_to receive(:set)
ldap_config = {
'user_uid' => 'samaccountname'

View file

@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe NotificationFactory::Slack do
describe '.template' do
subject(:template) do
NotificationFactory::Slack.template(
described_class.template(
template: action,
locale: 'en-us',
timezone: 'Europe/Berlin',
@ -64,11 +64,8 @@ RSpec.describe NotificationFactory::Slack do
end
context 'for "ticket_escalate"' do
before { ticket.escalation_at = escalation_time }
let(:escalation_time) { Time.zone.parse('2019-04-01T10:00:00Z') }
subject(:template) do
NotificationFactory::Slack.template(
described_class.template(
template: 'ticket_escalation',
locale: 'en-us',
timezone: 'Europe/Berlin',
@ -80,6 +77,10 @@ RSpec.describe NotificationFactory::Slack do
)
end
before { ticket.escalation_at = escalation_time }
let(:escalation_time) { Time.zone.parse('2019-04-01T10:00:00Z') }
it 'returns a hash with subject: <ticket title> (as Markdown heading)' do
expect(template).to include(subject: "# #{ticket.title}")
end

View file

@ -2,7 +2,7 @@ require 'rails_helper'
RSpec.describe NotificationFactory::Template do
subject(:template) do
NotificationFactory::Template.new(template_string, escape)
described_class.new(template_string, escape)
end
describe '#to_s' do

View file

@ -47,6 +47,7 @@ RSpec.describe NotificationFactory do
context 'if no locale given in arguments, but default locale is set' do
before { Setting.set('locale_default', 'de-de') }
let(:rendered_locale) { 'de' }
it 'tries template for default locale' do
@ -56,6 +57,7 @@ RSpec.describe NotificationFactory do
context 'and no such template exists' do
before { Setting.set('locale_default', 'xx') }
let(:rendered_locale) { 'en' }
it 'falls back to en template' do

View file

@ -57,12 +57,12 @@ RSpec.describe PasswordHash do
let(:zammad_sha2) { '{sha2}dd9c764fa7ea18cd992c8600006d3dc3ac983d1ba22e9ba2d71f6207456be0ba' }
it 'requires hash to be not blank' do
expect(described_class.legacy?(nil, pw_plain)).to be_falsy
expect(described_class.legacy?('', pw_plain)).to be_falsy
expect(described_class).not_to be_legacy(nil, pw_plain)
expect(described_class).not_to be_legacy('', pw_plain)
end
it 'requires password to be not nil' do
expect(described_class.legacy?(zammad_sha2, nil)).to be_falsy
expect(described_class).not_to be_legacy(zammad_sha2, nil)
end
it 'detects sha2 hashes' do

View file

@ -34,7 +34,7 @@ returns
selector: {}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
end.to_not raise_error
end.not_to raise_error
end
end
end

View file

@ -2,7 +2,8 @@ require 'rails_helper'
RSpec.describe SearchIndexBackend do
describe '.build_query' do
subject(:query) { SearchIndexBackend.build_query('', query_extension: params) }
subject(:query) { described_class.build_query('', query_extension: params) }
let(:params) { { 'bool' => { 'filter' => { 'term' => { 'a' => 'b' } } } } }
it 'coerces :query_extension hash keys to symbols' do
@ -11,7 +12,7 @@ RSpec.describe SearchIndexBackend do
end
describe '.search' do
subject(:search) { SearchIndexBackend.search(query, index, limit: 3000) }
subject(:search) { described_class.search(query, index, limit: 3000) }
context 'for query with no results' do
let(:query) { 'preferences.notification_sound.enabled:*' }
@ -51,7 +52,7 @@ RSpec.describe SearchIndexBackend do
QUERIES
it 'appends a * to the original query' do
expect(queries.map(&SearchIndexBackend.method(:append_wildcard_to_simple_query)))
expect(queries.map(&described_class.method(:append_wildcard_to_simple_query)))
.to eq(queries.map { |q| "#{q}*" })
end
end
@ -93,7 +94,7 @@ RSpec.describe SearchIndexBackend do
QUERIES
it 'returns the original query verbatim' do
expect(queries.map(&SearchIndexBackend.method(:append_wildcard_to_simple_query)))
expect(queries.map(&described_class.method(:append_wildcard_to_simple_query)))
.to eq(queries)
end
end

View file

@ -54,9 +54,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence
ldap_connection: connection,
import_job: import_job,
)
end.to change {
User.count
}.by(1)
end.to change(User, :count).by(1)
imported_user = User.last
@ -87,9 +85,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence
ldap_connection: connection,
import_job: import_job,
)
end.not_to change {
User.count
}
end.not_to change(User, :count)
imported_user.reload
@ -148,9 +144,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence
ldap_connection: connection,
import_job: import_job,
)
end.to change {
User.count
}.by(1)
end.to change(User, :count).by(1)
imported_user = User.last
@ -181,9 +175,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence
ldap_connection: connection,
import_job: import_job,
)
end.not_to change {
User.count
}
end.not_to change(User, :count)
imported_user.reload

View file

@ -20,7 +20,7 @@ RSpec.describe Sequencer::Unit::Import::Ldap::Users::Lost::Deactivate, sequencer
it 'enforces created_by_id => 1 in newly created History logs' do
expect { process(lost_ids: lost_users.pluck(:id), dry_run: false) }
.to change { History.count }.by(sample_length)
.to change(History, :count).by(sample_length)
expect(History.last(sample_length).pluck(:created_by_id))
.to eq(Array.new(sample_length, 1))

View file

@ -21,7 +21,7 @@ RSpec.describe SignatureDetection do
end
it 'returns the first 510-line substring they share in common' do
expect(SignatureDetection.find_signature(messages)).to eq(<<~SIG.chomp)
expect(described_class.find_signature(messages)).to eq(<<~SIG.chomp)
Mit freundlichen Grüßen
@ -48,7 +48,7 @@ RSpec.describe SignatureDetection do
end
it 'returns the first 510-line substring they share in common' do
expect(SignatureDetection.find_signature(messages)).to eq(<<~SIG.chomp)
expect(described_class.find_signature(messages)).to eq(<<~SIG.chomp)
Freundliche Grüße
@ -75,7 +75,7 @@ RSpec.describe SignatureDetection do
end
it 'converts messages (via #html2text) then returns the first 510-line substring they share in common' do
expect(SignatureDetection.find_signature(messages)).to eq(<<~SIG.chomp)
expect(described_class.find_signature(messages)).to eq(<<~SIG.chomp)
ChristianSmith
Technik
@ -112,7 +112,7 @@ RSpec.describe SignatureDetection do
SIG
it 'returns the line of the message where the signature begins' do
expect(SignatureDetection.find_signature_line(signature, content, content_type)).to eq(10)
expect(described_class.find_signature_line(signature, content, content_type)).to eq(10)
end
end
end
@ -135,7 +135,7 @@ RSpec.describe SignatureDetection do
SIG
it 'converts messages (via #html2text) then returns the line of the message where the signature begins' do
expect(SignatureDetection.find_signature_line(signature, content, content_type)).to eq(11)
expect(described_class.find_signature_line(signature, content, content_type)).to eq(11)
end
end
end
@ -152,7 +152,7 @@ RSpec.describe SignatureDetection do
end
it 'updates the signature-line data of all articles' do
expect { SignatureDetection.rebuild_all_articles }
expect { described_class.rebuild_all_articles }
.to change { articles.first.reload.preferences[:signature_detection] }.to(3)
.and change { articles.second.reload.preferences[:signature_detection] }.to(2)
end

View file

@ -7,19 +7,19 @@ RSpec.describe Stats::TicketWaitingTime do
context 'when given an agent with no tickets' do
it 'returns a hash with 1-day average ticket wait time for user (in minutes)' do
expect(Stats::TicketWaitingTime.generate(user)).to include(handling_time: 0)
expect(described_class.generate(user)).to include(handling_time: 0)
end
it 'returns a hash with 1-day average ticket wait time across users groups (in minutes)' do
expect(Stats::TicketWaitingTime.generate(user)).to include(average_per_agent: 0)
expect(described_class.generate(user)).to include(average_per_agent: 0)
end
it 'returns a hash with verbal grade for average ticket wait time' do
expect(Stats::TicketWaitingTime.generate(user)).to include(state: 'supergood')
expect(described_class.generate(user)).to include(state: 'supergood')
end
it 'returns a hash with decimal score (01) of users risk of falling to a lower grade' do
expect(Stats::TicketWaitingTime.generate(user)).to include(percent: 0.0)
expect(described_class.generate(user)).to include(percent: 0.0)
end
context 'and who belongs to a group with other tickets' do
@ -31,7 +31,7 @@ RSpec.describe Stats::TicketWaitingTime do
end
it 'returns a hash with 1-day average ticket wait time across users groups (in minutes)' do
expect(Stats::TicketWaitingTime.generate(user)).to include(average_per_agent: 60)
expect(described_class.generate(user)).to include(average_per_agent: 60)
end
end
end
@ -45,19 +45,19 @@ RSpec.describe Stats::TicketWaitingTime do
end
it 'returns a hash with 1-day average ticket wait time for user (in minutes)' do
expect(Stats::TicketWaitingTime.generate(user)).to include(handling_time: 60)
expect(described_class.generate(user)).to include(handling_time: 60)
end
it 'returns a hash with 1-day average ticket wait time across users groups (in minutes)' do
expect(Stats::TicketWaitingTime.generate(user)).to include(average_per_agent: 60)
expect(described_class.generate(user)).to include(average_per_agent: 60)
end
it 'returns a hash with verbal grade for average ticket wait time' do
expect(Stats::TicketWaitingTime.generate(user)).to include(state: 'supergood')
expect(described_class.generate(user)).to include(state: 'supergood')
end
it 'returns a hash with decimal score (01) of users risk of falling to a lower grade' do
expect(Stats::TicketWaitingTime.generate(user)).to include(percent: 1.0)
expect(described_class.generate(user)).to include(percent: 1.0)
end
context 'and who belongs to a group with other tickets' do
@ -69,7 +69,7 @@ RSpec.describe Stats::TicketWaitingTime do
end
it 'returns a hash with 1-day average ticket wait time across users groups (in minutes)' do
expect(Stats::TicketWaitingTime.generate(user)).to include(average_per_agent: 90)
expect(described_class.generate(user)).to include(average_per_agent: 90)
end
end
end
@ -81,7 +81,7 @@ RSpec.describe Stats::TicketWaitingTime do
context 'with empty tickets (no articles)' do
it 'returns 0' do
expect(Stats::TicketWaitingTime.calculate_average(ticket.id, start_time)).to eq(0)
expect(described_class.calculate_average(ticket.id, start_time)).to eq(0)
end
end
@ -92,7 +92,7 @@ RSpec.describe Stats::TicketWaitingTime do
end
it 'returns 0' do
expect(Stats::TicketWaitingTime.calculate_average(ticket.id, start_time)).to eq(0)
expect(described_class.calculate_average(ticket.id, start_time)).to eq(0)
end
end
@ -103,7 +103,7 @@ RSpec.describe Stats::TicketWaitingTime do
end
it 'returns elapsed time' do
expect(Stats::TicketWaitingTime.calculate_average(ticket.id, start_time)).to eq(1.minute)
expect(described_class.calculate_average(ticket.id, start_time)).to eq(1.minute)
end
end
@ -115,7 +115,7 @@ RSpec.describe Stats::TicketWaitingTime do
end
it 'ignores them (and measures time to actual response)' do
expect(Stats::TicketWaitingTime.calculate_average(ticket.id, start_time)).to eq(2.minutes)
expect(described_class.calculate_average(ticket.id, start_time)).to eq(2.minutes)
end
end
@ -128,7 +128,7 @@ RSpec.describe Stats::TicketWaitingTime do
end
it 'returns average of elapsed times' do
expect(Stats::TicketWaitingTime.calculate_average(ticket.id, start_time)).to eq(3.minutes)
expect(described_class.calculate_average(ticket.id, start_time)).to eq(3.minutes)
end
end
@ -152,7 +152,7 @@ RSpec.describe Stats::TicketWaitingTime do
end
it 'ignores all edge cases and returns only specified average response time' do
expect(Stats::TicketWaitingTime.calculate_average(ticket.id, start_time)).to eq(3.minutes)
expect(described_class.calculate_average(ticket.id, start_time)).to eq(3.minutes)
end
end
end

View file

@ -10,19 +10,19 @@ RSpec.describe Stats do
end
it 'generates stats' do
expect { Stats.generate }.to_not raise_error
expect { described_class.generate }.not_to raise_error
end
context 'when backend registration is invalid' do
it 'fails for empty registration' do
Setting.set('Stats::TicketWaitingTime', nil)
expect { Stats.generate }.to raise_error(RuntimeError)
expect { described_class.generate }.to raise_error(RuntimeError)
end
it 'fails for unknown backend' do
Setting.set('Stats::TicketWaitingTime', 'Stats::UNKNOWN')
expect { Stats.generate }.to raise_error(LoadError)
expect { described_class.generate }.to raise_error(LoadError)
end
end
end

View file

@ -27,7 +27,7 @@ RSpec.describe UploadCache do
'Content-Disposition' => 'attached',
},
)
end.to change { Store.count }.by(1)
end.to change(Store, :count).by(1)
end
end
@ -72,7 +72,7 @@ RSpec.describe UploadCache do
end
it 'removes all added Store items' do
expect { subject.destroy }.to change { Store.count }.by(-2)
expect { subject.destroy }.to change(Store, :count).by(-2)
end
end
@ -89,7 +89,7 @@ RSpec.describe UploadCache do
end
it 'removes the Store item matching the given ID' do
expect { subject.remove_item(Store.last.id) }.to change { Store.count }.by(-1)
expect { subject.remove_item(Store.last.id) }.to change(Store, :count).by(-1)
end
it 'prevents removage of non UploadCache Store items' do

View file

@ -1,5 +1,6 @@
RSpec.shared_examples 'ApplicationModel::CanAssets' do |associations: [], selectors: [], own_attributes: true|
subject { create(described_class.name.underscore, updated_by_id: admin.id) }
let(:admin) { create(:admin_user) }
describe '#assets (for supplying model data to front-end framework)' do
@ -37,6 +38,7 @@ RSpec.shared_examples 'ApplicationModel::CanAssets' do |associations: [], select
shared_examples 'single association' do
subject { create(described_class.name.underscore, association => single) }
let(:single) { create(reflection.class_name.underscore) }
it 'returns a hash with its asset attributes' do
@ -56,6 +58,7 @@ RSpec.shared_examples 'ApplicationModel::CanAssets' do |associations: [], select
shared_examples 'collection association' do
subject { create(described_class.name.underscore, association => collection) }
let(:collection) { create_list(reflection.class_name.underscore, 5) }
let(:collection_assets) { collection.reduce({}) { |assets_hash, single| single.assets(assets_hash) } }
@ -84,6 +87,7 @@ RSpec.shared_examples 'ApplicationModel::CanAssets' do |associations: [], select
Array(selectors).each do |s|
subject { create(described_class.name.underscore, s => selector) }
let(:selector) { { 'ticket.priority_id' => { operator: 'is', value: [1, 2] } } }
let(:priorities_assets) { Ticket::Priority.first(2).reduce({}) { |asset_hash, priority| priority.assets(asset_hash) } }

View file

@ -19,7 +19,7 @@ RSpec.shared_examples 'ApplicationModel::ChecksImport' do
before { Setting.set('system_init_done', false) }
it 'allows explicit setting of #id attribute' do
expect { subject.save }.not_to change { subject.id }
expect { subject.save }.not_to change(subject, :id)
end
end
@ -30,7 +30,7 @@ RSpec.shared_examples 'ApplicationModel::ChecksImport' do
before { Setting.set('import_mode', false) }
it 'prevents explicit setting of #id attribute' do
expect { subject.save }.to change { subject.id }
expect { subject.save }.to change(subject, :id)
end
end
@ -39,13 +39,13 @@ RSpec.shared_examples 'ApplicationModel::ChecksImport' do
shared_examples 'importable classes' do
it 'allows explicit setting of #id attribute' do
expect { subject.save }.not_to change { subject.id }
expect { subject.save }.not_to change(subject, :id)
end
end
shared_examples 'non-importable classes' do
it 'prevents explicit setting of #id attribute' do
expect { subject.save }.to change { subject.id }
expect { subject.save }.to change(subject, :id)
end
end

View file

@ -11,17 +11,18 @@ RSpec.describe Calendar, type: :model do
subject(:calendar) { build(:calendar, default: true) }
it 'stays true and sets all other calendars to default: false' do
expect { calendar.tap(&:save).reload }.not_to change { calendar.default }
expect { calendar.tap(&:save).reload }.not_to change(calendar, :default)
expect(Calendar.where(default: true) - [calendar]).to be_empty
end
end
context 'when set to true on update' do
subject(:calendar) { create(:calendar, default: false) }
before { calendar.default = true }
it 'stays true and sets all other calendars to default: false' do
expect { calendar.tap(&:save).reload }.not_to change { calendar.default }
expect { calendar.tap(&:save).reload }.not_to change(calendar, :default)
expect(Calendar.where(default: true) - [calendar]).to be_empty
end
end
@ -103,7 +104,7 @@ RSpec.describe Calendar, type: :model do
context 'and neither current date nor iCal URL have changed' do
it 'is idempotent' do
expect { calendar.sync }
.not_to change { calendar.public_holidays }
.not_to change(calendar, :public_holidays)
end
it 'does not create a background job for escalation rebuild' do
calendar # create and sync (1 inital background job is created)
@ -120,7 +121,7 @@ RSpec.describe Calendar, type: :model do
it 'is idempotent' do
expect { calendar.sync }
.not_to change { calendar.public_holidays }
.not_to change(calendar, :public_holidays)
end
it 'does not create a background job for escalation rebuild' do
expect { calendar.sync }
@ -135,7 +136,7 @@ RSpec.describe Calendar, type: :model do
end
it 'appends newly computed event data to #public_holidays' do
expect { calendar.sync }.to change { calendar.public_holidays }.to(
expect { calendar.sync }.to change(calendar, :public_holidays).to(
'2016-12-24' => { 'active' => true, 'summary' => 'Christmas1', 'feed' => Digest::MD5.hexdigest(calendar.ical_url) },
'2017-12-24' => { 'active' => true, 'summary' => 'Christmas1', 'feed' => Digest::MD5.hexdigest(calendar.ical_url) },
'2018-12-24' => { 'active' => true, 'summary' => 'Christmas1', 'feed' => Digest::MD5.hexdigest(calendar.ical_url) },
@ -154,7 +155,7 @@ RSpec.describe Calendar, type: :model do
it 'replaces #public_holidays with event data computed from new iCal URL' do
expect { calendar.save }
.to change { calendar.public_holidays }.to(
.to change(calendar, :public_holidays).to(
'2016-12-24' => { 'active' => true, 'summary' => 'Christmas1', 'feed' => Digest::MD5.hexdigest(calendar.ical_url) },
'2016-12-25' => { 'active' => true, 'summary' => 'Christmas2', 'feed' => Digest::MD5.hexdigest(calendar.ical_url) },
'2017-12-24' => { 'active' => true, 'summary' => 'Christmas1', 'feed' => Digest::MD5.hexdigest(calendar.ical_url) },

View file

@ -40,7 +40,7 @@ RSpec.describe Channel::EmailParser, type: :model do
describe 'auto-creating new users' do
context 'with one unrecognized email address' do
it 'creates one new user' do
expect { Channel::EmailParser.new.process({}, <<~RAW) }.to change { User.count }.by(1)
expect { Channel::EmailParser.new.process({}, <<~RAW) }.to change(User, :count).by(1)
From: #{Faker::Internet.unique.email}
RAW
end
@ -48,7 +48,7 @@ RSpec.describe Channel::EmailParser, type: :model do
context 'with a large number of unrecognized recipient addresses' do
it 'never creates more than 40 users' do
expect { Channel::EmailParser.new.process({}, <<~RAW) }.to change { User.count }.by(40)
expect { Channel::EmailParser.new.process({}, <<~RAW) }.to change(User, :count).by(40)
From: nicole.braun@zammad.org
To: #{Array.new(20) { Faker::Internet.unique.email }.join(', ')}
Cc: #{Array.new(21) { Faker::Internet.unique.email }.join(', ')}
@ -99,8 +99,8 @@ RSpec.describe Channel::EmailParser, type: :model do
it 'creates a ticket and article' do
expect { Channel::EmailParser.new.process({}, raw_mail) }
.to change { Ticket.count }.by(1)
.and change { Ticket::Article.count }.by_at_least(1)
.to change(Ticket, :count).by(1)
.and change(Ticket::Article, :count).by_at_least(1)
end
it 'sets #title to email subject' do
@ -260,7 +260,7 @@ RSpec.describe Channel::EmailParser, type: :model do
shared_examples 'creates a new ticket' do
it 'creates a new ticket' do
expect { described_class.new.process({}, raw_mail) }
.to change { Ticket.count }.by(1)
.to change(Ticket, :count).by(1)
.and not_change { ticket.articles.length }
end
end
@ -656,7 +656,7 @@ RSpec.describe Channel::EmailParser, type: :model do
context 'when "postmaster_sender_is_agent_search_for_customer" setting is true (default)' do
it 'sets ticket.customer to user with To: email' do
expect { Channel::EmailParser.new.process({}, raw_mail) }
.to change { Ticket.count }.by(1)
.to change(Ticket, :count).by(1)
expect(Ticket.last.customer).to eq(customer)
end
@ -667,7 +667,7 @@ RSpec.describe Channel::EmailParser, type: :model do
it 'sets ticket.customer to user with To: email' do
expect { Channel::EmailParser.new.process({}, raw_mail) }
.to change { Ticket.count }.by(1)
.to change(Ticket, :count).by(1)
expect(Ticket.last.customer).to eq(agent)
end
@ -959,7 +959,7 @@ RSpec.describe Channel::EmailParser, type: :model do
it 're-opens a closed ticket' do
expect { described_class.new.process({}, raw_mail) }
.to not_change { Ticket.count }
.to not_change(Ticket, :count)
.and change { ticket.reload.state.name }.to('open')
end
end
@ -972,7 +972,7 @@ RSpec.describe Channel::EmailParser, type: :model do
it 'does not re-open a closed ticket' do
expect { described_class.new.process({}, raw_mail) }
.to not_change { Ticket.count }
.to not_change(Ticket, :count)
.and not_change { ticket.reload.state.name }
end
end

View file

@ -2,7 +2,8 @@ require 'rails_helper'
RSpec.describe Channel::Filter::Match::EmailRegex do
describe '.match' do
subject(:match) { Channel::Filter::Match::EmailRegex.match(value: from, match_rule: sender, check_mode: check_mode) }
subject(:match) { described_class.match(value: from, match_rule: sender, check_mode: check_mode) }
let(:from) { 'foobar@foo.bar' }
context 'in normal (error-suppressing) mode (default)' do

View file

@ -49,7 +49,7 @@ RSpec.describe Channel do
it 'adds tickets as appropriate' do
expect { twitter_channel.fetch(true) }
.to change { Ticket.count }.by(26)
.to change(Ticket, :count).by(26)
expect(Ticket.last.attributes).to include(
'title' => 'Wir haben unsere DMs deaktiviert. ' \

View file

@ -1,6 +1,7 @@
RSpec.shared_examples 'HasGroups' do |group_access_factory:|
context 'group' do
subject { create(group_access_factory) }
let(:group_full) { create(:group) }
let(:group_read) { create(:group) }
let(:group_inactive) { create(:group, active: false) }
@ -45,7 +46,7 @@ RSpec.shared_examples 'HasGroups' do |group_access_factory:|
context 'result' do
before(:each) do
before do
subject.group_names_access_map = {
group_full.name => 'full',
group_read.name => 'read',
@ -78,16 +79,16 @@ RSpec.shared_examples 'HasGroups' do |group_access_factory:|
context '#group_access?' do
it 'responds to group_access?' do
expect(subject).to respond_to(:group_access?)
end
before(:each) do
before do
subject.group_names_access_map = {
group_read.name => 'read',
}
end
it 'responds to group_access?' do
expect(subject).to respond_to(:group_access?)
end
context 'Group ID parameter' do
include_examples '#group_access? call' do
let(:group_parameter) { group_read.id }
@ -121,16 +122,16 @@ RSpec.shared_examples 'HasGroups' do |group_access_factory:|
context '#group_ids_access' do
it 'responds to group_ids_access' do
expect(subject).to respond_to(:group_ids_access)
end
before(:each) do
before do
subject.group_names_access_map = {
group_read.name => 'read',
}
end
it 'responds to group_ids_access' do
expect(subject).to respond_to(:group_ids_access)
end
it 'lists only active Group IDs' do
subject.group_names_access_map = {
group_read.name => 'read',
@ -531,16 +532,16 @@ RSpec.shared_examples 'HasGroups' do |group_access_factory:|
context '.group_access' do
it 'responds to group_access' do
expect(described_class).to respond_to(:group_access)
end
before(:each) do
before do
subject.group_names_access_map = {
group_read.name => 'read',
}
end
it 'responds to group_access' do
expect(described_class).to respond_to(:group_access)
end
it 'lists only active instances' do
subject.update!(active: false)

View file

@ -1,9 +1,10 @@
RSpec.shared_examples 'HasGroups and Permissions' do |group_access_no_permission_factory:|
context 'group' do
subject { build(group_access_no_permission_factory) }
let(:group_read) { create(:group) }
before(:each) do
before do
subject.group_names_access_map = {
group_read.name => 'read',
}

View file

@ -1,6 +1,7 @@
RSpec.shared_examples 'HasRoles' do |group_access_factory:|
context 'role' do
subject { create(group_access_factory) }
let(:role) { create(:role) }
let(:group_instance) { create(:group) }
let(:group_role) { create(:group) }
@ -13,7 +14,7 @@ RSpec.shared_examples 'HasRoles' do |group_access_factory:|
end
context 'active Role' do
before(:each) do
before do
role.group_names_access_map = {
group_role.name => 'read',
}
@ -58,7 +59,7 @@ RSpec.shared_examples 'HasRoles' do |group_access_factory:|
context '.role_access_ids' do
before(:each) do
before do
role.group_names_access_map = {
group_role.name => 'read',
}
@ -101,7 +102,7 @@ RSpec.shared_examples 'HasRoles' do |group_access_factory:|
context 'group' do
before(:each) do
before do
role.group_names_access_map = {
group_role.name => 'read',
}
@ -129,7 +130,7 @@ RSpec.shared_examples 'HasRoles' do |group_access_factory:|
context '#group_ids_access' do
before(:each) do
before do
role.group_names_access_map = {
group_role.name => 'read',
}

View file

@ -3,13 +3,13 @@ RSpec.shared_examples 'HasSearchIndexBackend' do |indexed_factory:|
context '#search_index_update', performs_jobs: true do
subject { create(indexed_factory) }
before(:each) do
before do
allow(SearchIndexBackend).to receive(:enabled?).and_return(true)
end
context 'record indexing' do
before(:each) do
before do
expect(subject).to be_present
end

View file

@ -2,6 +2,7 @@ RSpec.shared_examples 'HasXssSanitizedNote' do |model_factory:|
describe 'XSS prevention' do
context 'with injected JS' do
subject { create(model_factory, note: 'test 123 <script type="text/javascript">alert("XSS!");</script> <b>some text</b>') }
it 'strips out <script> tag' do
expect(subject.note).to eq('test 123 alert("XSS!"); <b>some text</b>')
end

View file

@ -97,16 +97,17 @@ RSpec.describe Cti::CallerId do
describe '.lookup' do
context 'when given an unrecognized number' do
it 'returns an empty array' do
expect(Cti::CallerId.lookup('1')).to eq([])
expect(described_class.lookup('1')).to eq([])
end
end
context 'when given a recognized number' do
subject!(:caller_id) { create(:caller_id, caller_id: number) }
let(:number) { '1234567890' }
it 'returns an array with the corresponding CallerId' do
expect(Cti::CallerId.lookup(number)).to match_array([caller_id])
expect(described_class.lookup(number)).to match_array([caller_id])
end
context 'shared by multiple CallerIds' do
@ -117,7 +118,7 @@ RSpec.describe Cti::CallerId do
end
it 'returns all corresponding CallerId records' do
expect(Cti::CallerId.lookup(number)).to match_array(caller_ids)
expect(described_class.lookup(number)).to match_array(caller_ids)
end
end
@ -125,7 +126,7 @@ RSpec.describe Cti::CallerId do
subject!(:caller_ids) { create_list(:caller_id, 2, caller_id: number) }
it 'returns one corresponding CallerId record by MAX(id)' do
expect(Cti::CallerId.lookup(number)).to match_array(caller_ids.last(1))
expect(described_class.lookup(number)).to match_array(caller_ids.last(1))
end
end
@ -137,7 +138,7 @@ RSpec.describe Cti::CallerId do
end
it 'returns one CallerId record per unique #user_id, by MAX(id)' do
expect(Cti::CallerId.lookup(number)).to match_array(caller_ids.last(2))
expect(described_class.lookup(number)).to match_array(caller_ids.last(2))
end
end
end
@ -150,16 +151,16 @@ RSpec.describe Cti::CallerId do
context 'and no corresponding CallerId exists' do
it 'generates a CallerId record (with #level "known")' do
Cti::CallerId.destroy_all # CallerId already generated in User callback
described_class.destroy_all # CallerId already generated in User callback
expect { Cti::CallerId.rebuild }
.to change { Cti::CallerId.exists?(user_id: user.id, caller_id: '49123456', level: 'known') }
expect { described_class.rebuild }
.to change { described_class.exists?(user_id: user.id, caller_id: '49123456', level: 'known') }
.to(true)
end
end
it 'does not create duplicate CallerId records' do
expect { Cti::CallerId.rebuild }.not_to change { Cti::CallerId.count }
expect { described_class.rebuild }.not_to change(described_class, :count)
end
end
@ -167,8 +168,8 @@ RSpec.describe Cti::CallerId do
subject!(:caller_id) { create(:caller_id) }
it 'deletes the CallerId record' do
expect { Cti::CallerId.rebuild }
.to change { Cti::CallerId.exists?(caller_id.id) }.to(false)
expect { described_class.rebuild }
.to change { described_class.exists?(caller_id.id) }.to(false)
end
end
@ -176,12 +177,12 @@ RSpec.describe Cti::CallerId do
let!(:users) { create_list(:agent_user, 2, phone: '+49 123 456') }
it 'generates two corresponding CallerId records (with #level "known")' do
Cti::CallerId.destroy_all # CallerId already generated in User callback
described_class.destroy_all # CallerId already generated in User callback
expect { Cti::CallerId.rebuild }
.to change { Cti::CallerId.exists?(user_id: users.first.id, caller_id: '49123456', level: 'known') }
expect { described_class.rebuild }
.to change { described_class.exists?(user_id: users.first.id, caller_id: '49123456', level: 'known') }
.to(true)
.and change { Cti::CallerId.exists?(user_id: users.last.id, caller_id: '49123456', level: 'known') }
.and change { described_class.exists?(user_id: users.last.id, caller_id: '49123456', level: 'known') }
.to(true)
end
end
@ -196,10 +197,10 @@ RSpec.describe Cti::CallerId do
let(:sender_name) { 'Customer' }
it 'generates a CallerId record (with #level "maybe")' do
Cti::CallerId.destroy_all # CallerId already generated in Article observer job
described_class.destroy_all # CallerId already generated in Article observer job
expect { Cti::CallerId.rebuild }
.to change { Cti::CallerId.exists?(user_id: article.created_by_id, caller_id: '49123456', level: 'maybe') }
expect { described_class.rebuild }
.to change { described_class.exists?(user_id: article.created_by_id, caller_id: '49123456', level: 'maybe') }
.to(true)
end
end
@ -208,8 +209,8 @@ RSpec.describe Cti::CallerId do
let(:sender_name) { 'Agent' }
it 'does not generate a CallerId record' do
expect { Cti::CallerId.rebuild }
.not_to change { Cti::CallerId.exists?(caller_id: '49123456') }
expect { described_class.rebuild }
.not_to change { described_class.exists?(caller_id: '49123456') }
end
end
end
@ -219,20 +220,20 @@ RSpec.describe Cti::CallerId do
let(:attributes) { attributes_for(:caller_id) }
it 'wraps .find_or_initialize_by (passing only five defining attributes)' do
expect(Cti::CallerId)
expect(described_class)
.to receive(:find_or_initialize_by)
.with(attributes.slice(:caller_id, :level, :object, :o_id, :user_id))
.and_call_original
Cti::CallerId.maybe_add(attributes)
described_class.maybe_add(attributes)
end
context 'if no matching record found' do
it 'adds given #comment attribute' do
expect { Cti::CallerId.maybe_add(attributes.merge(comment: 'foo')) }
.to change { Cti::CallerId.count }.by(1)
expect { described_class.maybe_add(attributes.merge(comment: 'foo')) }
.to change(described_class, :count).by(1)
expect(Cti::CallerId.last.comment).to eq('foo')
expect(described_class.last.comment).to eq('foo')
end
end
@ -241,7 +242,7 @@ RSpec.describe Cti::CallerId do
let(:caller_id) { create(:caller_id) }
it 'ignores given #comment attribute' do
expect(Cti::CallerId.maybe_add(attributes.merge(comment: 'foo')))
expect(described_class.maybe_add(attributes.merge(comment: 'foo')))
.to eq(caller_id)
expect(caller_id.comment).to be_blank
@ -251,6 +252,7 @@ RSpec.describe Cti::CallerId do
describe 'callbacks' do
subject!(:caller_id) { build(:cti_caller_id, caller_id: phone) }
let(:phone) { '1234567890' }
describe 'on creation' do

View file

@ -5,7 +5,7 @@ RSpec.describe Cti::Log do
describe '.log' do
it 'returns a hash with :list and :assets keys' do
expect(Cti::Log.log).to be_a(Hash).and include(:list, :assets)
expect(described_class.log).to be_a(Hash).and include(:list, :assets)
end
context 'when over 60 Log records exist' do
@ -17,17 +17,18 @@ RSpec.describe Cti::Log do
end
it 'returns the 60 latest ones in the :list key' do
expect(Cti::Log.log[:list]).to match_array(cti_logs.last(60))
expect(described_class.log[:list]).to match_array(cti_logs.last(60))
end
end
context 'when Log records have arrays of CallerId attributes in #preferences[:to] / #preferences[:from]' do
subject!(:cti_log) { create(:'cti/log', preferences: { from: [caller_id] }) }
let(:caller_id) { create(:caller_id) }
let(:user) { User.find_by(id: caller_id.user_id) }
it 'returns a hash of the CallerId Users and their assets in the :assets key' do
expect(Cti::Log.log[:assets]).to eq(user.assets({}))
expect(described_class.log[:assets]).to eq(user.assets({}))
end
end
end
@ -52,33 +53,35 @@ RSpec.describe Cti::Log do
context 'with unrecognized "call_id"' do
it 'creates a new Log record (#state: "newCall", #done: false)' do
expect { Cti::Log.process(attributes) }
.to change { Cti::Log.count }.by(1)
expect { described_class.process(attributes) }
.to change(described_class, :count).by(1)
expect(Cti::Log.last.attributes)
expect(described_class.last.attributes)
.to include('state' => 'newCall', 'done' => false)
end
context 'for direction "in", with a CallerId record matching the "from" number' do
let!(:caller_id) { create(:caller_id, caller_id: '49123456') }
before { attributes.merge!('direction' => 'in') }
it 'saves that CallerIds attributes in the new Logs #preferences[:from] attribute' do
Cti::Log.process(attributes)
described_class.process(attributes)
expect(Cti::Log.last.preferences[:from].first)
expect(described_class.last.preferences[:from].first)
.to include(caller_id.attributes.except('created_at')) # Checking equality of Time objects is error-prone
end
end
context 'for direction "out", with a CallerId record matching the "to" number' do
let!(:caller_id) { create(:caller_id, caller_id: '49123457') }
before { attributes.merge!('direction' => 'out') }
it 'saves that CallerIds attributes in the new Logs #preferences[:to] attribute' do
Cti::Log.process(attributes)
described_class.process(attributes)
expect(Cti::Log.last.preferences[:to].first)
expect(described_class.last.preferences[:to].first)
.to include(caller_id.attributes.except('created_at')) # Checking equality of Time objects is error-prone
end
end
@ -88,7 +91,7 @@ RSpec.describe Cti::Log do
before { create(:'cti/log', call_id: '1') }
it 'raises an error' do
expect { Cti::Log.process(attributes) }.to raise_error(/call_id \S+ already exists!/)
expect { described_class.process(attributes) }.to raise_error(/call_id \S+ already exists!/)
end
end
end
@ -98,7 +101,7 @@ RSpec.describe Cti::Log do
context 'with unrecognized "call_id"' do
it 'raises an error' do
expect { Cti::Log.process(attributes) }.to raise_error(/No such call_id/)
expect { described_class.process(attributes) }.to raise_error(/No such call_id/)
end
end
@ -107,7 +110,7 @@ RSpec.describe Cti::Log do
let(:log) { create(:'cti/log', call_id: 1, state: 'newCall', done: false) }
it 'returns early with no changes' do
expect { Cti::Log.process(attributes) }
expect { described_class.process(attributes) }
.to change { log.reload.state }.to('answer')
.and change { log.reload.done }.to(true)
end
@ -117,8 +120,8 @@ RSpec.describe Cti::Log do
let(:log) { create(:'cti/log', call_id: 1, state: 'hangup', done: false) }
it 'returns early with no changes' do
expect { Cti::Log.process(attributes) }
.not_to change { log.reload }
expect { described_class.process(attributes) }
.not_to change(log, :reload)
end
end
end
@ -129,7 +132,7 @@ RSpec.describe Cti::Log do
context 'with unrecognized "call_id"' do
it 'raises an error' do
expect { Cti::Log.process(attributes) }.to raise_error(/No such call_id/)
expect { described_class.process(attributes) }.to raise_error(/No such call_id/)
end
end
@ -138,7 +141,7 @@ RSpec.describe Cti::Log do
let(:log) { create(:'cti/log', call_id: 1, state: 'newCall', done: false) }
it 'sets attributes #state: "hangup", #done: false' do
expect { Cti::Log.process(attributes) }
expect { described_class.process(attributes) }
.to change { log.reload.state }.to('hangup')
.and not_change { log.reload.done }
end
@ -147,7 +150,7 @@ RSpec.describe Cti::Log do
let(:cause) { 'forwarded' }
it 'sets attributes #state: "hangup", #done: true' do
expect { Cti::Log.process(attributes) }
expect { described_class.process(attributes) }
.to change { log.reload.state }.to('hangup')
.and change { log.reload.done }.to(true)
end
@ -158,7 +161,7 @@ RSpec.describe Cti::Log do
let(:log) { create(:'cti/log', call_id: 1, state: 'answer', done: true) }
it 'sets attributes #state: "hangup"' do
expect { Cti::Log.process(attributes) }
expect { described_class.process(attributes) }
.to change { log.reload.state }.to('hangup')
.and not_change { log.reload.done }
end
@ -167,7 +170,7 @@ RSpec.describe Cti::Log do
before { log.update(to_comment: 'voicemail') }
it 'sets attributes #state: "hangup", #done: false' do
expect { Cti::Log.process(attributes) }
expect { described_class.process(attributes) }
.to change { log.reload.state }.to('hangup')
.and change { log.reload.done }.to(false)
end

View file

@ -43,6 +43,7 @@ RSpec.describe EmailAddress, type: :model do
describe '#channel' do
subject(:email_addresses) { create_list(:email_address, 2, channel: channel) }
let(:channel) { create(:channel) }
context 'when a Channel is destroyed' do

View file

@ -515,7 +515,7 @@ RSpec.describe Job, type: :model do
it 'is set automatically on save (cannot be set manually)' do
job.next_run_at = 1.day.from_now
expect { job.save }.to change { job.next_run_at }
expect { job.save }.to change(job, :next_run_at)
end
context 'for an inactive Job' do
@ -523,7 +523,7 @@ RSpec.describe Job, type: :model do
it 'is nil' do
expect { job.save }
.not_to change { job.next_run_at }.from(nil)
.not_to change(job, :next_run_at).from(nil)
end
end
@ -532,12 +532,13 @@ RSpec.describe Job, type: :model do
it 'is nil' do
expect { job.save }
.not_to change { job.next_run_at }.from(nil)
.not_to change(job, :next_run_at).from(nil)
end
end
context 'when #timeplan contains at least one true value for :day, :hour, and :minute' do
subject(:job) { build(:job, :never_on) }
let(:base_time) { Time.current.beginning_of_week }
# Tuesday & Thursday @ 12:00a, 12:30a, 6:00p, and 6:30p

View file

@ -16,7 +16,7 @@ RSpec.describe ObjectLookup, type: :model do
it 'creates a new one with that name' do
expect { ObjectLookup.by_name(name) }
.to change { ObjectLookup.count }.by(1)
.to change(ObjectLookup, :count).by(1)
expect(ObjectLookup.last.name).to eq(name)
end

View file

@ -11,9 +11,6 @@ RSpec.describe ObjectManager::Attribute::Validation::Backend do
describe 'backend interface' do
let(:record) { build(:user) }
let(:attribute) { ::ObjectManager::Attribute.find_by(name: 'firstname') }
subject do
described_class.new(
record: record,
@ -21,6 +18,9 @@ RSpec.describe ObjectManager::Attribute::Validation::Backend do
)
end
let(:record) { build(:user) }
let(:attribute) { ::ObjectManager::Attribute.find_by(name: 'firstname') }
it 'has attr_accessor for record' do
expect(subject.record).to eq(record)
end

View file

@ -3,8 +3,6 @@ require 'models/object_manager/attribute/validation/backend_examples'
RSpec.describe ::ObjectManager::Attribute::Validation::FuturePast do
let(:record) { build(:user) }
let(:attribute) { build(:object_manager_attribute_datetime) }
subject do
described_class.new(
record: record,
@ -12,6 +10,9 @@ RSpec.describe ::ObjectManager::Attribute::Validation::FuturePast do
)
end
let(:record) { build(:user) }
let(:attribute) { build(:object_manager_attribute_datetime) }
before do
allow(subject).to receive(:value).and_return(value)
end

View file

@ -3,8 +3,6 @@ require 'models/object_manager/attribute/validation/backend_examples'
RSpec.describe ::ObjectManager::Attribute::Validation::Required do
let(:record) { build(:user) }
let(:attribute) { build(:object_manager_attribute_date) }
subject do
described_class.new(
record: record,
@ -12,6 +10,9 @@ RSpec.describe ::ObjectManager::Attribute::Validation::Required do
)
end
let(:record) { build(:user) }
let(:attribute) { build(:object_manager_attribute_date) }
before do
allow(subject).to receive(:value).and_return(value)
end

View file

@ -11,6 +11,7 @@ RSpec.describe ObjectManager::Attribute::Validation, application_handle: 'applic
describe '#validate' do
subject { described_class.new }
let(:record) { build(:user) }
let(:backend) { spy }
@ -63,13 +64,13 @@ RSpec.describe ObjectManager::Attribute::Validation, application_handle: 'applic
it 'is skipped because of irrelevant ApplicationHandleInfo', application_handle: 'non_application_server' do
subject.validate(record)
expect(backend).to_not have_received(:validate)
expect(backend).not_to have_received(:validate)
end
it 'is skipped because of import_mode is active' do
expect(Setting).to receive(:get).with('import_mode').and_return(true)
subject.validate(record)
expect(backend).to_not have_received(:validate)
expect(backend).not_to have_received(:validate)
end
it 'is skipped because of unchanged attributes' do

View file

@ -77,7 +77,7 @@ RSpec.describe ObjectManager::Attribute, type: :model do
ObjectManager::Attribute.add attribute
expect do
ObjectManager::Attribute.add attribute
end.to_not raise_error
end.not_to raise_error
end
it 'accepts duplicate attribute name on compatible types (editing the type of an existing attribute)' do
@ -87,13 +87,13 @@ RSpec.describe ObjectManager::Attribute, type: :model do
attribute[:data_option_new] = { default: '', options: { 'a' => 'a' } }
expect do
ObjectManager::Attribute.add attribute
end.to_not raise_error
end.not_to raise_error
end
it 'accepts valid attribute names' do
expect do
ObjectManager::Attribute.add attributes_for :object_manager_attribute_text
end.to_not raise_error
end.not_to raise_error
end
end
end

View file

@ -138,7 +138,7 @@ RSpec.describe RecentView, type: :model do
it 'wraps RecentView.create' do
expect do
described_class.log(viewed_object.class.name, viewed_object.id, admin)
end.to change { RecentView.count }.by(1)
end.to change(RecentView, :count).by(1)
end
describe 'access privileges' do
@ -152,7 +152,7 @@ RSpec.describe RecentView, type: :model do
expect do
described_class.log(viewed_object.class.name, viewed_object.id, agent)
end.not_to change { RecentView.count }
end.not_to change(RecentView, :count)
end
end
@ -160,19 +160,19 @@ RSpec.describe RecentView, type: :model do
it 'does not create RecentView for non-existent record' do
expect do
described_class.log('User', 99_999_999, admin)
end.not_to change { RecentView.count }
end.not_to change(RecentView, :count)
end
it 'does not create RecentView for instance of non-ObjectLookup class' do
expect do
described_class.log('Overview', 1, admin)
end.not_to change { RecentView.count }
end.not_to change(RecentView, :count)
end
it 'does not create RecentView for instance of non-existent class' do
expect do
described_class.log('NonExistentClass', 1, admin)
end.not_to change { RecentView.count }
end.not_to change(RecentView, :count)
end
end
end

View file

@ -13,27 +13,27 @@ RSpec.describe Role do
describe 'Default state' do
describe 'of whole table:' do
it 'has three records ("Admin", "Agent", and "Customer")' do
expect(Role.pluck(:name)).to match_array(%w[Admin Agent Customer])
expect(described_class.pluck(:name)).to match_array(%w[Admin Agent Customer])
end
end
describe 'of "Admin" role:' do
it 'has default admin permissions' do
expect(Role.find_by(name: 'Admin').permissions.pluck(:name))
expect(described_class.find_by(name: 'Admin').permissions.pluck(:name))
.to match_array(%w[admin user_preferences report])
end
end
describe 'of "Agent" role:' do
it 'has default agent permissions' do
expect(Role.find_by(name: 'Agent').permissions.pluck(:name))
expect(described_class.find_by(name: 'Agent').permissions.pluck(:name))
.to match_array(%w[ticket.agent chat.agent cti.agent user_preferences])
end
end
describe 'of "Customer" role:' do
it 'has default customer permissions' do
expect(Role.find_by(name: 'Customer').permissions.pluck(:name))
expect(described_class.find_by(name: 'Customer').permissions.pluck(:name))
.to match_array(
%w[
user_preferences.password
@ -54,7 +54,7 @@ RSpec.describe Role do
it 'can be created' do
expect { create(:role, permissions: [permission]) }
.to change { Role.count }.by(1)
.to change(described_class, :count).by(1)
end
it 'can be added' do
@ -69,7 +69,7 @@ RSpec.describe Role do
it 'cannot be created' do
expect { create(:role, permissions: [permission]) }
.to raise_error(/is disabled/)
.and change { Role.count }.by(0)
.and change(described_class, :count).by(0)
end
it 'cannot be added' do
@ -85,7 +85,7 @@ RSpec.describe Role do
it 'cannot be created' do
expect { create(:role, permissions: [Permission.first, permission]) }
.to raise_error(/conflicts with/)
.and change { Role.count }.by(0)
.and change(described_class, :count).by(0)
end
it 'cannot be added' do
@ -102,7 +102,7 @@ RSpec.describe Role do
it 'can be created' do
expect { create(:role, permissions: [Permission.first, permission]) }
.to change { Role.count }.by(1)
.to change(described_class, :count).by(1)
end
it 'can be added' do
@ -119,16 +119,17 @@ RSpec.describe Role do
describe '#validate_agent_limit_by_attributes' do
context 'when reactivating a role adds new agents' do
before { create(:user, roles: [role]) }
subject(:role) { create(:agent_role, active: false) }
before { create(:user, roles: [role]) }
context 'exceeding the system limit' do
before { Setting.set('system_agent_limit', agents.count) }
it 'fails and raises an error' do
expect { role.update!(active: true) }
.to raise_error(Exceptions::UnprocessableEntity)
.and change { agents.count }.by(0)
.and change(agents, :count).by(0)
end
end
end
@ -156,6 +157,7 @@ RSpec.describe Role do
context 'for roles with permissions that are children of "admin"' do
subject(:role) { build(:role, permissions: [permission]) }
let(:permission) { create(:permission, name: 'admin.foo') }
it 'cannot be set to true on creation' do
@ -199,40 +201,40 @@ RSpec.describe Role do
let(:result) { [] }
it 'returns an empty array' do
expect(Role.with_permissions(permission)).to match_array(result)
expect(described_class.with_permissions(permission)).to match_array(result)
end
end
context 'when given the name of a top-level permission' do
let(:permission) { 'user_preferences' }
let(:result) { Role.where(name: %w[Admin Agent]) }
let(:result) { described_class.where(name: %w[Admin Agent]) }
it 'returns an array of roles with that permission' do
expect(Role.with_permissions(permission)).to match_array(result)
expect(described_class.with_permissions(permission)).to match_array(result)
end
end
context 'when given the name of a child permission' do
let(:permission) { 'user_preferences.language' }
let(:result) { Role.all }
let(:result) { described_class.all }
it 'returns an array of roles with either that permission or an ancestor' do
expect(Role.with_permissions(permission)).to match_array(result)
expect(described_class.with_permissions(permission)).to match_array(result)
end
end
context 'when given the names of multiple permissions' do
let(:permissions) { %w[ticket.agent ticket.customer] }
let(:result) { Role.where(name: %w[Agent Customer]) }
let(:result) { described_class.where(name: %w[Agent Customer]) }
it 'returns an array of roles matching ANY given permission' do
expect(Role.with_permissions(permissions)).to match_array(result)
expect(described_class.with_permissions(permissions)).to match_array(result)
end
end
end
describe '#with_permission?' do
subject(:role) { Role.find_by(name: 'Admin') }
subject(:role) { described_class.find_by(name: 'Admin') }
context 'when given the name of a permission it has' do
it 'returns true' do

View file

@ -22,6 +22,7 @@ RSpec.describe Setting, type: :model do
context 'when #preferences hash includes a :cache key' do
subject(:setting) { create(:setting, preferences: { cache: ['foo'] }) }
before { Cache.write('foo', 'bar') }
it 'resets the cache key' do
@ -49,7 +50,7 @@ RSpec.describe Setting, type: :model do
it 'is set on creation, based on #state' do
expect { setting.save }
.to change { setting.state_initial }.from({}).to({ value: 'foo' })
.to change(setting, :state_initial).from({}).to({ value: 'foo' })
end
end
end

View file

@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe Tag do
context 'rename' do
before(:each) do
before do
Tag::Item.lookup_by_name_and_create('test1')
end

View file

@ -6,7 +6,7 @@ RSpec.describe Taskbar do
let(:taskbar) do
Taskbar.destroy_all
described_class.destroy_all
UserInfo.current_user_id = 1
create(:taskbar, params: {
@ -81,9 +81,9 @@ RSpec.describe Taskbar do
it 'create tasks' do
Taskbar.destroy_all
described_class.destroy_all
UserInfo.current_user_id = 1
taskbar1 = Taskbar.create(
taskbar1 = described_class.create(
client_id: 123,
key: 'Ticket-1234',
callback: 'TicketZoom',
@ -96,7 +96,7 @@ RSpec.describe Taskbar do
)
UserInfo.current_user_id = 2
taskbar2 = Taskbar.create(
taskbar2 = described_class.create(
client_id: 123,
key: 'Ticket-1234',
callback: 'TicketZoom',
@ -122,7 +122,7 @@ RSpec.describe Taskbar do
expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2)
expect(taskbar2.preferences[:tasks][1][:changed]).to eq(false)
taskbar3 = Taskbar.create(
taskbar3 = described_class.create(
client_id: 123,
key: 'Ticket-4444',
callback: 'TicketZoom',
@ -156,7 +156,7 @@ RSpec.describe Taskbar do
agent_user_id = create(:agent_user).id
UserInfo.current_user_id = agent_user_id
taskbar4 = Taskbar.create(
taskbar4 = described_class.create(
client_id: 123,
key: 'Ticket-1234',
callback: 'TicketZoom',

View file

@ -40,14 +40,14 @@ RSpec.describe Ticket::Article, type: :model do
end
context 'of subsequent articles on a ticket' do
let!(:first_article) do
create(:ticket_article, ticket: ticket, sender_name: 'Agent', type_name: 'email')
end
subject(:article) do
create(:ticket_article, ticket: ticket, sender_name: 'Customer', type_name: 'twitter status')
end
let!(:first_article) do
create(:ticket_article, ticket: ticket, sender_name: 'Agent', type_name: 'email')
end
it 'does not modify tickets sender/type attributes' do
expect { article }
.to not_change { ticket.reload.create_article_sender.name }
@ -243,6 +243,7 @@ RSpec.describe Ticket::Article, type: :model do
describe 'DoS protection:' do
context 'when #body exceeds 1.5MB' do
subject(:article) { create(:ticket_article, body: body) }
let(:body) { 'a' * 2_000_000 }
context 'for "web" thread', application_handle: 'web' do
@ -296,6 +297,7 @@ RSpec.describe Ticket::Article, type: :model do
describe 'Auto-setting of outgoing Twitter article attributes (via bg jobs):' do
subject!(:twitter_article) { create(:twitter_article, sender_name: 'Agent') }
let(:channel) { Channel.find(twitter_article.ticket.preferences[:channel_id]) }
let(:run_bg_jobs) do

View file

@ -26,7 +26,7 @@ RSpec.describe Ticket::Overviews do
}
overview = create(:overview, condition: condition)
result = Ticket::Overviews.index(user)
result = described_class.index(user)
result = result.select { |x| x[:overview][:name] == overview.name }
expect(result.count).to be == 1

View file

@ -10,7 +10,7 @@ RSpec.describe Ticket::TimeAccounting, type: :model do
context 'when destroyed' do
it 'destroys self' do
expect { time_accounting.ticket_article.destroy }
.to change { time_accounting.persisted? }.to(false)
.to change(time_accounting, :persisted?).to(false)
.and change { Ticket::TimeAccounting.count }.by(-1)
end

View file

@ -159,7 +159,7 @@ RSpec.describe Ticket, type: :model do
it 'performs a ticket deletion on a ticket' do
expect { ticket.perform_changes(perform, 'trigger', ticket, User.first) }
.to change { ticket.destroyed? }.to(true)
.to change(ticket, :destroyed?).to(true)
end
end
@ -242,6 +242,7 @@ RSpec.describe Ticket, type: :model do
context 'but the user is a customer from the same organization as tickets customer' do
subject(:ticket) { create(:ticket, customer: customer) }
let(:customer) { create(:customer_user, organization: create(:organization)) }
let(:colleague) { create(:customer_user, organization: customer.organization) }
@ -469,7 +470,7 @@ RSpec.describe Ticket, type: :model do
context 'when #state is updated to any non-"pending" value' do
it 'is reset to nil' do
expect { ticket.update!(state: Ticket::State.lookup(name: 'open')) }
.to change { ticket.pending_time }.to(nil)
.to change(ticket, :pending_time).to(nil)
end
end
@ -484,6 +485,7 @@ RSpec.describe Ticket, type: :model do
describe '#escalation_at' do
before { travel_to(Time.current) } # freeze time
let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 180, solution_time: 240) }
let(:calendar) { create(:calendar, :'24/7') }
@ -503,6 +505,7 @@ RSpec.describe Ticket, type: :model do
context 'after first agents response' do
before { ticket } # create ticket
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
it 'is updated based on the SLAs #update_time' do
@ -526,8 +529,10 @@ RSpec.describe Ticket, type: :model do
end
context 'when updated after an SLA has been added to the system' do
before { ticket } # create ticket
before { sla } # create sla
before do
ticket # create ticket
sla # create sla
end
it 'is updated based on the new SLAs #first_response_time' do
expect { ticket.save! }
@ -536,19 +541,22 @@ RSpec.describe Ticket, type: :model do
end
context 'when updated after all SLAs have been removed from the system' do
before { sla } # create sla
before { ticket } # create ticket
before { sla.destroy }
before do
sla # create sla
ticket # create ticket
sla.destroy
end
it 'is set to nil' do
expect { ticket.save! }
.to change { ticket.escalation_at }.to(nil)
.to change(ticket, :escalation_at).to(nil)
end
end
end
describe '#first_response_escalation_at' do
before { travel_to(Time.current) } # freeze time
let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 180, solution_time: 240) }
let(:calendar) { create(:calendar, :'24/7') }
@ -568,10 +576,11 @@ RSpec.describe Ticket, type: :model do
context 'after first agents response' do
before { ticket } # create ticket
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
it 'does not change' do
expect { article }.not_to change { ticket.first_response_escalation_at }
expect { article }.not_to change(ticket, :first_response_escalation_at)
end
end
end
@ -579,6 +588,7 @@ RSpec.describe Ticket, type: :model do
describe '#update_escalation_at' do
before { travel_to(Time.current) } # freeze time
let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 180, solution_time: 240) }
let(:calendar) { create(:calendar, :'24/7') }
@ -598,6 +608,7 @@ RSpec.describe Ticket, type: :model do
context 'after first agents response' do
before { ticket } # create ticket
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
it 'is updated based on the SLAs #update_time' do
@ -613,6 +624,7 @@ RSpec.describe Ticket, type: :model do
describe '#close_escalation_at' do
before { travel_to(Time.current) } # freeze time
let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 180, solution_time: 240) }
let(:calendar) { create(:calendar, :'24/7') }
@ -632,10 +644,11 @@ RSpec.describe Ticket, type: :model do
context 'after first agents response' do
before { ticket } # create ticket
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
it 'does not change' do
expect { article }.not_to change { ticket.close_escalation_at }
expect { article }.not_to change(ticket, :close_escalation_at)
end
end
end
@ -645,12 +658,13 @@ RSpec.describe Ticket, type: :model do
describe 'Associations:' do
describe '#organization' do
subject(:ticket) { build(:ticket, customer: customer, organization: nil) }
let(:customer) { create(:customer, :with_org) }
context 'on creation' do
it 'automatically adopts the organization of its #customer' do
expect { ticket.save }
.to change { ticket.organization }.to(customer.organization)
.to change(ticket, :organization).to(customer.organization)
end
end
@ -698,6 +712,7 @@ RSpec.describe Ticket, type: :model do
describe 'Cti::CallerId syncing:' do
subject(:ticket) { build(:ticket) }
before { allow(Cti::CallerId).to receive(:build) }
it 'adds numbers in article bodies (via Cti::CallerId.build)' do
@ -711,6 +726,7 @@ RSpec.describe Ticket, type: :model do
describe 'Touching associations on update:' do
subject(:ticket) { create(:ticket, customer: customer) }
let(:customer) { create(:customer_user, organization: organization) }
let(:organization) { create(:organization) }
let(:other_customer) { create(:customer_user, organization: other_organization) }
@ -828,11 +844,12 @@ RSpec.describe Ticket, type: :model do
context 'when ticket is generated from email (with attachments)' do
subject(:ticket) { Channel::EmailParser.new.process({}, raw_email).first }
let(:raw_email) { File.read(Rails.root.join('test', 'data', 'mail', 'mail001.box')) }
it 'adds attachments to the Store{::File,::Provider::DB} tables' do
expect { ticket }
.to change { Store.count }.by(2)
.to change(Store, :count).by(2)
.and change { Store::File.count }.by(2)
.and change { Store::Provider::DB.count }.by(2)
end
@ -842,7 +859,7 @@ RSpec.describe Ticket, type: :model do
ticket # create ticket
expect { ticket.destroy }
.to change { Store.count }.by(-2)
.to change(Store, :count).by(-2)
.and change { Store::File.count }.by(-2)
.and change { Store::Provider::DB.count }.by(-2)
end
@ -850,11 +867,12 @@ RSpec.describe Ticket, type: :model do
context 'and a duplicate ticket is generated from the same email' do
before { ticket } # create ticket
let(:duplicate) { Channel::EmailParser.new.process({}, raw_email).first }
it 'adds duplicate attachments to the Store table only' do
expect { duplicate }
.to change { Store.count }.by(2)
.to change(Store, :count).by(2)
.and change { Store::File.count }.by(0)
.and change { Store::Provider::DB.count }.by(0)
end
@ -864,7 +882,7 @@ RSpec.describe Ticket, type: :model do
duplicate # create ticket
expect { duplicate.destroy }
.to change { Store.count }.by(-2)
.to change(Store, :count).by(-2)
.and change { Store::File.count }.by(0)
.and change { Store::Provider::DB.count }.by(0)
end
@ -875,7 +893,7 @@ RSpec.describe Ticket, type: :model do
duplicate.destroy
expect { ticket.destroy }
.to change { Store.count }.by(-2)
.to change(Store, :count).by(-2)
.and change { Store::File.count }.by(-2)
.and change { Store::Provider::DB.count }.by(-2)
end

View file

@ -37,7 +37,7 @@ RSpec.describe Token, type: :model do
token # create token
expect { Token.check(action: token.action, name: token.name) }
.not_to change { Token.count }
.not_to change(Token, :count)
end
end
end
@ -56,7 +56,7 @@ RSpec.describe Token, type: :model do
token # create token
expect { Token.check(action: token.action, name: token.name) }
.not_to change { Token.count }
.not_to change(Token, :count)
end
end
@ -71,7 +71,7 @@ RSpec.describe Token, type: :model do
token # create token
expect { Token.check(action: token.action, name: token.name) }
.to change { Token.count }.by(-1)
.to change(Token, :count).by(-1)
end
end
end
@ -79,6 +79,7 @@ RSpec.describe Token, type: :model do
describe 'permission matching' do
subject(:token) { create(:api_token, user: agent, preferences: preferences) }
let(:agent) { create(:agent_user) }
let(:preferences) { { permission: %w[admin ticket.agent] } } # agent has no access to admin.*

View file

@ -3,30 +3,30 @@ require 'rails_helper'
RSpec.describe Translation do
before(:all) do
Translation.where(locale: 'de-de').destroy_all
Translation.sync('de-de')
described_class.where(locale: 'de-de').destroy_all
described_class.sync('de-de')
end
context 'default string translations' do
it 'en with existing word' do
expect(Translation.translate('en', 'New')).to eq('New')
expect(described_class.translate('en', 'New')).to eq('New')
end
it 'en-us with existing word' do
expect(Translation.translate('en-us', 'New')).to eq('New')
expect(described_class.translate('en-us', 'New')).to eq('New')
end
it 'en with not existing word' do
expect(Translation.translate('en', 'Some Not Existing Word')).to eq('Some Not Existing Word')
expect(described_class.translate('en', 'Some Not Existing Word')).to eq('Some Not Existing Word')
end
it 'de-de with existing word' do
expect(Translation.translate('de-de', 'New')).to eq('Neu')
expect(described_class.translate('de-de', 'New')).to eq('Neu')
end
it 'de-de with existing word' do
expect(Translation.translate('de-de', 'Some Not Existing Word')).to eq('Some Not Existing Word')
it 'de-de with not existing word' do
expect(described_class.translate('de-de', 'Some Not Existing Word')).to eq('Some Not Existing Word')
end
end
@ -34,39 +34,39 @@ RSpec.describe Translation do
context 'default timestamp translations' do
it 'de-de with array' do
expect(Translation.timestamp('de-de', 'Europe/Berlin', ['some value'])).to eq('["some value"]')
expect(described_class.timestamp('de-de', 'Europe/Berlin', ['some value'])).to eq('["some value"]')
end
it 'not_existing with timestamp as string' do
expect(Translation.timestamp('not_existing', 'Europe/Berlin', '2018-10-10T10:00:00Z0')).to eq('2018-10-10 10:00:00 UTC')
expect(described_class.timestamp('not_existing', 'Europe/Berlin', '2018-10-10T10:00:00Z0')).to eq('2018-10-10 10:00:00 UTC')
end
it 'not_existing with time object' do
expect(Translation.timestamp('not_existing', 'Europe/Berlin', Time.zone.parse('2018-10-10T10:00:00Z0'))).to eq('2018-10-10 10:00:00 UTC')
expect(described_class.timestamp('not_existing', 'Europe/Berlin', Time.zone.parse('2018-10-10T10:00:00Z0'))).to eq('2018-10-10 10:00:00 UTC')
end
it 'not_existing with invalid timestamp string' do
expect(Translation.timestamp('not_existing', 'Europe/Berlin', 'something')).to eq('something')
expect(described_class.timestamp('not_existing', 'Europe/Berlin', 'something')).to eq('something')
end
it 'en-us with invalid time zone' do
expect(Translation.timestamp('en-us', 'Europe/Berlin', '2018-10-10T10:00:00Z0')).to eq('10/10/2018 12:00 (Europe/Berlin)')
expect(described_class.timestamp('en-us', 'Invalid/TimeZone', '2018-10-10T10:00:00Z0')).to eq(Time.zone.parse('2018-10-10T10:00:00Z0').to_s)
end
it 'en-us with timestamp as string' do
expect(Translation.timestamp('en-us', 'Europe/Berlin', '2018-10-10T10:00:00Z0')).to eq('10/10/2018 12:00 (Europe/Berlin)')
expect(described_class.timestamp('en-us', 'Europe/Berlin', '2018-10-10T10:00:00Z0')).to eq('10/10/2018 12:00 (Europe/Berlin)')
end
it 'en-us with time object' do
expect(Translation.timestamp('en-us', 'Europe/Berlin', Time.zone.parse('2018-10-10T10:00:00Z0'))).to eq('10/10/2018 12:00 (Europe/Berlin)')
expect(described_class.timestamp('en-us', 'Europe/Berlin', Time.zone.parse('2018-10-10T10:00:00Z0'))).to eq('10/10/2018 12:00 (Europe/Berlin)')
end
it 'de-de with timestamp as string' do
expect(Translation.timestamp('de-de', 'Europe/Berlin', '2018-10-10T10:00:00Z0')).to eq('10.10.2018 12:00 (Europe/Berlin)')
expect(described_class.timestamp('de-de', 'Europe/Berlin', '2018-10-10T10:00:00Z0')).to eq('10.10.2018 12:00 (Europe/Berlin)')
end
it 'de-de with time object' do
expect(Translation.timestamp('de-de', 'Europe/Berlin', Time.zone.parse('2018-10-10T10:00:00Z0'))).to eq('10.10.2018 12:00 (Europe/Berlin)')
expect(described_class.timestamp('de-de', 'Europe/Berlin', Time.zone.parse('2018-10-10T10:00:00Z0'))).to eq('10.10.2018 12:00 (Europe/Berlin)')
end
end
@ -74,35 +74,35 @@ RSpec.describe Translation do
context 'default date translations' do
it 'de-de with array' do
expect(Translation.date('de-de', ['some value'])).to eq('["some value"]')
expect(described_class.date('de-de', ['some value'])).to eq('["some value"]')
end
it 'not_existing with date as string' do
expect(Translation.date('not_existing', '2018-10-10')).to eq('2018-10-10')
expect(described_class.date('not_existing', '2018-10-10')).to eq('2018-10-10')
end
it 'not_existing with date object' do
expect(Translation.date('not_existing', Date.parse('2018-10-10'))).to eq('2018-10-10')
expect(described_class.date('not_existing', Date.parse('2018-10-10'))).to eq('2018-10-10')
end
it 'not_existing with invalid data as string' do
expect(Translation.date('not_existing', 'something')).to eq('something')
expect(described_class.date('not_existing', 'something')).to eq('something')
end
it 'en-us with date as string' do
expect(Translation.date('en-us', '2018-10-10')).to eq('10/10/2018')
expect(described_class.date('en-us', '2018-10-10')).to eq('10/10/2018')
end
it 'en-us with date object' do
expect(Translation.date('en-us', Date.parse('2018-10-10'))).to eq('10/10/2018')
expect(described_class.date('en-us', Date.parse('2018-10-10'))).to eq('10/10/2018')
end
it 'de-de with date as string' do
expect(Translation.date('de-de', '2018-10-10')).to eq('10.10.2018')
expect(described_class.date('de-de', '2018-10-10')).to eq('10.10.2018')
end
it 'de-de with date object' do
expect(Translation.date('de-de', Date.parse('2018-10-10'))).to eq('10.10.2018')
expect(described_class.date('de-de', Date.parse('2018-10-10'))).to eq('10.10.2018')
end
end
@ -110,10 +110,10 @@ RSpec.describe Translation do
context 'remote_translation_need_update? tests' do
it 'translation is still the same' do
translation = Translation.where(locale: 'de-de', format: 'string').last
translations = Translation.where(locale: 'de-de').pluck(:id, :locale, :source, :format, :target, :target_initial).to_a
translation = described_class.where(locale: 'de-de', format: 'string').last
translations = described_class.where(locale: 'de-de').pluck(:id, :locale, :source, :format, :target, :target_initial).to_a
expect(
Translation.remote_translation_need_update?(
described_class.remote_translation_need_update?(
{
'source' => translation.source,
'format' => translation.format,
@ -126,12 +126,12 @@ RSpec.describe Translation do
end
it 'translation target has locally changed' do
translation = Translation.where(locale: 'de-de', format: 'string').last
translation = described_class.where(locale: 'de-de', format: 'string').last
translation.target = 'some new translation'
translation.save!
translations = Translation.where(locale: 'de-de').pluck(:id, :locale, :source, :format, :target, :target_initial).to_a
translations = described_class.where(locale: 'de-de').pluck(:id, :locale, :source, :format, :target, :target_initial).to_a
expect(
Translation.remote_translation_need_update?(
described_class.remote_translation_need_update?(
{
'source' => translation.source,
'format' => translation.format,
@ -144,9 +144,9 @@ RSpec.describe Translation do
end
it 'translation target has remotely changed' do
translation = Translation.where(locale: 'de-de', format: 'string').last
translations = Translation.where(locale: 'de-de').pluck(:id, :locale, :source, :format, :target, :target_initial).to_a
(result, translation_result) = Translation.remote_translation_need_update?(
translation = described_class.where(locale: 'de-de', format: 'string').last
translations = described_class.where(locale: 'de-de').pluck(:id, :locale, :source, :format, :target, :target_initial).to_a
(result, translation_result) = described_class.remote_translation_need_update?(
{
'source' => translation.source,
'format' => translation.format,
@ -160,12 +160,12 @@ RSpec.describe Translation do
end
it 'translation target has remotely and locally changed' do
translation = Translation.where(locale: 'de-de', format: 'string').last
translation = described_class.where(locale: 'de-de', format: 'string').last
translation.target = 'some new translation'
translation.save!
translations = Translation.where(locale: 'de-de').pluck(:id, :locale, :source, :format, :target, :target_initial).to_a
translations = described_class.where(locale: 'de-de').pluck(:id, :locale, :source, :format, :target, :target_initial).to_a
expect(
Translation.remote_translation_need_update?(
described_class.remote_translation_need_update?(
{
'source' => translation.source,
'format' => translation.format,
@ -185,26 +185,26 @@ RSpec.describe Translation do
locale = 'de-de'
# check for non existing custom changes
list = Translation.lang(locale)
list = described_class.lang(locale)
list['list'].each do |item|
translation = Translation.find_by(source: item[1], locale: locale)
expect(translation.class).to be(Translation)
translation = described_class.find_by(source: item[1], locale: locale)
expect(translation.class).to be(described_class)
expect(locale).to eq(translation.locale)
expect(translation.target).to eq(translation.target_initial)
end
# add custom changes
translation = Translation.find_by(locale: locale, source: 'open')
expect(translation.class).to be(Translation)
translation = described_class.find_by(locale: locale, source: 'open')
expect(translation.class).to be(described_class)
expect(translation.target).to eq('offen')
expect(translation.target_initial).to eq('offen')
translation.target = 'offen2'
translation.save!
list = Translation.lang(locale)
list = described_class.lang(locale)
list['list'].each do |item|
translation = Translation.find_by(source: item[1], locale: locale)
expect(translation.class).to be(Translation)
translation = described_class.find_by(source: item[1], locale: locale)
expect(translation.class).to be(described_class)
expect(locale).to eq(translation.locale)
if translation.source == 'open'
expect(translation.target).to eq('offen2')
@ -215,11 +215,11 @@ RSpec.describe Translation do
end
# check for existing custom changes after new translations are loaded
Translation.load(locale)
list = Translation.lang(locale)
described_class.load(locale)
list = described_class.lang(locale)
list['list'].each do |item|
translation = Translation.find_by(source: item[1], locale: locale)
expect(translation.class).to be(Translation)
translation = described_class.find_by(source: item[1], locale: locale)
expect(translation.class).to be(described_class)
expect(locale).to eq(translation.locale)
if translation.source == 'open'
expect(translation.target).to eq('offen2')
@ -230,11 +230,11 @@ RSpec.describe Translation do
end
# reset custom translations and check for non existing custom changes
Translation.reset(locale)
list = Translation.lang(locale)
described_class.reset(locale)
list = described_class.lang(locale)
list['list'].each do |item|
translation = Translation.find_by(source: item[1], locale: locale)
expect(translation.class).to be(Translation)
translation = described_class.find_by(source: item[1], locale: locale)
expect(translation.class).to be(described_class)
expect(locale).to eq(translation.locale)
expect(translation.target).to eq(translation.target_initial)
end
@ -265,7 +265,7 @@ RSpec.describe Translation do
end
file = Rails.root.join(directory, "#{locale}-#{version}.yml")
expect(File.exist?(file)).to be false
Translation.fetch(locale)
described_class.fetch(locale)
expect(File.exist?(file)).to be true
end
@ -274,12 +274,12 @@ RSpec.describe Translation do
context 'sync duplicate tests' do
it 'check duplication of entries' do
Translation.where(locale: 'de-de').destroy_all
Translation.sync('de-de')
translation_count = Translation.where(locale: 'de-de').count
Translation.sync('de-de')
described_class.where(locale: 'de-de').destroy_all
described_class.sync('de-de')
translation_count = described_class.where(locale: 'de-de').count
described_class.sync('de-de')
expect(
Translation.where(locale: 'de-de').count
described_class.where(locale: 'de-de').count
).to be translation_count
end

View file

@ -24,8 +24,8 @@ RSpec.describe Trigger do
triggered_article = Ticket::Article.last
expect(triggered_article.body.match?(/space between/)).to be_truthy
expect(triggered_article.body.match?(ticket.title)).to be_truthy
expect(triggered_article.body).to match(/space between/)
expect(triggered_article.body).to match(ticket.title)
end
end
end

View file

@ -2,23 +2,16 @@ require 'rails_helper'
require 'models/application_model_examples'
RSpec.describe Trigger, type: :model do
subject(:trigger) { create(:trigger, condition: condition, perform: perform) }
it_behaves_like 'ApplicationModel', can_assets: { selectors: %i[condition perform] }
before { Trigger.destroy_all } # Default DB state includes three sample triggers
subject!(:trigger) { create(:trigger, condition: condition, perform: perform) }
describe '#assets (for supplying model data to front-end framework)' do
let(:condition) { { 'ticket.state_id' => { operator: 'is', value: 1 } } }
let(:perform) { { 'ticket.priority_id' => { value: 1 } } }
it 'returns a hash with asset attributes for objects referenced in #condition and #perform' do
expect(trigger.assets({}))
.to include(Ticket::State.first.assets({}))
.and include(Ticket::Priority.first.assets({}))
end
end
describe 'Send-email triggers' do
before do
Trigger.destroy_all # Default DB state includes three sample triggers
trigger # create subject trigger
end
let(:perform) do
{
'notification.email' => {
@ -39,18 +32,19 @@ RSpec.describe Trigger, type: :model do
it 'fires (without altering ticket state)' do
expect { Observer::Transaction.commit }
.to change { Ticket::Article.count }.by(1)
.to change(Ticket::Article, :count).by(1)
.and not_change { ticket.reload.state.name }.from('new')
end
end
context 'when ticket is created via Channel::EmailParser.process' do
before { create(:email_address, groups: [Group.first]) }
let(:raw_email) { File.read(Rails.root.join('test', 'data', 'mail', 'mail001.box')) }
it 'fires (without altering ticket state)' do
expect { Channel::EmailParser.new.process({}, raw_email) }
.to change { Ticket.count }.by(1)
.to change(Ticket, :count).by(1)
.and change { Ticket::Article.count }.by(2)
expect(Ticket.last.state.name).to eq('new')
@ -59,11 +53,12 @@ RSpec.describe Trigger, type: :model do
context 'when ticket is created via Channel::EmailParser.process with inline image' do
before { create(:email_address, groups: [Group.first]) }
let(:raw_email) { File.read(Rails.root.join('test', 'data', 'mail', 'mail010.box')) }
it 'fires (without altering ticket state)' do
expect { Channel::EmailParser.new.process({}, raw_email) }
.to change { Ticket.count }.by(1)
.to change(Ticket, :count).by(1)
.and change { Ticket::Article.count }.by(2)
expect(Ticket.last.state.name).to eq('new')

View file

@ -16,7 +16,7 @@ RSpec.describe TypeLookup, type: :model do
it 'creates a new one with that name' do
expect { TypeLookup.by_name(name) }
.to change { TypeLookup.count }.by(1)
.to change(TypeLookup, :count).by(1)
expect(TypeLookup.last.name).to eq(name)
end

View file

@ -9,6 +9,12 @@ require 'models/concerns/can_lookup_examples'
require 'models/concerns/has_object_manager_attributes_validation_examples'
RSpec.describe User, type: :model do
subject(:user) { create(:user) }
let(:customer) { create(:customer_user) }
let(:agent) { create(:agent_user) }
let(:admin) { create(:admin_user) }
it_behaves_like 'ApplicationModel', can_assets: { associations: :organization }
it_behaves_like 'HasGroups', group_access_factory: :agent_user
it_behaves_like 'HasRoles', group_access_factory: :agent_user
@ -18,14 +24,10 @@ RSpec.describe User, type: :model do
it_behaves_like 'CanLookup'
it_behaves_like 'HasObjectManagerAttributesValidation'
subject(:user) { create(:user) }
let(:admin) { create(:admin_user) }
let(:agent) { create(:agent_user) }
let(:customer) { create(:customer_user) }
describe 'Class methods:' do
describe '.authenticate' do
subject(:user) { create(:user, password: password) }
let(:password) { Faker::Internet.password }
context 'with valid credentials' do
@ -153,22 +155,26 @@ RSpec.describe User, type: :model do
it { is_expected.to respond_to(:max_login_failed?) }
context 'with "password_max_login_failed" setting' do
before { Setting.set('password_max_login_failed', 5) }
before { user.update(login_failed: 5) }
before do
Setting.set('password_max_login_failed', 5)
user.update(login_failed: 5)
end
it 'returns true once users #login_failed count exceeds the setting' do
expect { user.update(login_failed: 6) }
.to change { user.max_login_failed? }.to(true)
.to change(user, :max_login_failed?).to(true)
end
end
context 'without password_max_login_failed setting' do
before { Setting.set('password_max_login_failed', nil) }
before { user.update(login_failed: 0) }
before do
Setting.set('password_max_login_failed', nil)
user.update(login_failed: 0)
end
it 'defaults to 0' do
expect { user.update(login_failed: 1) }
.to change { user.max_login_failed? }.to(true)
.to change(user, :max_login_failed?).to(true)
end
end
end
@ -226,8 +232,6 @@ RSpec.describe User, type: :model do
end
context 'when user has designated substitute' do
let(:substitute) { create(:user) }
subject(:user) do
create(:user,
out_of_office: out_of_office,
@ -236,6 +240,8 @@ RSpec.describe User, type: :model do
out_of_office_replacement_id: substitute.id,)
end
let(:substitute) { create(:user) }
context 'but is not out of office' do
let(:out_of_office) { false }
@ -296,9 +302,10 @@ RSpec.describe User, type: :model do
end
describe '#by_reset_token' do
let(:token) { create(:token_password_reset) }
subject(:user) { token.user }
let(:token) { create(:token_password_reset) }
context 'with a valid token' do
it 'returns the matching user' do
expect(described_class.by_reset_token(token.name)).to eq(user)
@ -313,13 +320,14 @@ RSpec.describe User, type: :model do
end
describe '#password_reset_via_token' do
let!(:token) { create(:token_password_reset) }
subject(:user) { token.user }
let!(:token) { create(:token_password_reset) }
it 'changes the password of the token user and destroys the token' do
expect { described_class.password_reset_via_token(token.name, Faker::Internet.password) }
.to change { user.reload.password }
.and change { Token.count }.by(-1)
.and change(Token, :count).by(-1)
end
end
@ -419,6 +427,7 @@ RSpec.describe User, type: :model do
context 'when a customer' do
subject(:user) { create(:customer_user, :with_org) }
let(:colleague) { create(:customer_user, organization: user.organization) }
context 'wants to read' do
@ -457,6 +466,7 @@ RSpec.describe User, type: :model do
describe '#permissions?' do
subject(:user) { create(:user, roles: [role]) }
let(:role) { create(:role, permissions: [permission]) }
let(:permission) { create(:permission, name: permission_name) }
@ -578,6 +588,7 @@ RSpec.describe User, type: :model do
describe '#permissions_with_child_ids' do
context 'with privileges for a root permission (e.g., "foo", not "foo.bar")' do
subject(:user) { create(:user, roles: [role]) }
let(:role) { create(:role, permissions: [permission]) }
let!(:permission) { create(:permission, name: 'foo') }
let!(:child_permission) { create(:permission, name: 'foo.bar') }
@ -601,6 +612,7 @@ RSpec.describe User, type: :model do
context 'with no #preferences[:locale]' do
let(:preferences) { {} }
before { Setting.set('locale_default', 'foo') }
it 'returns the system-wide default locale' do
@ -683,7 +695,7 @@ RSpec.describe User, type: :model do
it 'is reset to 0 when password is updated' do
expect { user.update(password: Faker::Internet.password) }
.to change { user.login_failed }.to(0)
.to change(user, :login_failed).to(0)
end
end
@ -693,7 +705,7 @@ RSpec.describe User, type: :model do
user.password = 'password'
expect { user.save }
.to change { user.password }.to(PasswordHash.crypt('password'))
.to change(user, :password).to(PasswordHash.crypt('password'))
end
end
@ -701,7 +713,7 @@ RSpec.describe User, type: :model do
it 'does not re-hash before saving' do
user.password = "{sha2}#{Digest::SHA2.hexdigest('password')}"
expect { user.save }.not_to change { user.password }
expect { user.save }.not_to change(user, :password)
end
end
@ -709,7 +721,7 @@ RSpec.describe User, type: :model do
it 'does not re-hash before saving' do
user.password = PasswordHash.crypt('password')
expect { user.save }.not_to change { user.password }
expect { user.save }.not_to change(user, :password)
end
end
end
@ -817,13 +829,14 @@ RSpec.describe User, type: :model do
context 'and #email domain matches an existing Organization#domain' do
before { user.assign_attributes(email: 'user@example.com') }
let(:organization) { create(:organization, domain: 'example.com') }
context 'and Organization#domain_assignment is false (default)' do
before { organization.update(domain_assignment: false) }
it 'remains nil' do
expect { user.save }.not_to change { user.organization }
expect { user.save }.not_to change(user, :organization)
end
end
@ -832,20 +845,21 @@ RSpec.describe User, type: :model do
it 'is automatically set to matching Organization' do
expect { user.save }
.to change { user.organization }.to(organization)
.to change(user, :organization).to(organization)
end
end
end
context 'and #email domain doesnt match any Organization#domain' do
before { user.assign_attributes(email: 'user@example.net') }
let(:organization) { create(:organization, domain: 'example.com') }
context 'and Organization#domain_assignment is true' do
before { organization.update(domain_assignment: true) }
it 'remains nil' do
expect { user.save }.not_to change { user.organization }
expect { user.save }.not_to change(user, :organization)
end
end
end
@ -853,10 +867,12 @@ RSpec.describe User, type: :model do
context 'when set on creation' do
before { user.assign_attributes(organization: specified_organization) }
let(:specified_organization) { create(:organization, domain: 'example.net') }
context 'and #email domain matches a DIFFERENT Organization#domain' do
before { user.assign_attributes(email: 'user@example.com') }
let!(:matching_organization) { create(:organization, domain: 'example.com') }
context 'and Organization#domain_assignment is true' do
@ -864,7 +880,7 @@ RSpec.describe User, type: :model do
it 'is NOT automatically set to matching Organization' do
expect { user.save }
.not_to change { user.organization }.from(specified_organization)
.not_to change(user, :organization).from(specified_organization)
end
end
end
@ -886,14 +902,14 @@ RSpec.describe User, type: :model do
it 'grants agent creation' do
expect { create(:agent_user) }
.to change { current_agents.count }.by(1)
.to change(current_agents, :count).by(1)
end
it 'grants role change' do
future_agent = create(:customer_user)
expect { future_agent.roles = [agent_role] }
.to change { current_agents.count }.by(1)
.to change(current_agents, :count).by(1)
end
describe 'role updates' do
@ -924,7 +940,7 @@ RSpec.describe User, type: :model do
expect { create(:agent_user) }
.to raise_error(Exceptions::UnprocessableEntity)
.and change { current_agents.count }.by(0)
.and change(current_agents, :count).by(0)
end
it 'prevents role change' do
@ -934,7 +950,7 @@ RSpec.describe User, type: :model do
expect { future_agent.roles = [agent_role] }
.to raise_error(Exceptions::UnprocessableEntity)
.and change { current_agents.count }.by(0)
.and change(current_agents, :count).by(0)
end
end
end
@ -945,14 +961,14 @@ RSpec.describe User, type: :model do
it 'grants agent creation' do
expect { create(:agent_user) }
.to change { current_agents.count }.by(1)
.to change(current_agents, :count).by(1)
end
it 'grants role change' do
future_agent = create(:customer_user)
expect { future_agent.roles = [agent_role] }
.to change { current_agents.count }.by(1)
.to change(current_agents, :count).by(1)
end
describe 'role updates' do
@ -983,7 +999,7 @@ RSpec.describe User, type: :model do
expect { create(:agent_user) }
.to raise_error(Exceptions::UnprocessableEntity)
.and change { current_agents.count }.by(0)
.and change(current_agents, :count).by(0)
end
it 'prevents role change' do
@ -993,7 +1009,7 @@ RSpec.describe User, type: :model do
expect { future_agent.roles = [agent_role] }
.to raise_error(Exceptions::UnprocessableEntity)
.and change { current_agents.count }.by(0)
.and change(current_agents, :count).by(0)
end
end
end
@ -1009,7 +1025,7 @@ RSpec.describe User, type: :model do
expect { inactive_agent.update!(active: true) }
.to raise_error(Exceptions::UnprocessableEntity)
.and change { current_agents.count }.by(0)
.and change(current_agents, :count).by(0)
end
end
end
@ -1023,7 +1039,7 @@ RSpec.describe User, type: :model do
expect { inactive_agent.update!(active: true) }
.to raise_error(Exceptions::UnprocessableEntity)
.and change { current_agents.count }.by(0)
.and change(current_agents, :count).by(0)
end
end
end
@ -1032,6 +1048,7 @@ RSpec.describe User, type: :model do
describe 'Touching associations on update:' do
subject(:user) { create(:customer_user, organization: organization) }
let(:organization) { create(:organization) }
let(:other_customer) { create(:customer_user) }
@ -1139,6 +1156,7 @@ RSpec.describe User, type: :model do
context 'for incoming calls from the given user' do
subject(:user) { create(:user, phone: '1234567890') }
let!(:logs) { create_list(:'cti/log', 5, :with_preferences, from: user.phone, direction: 'in') }
context 'when updating #phone attribute' do

View file

@ -27,7 +27,7 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do
}
authenticated_as(admin_user, on_behalf_of: customer_user.id)
post '/api/v1/tickets', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
expect(customer_user.id).to eq(json_response['created_by_id'])
end
@ -47,14 +47,14 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do
}
authenticated_as(admin_user, on_behalf_of: customer_user.login)
post '/api/v1/tickets', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
json_response_ticket = json_response
expect(json_response_ticket).to be_a_kind_of(Hash)
expect(customer_user.id).to eq(json_response_ticket['created_by_id'])
authenticated_as(admin_user)
get '/api/v1/activity_stream?full=true', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
json_response_activity = json_response
expect(json_response_activity).to be_a_kind_of(Hash)
@ -71,7 +71,7 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do
expect(customer_user.id).to eq(ticket_created.created_by_id)
get '/api/v1/activity_stream', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
json_response_activity = json_response
expect(json_response_activity).to be_a_kind_of(Array)
@ -101,7 +101,7 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do
}
authenticated_as(admin_user, on_behalf_of: customer_user.email)
post '/api/v1/tickets', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
expect(customer_user.id).to eq(json_response['created_by_id'])
end
@ -119,8 +119,8 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do
}
authenticated_as(admin_user, on_behalf_of: 99_449_494_949)
post '/api/v1/tickets', params: params, as: :json
expect(response).to have_http_status(401)
expect(@response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:unauthorized)
expect(@response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq("No such user '99449494949'")
end
@ -138,8 +138,8 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do
}
authenticated_as(customer_user, on_behalf_of: admin_user.email)
post '/api/v1/tickets', params: params, as: :json
expect(response).to have_http_status(401)
expect(@response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:unauthorized)
expect(@response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq("Current user has no permission to use 'X-On-Behalf-Of'!")
end
@ -157,8 +157,8 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do
}
authenticated_as(admin_user, on_behalf_of: customer_user.email)
post '/api/v1/tickets', params: params, as: :json
expect(response).to have_http_status(422)
expect(@response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:unprocessable_entity)
expect(@response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('No lookup value found for \'group\': "secret1234"')
end

View file

@ -2,7 +2,7 @@ require 'rails_helper'
RSpec.describe 'Api Auth', type: :request do
around(:each) do |example|
around do |example|
orig = ActionController::Base.allow_forgery_protection
begin
@ -30,14 +30,14 @@ RSpec.describe 'Api Auth', type: :request do
Setting.set('api_password_access', false)
authenticated_as(admin_user)
get '/api/v1/sessions', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:unauthorized)
expect(response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('API password access disabled!')
Setting.set('api_password_access', true)
get '/api/v1/sessions', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(response.header['Access-Control-Allow-Origin']).to eq('*')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
@ -48,14 +48,14 @@ RSpec.describe 'Api Auth', type: :request do
Setting.set('api_password_access', false)
authenticated_as(agent_user)
get '/api/v1/tickets', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:unauthorized)
expect(response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('API password access disabled!')
Setting.set('api_password_access', true)
get '/api/v1/tickets', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(response.header['Access-Control-Allow-Origin']).to eq('*')
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
@ -66,14 +66,14 @@ RSpec.describe 'Api Auth', type: :request do
Setting.set('api_password_access', false)
authenticated_as(customer_user)
get '/api/v1/tickets', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:unauthorized)
expect(response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('API password access disabled!')
Setting.set('api_password_access', true)
get '/api/v1/tickets', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(response.header['Access-Control-Allow-Origin']).to eq('*')
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
@ -95,14 +95,14 @@ RSpec.describe 'Api Auth', type: :request do
Setting.set('api_token_access', false)
get '/api/v1/sessions', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:unauthorized)
expect(response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('API token access disabled!')
Setting.set('api_token_access', true)
get '/api/v1/sessions', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(response.header['Access-Control-Allow-Origin']).to eq('*')
expect(json_response).to be_a_kind_of(Hash)
@ -112,7 +112,7 @@ RSpec.describe 'Api Auth', type: :request do
admin_token.save!
get '/api/v1/sessions', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not authorized (token)!')
@ -120,7 +120,7 @@ RSpec.describe 'Api Auth', type: :request do
admin_token.save!
get '/api/v1/sessions', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not authorized (token)!')
@ -128,7 +128,7 @@ RSpec.describe 'Api Auth', type: :request do
admin_user.save!
get '/api/v1/sessions', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('User is inactive!')
@ -136,7 +136,7 @@ RSpec.describe 'Api Auth', type: :request do
admin_token.save!
get '/api/v1/sessions', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('User is inactive!')
@ -144,12 +144,12 @@ RSpec.describe 'Api Auth', type: :request do
admin_user.save!
get '/api/v1/sessions', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
get '/api/v1/roles', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not authorized (token)!')
@ -157,7 +157,7 @@ RSpec.describe 'Api Auth', type: :request do
admin_token.save!
get '/api/v1/roles', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
@ -165,20 +165,20 @@ RSpec.describe 'Api Auth', type: :request do
admin_token.save!
get '/api/v1/organizations', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
name = "some org name #{rand(999_999_999)}"
post '/api/v1/organizations', params: { name: name }, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq(name)
expect(json_response).to be_truthy
name = "some org name #{rand(999_999_999)} - 2"
put "/api/v1/organizations/#{json_response['id']}", params: { name: name }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq(name)
expect(json_response).to be_truthy
@ -187,20 +187,20 @@ RSpec.describe 'Api Auth', type: :request do
admin_token.save!
get '/api/v1/organizations', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
name = "some org name #{rand(999_999_999)}"
post '/api/v1/organizations', params: { name: name }, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq(name)
expect(json_response).to be_truthy
name = "some org name #{rand(999_999_999)} - 2"
put "/api/v1/organizations/#{json_response['id']}", params: { name: name }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq(name)
expect(json_response).to be_truthy
@ -209,20 +209,20 @@ RSpec.describe 'Api Auth', type: :request do
admin_token.save!
get '/api/v1/organizations', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
name = "some org name #{rand(999_999_999)}"
post '/api/v1/organizations', params: { name: name }, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq(name)
expect(json_response).to be_truthy
name = "some org name #{rand(999_999_999)} - 2"
put "/api/v1/organizations/#{json_response['id']}", params: { name: name }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq(name)
expect(json_response).to be_truthy
@ -242,26 +242,26 @@ RSpec.describe 'Api Auth', type: :request do
Setting.set('api_token_access', false)
get '/api/v1/tickets', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:unauthorized)
expect(response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('API token access disabled!')
Setting.set('api_token_access', true)
get '/api/v1/tickets', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(response.header['Access-Control-Allow-Origin']).to eq('*')
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
get '/api/v1/organizations', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
name = "some org name #{rand(999_999_999)}"
post '/api/v1/organizations', params: { name: name }, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
end
@ -278,26 +278,26 @@ RSpec.describe 'Api Auth', type: :request do
Setting.set('api_token_access', false)
get '/api/v1/tickets', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:unauthorized)
expect(response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('API token access disabled!')
Setting.set('api_token_access', true)
get '/api/v1/tickets', params: {}, as: :json
expect(response.header['Access-Control-Allow-Origin']).to eq('*')
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
get '/api/v1/organizations', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
name = "some org name #{rand(999_999_999)}"
post '/api/v1/organizations', params: { name: name }, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
end
it 'does token auth - invalid user - admin', last_admin_check: false do
@ -316,15 +316,15 @@ RSpec.describe 'Api Auth', type: :request do
Setting.set('api_token_access', false)
get '/api/v1/sessions', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:unauthorized)
expect(response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('API token access disabled!')
Setting.set('api_token_access', true)
get '/api/v1/sessions', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:unauthorized)
expect(response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('User is inactive!')
end
@ -344,8 +344,8 @@ RSpec.describe 'Api Auth', type: :request do
authenticated_as(admin_user, token: admin_token)
get '/api/v1/tickets', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:unauthorized)
expect(response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not authorized (token expired)!')
@ -368,7 +368,7 @@ RSpec.describe 'Api Auth', type: :request do
authenticated_as(admin_user, token: admin_token)
get '/api/v1/tickets', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(response.header['Access-Control-Allow-Origin']).to eq('*')
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
@ -384,12 +384,12 @@ RSpec.describe 'Api Auth', type: :request do
token = response.headers['CSRF-TOKEN']
post '/api/v1/signin', params: { username: 'api-admin@example.com', password: 'adminpw', fingerprint: '123456789' }, headers: { 'X-CSRF-Token' => token }
expect(response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(201)
expect(response.header).not_to be_key('Access-Control-Allow-Origin')
expect(response).to have_http_status(:created)
get '/api/v1/sessions', params: {}
expect(response).to have_http_status(200)
expect(response.header.key?('Access-Control-Allow-Origin')).to be_falsey
expect(response).to have_http_status(:ok)
expect(response.header).not_to be_key('Access-Control-Allow-Origin')
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
end

View file

@ -8,43 +8,43 @@ RSpec.describe 'Basics', type: :request do
# 404
get '/not_existing_url', as: :json
expect(response).to have_http_status(404)
expect(response).to have_http_status(:not_found)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('No route matches [GET] /not_existing_url')
# 401
get '/api/v1/organizations', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('authentication failed')
# 422
get '/tests/unprocessable_entity', as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('some error message')
# 401
get '/tests/not_authorized', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('some error message')
# 401
get '/tests/ar_not_found', as: :json
expect(response).to have_http_status(404)
expect(response).to have_http_status(:not_found)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('some error message')
# 500
get '/tests/standard_error', as: :json
expect(response).to have_http_status(500)
expect(response).to have_http_status(:internal_server_error)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('some error message')
# 422
get '/tests/argument_error', as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('some error message')
end
@ -53,7 +53,7 @@ RSpec.describe 'Basics', type: :request do
# 404
get '/not_existing_url'
expect(response).to have_http_status(404)
expect(response).to have_http_status(:not_found)
expect(response.body).to match(/<html/)
expect(response.body).to match(%r{<title>404: Not Found</title>})
expect(response.body).to match(%r{<h1>404: Requested resource was not found</h1>})
@ -61,7 +61,7 @@ RSpec.describe 'Basics', type: :request do
# 401
get '/api/v1/organizations'
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(response.body).to match(/<html/)
expect(response.body).to match(%r{<title>401: Unauthorized</title>})
expect(response.body).to match(%r{<h1>401: Unauthorized</h1>})
@ -69,7 +69,7 @@ RSpec.describe 'Basics', type: :request do
# 422
get '/tests/unprocessable_entity'
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(response.body).to match(/<html/)
expect(response.body).to match(%r{<title>422: Unprocessable Entity</title>})
expect(response.body).to match(%r{<h1>422: The change you wanted was rejected.</h1>})
@ -77,7 +77,7 @@ RSpec.describe 'Basics', type: :request do
# 401
get '/tests/not_authorized'
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(response.body).to match(/<html/)
expect(response.body).to match(%r{<title>401: Unauthorized</title>})
expect(response.body).to match(%r{<h1>401: Unauthorized</h1>})
@ -85,7 +85,7 @@ RSpec.describe 'Basics', type: :request do
# 401
get '/tests/ar_not_found'
expect(response).to have_http_status(404)
expect(response).to have_http_status(:not_found)
expect(response.body).to match(/<html/)
expect(response.body).to match(%r{<title>404: Not Found</title>})
expect(response.body).to match(%r{<h1>404: Requested resource was not found</h1>})
@ -93,7 +93,7 @@ RSpec.describe 'Basics', type: :request do
# 500
get '/tests/standard_error'
expect(response).to have_http_status(500)
expect(response).to have_http_status(:internal_server_error)
expect(response.body).to match(/<html/)
expect(response.body).to match(%r{<title>500: Something went wrong</title>})
expect(response.body).to match(%r{<h1>500: We're sorry, but something went wrong.</h1>})
@ -101,7 +101,7 @@ RSpec.describe 'Basics', type: :request do
# 422
get '/tests/argument_error'
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(response.body).to match(/<html/)
expect(response.body).to match(%r{<title>422: Unprocessable Entity</title>})
expect(response.body).to match(%r{<h1>422: The change you wanted was rejected.</h1>})

View file

@ -10,19 +10,19 @@ RSpec.describe 'Calendars', type: :request do
it 'does calendar index with nobody' do
get '/api/v1/calendars', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('authentication failed')
get '/api/v1/calendars_init', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('authentication failed')
get '/api/v1/calendars/timezones', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('authentication failed')
@ -31,19 +31,19 @@ RSpec.describe 'Calendars', type: :request do
it 'does calendar index with admin' do
authenticated_as(admin_user)
get '/api/v1/calendars', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
expect(json_response.count).to eq(1)
get '/api/v1/calendars?expand=true', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
expect(json_response.count).to eq(1)
get '/api/v1/calendars?full=true', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['record_ids']).to be_truthy
@ -53,7 +53,7 @@ RSpec.describe 'Calendars', type: :request do
# index
get '/api/v1/calendars_init', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['record_ids']).to be_truthy
expect(json_response['ical_feeds']).to be_truthy
@ -67,7 +67,7 @@ RSpec.describe 'Calendars', type: :request do
# timezones
get '/api/v1/calendars/timezones', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['timezones']).to be_a_kind_of(Hash)
expect(json_response['timezones']['America/New_York']).to be_truthy

View file

@ -8,7 +8,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 401 unauthorized' do
get '/api/v1/external_credentials', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to include('error' => 'authentication failed')
end
end
@ -17,7 +17,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 401 unauthorized' do
post '/api/v1/external_credentials/facebook/app_verify', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to include('error' => 'authentication failed')
end
end
@ -26,7 +26,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 401 unauthorized' do
get '/api/v1/external_credentials/facebook/link_account', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to include('error' => 'authentication failed')
end
end
@ -35,7 +35,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 401 unauthorized' do
get '/api/v1/external_credentials/facebook/callback', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to include('error' => 'authentication failed')
end
end
@ -48,7 +48,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'responds with an array of ExternalCredential records' do
get '/api/v1/external_credentials', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to eq([])
end
@ -56,7 +56,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'responds with an array of ExternalCredential records and their association data' do
get '/api/v1/external_credentials?expand=true', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to eq([])
end
end
@ -74,7 +74,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 401 unauthorized with internal (Zammad) error' do
post '/api/v1/external_credentials/facebook/app_verify', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to include('error' => 'Not authorized (user)!')
end
end
@ -83,7 +83,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 200 with internal (Zammad) error' do
post '/api/v1/external_credentials/facebook/app_verify', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to include('error' => 'No application_id param!')
end
end
@ -94,7 +94,7 @@ RSpec.describe 'External Credentials', type: :request do
post '/api/v1/external_credentials/facebook/app_verify', params: invalid_credentials, as: :json
end
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to include('error' => 'type: OAuthException, code: 101, message: Error validating application. Cannot get application info due to a system error. [HTTP 400]')
end
end
@ -107,7 +107,7 @@ RSpec.describe 'External Credentials', type: :request do
post '/api/v1/external_credentials/facebook/app_verify', as: :json
end
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to include('error' => 'type: OAuthException, code: 101, message: Error validating application. Cannot get application info due to a system error. [HTTP 400]')
end
end
@ -120,7 +120,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 422 unprocessable entity with internal (Zammad) error' do
get '/api/v1/external_credentials/facebook/link_account', as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => 'No facebook app configured!')
end
end
@ -129,7 +129,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 422 unprocessable entity with internal (Zammad) error' do
get '/api/v1/external_credentials/facebook/link_account', params: invalid_credentials, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => 'No facebook app configured!')
end
end
@ -142,7 +142,7 @@ RSpec.describe 'External Credentials', type: :request do
get '/api/v1/external_credentials/facebook/link_account', as: :json
end
expect(response).to have_http_status(500)
expect(response).to have_http_status(:internal_server_error)
expect(json_response).to include('error' => 'type: OAuthException, code: 101, message: Error validating application. Cannot get application info due to a system error. [HTTP 400]')
end
end
@ -155,7 +155,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 422 unprocessable entity with internal (Zammad) error' do
get '/api/v1/external_credentials/facebook/callback', as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => 'No facebook app configured!')
end
end
@ -164,7 +164,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 422 unprocessable entity with internal (Zammad) error' do
get '/api/v1/external_credentials/facebook/callback', params: invalid_credentials, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => 'No facebook app configured!')
end
end
@ -177,7 +177,7 @@ RSpec.describe 'External Credentials', type: :request do
get '/api/v1/external_credentials/facebook/callback', as: :json
end
expect(response).to have_http_status(500)
expect(response).to have_http_status(:internal_server_error)
expect(json_response).to include('error' => 'type: OAuthException, code: 101, message: Error validating application. Cannot get application info due to a system error. [HTTP 400]')
end
end
@ -197,7 +197,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 401 unauthorized with internal (Zammad) error' do
post '/api/v1/external_credentials/twitter/app_verify', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to include('error' => 'Not authorized (user)!')
end
end
@ -206,7 +206,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 200 with internal (Zammad) error' do
post '/api/v1/external_credentials/twitter/app_verify', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to include('error' => 'No consumer_key param!')
end
end
@ -217,7 +217,7 @@ RSpec.describe 'External Credentials', type: :request do
post '/api/v1/external_credentials/twitter/app_verify', params: invalid_credentials, as: :json
end
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to include('error' => '401 Authorization Required')
end
end
@ -230,7 +230,7 @@ RSpec.describe 'External Credentials', type: :request do
post '/api/v1/external_credentials/twitter/app_verify', as: :json
end
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to include('error' => '401 Authorization Required')
end
end
@ -243,7 +243,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 422 unprocessable entity with internal (Zammad) error' do
get '/api/v1/external_credentials/twitter/link_account', as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => 'No twitter app configured!')
end
end
@ -252,7 +252,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 422 unprocessable entity with internal (Zammad) error' do
get '/api/v1/external_credentials/twitter/link_account', params: invalid_credentials, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => 'No twitter app configured!')
end
end
@ -265,7 +265,7 @@ RSpec.describe 'External Credentials', type: :request do
get '/api/v1/external_credentials/twitter/link_account', as: :json
end
expect(response).to have_http_status(500)
expect(response).to have_http_status(:internal_server_error)
expect(json_response).to include('error' => '401 Authorization Required')
end
end
@ -278,7 +278,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 422 unprocessable entity with internal (Zammad) error' do
get '/api/v1/external_credentials/twitter/callback', as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => 'No twitter app configured!')
end
end
@ -287,7 +287,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 422 unprocessable entity with internal (Zammad) error' do
get '/api/v1/external_credentials/twitter/callback', params: invalid_credentials, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => 'No twitter app configured!')
end
end
@ -298,7 +298,7 @@ RSpec.describe 'External Credentials', type: :request do
it 'returns 422 unprocessable entity with internal (Zammad) error' do
get '/api/v1/external_credentials/twitter/callback', as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => 'No request_token for session found!')
end
end

View file

@ -2,7 +2,7 @@ require 'rails_helper'
RSpec.describe 'Form', type: :request, searchindex: true do
before(:each) do
before do
configure_elasticsearch
rebuild_searchindex
end
@ -11,7 +11,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
it 'does get config call' do
post '/api/v1/form_config', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not authorized')
end
@ -19,7 +19,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
it 'does get config call' do
Setting.set('form_ticket_create', true)
post '/api/v1/form_config', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not authorized')
@ -30,7 +30,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
fingerprint = SecureRandom.hex(40)
post '/api/v1/form_config', params: { fingerprint: fingerprint }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['enabled']).to eq(true)
expect(json_response['endpoint']).to eq('http://zammad.example.com/api/v1/form_submit')
@ -38,12 +38,12 @@ RSpec.describe 'Form', type: :request, searchindex: true do
token = json_response['token']
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: 'invalid' }, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not authorized')
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['errors']).to be_truthy
@ -53,7 +53,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
expect(json_response['errors']['body']).to eq('required')
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, email: 'some' }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['errors']).to be_truthy
@ -63,7 +63,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
expect(json_response['errors']['body']).to eq('required')
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, name: 'Bob Smith', email: 'discard@znuny.com', title: 'test', body: 'hello' }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['errors']).to be_falsey
@ -75,7 +75,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, name: 'Bob Smith', email: 'discard@znuny.com', title: 'test', body: 'hello' }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['errors']).to be_falsey
@ -86,7 +86,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
travel 20.hours
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, name: 'Bob Smith', email: 'discard@znuny.com', title: 'test', body: 'hello' }, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
end
@ -95,7 +95,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
fingerprint = SecureRandom.hex(40)
post '/api/v1/form_config', params: { fingerprint: fingerprint }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['enabled']).to eq(true)
expect(json_response['endpoint']).to eq('http://zammad.example.com/api/v1/form_submit')
@ -103,12 +103,12 @@ RSpec.describe 'Form', type: :request, searchindex: true do
token = json_response['token']
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: 'invalid' }, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not authorized')
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['errors']).to be_truthy
@ -118,7 +118,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
expect(json_response['errors']['body']).to eq('required')
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, email: 'some' }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['errors']).to be_truthy
@ -128,7 +128,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
expect(json_response['errors']['body']).to eq('required')
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, name: 'Bob Smith', email: 'somebody@somedomainthatisinvalid.com', title: 'test', body: 'hello' }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['errors']).to be_truthy
@ -143,7 +143,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
fingerprint = SecureRandom.hex(40)
post '/api/v1/form_config', params: { fingerprint: fingerprint }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['enabled']).to eq(true)
expect(json_response['endpoint']).to eq('http://zammad.example.com/api/v1/form_submit')
@ -153,7 +153,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
(1..20).each do |count|
travel 10.seconds
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, name: 'Bob Smith', email: 'discard@znuny.com', title: "test#{count}", body: 'hello' }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['errors']).to be_falsey
@ -168,7 +168,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
sleep 10 # wait until elasticsearch is index
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, name: 'Bob Smith', email: 'discard@znuny.com', title: 'test-last', body: 'hello' }, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to be_truthy
@ -177,7 +177,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
(1..20).each do |count|
travel 10.seconds
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, name: 'Bob Smith', email: 'discard@znuny.com', title: "test-2-#{count}", body: 'hello' }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['errors']).to be_falsey
@ -191,7 +191,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
sleep 10 # wait until elasticsearch is index
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, name: 'Bob Smith', email: 'discard@znuny.com', title: 'test-2-last', body: 'hello' }, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to be_truthy
end
@ -216,7 +216,7 @@ RSpec.describe 'Form', type: :request, searchindex: true do
post '/api/v1/form_submit', params: params, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
end
end
end

View file

@ -2,7 +2,7 @@ require 'rails_helper'
RSpec.describe 'Integration Check MK', type: :request do
before(:each) do
before do
token = SecureRandom.urlsafe_base64(16)
Setting.set('check_mk_token', token)
Setting.set('check_mk_integration', true)
@ -11,12 +11,12 @@ RSpec.describe 'Integration Check MK', type: :request do
describe 'request handling' do
it 'does fail without a token' do
post '/api/v1/integration/check_mk/', params: {}
expect(response).to have_http_status(404)
expect(response).to have_http_status(:not_found)
end
it 'does fail with invalid token and feature enabled' do
post '/api/v1/integration/check_mk/invalid_token', params: {}
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Invalid token!')
@ -30,7 +30,7 @@ RSpec.describe 'Integration Check MK', type: :request do
service: 'some service',
}
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to be_truthy
@ -48,7 +48,7 @@ RSpec.describe 'Integration Check MK', type: :request do
service: 'some service',
}
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).not_to be_empty
@ -67,7 +67,7 @@ RSpec.describe 'Integration Check MK', type: :request do
service: 'some service',
}
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to be_truthy
@ -85,7 +85,7 @@ RSpec.describe 'Integration Check MK', type: :request do
service: 'some service',
}
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to eq('ticket already open, added note')
@ -102,7 +102,7 @@ RSpec.describe 'Integration Check MK', type: :request do
service: 'some service',
}
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to be_truthy
@ -121,7 +121,7 @@ RSpec.describe 'Integration Check MK', type: :request do
service: 'some service',
}
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to eq('no open tickets found, ignore action')
@ -136,7 +136,7 @@ RSpec.describe 'Integration Check MK', type: :request do
service: 'some service',
}
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to be_truthy
@ -154,7 +154,7 @@ RSpec.describe 'Integration Check MK', type: :request do
service: 'some service',
}
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to eq('ticket already open, added note')
@ -171,7 +171,7 @@ RSpec.describe 'Integration Check MK', type: :request do
service: 'some service',
}
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to eq('ticket already open, added note')
@ -189,7 +189,7 @@ RSpec.describe 'Integration Check MK', type: :request do
host: 'some host',
}
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to be_truthy
@ -206,7 +206,7 @@ RSpec.describe 'Integration Check MK', type: :request do
host: 'some host',
}
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to eq('ticket already open, added note')
@ -222,7 +222,7 @@ RSpec.describe 'Integration Check MK', type: :request do
host: 'some host',
}
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result']).to be_truthy

View file

@ -36,7 +36,7 @@ RSpec.describe 'Integration CTI', type: :request do
)
end
before(:each) do
before do
Cti::Log.destroy_all
Setting.set('cti_integration', true)
@ -76,7 +76,7 @@ RSpec.describe 'Integration CTI', type: :request do
it 'does token check' do
params = 'event=newCall&direction=in&from=4912347114711&to=4930600000000&call_id=4991155921769858278-1&user%5B%5D=user+1&user%5B%5D=user+2'
post '/api/v1/cti/not_existing_token', params: params
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Invalid token, please contact your admin!')
end
@ -87,7 +87,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - I
params = 'event=newCall&direction=in&from=4912347114711&to=4930600000000&call_id=4991155921769858278-1&user%5B%5D=user+1&user%5B%5D=user+2'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_blank
@ -95,7 +95,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - II - block caller
params = 'event=newCall&direction=in&from=491715000000&to=4930600000000&call_id=4991155921769858278-2&user%5B%5D=user+1&user%5B%5D=user+2'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['action']).to eq('reject')
@ -104,7 +104,7 @@ RSpec.describe 'Integration CTI', type: :request do
# outbound - I - set default_caller_id
params = 'event=newCall&direction=out&from=4930600000000&to=4912347114711&call_id=8621106404543334274-3&user%5B%5D=user+1'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['action']).to eq('dial')
expect(json_response['number']).to eq('4912347114711')
@ -113,7 +113,7 @@ RSpec.describe 'Integration CTI', type: :request do
# outbound - II - set caller_id based on routing_table by explicite number
params = 'event=newCall&direction=out&from=4930600000000&to=491714000000&call_id=8621106404543334274-4&user%5B%5D=user+1'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['action']).to eq('dial')
expect(json_response['number']).to eq('491714000000')
@ -122,7 +122,7 @@ RSpec.describe 'Integration CTI', type: :request do
# outbound - III - set caller_id based on routing_table by 41*
params = 'event=newCall&direction=out&from=4930600000000&to=4147110000000&call_id=8621106404543334274-5&user%5B%5D=user+1'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['action']).to eq('dial')
expect(json_response['number']).to eq('4147110000000')
@ -132,7 +132,7 @@ RSpec.describe 'Integration CTI', type: :request do
Setting.set('cti_config', {})
params = 'event=newCall&direction=in&from=4912347114711&to=4930600000000&call_id=4991155921769858278-6&user%5B%5D=user+1&user%5B%5D=user+2'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Feature not configured, please contact your admin!')
@ -144,7 +144,7 @@ RSpec.describe 'Integration CTI', type: :request do
# outbound - I - new call
params = 'event=newCall&direction=out&from=4930600000000&to=4912347114711&call_id=1234567890-1&user%5B%5D=user+1'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-1')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -167,7 +167,7 @@ RSpec.describe 'Integration CTI', type: :request do
# outbound - I - hangup by agent
params = 'event=hangup&direction=out&call_id=1234567890-1&cause=cancel'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-1')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -188,7 +188,7 @@ RSpec.describe 'Integration CTI', type: :request do
# outbound - II - new call
params = 'event=newCall&direction=out&from=4930600000000&to=4912347114711&call_id=1234567890-2&user%5B%5D=user+1'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-2')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -211,7 +211,7 @@ RSpec.describe 'Integration CTI', type: :request do
# outbound - II - answer by customer
params = 'event=answer&direction=out&call_id=1234567890-2&from=4930600000000&to=4912347114711'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-2')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -234,7 +234,7 @@ RSpec.describe 'Integration CTI', type: :request do
# outbound - II - hangup by customer
params = 'event=hangup&direction=out&call_id=1234567890-2&cause=normalClearing&from=4930600000000&to=4912347114711'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-2')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -257,7 +257,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - I - new call
params = 'event=newCall&direction=in&to=4930600000000&from=4912347114711&call_id=1234567890-3&user%5B%5D=user+1'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-3')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -280,7 +280,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - I - answer by customer
params = 'event=answer&direction=in&call_id=1234567890-3&to=4930600000000&from=4912347114711'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-3')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -303,7 +303,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - I - hangup by customer
params = 'event=hangup&direction=in&call_id=1234567890-3&cause=normalClearing&to=4930600000000&from=4912347114711'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-3')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -326,7 +326,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - II - new call
params = 'event=newCall&direction=in&to=4930600000000&from=4912347114711&call_id=1234567890-4&user%5B%5D=user+1,user+2'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-4')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -349,7 +349,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - II - answer by voicemail
params = 'event=answer&direction=in&call_id=1234567890-4&to=4930600000000&from=4912347114711&user=voicemail'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-4')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -372,7 +372,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - II - hangup by customer
params = 'event=hangup&direction=in&call_id=1234567890-4&cause=normalClearing&to=4930600000000&from=4912347114711'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-4')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -395,7 +395,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - III - new call
params = 'event=newCall&direction=in&to=4930600000000&from=4912347114711&call_id=1234567890-5&user%5B%5D=user+1,user+2'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-5')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -418,7 +418,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - III - hangup by customer
params = 'event=hangup&direction=in&call_id=1234567890-5&cause=normalClearing&to=4930600000000&from=4912347114711'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-5')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -441,7 +441,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - IV - new call
params = 'event=newCall&direction=in&to=4930600000000&from=49999992222222&call_id=1234567890-6&user%5B%5D=user+1,user+2'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-6')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -466,7 +466,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - IV - new call
params = 'event=newCall&direction=in&to=4930600000000&from=anonymous&call_id=1234567890-7&user%5B%5D=user+1,user+2&queue=some_queue_name'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-7')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -488,11 +488,11 @@ RSpec.describe 'Integration CTI', type: :request do
# get caller list
get '/api/v1/cti/log'
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
authenticated_as(agent_user)
get '/api/v1/cti/log', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['list']).to be_a_kind_of(Array)
expect(json_response['list'].count).to eq(7)
expect(json_response['assets']).to be_truthy
@ -521,7 +521,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - queue & user
params = 'event=newCall&direction=in&to=4930600000000&from=anonymous&call_id=1234567890-1&user%5B%5D=user+1,user+2&queue=some_queue_name'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-1')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -544,7 +544,7 @@ RSpec.describe 'Integration CTI', type: :request do
# inbound - queue & no user
params = 'event=newCall&direction=in&to=4930600000000&from=anonymous&call_id=1234567890-2&user%5B%5D=&queue=some_queue_name'
post "/api/v1/cti/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-2')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')

View file

@ -18,7 +18,7 @@ RSpec.describe 'Idoit', type: :request do
'https://idoit.example.com/i-doit/'
end
before(:each) do
before do
Setting.set('idoit_integration', true)
Setting.set('idoit_config', {
api_token: token,
@ -38,9 +38,9 @@ RSpec.describe 'Idoit', type: :request do
}
authenticated_as(agent_user)
post '/api/v1/integration/idoit/verify', params: params, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to_not be_blank
expect(json_response).not_to be_blank
expect(json_response['error']).to eq('Not authorized (user)!')
stub_request(:post, "#{endpoint}src/jsonrpc.php")
@ -54,9 +54,9 @@ RSpec.describe 'Idoit', type: :request do
}
authenticated_as(admin_user)
post '/api/v1/integration/idoit/verify', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to_not be_blank
expect(json_response).not_to be_blank
expect(json_response['result']).to eq('ok')
expect(json_response['response']).to be_truthy
expect(json_response['response']['jsonrpc']).to eq('2.0')
@ -68,9 +68,9 @@ RSpec.describe 'Idoit', type: :request do
client_id: '',
}
post '/api/v1/integration/idoit/verify', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to_not be_blank
expect(json_response).not_to be_blank
expect(json_response['result']).to eq('ok')
expect(json_response['response']).to be_truthy
expect(json_response['response']['jsonrpc']).to eq('2.0')
@ -89,10 +89,10 @@ RSpec.describe 'Idoit', type: :request do
}
authenticated_as(agent_user)
post '/api/v1/integration/idoit', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to_not be_blank
expect(json_response).not_to be_blank
expect(json_response['result']).to eq('ok')
expect(json_response['response']).to be_truthy
expect(json_response['response']['jsonrpc']).to eq('2.0')
@ -105,10 +105,10 @@ RSpec.describe 'Idoit', type: :request do
}
authenticated_as(admin_user)
post '/api/v1/integration/idoit', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to_not be_blank
expect(json_response).not_to be_blank
expect(json_response['result']).to eq('ok')
expect(json_response['response']).to be_truthy
expect(json_response['response']['jsonrpc']).to eq('2.0')
@ -132,10 +132,10 @@ RSpec.describe 'Idoit', type: :request do
}
authenticated_as(agent_user)
post '/api/v1/integration/idoit', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to_not be_blank
expect(json_response).not_to be_blank
expect(json_response['result']).to eq('ok')
expect(json_response['response']).to be_truthy
expect(json_response['response']['jsonrpc']).to eq('2.0')

View file

@ -15,7 +15,7 @@ RSpec.describe 'Monitoring', type: :request do
SecureRandom.urlsafe_base64(64)
end
before(:each) do
before do
Setting.set('monitoring_token', token)
# channel cleanup
@ -48,7 +48,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check
get '/api/v1/monitoring/health_check', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['healthy']).to be_falsey
@ -56,7 +56,7 @@ RSpec.describe 'Monitoring', type: :request do
# status
get '/api/v1/monitoring/status', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['agents']).to be_falsey
@ -67,7 +67,7 @@ RSpec.describe 'Monitoring', type: :request do
# token
post '/api/v1/monitoring/token', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['token']).to be_falsey
@ -79,7 +79,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check
get '/api/v1/monitoring/health_check?token=abc', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['healthy']).to be_falsey
@ -87,7 +87,7 @@ RSpec.describe 'Monitoring', type: :request do
# status
get '/api/v1/monitoring/status?token=abc', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['agents']).to be_falsey
@ -98,7 +98,7 @@ RSpec.describe 'Monitoring', type: :request do
# token
post '/api/v1/monitoring/token', params: { token: 'abc' }, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['token']).to be_falsey
@ -124,7 +124,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to be_falsey
@ -133,22 +133,22 @@ RSpec.describe 'Monitoring', type: :request do
# status
get "/api/v1/monitoring/status?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to be_falsey
expect(json_response.key?('agents')).to be_truthy
expect(json_response.key?('last_login')).to be_truthy
expect(json_response.key?('counts')).to be_truthy
expect(json_response.key?('last_created_at')).to be_truthy
expect(json_response).to be_key('agents')
expect(json_response).to be_key('last_login')
expect(json_response).to be_key('counts')
expect(json_response).to be_key('last_created_at')
first_json_response_kb = 0
if ActiveRecord::Base.connection_config[:adapter] == 'postgresql'
expect(json_response['storage']).to be_truthy
expect(json_response['storage'].key?('kB')).to be_truthy
expect(json_response['storage']).to be_key('kB')
expect(json_response['storage']['kB']).to be > 0
expect(json_response['storage'].key?('MB')).to be_truthy
expect(json_response['storage'].key?('GB')).to be_truthy
expect(json_response['storage']).to be_key('MB')
expect(json_response['storage']).to be_key('GB')
first_json_response_kb = json_response['storage']['kB']
else
@ -166,23 +166,23 @@ RSpec.describe 'Monitoring', type: :request do
# status
get "/api/v1/monitoring/status?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to be_falsey
expect(json_response.key?('agents')).to be_truthy
expect(json_response.key?('last_login')).to be_truthy
expect(json_response.key?('counts')).to be_truthy
expect(json_response.key?('last_created_at')).to be_truthy
expect(json_response).to be_key('agents')
expect(json_response).to be_key('last_login')
expect(json_response).to be_key('counts')
expect(json_response).to be_key('last_created_at')
if ActiveRecord::Base.connection_config[:adapter] == 'postgresql'
expect(json_response['storage']).to be_truthy
expect(json_response['storage'].key?('kB')).to be_truthy
expect(json_response['storage']).to be_key('kB')
# check if the stores got summarized. value should be the same because the file has the same fingerprint
expect(json_response['storage']['kB']).to eq(first_json_response_kb)
expect(json_response['storage'].key?('MB')).to be_truthy
expect(json_response['storage'].key?('GB')).to be_truthy
expect(json_response['storage']).to be_key('MB')
expect(json_response['storage']).to be_key('GB')
else
expect(json_response['storage']).to be_falsey
end
@ -197,30 +197,30 @@ RSpec.describe 'Monitoring', type: :request do
# status
get "/api/v1/monitoring/status?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to be_falsey
expect(json_response.key?('agents')).to be_truthy
expect(json_response.key?('last_login')).to be_truthy
expect(json_response.key?('counts')).to be_truthy
expect(json_response.key?('last_created_at')).to be_truthy
expect(json_response).to be_key('agents')
expect(json_response).to be_key('last_login')
expect(json_response).to be_key('counts')
expect(json_response).to be_key('last_created_at')
if ActiveRecord::Base.connection_config[:adapter] == 'postgresql'
expect(json_response['storage']).to be_truthy
expect(json_response['storage'].key?('kB')).to be_truthy
expect(json_response['storage']).to be_key('kB')
# check if the stores got summarized. value should be greather than the size of just one file (saved 2 times)
expect(json_response['storage']['kB']).to be > first_json_response_kb
expect(json_response['storage'].key?('MB')).to be_truthy
expect(json_response['storage'].key?('GB')).to be_truthy
expect(json_response['storage']).to be_key('MB')
expect(json_response['storage']).to be_key('GB')
else
expect(json_response['storage']).to be_falsey
end
# token
post '/api/v1/monitoring/token', params: { token: token }, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['token']).to be_falsey
@ -233,7 +233,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check
authenticated_as(admin_user)
get '/api/v1/monitoring/health_check', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to be_falsey
@ -242,18 +242,18 @@ RSpec.describe 'Monitoring', type: :request do
# status
get '/api/v1/monitoring/status', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to be_falsey
expect(json_response.key?('agents')).to be_truthy
expect(json_response.key?('last_login')).to be_truthy
expect(json_response.key?('counts')).to be_truthy
expect(json_response.key?('last_created_at')).to be_truthy
expect(json_response).to be_key('agents')
expect(json_response).to be_key('last_login')
expect(json_response).to be_key('counts')
expect(json_response).to be_key('last_created_at')
# token
post '/api/v1/monitoring/token', params: { token: token }, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['token']).to be_truthy
@ -267,7 +267,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check
authenticated_as(agent_user)
get '/api/v1/monitoring/health_check', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['healthy']).to be_falsey
@ -275,7 +275,7 @@ RSpec.describe 'Monitoring', type: :request do
# status
get '/api/v1/monitoring/status', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['agents']).to be_falsey
@ -286,7 +286,7 @@ RSpec.describe 'Monitoring', type: :request do
# token
post '/api/v1/monitoring/token', params: { token: token }, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['token']).to be_falsey
@ -303,7 +303,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check
authenticated_as(admin_user)
get '/api/v1/monitoring/health_check', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['healthy']).to be_falsey
@ -311,7 +311,7 @@ RSpec.describe 'Monitoring', type: :request do
# status
get '/api/v1/monitoring/status', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['agents']).to be_falsey
@ -322,7 +322,7 @@ RSpec.describe 'Monitoring', type: :request do
# token
post '/api/v1/monitoring/token', params: { token: token }, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['token']).to be_falsey
@ -340,7 +340,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to be_falsey
@ -349,18 +349,18 @@ RSpec.describe 'Monitoring', type: :request do
# status
get "/api/v1/monitoring/status?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to be_falsey
expect(json_response.key?('agents')).to be_truthy
expect(json_response.key?('last_login')).to be_truthy
expect(json_response.key?('counts')).to be_truthy
expect(json_response.key?('last_created_at')).to be_truthy
expect(json_response).to be_key('agents')
expect(json_response).to be_key('last_login')
expect(json_response).to be_key('counts')
expect(json_response).to be_key('last_created_at')
# token
post '/api/v1/monitoring/token', params: { token: token }, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['token']).to be_falsey
@ -381,7 +381,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check - channel
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['message']).to be_truthy
@ -396,7 +396,7 @@ RSpec.describe 'Monitoring', type: :request do
scheduler.save!
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['message']).to be_truthy
@ -411,7 +411,7 @@ RSpec.describe 'Monitoring', type: :request do
scheduler.save!
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['message']).to be_truthy
@ -431,7 +431,7 @@ RSpec.describe 'Monitoring', type: :request do
total_jobs = Delayed::Job.count
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['message']).to be_truthy
@ -446,7 +446,7 @@ RSpec.describe 'Monitoring', type: :request do
end
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['message']).to be_truthy
@ -463,7 +463,7 @@ RSpec.describe 'Monitoring', type: :request do
FileUtils.touch("#{dir}/test.eml")
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['message']).to be_truthy
@ -483,7 +483,7 @@ RSpec.describe 'Monitoring', type: :request do
)
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['message']).to be_truthy
@ -501,7 +501,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['message']).to be_truthy
@ -515,7 +515,7 @@ RSpec.describe 'Monitoring', type: :request do
it 'does check restart_failed_jobs' do
authenticated_as(admin_user)
post '/api/v1/monitoring/restart_failed_jobs', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
end
it 'does check failed delayed job', db_strategy: :reset do
@ -574,7 +574,7 @@ RSpec.describe 'Monitoring', type: :request do
migration = ObjectManager::Attribute.migration_execute
expect(true).to eq(migration)
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_truthy
expect(json_response['data_option']['null']).to be_truthy
expect('test4').to eq(json_response['name'])
@ -590,7 +590,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['message']).to be_truthy
@ -604,7 +604,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['message']).to be_truthy
@ -625,7 +625,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['message']).to be_truthy
@ -644,7 +644,7 @@ RSpec.describe 'Monitoring', type: :request do
# health_check
get "/api/v1/monitoring/health_check?token=#{token}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['message']).to be_truthy
@ -661,7 +661,7 @@ RSpec.describe 'Monitoring', type: :request do
# amount_check - ok
get "/api/v1/monitoring/amount_check?token=#{token}&periode=1h", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response.key?('state')).to eq(false)
@ -675,7 +675,7 @@ RSpec.describe 'Monitoring', type: :request do
end
get "/api/v1/monitoring/amount_check?token=#{token}&periode=1h&min_warning=10&min_critical=8", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['state']).to eq('critical')
@ -683,7 +683,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['count']).to eq(6)
get "/api/v1/monitoring/amount_check?token=#{token}&periode=1h&min_warning=7&min_critical=2", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['state']).to eq('warning')
@ -691,7 +691,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['count']).to eq(6)
get "/api/v1/monitoring/amount_check?token=#{token}&periode=1h&max_warning=10&max_critical=20", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['state']).to eq('ok')
@ -704,7 +704,7 @@ RSpec.describe 'Monitoring', type: :request do
end
get "/api/v1/monitoring/amount_check?token=#{token}&periode=1h&max_warning=10&max_critical=20", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['state']).to eq('warning')
@ -717,7 +717,7 @@ RSpec.describe 'Monitoring', type: :request do
end
get "/api/v1/monitoring/amount_check?token=#{token}&periode=1h&max_warning=10&max_critical=20", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['state']).to eq('critical')
@ -725,7 +725,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['count']).to eq(22)
get "/api/v1/monitoring/amount_check?token=#{token}&periode=1h&max_warning=30", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['state']).to eq('ok')
@ -733,7 +733,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['count']).to eq(22)
get "/api/v1/monitoring/amount_check?token=#{token}&periode=1h", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response.key?('state')).to eq(false)
@ -743,7 +743,7 @@ RSpec.describe 'Monitoring', type: :request do
travel 2.hours
get "/api/v1/monitoring/amount_check?token=#{token}&periode=1h&max_warning=30", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['state']).to eq('ok')
@ -751,7 +751,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['count']).to eq(0)
get "/api/v1/monitoring/amount_check?token=#{token}&periode=1h", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response.key?('state')).to eq(false)

View file

@ -49,7 +49,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
}
post '/api/v1/object_manager_attributes', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_truthy
expect(json_response['data_option']['null']).to be_truthy
expect(json_response['data_option']['null']).to eq(true)
@ -96,7 +96,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
}
post '/api/v1/object_manager_attributes', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_truthy
expect(json_response['data_option']['null']).to be_truthy
expect(json_response['data_option']['null']).to eq(true)
@ -152,7 +152,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
# update the object
put "/api/v1/object_manager_attributes/#{object.id}", params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_truthy
expect(json_response['data_option']['null']).to be_truthy
expect(json_response['name']).to eq('test4')
@ -201,7 +201,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
}
post '/api/v1/object_manager_attributes', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_truthy
expect(json_response['data_option']['null']).to be_truthy
expect(json_response['data_option']['null']).to eq(true)
@ -261,7 +261,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
}
post '/api/v1/object_manager_attributes', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_truthy
expect(json_response['data_option']['null']).to be_truthy
expect(json_response['data_option']['null']).to eq(true)
@ -330,7 +330,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
# update the object
authenticated_as(admin_user)
put "/api/v1/object_manager_attributes/#{object.id}", params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_truthy
expect(json_response['data_option']['options']).to be_truthy
expect(json_response['name']).to eq('test7')
@ -380,7 +380,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
migration = ObjectManager::Attribute.migration_execute
expect(migration).to eq(true)
expect(response).to have_http_status(201) # created
expect(response).to have_http_status(:created) # created
expect(json_response).to be_truthy
expect(json_response['data_option']['default']).to be_truthy
@ -430,7 +430,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
migration = ObjectManager::Attribute.migration_execute
expect(migration).to eq(true)
expect(response).to have_http_status(201) # created
expect(response).to have_http_status(:created) # created
expect(json_response).to be_truthy
expect(json_response['data_option']['default']).to be_falsey
@ -514,20 +514,20 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
if Overview.where('name like ?', '%test%').empty?
post '/api/v1/overviews', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(Hash).to eq(json_response.class)
expect('test_overview').to eq(json_response['name'])
end
# 3. attempt to delete the ticket attribute
get '/api/v1/object_manager_attributes', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
target_attribute = json_response.select { |x| x['name'] == 'test_attribute_referenced_by_an_overview' && x['object'] == 'Ticket' }
expect(target_attribute.size).to eq(1)
target_id = target_attribute[0]['id']
delete "/api/v1/object_manager_attributes/#{target_id}", as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(response.body).to include('Overview')
expect(response.body).to include('test_overview')
expect(response.body).to include('cannot be deleted!')
@ -600,20 +600,20 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
if Trigger.where('name like ?', '%test%').empty?
post '/api/v1/triggers', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(Hash).to eq(json_response.class)
expect('test_trigger').to eq(json_response['name'])
end
# 3. attempt to delete the ticket attribute
get '/api/v1/object_manager_attributes', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
target_attribute = json_response.select { |x| x['name'] == 'test_attribute_referenced_by_a_trigger' && x['object'] == 'Ticket' }
expect(target_attribute.size).to eq(1)
target_id = target_attribute[0]['id']
delete "/api/v1/object_manager_attributes/#{target_id}", as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(response.body).to include('Trigger')
expect(response.body).to include('test_trigger')
expect(response.body).to include('cannot be deleted!')
@ -733,20 +733,20 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
if Job.where('name like ?', '%test%').empty?
post '/api/v1/jobs', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(Hash).to eq(json_response.class)
expect('test_scheduler').to eq(json_response['name'])
end
# 3. attempt to delete the ticket attribute
get '/api/v1/object_manager_attributes', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
target_attribute = json_response.select { |x| x['name'] == 'test_attribute_referenced_by_a_scheduler' && x['object'] == 'Ticket' }
expect(target_attribute.size).to eq(1)
target_id = target_attribute[0]['id']
delete "/api/v1/object_manager_attributes/#{target_id}", as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(response.body).to include('Job')
expect(response.body).to include('test_scheduler')
expect(response.body).to include('cannot be deleted!')
@ -866,14 +866,14 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
if Overview.where('name like ?', '%test%').empty?
post '/api/v1/overviews', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(Hash).to eq(json_response.class)
expect('test_overview').to eq(json_response['name'])
end
# 3. attempt to delete the ticket attribute
get '/api/v1/object_manager_attributes', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
all_json_response = json_response
target_attribute = all_json_response.select { |x| x['name'] == 'test_attribute_referenced_by_an_overview' && x['object'] == 'User' }
@ -881,14 +881,14 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
target_id = target_attribute[0]['id']
delete "/api/v1/object_manager_attributes/#{target_id}", as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
target_attribute = all_json_response.select { |x| x['name'] == 'test_attribute_referenced_by_an_overview' && x['object'] == 'Ticket' }
expect(target_attribute.size).to eq(1)
target_id = target_attribute[0]['id']
delete "/api/v1/object_manager_attributes/#{target_id}", as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(response.body).to include('Overview')
expect(response.body).to include('test_overview')
expect(response.body).to include('cannot be deleted!')
@ -937,7 +937,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
authenticated_as(admin_user)
post '/api/v1/object_manager_attributes', params: params, as: :json
expect(response).to have_http_status(201) # created
expect(response).to have_http_status(:created) # created
expect(json_response).to be_truthy
expect(json_response['data_option']['default']).to be_falsey
@ -955,7 +955,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
}
put "/api/v1/object_manager_attributes/#{json_response['id']}", params: params, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_truthy
expect(json_response['error']).to be_truthy
@ -999,7 +999,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
authenticated_as(admin_user)
post '/api/v1/object_manager_attributes', params: params, as: :json
expect(response).to have_http_status(201) # created
expect(response).to have_http_status(:created) # created
expect(json_response).to be_truthy
expect(json_response['data_option']['default']).to eq('test')
@ -1019,7 +1019,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do
put "/api/v1/object_manager_attributes/#{json_response['id']}", params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_truthy
expect(json_response['data_option']['default']).to eq('test')
expect(json_response['data_option_new']['default']).to eq('fuu')

View file

@ -36,7 +36,7 @@ RSpec.describe 'Integration Placetel', type: :request do
)
end
before(:each) do
before do
Cti::Log.destroy_all
Setting.set('placetel_integration', true)
@ -76,7 +76,7 @@ RSpec.describe 'Integration Placetel', type: :request do
it 'does token check' do
params = 'event=IncomingCall&from=01114100300&to=030600000000&call_id=4991155921769858278-1'
post '/api/v1/placetel/not_existing_token', params: params
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
error = nil
local_response = REXML::Document.new(response.body)
@ -92,7 +92,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# inbound - I
params = 'event=IncomingCall&from=01114100300&to=030600000000&call_id=4991155921769858278-1'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
local_response = REXML::Document.new(response.body)
expect(local_response.elements.count).to eq(1)
@ -101,7 +101,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# inbound - II - block caller
params = 'event=IncomingCall&from=491715000000&to=030600000000&call_id=4991155921769858278-2'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
local_response = REXML::Document.new(response.body)
reason = nil
@ -113,7 +113,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# outbound - I - set default_caller_id
params = 'event=newCall&direction=out&from=030600000000&to=01114100300&call_id=8621106404543334274-3'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
caller_id = nil
number_to_dail = nil
@ -130,7 +130,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# outbound - II - set caller_id based on routing_table by explicite number
params = 'event=newCall&direction=out&from=030600000000&to=491714000000&call_id=8621106404543334274-4'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
caller_id = nil
number_to_dail = nil
@ -147,7 +147,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# outbound - III - set caller_id based on routing_table by 41*
params = 'event=newCall&direction=out&from=030600000000&to=4147110000000&call_id=8621106404543334274-5'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
caller_id = nil
number_to_dail = nil
@ -165,7 +165,7 @@ RSpec.describe 'Integration Placetel', type: :request do
Setting.set('placetel_config', {})
params = 'event=IncomingCall&from=01114100300&to=030600000000&call_id=4991155921769858278-6'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
error = nil
local_response = REXML::Document.new(response.body)
@ -181,7 +181,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# outbound - I - new call
params = 'event=newCall&direction=out&from=030600000000&to=01114100300&call_id=1234567890-1'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-1')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -203,7 +203,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# outbound - I - hangup by agent
params = 'event=HungUp&call_id=1234567890-1&type=missed'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-1')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -225,7 +225,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# outbound - II - new call
params = 'event=newCall&direction=out&from=030600000000&to=01114100300&call_id=1234567890-2'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-2')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -247,7 +247,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# outbound - II - answer by customer
params = 'event=CallAccepted&call_id=1234567890-2&from=030600000000&to=01114100300'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-2')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -269,7 +269,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# outbound - II - hangup by customer
params = 'event=HungUp&call_id=1234567890-2&type=accepted&from=030600000000&to=01114100300'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-2')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -291,7 +291,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# inbound - I - new call
params = 'event=IncomingCall&to=030600000000&from=01114100300&call_id=1234567890-3'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-3')
expect(log).to be_truthy
expect(log.to).to eq('030600000000')
@ -313,7 +313,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# inbound - I - answer by customer
params = 'event=CallAccepted&call_id=1234567890-3&to=030600000000&from=01114100300'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-3')
expect(log).to be_truthy
expect(log.to).to eq('030600000000')
@ -335,7 +335,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# inbound - I - hangup by customer
params = 'event=HungUp&call_id=1234567890-3&type=accepted&to=030600000000&from=01114100300'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-3')
expect(log).to be_truthy
expect(log.to).to eq('030600000000')
@ -357,7 +357,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# inbound - II - new call
params = 'event=IncomingCall&to=030600000000&from=01114100300&call_id=1234567890-4'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-4')
expect(log).to be_truthy
expect(log.to).to eq('030600000000')
@ -379,7 +379,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# inbound - II - answer by voicemail
params = 'event=CallAccepted&call_id=1234567890-4&to=030600000000&from=01114100300&user=voicemail'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-4')
expect(log).to be_truthy
expect(log.to).to eq('030600000000')
@ -401,7 +401,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# inbound - II - hangup by customer
params = 'event=HungUp&call_id=1234567890-4&type=accepted&to=030600000000&from=01114100300'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-4')
expect(log).to be_truthy
expect(log.to).to eq('030600000000')
@ -423,7 +423,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# inbound - III - new call
params = 'event=IncomingCall&to=030600000000&from=01114100300&call_id=1234567890-5'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-5')
expect(log).to be_truthy
expect(log.to).to eq('030600000000')
@ -445,7 +445,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# inbound - III - hangup by customer
params = 'event=HungUp&call_id=1234567890-5&type=accepted&to=030600000000&from=01114100300'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-5')
expect(log).to be_truthy
expect(log.to).to eq('030600000000')
@ -467,7 +467,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# inbound - IV - new call
params = 'event=IncomingCall&to=030600000000&from=49999992222222&call_id=1234567890-6'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-6')
expect(log).to be_truthy
expect(log.to).to eq('030600000000')
@ -491,7 +491,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# inbound - IV - new call
params = 'event=IncomingCall&to=030600000000&from=anonymous&call_id=1234567890-7'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-7')
expect(log).to be_truthy
expect(log.to).to eq('030600000000')
@ -512,11 +512,11 @@ RSpec.describe 'Integration Placetel', type: :request do
# get caller list
get '/api/v1/cti/log'
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
authenticated_as(agent_user)
get '/api/v1/cti/log', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['list']).to be_a_kind_of(Array)
expect(json_response['list'].count).to eq(7)
expect(json_response['assets']).to be_truthy
@ -545,7 +545,7 @@ RSpec.describe 'Integration Placetel', type: :request do
# outbound - I - new call
params = 'event=newCall&direction=out&from=030600000000&to=01114100300&call_id=1234567890-1&peer=something@example.com'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-1')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -571,7 +571,7 @@ RSpec.describe 'Integration Placetel', type: :request do
params = 'event=newCall&direction=out&from=030600000000&to=01114100300&call_id=1234567890-2&peer=777008478072@example.com'
post "/api/v1/placetel/#{token}", params: params
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-2')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')

View file

@ -36,7 +36,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
)
end
before(:each) do
before do
Cti::Log.destroy_all
Setting.set('sipgate_integration', true)
@ -78,7 +78,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# inbound - I
params = 'event=newCall&direction=in&from=4912347114711&to=4930600000000&callId=4991155921769858278-1&user%5B%5D=user+1&user%5B%5D=user+2'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
on_hangup = nil
on_answer = nil
content = @response.body
@ -93,7 +93,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# inbound - II - block caller
params = 'event=newCall&direction=in&from=491715000000&to=4930600000000&callId=4991155921769858278-2&user%5B%5D=user+1&user%5B%5D=user+2'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
on_hangup = nil
on_answer = nil
content = @response.body
@ -113,7 +113,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# outbound - I - set default_caller_id
params = 'event=newCall&direction=out&from=4930600000000&to=4912347114711&callId=8621106404543334274-3&user%5B%5D=user+1'
post '/api/v1/sipgate/out', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
on_hangup = nil
on_answer = nil
caller_id = nil
@ -138,7 +138,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# outbound - II - set caller_id based on routing_table by explicite number
params = 'event=newCall&direction=out&from=4930600000000&to=491714000000&callId=8621106404543334274-4&user%5B%5D=user+1'
post '/api/v1/sipgate/out', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
on_hangup = nil
on_answer = nil
caller_id = nil
@ -163,7 +163,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# outbound - III - set caller_id based on routing_table by 41*
params = 'event=newCall&direction=out&from=4930600000000&to=4147110000000&callId=8621106404543334274-5&user%5B%5D=user+1'
post '/api/v1/sipgate/out', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
on_hangup = nil
on_answer = nil
caller_id = nil
@ -189,7 +189,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
Setting.set('sipgate_config', {})
params = 'event=newCall&direction=in&from=4912347114711&to=4930600000000&callId=4991155921769858278-6&user%5B%5D=user+1&user%5B%5D=user+2'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(422)
expect(@response).to have_http_status(:unprocessable_entity)
error = nil
content = @response.body
response = REXML::Document.new(content)
@ -205,7 +205,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# outbound - I - new call
params = 'event=newCall&direction=out&from=4930600000000&to=4912347114711&callId=1234567890-1&user%5B%5D=user+1'
post '/api/v1/sipgate/out', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-1')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -222,7 +222,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# outbound - I - hangup by agent
params = 'event=hangup&direction=out&callId=1234567890-1&cause=cancel'
post '/api/v1/sipgate/out', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-1')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -239,7 +239,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# outbound - II - new call
params = 'event=newCall&direction=out&from=4930600000000&to=4912347114711&callId=1234567890-2&user%5B%5D=user+1'
post '/api/v1/sipgate/out', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-2')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -256,7 +256,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# outbound - II - answer by customer
params = 'event=answer&direction=out&callId=1234567890-2&from=4930600000000&to=4912347114711'
post '/api/v1/sipgate/out', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-2')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -273,7 +273,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# outbound - II - hangup by customer
params = 'event=hangup&direction=out&callId=1234567890-2&cause=normalClearing&from=4930600000000&to=4912347114711'
post '/api/v1/sipgate/out', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-2')
expect(log).to be_truthy
expect(log.from).to eq('4930777000000')
@ -290,7 +290,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# inbound - I - new call
params = 'event=newCall&direction=in&to=4930600000000&from=4912347114711&callId=1234567890-3&user%5B%5D=user+1'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-3')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -307,7 +307,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# inbound - I - answer by customer
params = 'event=answer&direction=in&callId=1234567890-3&to=4930600000000&from=4912347114711'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-3')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -324,7 +324,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# inbound - I - hangup by customer
params = 'event=hangup&direction=in&callId=1234567890-3&cause=normalClearing&to=4930600000000&from=4912347114711'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-3')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -341,7 +341,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# inbound - II - new call
params = 'event=newCall&direction=in&to=4930600000000&from=4912347114711&callId=1234567890-4&user%5B%5D=user+1,user+2'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-4')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -358,7 +358,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# inbound - II - answer by voicemail
params = 'event=answer&direction=in&callId=1234567890-4&to=4930600000000&from=4912347114711&user=voicemail'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-4')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -375,7 +375,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# inbound - II - hangup by customer
params = 'event=hangup&direction=in&callId=1234567890-4&cause=normalClearing&to=4930600000000&from=4912347114711'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-4')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -392,7 +392,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# inbound - III - new call
params = 'event=newCall&direction=in&to=4930600000000&from=4912347114711&callId=1234567890-5&user%5B%5D=user+1,user+2'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-5')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -409,7 +409,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# inbound - III - hangup by customer
params = 'event=hangup&direction=in&callId=1234567890-5&cause=normalClearing&to=4930600000000&from=4912347114711'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-5')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -426,7 +426,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# inbound - IV - new call
params = 'event=newCall&direction=in&to=4930600000000&from=49999992222222&callId=1234567890-6&user%5B%5D=user+1,user+2'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
log = Cti::Log.find_by(call_id: '1234567890-6')
expect(log).to be_truthy
expect(log.to).to eq('4930600000000')
@ -442,11 +442,11 @@ RSpec.describe 'Integration Sipgate', type: :request do
# get caller list
get '/api/v1/cti/log'
expect(@response).to have_http_status(401)
expect(@response).to have_http_status(:unauthorized)
authenticated_as(agent_user)
get '/api/v1/cti/log', as: :json
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
expect(json_response['list']).to be_a_kind_of(Array)
expect(json_response['list'].count).to eq(6)
expect(json_response['assets']).to be_truthy
@ -474,7 +474,7 @@ RSpec.describe 'Integration Sipgate', type: :request do
# inbound - I
params = 'event=newCall&direction=in&from=4912347114711&to=4930600000000&callId=4991155921769858278-1&user%5B%5D=user+1&user%5B%5D=user+2'
post '/api/v1/sipgate/in', params: params
expect(@response).to have_http_status(200)
expect(@response).to have_http_status(:ok)
on_hangup = nil
on_answer = nil
content = @response.body

View file

@ -72,24 +72,24 @@ RSpec.describe 'Telegram', type: :request do
# start communication #1
post '/api/v1/channels/telegram_webhook', params: read_message('personal1_message_start'), as: :json
expect(response).to have_http_status(404)
expect(response).to have_http_status(:not_found)
post '/api/v1/channels_telegram_webhook/not_existing', params: read_message('personal1_message_start'), as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response['error']).to eq('bot param missing')
callback_url = "/api/v1/channels_telegram_webhook/not_existing?bid=#{channel.options[:bot][:id]}"
post callback_url, params: read_message('personal1_message_start'), as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response['error']).to eq('invalid callback token')
callback_url = "/api/v1/channels_telegram_webhook/#{channel.options[:callback_token]}?bid=#{channel.options[:bot][:id]}"
post callback_url, params: read_message('personal1_message_start'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
# send message1
post callback_url, params: read_message('personal1_message_content1'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(1)
ticket = Ticket.last
expect(ticket.title).to eq('Hello, I need your Help')
@ -100,7 +100,7 @@ RSpec.describe 'Telegram', type: :request do
# send channel message1
post callback_url, params: read_message('channel1_message_content1'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(1)
ticket = Ticket.last
expect(ticket.title).to eq('Hello, I need your Help')
@ -111,7 +111,7 @@ RSpec.describe 'Telegram', type: :request do
# edit channel message1
post callback_url, params: read_message('channel2_message_content1'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(1)
ticket = Ticket.last
expect(ticket.title).to eq('Hello, I need your Help')
@ -122,7 +122,7 @@ RSpec.describe 'Telegram', type: :request do
# send same message again, ignore it
post callback_url, params: read_message('personal1_message_content1'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
ticket = Ticket.last
expect(ticket.title).to eq('Hello, I need your Help')
expect(ticket.state.name).to eq('new')
@ -132,7 +132,7 @@ RSpec.describe 'Telegram', type: :request do
# send message2
post callback_url, params: read_message('personal1_message_content2'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
ticket = Ticket.last
expect(ticket.title).to eq('Hello, I need your Help')
expect(ticket.state.name).to eq('new')
@ -142,7 +142,7 @@ RSpec.describe 'Telegram', type: :request do
# send end message
post callback_url, params: read_message('personal1_message_end'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
ticket = Ticket.last
expect(ticket.title).to eq('Hello, I need your Help')
expect(ticket.state.name).to eq('closed')
@ -152,11 +152,11 @@ RSpec.describe 'Telegram', type: :request do
# start communication #2
post callback_url, params: read_message('personal2_message_start'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
# send message1
post callback_url, params: read_message('personal2_message_content1'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(2)
ticket = Ticket.last
expect(ticket.title).to eq('Can you help me with my feature?')
@ -167,7 +167,7 @@ RSpec.describe 'Telegram', type: :request do
# send message2
post callback_url, params: read_message('personal2_message_content2'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(2)
ticket = Ticket.last
expect(ticket.title).to eq('Can you help me with my feature?')
@ -178,11 +178,11 @@ RSpec.describe 'Telegram', type: :request do
# start communication #3
post callback_url, params: read_message('personal3_message_start'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
# send message1
post callback_url, params: read_message('personal3_message_content1'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(3)
ticket = Ticket.last
expect(ticket.title).to eq('Can you help me with my feature?')
@ -199,7 +199,7 @@ RSpec.describe 'Telegram', type: :request do
.to_return(status: 200, body: 'ABC1', headers: {})
post callback_url, params: read_message('personal3_message_content2'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(3)
ticket = Ticket.last
expect(ticket.title).to eq('Can you help me with my feature?')
@ -210,7 +210,7 @@ RSpec.describe 'Telegram', type: :request do
# send channel message 3
post callback_url, params: read_message('channel1_message_content3'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(3)
ticket = Ticket.last
expect(ticket.title).to eq('Can you help me with my feature?')
@ -230,7 +230,7 @@ RSpec.describe 'Telegram', type: :request do
.to_return(status: 200, body: '{"result":{"file_size":123,"file_id":"ABC-123BQADAgADDgAD7x6ZSC_-1LMkOEmoAg","file_path":"abc123"}}', headers: {})
post callback_url, params: read_message('personal3_message_content3'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(3)
ticket = Ticket.last
expect(ticket.title).to eq('Can you help me with my feature?')
@ -242,7 +242,7 @@ RSpec.describe 'Telegram', type: :request do
# isend channel message 2
post callback_url, params: read_message('channel1_message_content2'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(3)
ticket = Ticket.last
expect(ticket.title).to eq('Can you help me with my feature?')
@ -254,7 +254,7 @@ RSpec.describe 'Telegram', type: :request do
# update message1
post callback_url, params: read_message('personal3_message_content4'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(3)
ticket = Ticket.last
expect(ticket.title).to eq('Can you help me with my feature?')
@ -273,7 +273,7 @@ RSpec.describe 'Telegram', type: :request do
.to_return(status: 200, body: '{"result":{"file_size":123,"file_id":"ABC-123AwADAgADVQADCEIYSZwyOmSZK9iZAg","file_path":"abc123"}}', headers: {})
post callback_url, params: read_message('personal3_message_content5'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(3)
ticket = Ticket.last
expect(ticket.title).to eq('Can you help me with my feature?')
@ -284,7 +284,7 @@ RSpec.describe 'Telegram', type: :request do
# send channel message 4 with voice
post callback_url, params: read_message('channel1_message_content4'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(3)
ticket = Ticket.last
expect(ticket.title).to eq('Can you help me with my feature?')
@ -302,7 +302,7 @@ RSpec.describe 'Telegram', type: :request do
.to_return(status: 200, body: '{"result":{"file_size":123,"file_id":"ABC-123BQADAwAD0QIAAqbJWAAB8OkQqgtDQe0C","file_path":"abc123"}}', headers: {})
post callback_url, params: read_message('personal4_message_content1'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(4)
ticket = Ticket.last
if Rails.application.config.db_4bytes_utf8
@ -318,7 +318,7 @@ RSpec.describe 'Telegram', type: :request do
# send channel message #5 with sticker
post callback_url, params: read_message('channel1_message_content5'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(4)
ticket = Ticket.last
if Rails.application.config.db_4bytes_utf8
@ -338,7 +338,7 @@ RSpec.describe 'Telegram', type: :request do
.to_return(status: 200, body: '{"result":{"file_size":123,"file_id":"ABC-123AgADAgADwacxGxk5MUmim45lijOwsKk1Sw0ABNQoaI8BwR_z_2MFAAEC","file_path":"abc123"}}', headers: {})
post callback_url, params: read_message('personal5_message_content1'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(5)
ticket = Ticket.last
expect(ticket.title).to eq('-')
@ -349,7 +349,7 @@ RSpec.describe 'Telegram', type: :request do
expect(ticket.articles.last.attachments.count).to eq(0)
post callback_url, params: read_message('personal5_message_content2'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(Ticket.count).to eq(5)
ticket = Ticket.last
expect(ticket.title).to eq('Hello, I need your Help')

View file

@ -30,20 +30,20 @@ RSpec.describe 'Twilio SMS', type: :request do
# process inbound sms
post '/api/v1/sms_webhook', params: read_message('inbound_sms1'), as: :json
expect(response).to have_http_status(404)
expect(response).to have_http_status(:not_found)
post '/api/v1/sms_webhook/not_existing', params: read_message('inbound_sms1'), as: :json
expect(response).to have_http_status(404)
expect(response).to have_http_status(:not_found)
post '/api/v1/sms_webhook/f409460e50f76d331fdac8ba7b7963b6', params: read_message('inbound_sms1'), as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect('Can\'t use Channel::Driver::Sms::Twilio: #<Exceptions::UnprocessableEntity: Group needed in channel definition!>').to eq(json_response['error'])
channel.group_id = Group.first.id
channel.save!
post '/api/v1/sms_webhook/f409460e50f76d331fdac8ba7b7963b6', params: read_message('inbound_sms1'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
xml_response = REXML::Document.new(response.body)
expect(1).to eq(xml_response.elements.count)
@ -66,7 +66,7 @@ RSpec.describe 'Twilio SMS', type: :request do
expect(article.type.name).to eq('sms')
post '/api/v1/sms_webhook/f409460e50f76d331fdac8ba7b7963b6', params: read_message('inbound_sms2'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
xml_response = REXML::Document.new(response.body)
expect(1).to eq(xml_response.elements.count)
@ -86,7 +86,7 @@ RSpec.describe 'Twilio SMS', type: :request do
# check duplicate callbacks
post '/api/v1/sms_webhook/f409460e50f76d331fdac8ba7b7963b6', params: read_message('inbound_sms2'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
xml_response = REXML::Document.new(response.body)
expect(1).to eq(xml_response.elements.count)
@ -100,13 +100,13 @@ RSpec.describe 'Twilio SMS', type: :request do
ticket.save!
post '/api/v1/sms_webhook/f409460e50f76d331fdac8ba7b7963b6', params: read_message('inbound_sms3'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
xml_response = REXML::Document.new(response.body)
expect(1).to eq(xml_response.elements.count)
ticket.reload
expect(ticket.articles.count).to eq(2)
expect(ticket.id).to_not eq(Ticket.last.id)
expect(ticket.id).not_to eq(Ticket.last.id)
expect(ticket.state.name).to eq('closed')
ticket = Ticket.last
@ -134,7 +134,7 @@ RSpec.describe 'Twilio SMS', type: :request do
}
authenticated_as(agent_user)
post '/api/v1/ticket_articles', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['subject']).to be_nil
expect(json_response['body']).to eq('some test')
@ -196,7 +196,7 @@ RSpec.describe 'Twilio SMS', type: :request do
)
post '/api/v1/sms_webhook/f409460e50f76d331fdac8ba7b7963b6', params: read_message('inbound_sms1'), as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
xml_response = REXML::Document.new(response.body)
expect(1).to eq(xml_response.elements.count)

View file

@ -7,6 +7,7 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
describe '#webhook_verify (for Twitter to confirm Zammads credentials)' do
context 'with only cached credentials' do
let!(:external_credential) { nil }
before { Cache.write('external_credential_twitter', credentials) }
it 'returns an HMAC signature for cached credentials plus params[:crc_token]' do
@ -15,7 +16,7 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
headers: { 'x-twitter-webhooks-signature' => 'something' },
as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to include('response_token' => 'sha256=VE19eUk6krbdSqWPdvH71xtFhApBAU81uPW3UT65vOs=')
end
end
@ -27,7 +28,7 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
headers: { 'x-twitter-webhooks-signature' => 'something' },
as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to include('response_token' => 'sha256=VE19eUk6krbdSqWPdvH71xtFhApBAU81uPW3UT65vOs=')
end
end
@ -74,7 +75,7 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
headers: { 'x-twitter-webhooks-signature' => 'sha256=JjEmBe1lVKT8XldrYUKibF+D5ehp8f0jDk3PXZSHEWI=' },
as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
end
end
@ -82,7 +83,7 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
it 'returns 422 with error message' do
post '/api/v1/channels_twitter_webhook', as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => "Missing 'x-twitter-webhooks-signature' header")
end
end
@ -96,7 +97,7 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
headers: { 'x-twitter-webhooks-signature' => 'something' },
as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => "No such external_credential 'twitter'!")
end
end
@ -107,7 +108,7 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
headers: { 'x-twitter-webhooks-signature' => 'something' },
as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to include('error' => 'Not authorized')
end
end
@ -119,7 +120,7 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
headers: { 'x-twitter-webhooks-signature' => 'sha256=EERHBy/k17v+SuT+K0OXuwhJtKnPtxi0n/Y4Wye4kVU=' },
as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => "Missing 'for_user_id' in payload!")
end
end
@ -131,7 +132,7 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
headers: { 'x-twitter-webhooks-signature' => 'sha256=QaJiQl/4WRp/GF37b+eAdF6kPgptjDCLOgAIIbB1s0I=' },
as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to include('error' => "No such channel for user id 'not_existing'!")
end
end
@ -149,12 +150,12 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
it 'returns 200' do
post '/api/v1/channels_twitter_webhook', **webhook_payload, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
end
it 'creates closed ticket' do
expect { post '/api/v1/channels_twitter_webhook', **webhook_payload, as: :json }
.to change { Ticket.count }.by(1)
.to change(Ticket, :count).by(1)
expect(Ticket.last.attributes)
.to include(
@ -194,12 +195,12 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
it 'returns 200' do
post '/api/v1/channels_twitter_webhook', **webhook_payload, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
end
it 'creates new ticket' do
expect { post '/api/v1/channels_twitter_webhook', **webhook_payload, as: :json }
.to change { Ticket.count }.by(1)
.to change(Ticket, :count).by(1)
expect(Ticket.last.attributes)
.to include(
@ -243,12 +244,12 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
it 'returns 200' do
post '/api/v1/channels_twitter_webhook', **webhook_payload, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
end
it 'does not create new ticket' do
expect { post '/api/v1/channels_twitter_webhook', **webhook_payload, as: :json }
.not_to change { Ticket.count }
.not_to change(Ticket, :count)
end
it 'adds new article to existing, open ticket' do
@ -280,7 +281,7 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
it 'still returns 200' do
2.times { post '/api/v1/channels_twitter_webhook', **webhook_payload, as: :json }
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
end
it 'does not create duplicate articles' do
@ -305,12 +306,12 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
it 'returns 200' do
post '/api/v1/channels_twitter_webhook', **webhook_payload, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
end
it 'creates a closed ticket' do
expect { post '/api/v1/channels_twitter_webhook', **webhook_payload, as: :json }
.to change { Ticket.count }.by(1)
.to change(Ticket, :count).by(1)
expect(Ticket.last.attributes)
.to include(
@ -353,12 +354,12 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
it 'returns 200' do
post '/api/v1/channels_twitter_webhook', **webhook_payload, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
end
it 'creates a new ticket' do
expect { post '/api/v1/channels_twitter_webhook', **webhook_payload, as: :json }
.to change { Ticket.count }.by(1)
.to change(Ticket, :count).by(1)
expect(Ticket.last.attributes)
.to include(
@ -397,7 +398,7 @@ RSpec.describe 'Twitter Webhook Integration', type: :request do
it 'still returns 200' do
2.times { post '/api/v1/channels_twitter_webhook', **webhook_payload, as: :json }
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
end
it 'does not create duplicate articles' do

View file

@ -9,7 +9,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
create(:agent_user, login: 'user-device-agent', password: 'agentpw', groups: Group.all)
end
before(:each) do
before do
ENV['TEST_REMOTE_IP'] = '5.9.62.170' # de
ENV['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:46.0) Gecko/20100101 Firefox/46.0'
ENV['SWITCHED_FROM_USER_ID'] = nil
@ -22,7 +22,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
it 'does index with nobody (01)' do
get '/api/v1/signshow'
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect('no valid session').to eq(json_response['error'])
expect(json_response['config']).to be_truthy
@ -35,7 +35,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = { without_fingerprint: 'none', username: 'user-device-admin', password: 'adminpw' }
post '/api/v1/signin', params: params, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Need fingerprint param!')
@ -62,7 +62,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
it 'does login index with admin with fingerprint - I (03)' do
params = { fingerprint: 'my_finger_print', username: 'user-device-admin', password: 'adminpw' }
post '/api/v1/signin', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to be_falsey
expect(json_response['config']).to be_truthy
@ -88,7 +88,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = {}
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(controller.session[:user_device_fingerprint]).to eq('my_finger_print')
@ -112,7 +112,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = { fingerprint: 'my_finger_print' }
get '/api/v1/signshow', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['session']).to be_truthy
expect('user-device-admin').to eq(json_response['session']['login'])
@ -139,7 +139,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
ENV['USER_DEVICE_UPDATED_AT'] = (Time.zone.now - 4.hours).to_s
params = {}
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(controller.session[:user_device_fingerprint]).to eq('my_finger_print')
@ -159,7 +159,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
expect(UserDevice.where(user_id: admin_user.id).count).to eq(1)
user_device_last = UserDevice.last
expect(user_device_last.updated_at.to_s).to_not eq(user_device_first.updated_at.to_s)
expect(user_device_last.updated_at.to_s).not_to eq(user_device_first.updated_at.to_s)
ENV['USER_DEVICE_UPDATED_AT'] = nil
ENV['TEST_REMOTE_IP'] = '195.65.29.254' # ch
@ -168,7 +168,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = {}
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
check_notification do
@ -201,7 +201,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = { fingerprint: 'my_finger_print_II', username: 'user-device-admin', password: 'adminpw' }
post '/api/v1/signin', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
check_notification do
@ -224,7 +224,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
expect(controller.session[:user_device_fingerprint]).to be_truthy
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
check_notification do
@ -245,7 +245,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = { fingerprint: 'my_finger_print_II' }
get '/api/v1/signshow', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['session']).to be_truthy
expect('user-device-admin').to eq(json_response['session']['login'])
@ -271,7 +271,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = {}
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
check_notification do
@ -307,7 +307,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = { fingerprint: 'my_finger_print_II', username: 'user-device-admin', password: 'adminpw' }
post '/api/v1/signin', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
check_notification do
@ -346,7 +346,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = {}
authenticated_as(admin_user, password: 'adminpw')
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
check_notification do
@ -369,7 +369,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = {}
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
check_notification do
@ -396,7 +396,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = {}
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
check_notification do
@ -436,7 +436,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = {}
authenticated_as(admin_user, password: 'adminpw')
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
check_notification do
@ -463,7 +463,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = {}
authenticated_as(agent_user, password: 'agentpw')
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
check_notification do
@ -500,7 +500,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = {}
authenticated_as(agent_user, password: 'agentpw')
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
check_notification do
@ -528,7 +528,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
params = { fingerprint: 'my_finger_print_II', username: 'user-device-agent', password: 'agentpw' }
post '/api/v1/signin', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
check_notification do
@ -568,7 +568,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
ENV['USER_DEVICE_UPDATED_AT'] = (Time.zone.now - 4.hours).to_s
params = {}
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
check_notification do
@ -591,7 +591,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
ENV['TEST_REMOTE_IP'] = '195.65.29.254' # ch
params = {}
get '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
check_notification do
@ -616,7 +616,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
it 'does login with invalid fingerprint (11)' do
params = { fingerprint: 'to_long_1234567890to_long_1234567890to_long_1234567890to_long_1234567890to_long_1234567890to_long_1234567890to_long_1234567890to_long_1234567890to_long_1234567890to_long_1234567890to_long_1234567890', username: 'user-device-admin', password: 'adminpw' }
post '/api/v1/signin', params: params, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('fingerprint is 198 chars but can only be 160 chars!')
@ -643,7 +643,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
it 'does login with integer as fingerprint (12)' do
params = { fingerprint: 123_456_789, username: 'user-device-admin', password: 'adminpw' }
post '/api/v1/signin', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(controller.session[:user_device_fingerprint]).to be_truthy
check_notification do
@ -673,7 +673,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do
}
authenticated_as(admin_user, password: 'adminpw')
post '/api/v1/form_config', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to be_falsey

View file

@ -6,7 +6,7 @@ RSpec.describe 'LongPolling', type: :request do
create(:agent_user)
end
before(:each) do
before do
Sessions.sessions.each do |client_id|
Sessions.destroy(client_id)
end
@ -17,25 +17,25 @@ RSpec.describe 'LongPolling', type: :request do
it 'receive without client_id - no user login' do
get '/api/v1/message_receive', params: { data: {} }, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Invalid client_id receive!')
end
it 'send without client_id - no user login' do
get '/api/v1/message_send', params: { data: {} }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['client_id'].to_i).to be_between(1, 9_999_999_999)
client_id = json_response['client_id']
get '/api/v1/message_send', params: { client_id: client_id, data: { event: 'spool' } }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['client_id'].to_i).to be_between(1, 9_999_999_999)
get '/api/v1/message_receive', params: { client_id: client_id, data: {} }, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Invalid client_id receive!')
end
@ -43,7 +43,7 @@ RSpec.describe 'LongPolling', type: :request do
it 'receive without client_id' do
authenticated_as(agent_user)
get '/api/v1/message_receive', params: { data: {} }, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Invalid client_id receive!')
end
@ -51,7 +51,7 @@ RSpec.describe 'LongPolling', type: :request do
it 'receive without wrong client_id' do
authenticated_as(agent_user)
get '/api/v1/message_receive', params: { client_id: 'not existing', data: {} }, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Invalid client_id receive!')
end
@ -59,7 +59,7 @@ RSpec.describe 'LongPolling', type: :request do
it 'send without client_id' do
authenticated_as(agent_user)
get '/api/v1/message_send', params: { data: {} }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['client_id'].to_i).to be_between(1, 9_999_999_999)
end
@ -68,7 +68,7 @@ RSpec.describe 'LongPolling', type: :request do
Sessions.create('123456', {}, { type: 'ajax' })
authenticated_as(agent_user)
get '/api/v1/message_send', params: { client_id: '123456', data: {} }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to eq({})
end
@ -79,22 +79,22 @@ RSpec.describe 'LongPolling', type: :request do
# will update the user by every request and return a different result for the test
authenticated_as(agent_user, token: create(:token, action: 'api', user_id: agent_user.id) )
get '/api/v1/message_send', params: { data: { event: 'login' } }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['client_id'].to_i).to be_between(1, 9_999_999_999)
client_id = json_response['client_id']
get '/api/v1/message_receive', params: { client_id: client_id, data: {} }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to eq([{ 'data' => { 'success' => true }, 'event' => 'ws:login' }])
get '/api/v1/message_send', params: { client_id: client_id, data: { event: 'spool' } }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to eq({})
get '/api/v1/message_receive', params: { client_id: client_id, data: {} }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response[0]['event']).to eq('spool:sent')
expect(json_response[0]['event']).to eq('spool:sent')
@ -104,12 +104,12 @@ RSpec.describe 'LongPolling', type: :request do
expect(spool_list).to eq([])
get '/api/v1/message_send', params: { client_id: client_id, data: { event: 'broadcast', spool: true, recipient: { user_id: [agent_user.id] }, data: { taskbar_id: 9_391_633 } } }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to eq({})
get '/api/v1/message_receive', params: { client_id: client_id, data: {} }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to eq({ 'event' => 'pong' })

View file

@ -6,7 +6,7 @@ RSpec.describe 'OAuth', type: :request do
it 'does o365 - start' do
get '/auth/microsoft_office365'
expect(response).to have_http_status(302)
expect(response).to have_http_status(:found)
expect(response.body).to include('https://login.microsoftonline.com/common/oauth2/v2.0/authorize')
expect(response.body).to include('redirect_uri=http%3A%2F%2Fzammad.example.com%2Fauth%2Fmicrosoft_office365%2Fcallback')
expect(response.body).to include('scope=openid+email+profile')
@ -15,13 +15,13 @@ RSpec.describe 'OAuth', type: :request do
it 'does o365 - callback' do
get '/auth/microsoft_office365/callback?code=1234&state=1234'
expect(response).to have_http_status(302)
expect(response).to have_http_status(:found)
expect(response.body).to include('302 Moved')
end
it 'does auth failure' do
get '/auth/failure?message=123&strategy=some_provider'
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(response.body).to include('<title>422: Unprocessable Entity</title>')
expect(response.body).to include('<h1>422: The change you wanted was rejected.</h1>')
expect(response.body).to include('<div>Message from some_provider: 123</div>')

View file

@ -39,7 +39,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
create(:customer_user, organization: organization)
end
before(:each) do
before do
configure_elasticsearch do
travel 1.minute
@ -60,13 +60,13 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
# index
authenticated_as(agent_user)
get '/api/v1/organizations', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response[0]['member_ids']).to be_a_kind_of(Array)
expect(json_response.length >= 3).to be_truthy
get '/api/v1/organizations?limit=40&page=1&per_page=2', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
organizations = Organization.order(:id).limit(2)
expect(json_response[0]['id']).to eq(organizations[0].id)
@ -76,7 +76,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
expect(json_response.count).to eq(2)
get '/api/v1/organizations?limit=40&page=2&per_page=2', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
organizations = Organization.order(:id).limit(4)
expect(json_response[0]['id']).to eq(organizations[2].id)
@ -88,14 +88,14 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
# show/:id
get "/api/v1/organizations/#{organization.id}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['member_ids']).to be_a_kind_of(Array)
expect(json_response['members']).to be_falsey
expect('Rest Org #1').to eq(json_response['name'])
get "/api/v1/organizations/#{organization2.id}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['member_ids']).to be_a_kind_of(Array)
expect(json_response['members']).to be_falsey
@ -104,21 +104,21 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
# search as agent
Scheduler.worker(true)
get "/api/v1/organizations/search?query=#{CGI.escape('Zammad')}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response[0]['name']).to eq('Zammad Foundation')
expect(json_response[0]['member_ids']).to be_truthy
expect(json_response[0]['members']).to be_falsey
get "/api/v1/organizations/search?query=#{CGI.escape('Zammad')}&expand=true", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response[0]['name']).to eq('Zammad Foundation')
expect(json_response[0]['member_ids']).to be_truthy
expect(json_response[0]['members']).to be_truthy
get "/api/v1/organizations/search?query=#{CGI.escape('Zammad')}&label=true", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response[0]['label']).to eq('Zammad Foundation')
expect(json_response[0]['value']).to eq('Zammad Foundation')
@ -131,25 +131,25 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
# index
authenticated_as(customer_user)
get '/api/v1/organizations', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response.length).to eq(0)
# show/:id
get "/api/v1/organizations/#{organization.id}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to be_nil
get "/api/v1/organizations/#{organization2.id}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to be_nil
# search
Scheduler.worker(true)
get "/api/v1/organizations/search?query=#{CGI.escape('Zammad')}", params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
end
it 'does index with customer2' do
@ -157,59 +157,59 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
# index
authenticated_as(customer_user2)
get '/api/v1/organizations', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response.length).to eq(1)
# show/:id
get "/api/v1/organizations/#{organization.id}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect('Rest Org #1').to eq(json_response['name'])
get "/api/v1/organizations/#{organization2.id}", params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to be_nil
# search
Scheduler.worker(true)
get "/api/v1/organizations/search?query=#{CGI.escape('Zammad')}", params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
end
it 'does organization search sortable' do
authenticated_as(admin_user)
get "/api/v1/organizations/search?query=#{CGI.escape('Rest Org')}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
result = json_response
result.collect! { |v| v['id'] }
expect(result).to be_a_kind_of(Array)
expect(result).to eq([ organization.id, organization3.id, organization2.id ])
get "/api/v1/organizations/search?query=#{CGI.escape('Rest Org')}", params: { sort_by: 'created_at', order_by: 'asc' }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
result = json_response
result.collect! { |v| v['id'] }
expect(result).to be_a_kind_of(Array)
expect(result).to eq([ organization.id, organization2.id, organization3.id ])
get "/api/v1/organizations/search?query=#{CGI.escape('Rest Org')}", params: { sort_by: 'note', order_by: 'asc' }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
result = json_response
result.collect! { |v| v['id'] }
expect(result).to be_a_kind_of(Array)
expect(result).to eq([ organization.id, organization2.id, organization3.id ])
get "/api/v1/organizations/search?query=#{CGI.escape('Rest Org')}", params: { sort_by: 'note', order_by: 'desc' }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
result = json_response
result.collect! { |v| v['id'] }
expect(result).to be_a_kind_of(Array)
expect(result).to eq([ organization3.id, organization2.id, organization.id ])
get "/api/v1/organizations/search?query=#{CGI.escape('Rest Org')}", params: { sort_by: %w[note created_at], order_by: %w[desc asc] }, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
result = json_response
result.collect! { |v| v['id'] }
expect(result).to be_a_kind_of(Array)
@ -227,7 +227,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
authenticated_as(admin_user)
get "/api/v1/organizations/#{organization.id}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['id']).to eq(organization.id)
expect(json_response['name']).to eq(organization.name)
@ -237,7 +237,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
expect(json_response['created_by_id']).to eq(admin_user.id)
get "/api/v1/organizations/#{organization.id}?expand=true", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['id']).to eq(organization.id)
expect(json_response['name']).to eq(organization.name)
@ -247,7 +247,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
expect(json_response['created_by_id']).to eq(admin_user.id)
get "/api/v1/organizations/#{organization.id}?expand=false", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['id']).to eq(organization.id)
expect(json_response['name']).to eq(organization.name)
@ -257,7 +257,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
expect(json_response['created_by_id']).to eq(admin_user.id)
get "/api/v1/organizations/#{organization.id}?full=true", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['id']).to eq(organization.id)
@ -270,7 +270,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
expect(json_response['assets']['Organization'][organization.id.to_s]['members']).to be_falsey
get "/api/v1/organizations/#{organization.id}?full=false", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['id']).to eq(organization.id)
expect(json_response['name']).to eq(organization.name)
@ -291,7 +291,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
authenticated_as(admin_user)
get '/api/v1/organizations', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response[0].class).to eq(Hash)
expect(json_response.last['id']).to eq(organization.id)
@ -302,7 +302,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
expect(json_response.last['created_by_id']).to eq(admin_user.id)
get '/api/v1/organizations?expand=true', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response[0].class).to eq(Hash)
expect(json_response.last['id']).to eq(organization.id)
@ -313,7 +313,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
expect(json_response.last['created_by_id']).to eq(admin_user.id)
get '/api/v1/organizations?expand=false', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response[0].class).to eq(Hash)
expect(json_response.last['id']).to eq(organization.id)
@ -324,7 +324,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
expect(json_response.last['created_by_id']).to eq(admin_user.id)
get '/api/v1/organizations?full=true', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['record_ids'].class).to eq(Array)
@ -339,7 +339,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
expect(json_response['assets']['Organization'][organization.id.to_s]['members']).to be_falsey
get '/api/v1/organizations?full=false', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response[0].class).to eq(Hash)
expect(json_response.last['id']).to eq(organization.id)
@ -358,7 +358,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
authenticated_as(admin_user)
post '/api/v1/organizations', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
organization = Organization.find(json_response['id'])
@ -370,7 +370,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
params[:name] = 'Rest Org NEW #2'
post '/api/v1/organizations?expand=true', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
organization = Organization.find(json_response['id'])
@ -382,7 +382,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
params[:name] = 'Rest Org NEW #3'
post '/api/v1/organizations?full=true', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
organization = Organization.find(json_response['id'])
@ -410,7 +410,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
}
authenticated_as(admin_user)
put "/api/v1/organizations/#{organization.id}", params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
organization = Organization.find(json_response['id'])
@ -424,7 +424,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
name: 'a update name #2',
}
put "/api/v1/organizations/#{organization.id}?expand=true", params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
organization = Organization.find(json_response['id'])
@ -438,7 +438,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
name: 'a update name #3',
}
put "/api/v1/organizations/#{organization.id}?full=true", params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
organization = Organization.find(json_response['id'])
@ -460,7 +460,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
authenticated_as(agent_user)
get "/api/v1/organizations/history/#{organization1.id}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['history'].class).to eq(Array)
expect(json_response['assets'].class).to eq(Hash)
@ -471,14 +471,14 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
it 'does csv example - customer no access' do
authenticated_as(customer_user)
get '/api/v1/organizations/import_example', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']).to eq('Not authorized (user)!')
end
it 'does csv example - admin access' do
authenticated_as(admin_user)
get '/api/v1/organizations/import_example', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
rows = CSV.parse(@response.body)
header = rows.shift
@ -490,7 +490,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
expect(header[4]).to eq('domain_assignment')
expect(header[5]).to eq('active')
expect(header[6]).to eq('note')
expect(header.include?('members')).to be_truthy
expect(header).to include('members')
end
it 'does csv import - admin access' do
@ -520,7 +520,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
authenticated_as(admin_user)
csv_file = fixture_file_upload('csv_import/organization/simple_col_not_existing.csv', 'text/csv')
post '/api/v1/organizations/import?try=true', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['try']).to eq(true)
@ -533,7 +533,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
# valid file try
csv_file = fixture_file_upload('csv_import/organization/simple.csv', 'text/csv')
post '/api/v1/organizations/import?try=true', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['try']).to eq(true)
@ -546,7 +546,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
# valid file
csv_file = fixture_file_upload('csv_import/organization/simple.csv', 'text/csv')
post '/api/v1/organizations/import', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['try']).to eq(false)

View file

@ -35,7 +35,7 @@ RSpec.describe 'Overviews', type: :request do
authenticated_as(agent_user)
post '/api/v1/overviews', params: params, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('authentication failed')
end
@ -65,13 +65,13 @@ RSpec.describe 'Overviews', type: :request do
authenticated_as(admin_user)
post '/api/v1/overviews', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq('Overview2')
expect(json_response['link']).to eq('my_overview')
post '/api/v1/overviews', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq('Overview2')
expect(json_response['link']).to eq('my_overview_1')
@ -136,7 +136,7 @@ RSpec.describe 'Overviews', type: :request do
}
authenticated_as(admin_user)
post '/api/v1/overviews_prio', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['success']).to eq(true)
@ -175,7 +175,7 @@ RSpec.describe 'Overviews', type: :request do
authenticated_as(admin_user)
post '/api/v1/overviews', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq('Overview2')
expect(json_response['link']).to eq('my_overview')

View file

@ -16,7 +16,7 @@ RSpec.describe 'Packages', type: :request do
it 'does packages index with nobody' do
get '/api/v1/packages', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['packages']).to be_falsey
@ -27,7 +27,7 @@ RSpec.describe 'Packages', type: :request do
authenticated_as(admin_user)
get '/api/v1/packages', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['packages']).to be_truthy
end
@ -36,7 +36,7 @@ RSpec.describe 'Packages', type: :request do
authenticated_as(admin_user, password: 'wrongadminpw')
get '/api/v1/packages', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('authentication failed')
end
@ -47,7 +47,7 @@ RSpec.describe 'Packages', type: :request do
authenticated_as(admin_user)
get '/api/v1/packages', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('authentication failed')
end
@ -56,7 +56,7 @@ RSpec.describe 'Packages', type: :request do
authenticated_as(agent_user)
get '/api/v1/packages', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['packages']).to be_falsey
expect(json_response['error']).to eq('Not authorized (user)!')
@ -66,7 +66,7 @@ RSpec.describe 'Packages', type: :request do
authenticated_as(customer_user)
get '/api/v1/packages', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['packages']).to be_falsey
expect(json_response['error']).to eq('Not authorized (user)!')

View file

@ -42,7 +42,7 @@ RSpec.describe 'Report', type: :request, searchindex: true do
}
end
before(:each) do
before do
configure_elasticsearch do
travel 1.minute
@ -75,7 +75,7 @@ RSpec.describe 'Report', type: :request, searchindex: true do
authenticated_as(admin_user)
get "/api/v1/reports/sets?sheet=true;metric=count;year=#{year};month=#{month};week=#{week};day=#{day};timeRange=year;profile_id=1;downloadBackendSelected=count::created", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
assert(@response['Content-Disposition'])
expect(@response['Content-Disposition']).to eq('attachment; filename="tickets--all--Created.xls"')
expect(@response['Content-Type']).to eq('application/vnd.ms-excel')
@ -99,28 +99,28 @@ RSpec.describe 'Report', type: :request, searchindex: true do
backends: backends
}
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1])
Setting.set('timezone_default', 'Europe/Berlin')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1])
Setting.set('timezone_default', 'America/Chicago')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'Australia/Melbourne')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
@ -139,21 +139,21 @@ RSpec.describe 'Report', type: :request, searchindex: true do
}
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
Setting.set('timezone_default', 'Europe/Berlin')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'America/Chicago')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2])
@ -178,7 +178,7 @@ RSpec.describe 'Report', type: :request, searchindex: true do
}
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
@ -191,7 +191,7 @@ RSpec.describe 'Report', type: :request, searchindex: true do
Setting.set('timezone_default', 'America/Chicago')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2])
@ -216,7 +216,7 @@ RSpec.describe 'Report', type: :request, searchindex: true do
}
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
@ -229,7 +229,7 @@ RSpec.describe 'Report', type: :request, searchindex: true do
Setting.set('timezone_default', 'America/Chicago')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
@ -252,28 +252,28 @@ RSpec.describe 'Report', type: :request, searchindex: true do
backends: backends
}
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([0, 1, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 1, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'Europe/Berlin')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([0, 0, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 7, 2, 0, 0, 0, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'America/Chicago')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([0, 2, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 2, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'Australia/Melbourne')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['data']['count::created']).to eq([0, 0, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 7, 2, 0, 0, 0, 0, 0, 0, 0, 0])

View file

@ -52,7 +52,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
create(:ticket_article, ticket_id: ticket3.id)
end
before(:each) do
before do
configure_elasticsearch do
travel 1.minute
@ -75,21 +75,21 @@ RSpec.describe 'Search', type: :request, searchindex: true do
}
post '/api/v1/search/ticket', params: params, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to_not be_blank
expect(json_response).not_to be_blank
expect(json_response['error']).to eq('authentication failed')
post '/api/v1/search/user', params: params, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to_not be_blank
expect(json_response).not_to be_blank
expect(json_response['error']).to eq('authentication failed')
post '/api/v1/search', params: params, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to_not be_blank
expect(json_response).not_to be_blank
expect(json_response['error']).to eq('authentication failed')
end
@ -100,7 +100,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
}
authenticated_as(admin_user)
post '/api/v1/search', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['result'][0]['type']).to eq('Ticket')
@ -115,7 +115,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
}
post '/api/v1/search', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['result'][0]['type']).to eq('Ticket')
@ -134,7 +134,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
}
post '/api/v1/search/ticket', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['result'][0]['type']).to eq('Ticket')
@ -151,7 +151,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
}
post '/api/v1/search/user', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result'][0]['type']).to eq('User')
expect(json_response['result'][0]['id']).to eq(agent_user.id)
@ -166,7 +166,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
authenticated_as(agent_user)
post '/api/v1/search', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['result'][0]['type']).to eq('Ticket')
@ -181,7 +181,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
}
post '/api/v1/search', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['result'][0]['type']).to eq('Ticket')
@ -200,7 +200,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
}
post '/api/v1/search/ticket', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['result'][0]['type']).to eq('Ticket')
@ -217,7 +217,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
}
post '/api/v1/search/user', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result'][0]['type']).to eq('User')
expect(json_response['result'][0]['id']).to eq(agent_user.id)
@ -232,7 +232,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
authenticated_as(customer_user)
post '/api/v1/search', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['result'][0]['type']).to eq('Ticket')
@ -245,7 +245,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
}
post '/api/v1/search/ticket', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['result'][0]['type']).to eq('Ticket')
@ -258,7 +258,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
}
post '/api/v1/search/user', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result'][0]).to be_falsey
end
@ -271,7 +271,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
authenticated_as(customer_user2)
post '/api/v1/search', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['result'][0]['type']).to eq('Ticket')
@ -286,7 +286,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
}
post '/api/v1/search/ticket', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['result'][0]['type']).to eq('Ticket')
@ -301,7 +301,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
}
post '/api/v1/search/user', params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['result'][0]).to be_falsey
end
@ -310,7 +310,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
it 'does searching for organization with a dot in its name' do
authenticated_as(agent_user)
get '/api/v1/search/organization?query=tes.', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['result'].size).to eq(1)
expect(json_response['result'][0]['type']).to eq('Organization')
target_id = json_response['result'][0]['id']
@ -321,7 +321,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do
it 'does searching for organization with _ in its name' do
authenticated_as(agent_user)
get '/api/v1/search/organization?query=abc_', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response['result'].size).to eq(1)
expect(json_response['result'][0]['type']).to eq('Organization')
target_id = json_response['result'][0]['id']

View file

@ -24,14 +24,14 @@ RSpec.describe 'Settings', type: :request do
# index
get '/api/v1/settings', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['settings']).to be_falsey
# show
setting = Setting.find_by(name: 'product_name')
get "/api/v1/settings/#{setting.id}", params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']).to eq('authentication failed')
end
@ -40,7 +40,7 @@ RSpec.describe 'Settings', type: :request do
# index
authenticated_as(admin_user)
get '/api/v1/settings', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
hit_api = false
@ -59,13 +59,13 @@ RSpec.describe 'Settings', type: :request do
# show
setting = Setting.find_by(name: 'product_name')
get "/api/v1/settings/#{setting.id}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq('product_name')
setting = Setting.find_by(name: 'api_token_access')
get "/api/v1/settings/#{setting.id}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq('api_token_access')
@ -80,7 +80,7 @@ RSpec.describe 'Settings', type: :request do
}
}
put "/api/v1/settings/#{setting.id}", params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq('product_name')
expect(json_response['preferences']['permission'].length).to eq(1)
@ -98,7 +98,7 @@ RSpec.describe 'Settings', type: :request do
}
}
put "/api/v1/settings/#{setting.id}", params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq('api_token_access')
expect(json_response['preferences']['permission'].length).to eq(1)
@ -108,7 +108,7 @@ RSpec.describe 'Settings', type: :request do
# delete
setting = Setting.find_by(name: 'product_name')
delete "/api/v1/settings/#{setting.id}", params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']).to eq('Not authorized (feature not possible)')
end
@ -117,7 +117,7 @@ RSpec.describe 'Settings', type: :request do
# index
authenticated_as(admin_api_user)
get '/api/v1/settings', params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
hit_api = false
@ -136,12 +136,12 @@ RSpec.describe 'Settings', type: :request do
# show
setting = Setting.find_by(name: 'product_name')
get "/api/v1/settings/#{setting.id}", params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']).to eq('Not authorized (required ["admin.branding"])')
setting = Setting.find_by(name: 'api_token_access')
get "/api/v1/settings/#{setting.id}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq('api_token_access')
@ -156,7 +156,7 @@ RSpec.describe 'Settings', type: :request do
}
}
put "/api/v1/settings/#{setting.id}", params: params, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']).to eq('Not authorized (required ["admin.branding"])')
# update
@ -170,7 +170,7 @@ RSpec.describe 'Settings', type: :request do
}
}
put "/api/v1/settings/#{setting.id}", params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['name']).to eq('api_token_access')
expect(json_response['preferences']['permission'].length).to eq(1)
@ -180,7 +180,7 @@ RSpec.describe 'Settings', type: :request do
# delete
setting = Setting.find_by(name: 'product_name')
delete "/api/v1/settings/#{setting.id}", params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']).to eq('Not authorized (feature not possible)')
end
@ -189,7 +189,7 @@ RSpec.describe 'Settings', type: :request do
# index
authenticated_as(agent_user)
get '/api/v1/settings', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['settings']).to be_falsey
expect(json_response['error']).to eq('Not authorized (user)!')
@ -197,7 +197,7 @@ RSpec.describe 'Settings', type: :request do
# show
setting = Setting.find_by(name: 'product_name')
get "/api/v1/settings/#{setting.id}", params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']).to eq('Not authorized (user)!')
end
@ -206,7 +206,7 @@ RSpec.describe 'Settings', type: :request do
# index
authenticated_as(customer_user)
get '/api/v1/settings', params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['settings']).to be_falsey
expect(json_response['error']).to eq('Not authorized (user)!')
@ -214,13 +214,13 @@ RSpec.describe 'Settings', type: :request do
# show
setting = Setting.find_by(name: 'product_name')
get "/api/v1/settings/#{setting.id}", params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']).to eq('Not authorized (user)!')
# delete
setting = Setting.find_by(name: 'product_name')
delete "/api/v1/settings/#{setting.id}", params: {}, as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']).to eq('Not authorized (user)!')
end
end

View file

@ -10,7 +10,7 @@ RSpec.describe 'SLAs', type: :request do
it 'does index sla with nobody' do
get '/api/v1/slas', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('authentication failed')
@ -19,19 +19,19 @@ RSpec.describe 'SLAs', type: :request do
it 'does index sla with admin' do
authenticated_as(admin_user)
get '/api/v1/slas', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
expect(json_response.count).to eq(0)
get '/api/v1/slas?expand=true', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Array)
expect(json_response).to be_truthy
expect(json_response.count).to eq(0)
get '/api/v1/slas?full=true', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['record_ids']).to be_truthy

View file

@ -34,7 +34,7 @@ RSpec.describe 'Taskbars', type: :request do
authenticated_as(agent_user)
post '/api/v1/taskbar', params: params, as: :json
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['client_id']).to eq('123')
expect(json_response['user_id']).to eq(agent_user.id)
@ -48,7 +48,7 @@ RSpec.describe 'Taskbars', type: :request do
shown: false,
}
put "/api/v1/taskbar/#{taskbar_id}", params: params, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['client_id']).to eq('123')
expect(json_response['user_id']).to eq(agent_user.id)
@ -62,19 +62,19 @@ RSpec.describe 'Taskbars', type: :request do
authenticated_as(customer_user)
put "/api/v1/taskbar/#{taskbar_id}", params: params, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not allowed to access this task.')
delete "/api/v1/taskbar/#{taskbar_id}", params: {}, as: :json
expect(response).to have_http_status(422)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not allowed to access this task.')
# delete with correct user
authenticated_as(agent_user)
delete "/api/v1/taskbar/#{taskbar_id}", params: {}, as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_blank
end

View file

@ -18,7 +18,7 @@ RSpec.describe 'Text Module', type: :request do
it 'does csv example - customer no access' do
authenticated_as(customer_user)
get '/api/v1/text_modules/import_example', as: :json
expect(response).to have_http_status(401)
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']).to eq('Not authorized (user)!')
end
@ -27,7 +27,7 @@ RSpec.describe 'Text Module', type: :request do
authenticated_as(admin_user)
get '/api/v1/text_modules/import_example', as: :json
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
rows = CSV.parse(@response.body)
header = rows.shift
@ -37,11 +37,11 @@ RSpec.describe 'Text Module', type: :request do
expect(header[3]).to eq('content')
expect(header[4]).to eq('note')
expect(header[5]).to eq('active')
expect(header).to_not include('organization')
expect(header).to_not include('priority')
expect(header).to_not include('state')
expect(header).to_not include('owner')
expect(header).to_not include('customer')
expect(header).not_to include('organization')
expect(header).not_to include('priority')
expect(header).not_to include('state')
expect(header).not_to include('owner')
expect(header).not_to include('customer')
end
it 'does csv import - admin access' do
@ -51,7 +51,7 @@ RSpec.describe 'Text Module', type: :request do
authenticated_as(admin_user)
post '/api/v1/text_modules/import', params: { try: true, file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['try']).to be_truthy
@ -64,7 +64,7 @@ RSpec.describe 'Text Module', type: :request do
# valid file try
csv_file = fixture_file_upload('csv_import/text_module/simple.csv', 'text/csv')
post '/api/v1/text_modules/import?try=true', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['try']).to be_truthy
@ -77,7 +77,7 @@ RSpec.describe 'Text Module', type: :request do
# valid file
csv_file = fixture_file_upload('csv_import/text_module/simple.csv', 'text/csv')
post '/api/v1/text_modules/import', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['try']).to eq(false)

Some files were not shown because too many files have changed in this diff Show more