From 83239518d0fa4cd4779055b24d660facf2fb2047 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 19 Jun 2020 11:17:18 +0200 Subject: [PATCH] Refactoring: Restore consistency by replacing *_user suffix factories with just customer, admin and agent factory name. --- spec/factories/authorization.rb | 2 +- spec/factories/recent_view.rb | 2 +- spec/factories/template.rb | 4 +- spec/factories/user.rb | 6 +- spec/lib/auto_wizard_spec.rb | 2 +- spec/lib/notification_factory/mailer_spec.rb | 4 +- spec/lib/notification_factory/slack_spec.rb | 4 +- .../attributes/role_ids/unassigned_spec.rb | 2 +- .../sessions/backend/activity_stream_spec.rb | 2 +- spec/lib/sessions/backend/base_spec.rb | 2 +- .../backend/ticket_overview_list_spec.rb | 2 +- .../sessions/event/chat_session_start_spec.rb | 4 +- spec/lib/sessions/event/chat_transfer_spec.rb | 4 +- spec/lib/signature_detection_spec.rb | 2 +- spec/lib/stats/ticket_waiting_time_spec.rb | 2 +- spec/lib/stats_spec.rb | 2 +- .../application_model/can_assets_examples.rb | 2 +- spec/models/channel/email_parser_spec.rb | 10 +- spec/models/concerns/has_history_examples.rb | 2 +- spec/models/cti/caller_id_spec.rb | 16 +- spec/models/cti/driver/base_spec.rb | 10 +- spec/models/cti/log_spec.rb | 24 +- spec/models/job_spec.rb | 4 +- .../search_with_attachment_spec.rb | 2 +- spec/models/knowledge_base_spec.rb | 4 +- .../attribute/validation/required_spec.rb | 4 +- spec/models/organization_spec.rb | 4 +- spec/models/recent_view_spec.rb | 6 +- spec/models/taskbar_spec.rb | 40 +- spec/models/ticket_spec.rb | 16 +- spec/models/token_spec.rb | 2 +- spec/models/trigger/sms_spec.rb | 12 +- spec/models/trigger_spec.rb | 4 +- ...lookup_search_index_attributes_examples.rb | 2 +- spec/models/user_device_spec.rb | 8 +- spec/models/user_group_spec.rb | 2 +- spec/models/user_spec.rb | 42 +- spec/policies/ticket_policy_spec.rb | 6 +- spec/policies/user_policy_spec.rb | 32 +- spec/requests/api_auth_on_behalf_of_spec.rb | 48 +- spec/requests/api_auth_spec.rb | 58 +- spec/requests/calendar_spec.rb | 6 +- spec/requests/error_spec.rb | 4 +- spec/requests/external_credentials_spec.rb | 4 +- spec/requests/integration/check_mk_spec.rb | 12 +- spec/requests/integration/cti_spec.rb | 34 +- spec/requests/integration/idoit_spec.rb | 22 +- spec/requests/integration/monitoring_spec.rb | 22 +- .../object_manager_attributes_spec.rb | 36 +- spec/requests/integration/placetel_spec.rb | 22 +- spec/requests/integration/sipgate_spec.rb | 22 +- spec/requests/integration/smime_spec.rb | 4 +- spec/requests/integration/twilio_sms_spec.rb | 12 +- spec/requests/integration/user_device_spec.rb | 184 +++--- .../knowledge_base/translation_update_spec.rb | 8 +- spec/requests/long_polling_spec.rb | 22 +- spec/requests/organization_spec.rb | 124 ++-- spec/requests/overview_spec.rb | 14 +- spec/requests/package_spec.rb | 24 +- spec/requests/report_spec.rb | 8 +- spec/requests/search_spec.rb | 70 +-- spec/requests/session_spec.rb | 2 +- spec/requests/settings_spec.rb | 24 +- spec/requests/sla_spec.rb | 6 +- spec/requests/tag_spec.rb | 2 +- spec/requests/taskbar_spec.rb | 24 +- spec/requests/text_module_spec.rb | 18 +- .../ticket/article_attachments_spec.rb | 20 +- spec/requests/ticket/article_spec.rb | 92 +-- spec/requests/ticket/escalation_spec.rb | 18 +- spec/requests/ticket_spec.rb | 554 +++++++++--------- spec/requests/time_accounting_spec.rb | 4 +- spec/requests/upload_cache_spec.rb | 2 +- spec/requests/user/organization_spec.rb | 22 +- spec/requests/user/permission_spec.rb | 70 +-- spec/requests/user_spec.rb | 212 +++---- spec/support/request.rb | 4 +- spec/support/sends_notification_emails.rb | 6 +- spec/system/ticket/create_spec.rb | 6 +- spec/system/ticket/zoom_spec.rb | 38 +- 80 files changed, 1092 insertions(+), 1092 deletions(-) diff --git a/spec/factories/authorization.rb b/spec/factories/authorization.rb index 11dcf043f..9f4a5dd40 100644 --- a/spec/factories/authorization.rb +++ b/spec/factories/authorization.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :authorization do transient do - user { create(:customer_user) } + user { create(:customer) } end factory :twitter_authorization do diff --git a/spec/factories/recent_view.rb b/spec/factories/recent_view.rb index b6f9adc94..cc2829c3a 100644 --- a/spec/factories/recent_view.rb +++ b/spec/factories/recent_view.rb @@ -11,7 +11,7 @@ FactoryBot.define do # assign to an existing user, if possible created_by_id do User.find { |u| u.role?(user_role.capitalize) }&.id || - create("#{user_role}_user").id + create(user_role).id end end end diff --git a/spec/factories/template.rb b/spec/factories/template.rb index eeeb2029c..8bfb45d5c 100644 --- a/spec/factories/template.rb +++ b/spec/factories/template.rb @@ -9,9 +9,9 @@ FactoryBot.define do title { 'Title dummy.' } body { 'Content dummy.' } sender_type { 'email-out' } - customer { create(:customer_user) } + customer { create(:customer) } group { Group.first } - owner { create(:agent_user) } + owner { create(:agent) } end trait :dummy_data do diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 93da4b575..d63b33937 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -21,7 +21,7 @@ FactoryBot.define do object.preferences[:intro] = true end - factory :customer_user, aliases: %i[customer] do + factory :customer do role_ids { Role.signup_role_ids.sort } trait :with_org do @@ -29,11 +29,11 @@ FactoryBot.define do end end - factory :agent_user, aliases: %i[agent] do + factory :agent do roles { Role.where(name: 'Agent') } end - factory :admin_user, aliases: %i[admin] do + factory :admin do roles { Role.where(name: %w[Admin Agent]) } end diff --git a/spec/lib/auto_wizard_spec.rb b/spec/lib/auto_wizard_spec.rb index c727c0450..88ee6a9c5 100644 --- a/spec/lib/auto_wizard_spec.rb +++ b/spec/lib/auto_wizard_spec.rb @@ -107,7 +107,7 @@ RSpec.describe AutoWizard do } end - let(:group_agent) { create(:agent_user) } + let(:group_agent) { create(:agent) } let(:group_signature) { create(:signature) } let(:group_email) { create(:email_address) } diff --git a/spec/lib/notification_factory/mailer_spec.rb b/spec/lib/notification_factory/mailer_spec.rb index 901162540..93efbe1ee 100644 --- a/spec/lib/notification_factory/mailer_spec.rb +++ b/spec/lib/notification_factory/mailer_spec.rb @@ -101,7 +101,7 @@ RSpec.describe NotificationFactory::Mailer do end context 'recipient with email address' do - let(:user) { create(:agent_user, email: 'somebody@example.com') } + let(:user) { create(:agent, email: 'somebody@example.com') } it 'returns a Mail::Message' do expect( result ).to be_kind_of(Mail::Message) @@ -109,7 +109,7 @@ RSpec.describe NotificationFactory::Mailer do end context 'recipient without email address' do - let(:user) { create(:agent_user, email: '') } + let(:user) { create(:agent, email: '') } it 'raises Exceptions::UnprocessableEntity' do expect { result }.to raise_error(Exceptions::UnprocessableEntity) diff --git a/spec/lib/notification_factory/slack_spec.rb b/spec/lib/notification_factory/slack_spec.rb index 3b7aae850..cbe620939 100644 --- a/spec/lib/notification_factory/slack_spec.rb +++ b/spec/lib/notification_factory/slack_spec.rb @@ -19,8 +19,8 @@ RSpec.describe NotificationFactory::Slack do let(:ticket) { article.ticket } let(:article) { create(:ticket_article) } - let(:agent) { create(:agent_user) } - let(:current_user) { create(:agent_user) } + let(:agent) { create(:agent) } + let(:current_user) { create(:agent) } context 'for "ticket_create", with an empty "changes" hash' do let(:action) { 'ticket_create' } diff --git a/spec/lib/sequencer/unit/import/ldap/user/attributes/role_ids/unassigned_spec.rb b/spec/lib/sequencer/unit/import/ldap/user/attributes/role_ids/unassigned_spec.rb index 5eeb108ef..a7b29a32c 100644 --- a/spec/lib/sequencer/unit/import/ldap/user/attributes/role_ids/unassigned_spec.rb +++ b/spec/lib/sequencer/unit/import/ldap/user/attributes/role_ids/unassigned_spec.rb @@ -35,7 +35,7 @@ RSpec.describe Sequencer::Unit::Import::Ldap::User::Attributes::RoleIds::Unassig login: 'jane_doe' }.with_indifferent_access end - let(:instance) { create(:agent_user, mapped) } + let(:instance) { create(:agent, mapped) } context 'when user exists from previous import' do context 'and is active' do diff --git a/spec/lib/sessions/backend/activity_stream_spec.rb b/spec/lib/sessions/backend/activity_stream_spec.rb index c79419b95..52dc4aac3 100644 --- a/spec/lib/sessions/backend/activity_stream_spec.rb +++ b/spec/lib/sessions/backend/activity_stream_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe Sessions::Backend::ActivityStream do context 'when async processes affect associated objects / DB records (#2066)' do let(:subject) { described_class.new(user, {}) } - let(:user) { create(:agent_user, groups: [group]) } + let(:user) { create(:agent, groups: [group]) } let(:group) { Group.find_by(name: 'Users') } let(:associated_tickets) { create_list(:ticket, ticket_count, group: group) } let(:ticket_count) { 20 } diff --git a/spec/lib/sessions/backend/base_spec.rb b/spec/lib/sessions/backend/base_spec.rb index dcf84643d..337e5ad88 100644 --- a/spec/lib/sessions/backend/base_spec.rb +++ b/spec/lib/sessions/backend/base_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe Sessions::Backend::Base do subject(:backend) { described_class.new(agent, {}, false, client_id, ttl) } - let(:agent) { create(:agent_user) } + let(:agent) { create(:agent) } let(:client_id) { '123-1' } let(:ttl) { 3 } # seconds let!(:ticket) { Ticket.first || create(:ticket) } diff --git a/spec/lib/sessions/backend/ticket_overview_list_spec.rb b/spec/lib/sessions/backend/ticket_overview_list_spec.rb index b2b1fa77e..1ce186d02 100644 --- a/spec/lib/sessions/backend/ticket_overview_list_spec.rb +++ b/spec/lib/sessions/backend/ticket_overview_list_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Sessions::Backend::TicketOverviewList do end describe '.push' do - let(:admin) { create(:admin_user, groups: [group]) } + let(:admin) { create(:admin, groups: [group]) } let(:group) { create(:group) } let(:client_id) { '12345' } let(:ttl) { 3 } # seconds diff --git a/spec/lib/sessions/event/chat_session_start_spec.rb b/spec/lib/sessions/event/chat_session_start_spec.rb index 3f4453d24..a8e2eba5d 100644 --- a/spec/lib/sessions/event/chat_session_start_spec.rb +++ b/spec/lib/sessions/event/chat_session_start_spec.rb @@ -14,7 +14,7 @@ RSpec.describe Sessions::Event::ChatSessionStart do ) end let!(:agent) do - agent = create(:agent_user, preferences: { chat: { active: { chat.id.to_s => 'on' } } }) + agent = create(:agent, preferences: { chat: { active: { chat.id.to_s => 'on' } } }) file = File.open('test/data/image/1000x1000.png', 'rb') contents = file.read avatar = Avatar.add( @@ -35,7 +35,7 @@ RSpec.describe Sessions::Event::ChatSessionStart do agent.save! agent end - let!(:customer) { create(:customer_user) } + let!(:customer) { create(:customer) } let(:subject_as_agent) do Sessions.create(client_id, { 'id' => agent.id }, {}) Sessions.queue(client_id) diff --git a/spec/lib/sessions/event/chat_transfer_spec.rb b/spec/lib/sessions/event/chat_transfer_spec.rb index 879e65909..9057656fa 100644 --- a/spec/lib/sessions/event/chat_transfer_spec.rb +++ b/spec/lib/sessions/event/chat_transfer_spec.rb @@ -15,9 +15,9 @@ RSpec.describe Sessions::Event::ChatTransfer do ) end let!(:agent) do - create(:agent_user, preferences: { chat: { active: { chat.id.to_s => 'on' } } }) + create(:agent, preferences: { chat: { active: { chat.id.to_s => 'on' } } }) end - let!(:customer) { create(:customer_user) } + let!(:customer) { create(:customer) } let(:subject_as_agent) do Sessions.create(client_id, { 'id' => agent.id }, {}) Sessions.queue(client_id) diff --git a/spec/lib/signature_detection_spec.rb b/spec/lib/signature_detection_spec.rb index b4f7b5775..e5971dab3 100644 --- a/spec/lib/signature_detection_spec.rb +++ b/spec/lib/signature_detection_spec.rb @@ -158,7 +158,7 @@ RSpec.describe SignatureDetection do describe '.rebuild_all_articles' do context 'when a user exists with a recorded signature' do - let!(:customer) { create(:customer_user, preferences: { signature_detection: "\nbar" }) } + let!(:customer) { create(:customer, preferences: { signature_detection: "\nbar" }) } context 'and multiple articles exist for that customer' do let!(:articles) do diff --git a/spec/lib/stats/ticket_waiting_time_spec.rb b/spec/lib/stats/ticket_waiting_time_spec.rb index 838dfab23..9f0d34367 100644 --- a/spec/lib/stats/ticket_waiting_time_spec.rb +++ b/spec/lib/stats/ticket_waiting_time_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' RSpec.describe Stats::TicketWaitingTime do describe '.generate' do - let(:user) { create(:agent_user, groups: [group]) } + let(:user) { create(:agent, groups: [group]) } let(:group) { create(:group) } context 'when given an agent with no tickets' do diff --git a/spec/lib/stats_spec.rb b/spec/lib/stats_spec.rb index 256a6fdbd..68e6d688f 100644 --- a/spec/lib/stats_spec.rb +++ b/spec/lib/stats_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Stats do before do # create a user for which the stats can be generated - create(:agent_user) + create(:agent) end it 'generates stats' do diff --git a/spec/models/application_model/can_assets_examples.rb b/spec/models/application_model/can_assets_examples.rb index aedaa36cc..b5047be27 100644 --- a/spec/models/application_model/can_assets_examples.rb +++ b/spec/models/application_model/can_assets_examples.rb @@ -1,7 +1,7 @@ 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) } + let(:admin) { create(:admin) } describe '#assets (for supplying model data to front-end framework)' do shared_examples 'own asset attributes' do diff --git a/spec/models/channel/email_parser_spec.rb b/spec/models/channel/email_parser_spec.rb index fef83cc7c..25faec8df 100644 --- a/spec/models/channel/email_parser_spec.rb +++ b/spec/models/channel/email_parser_spec.rb @@ -125,7 +125,7 @@ RSpec.describe Channel::EmailParser, type: :model do end context 'when from address matches an existing agent' do - let!(:agent) { create(:agent_user, email: 'foo@bar.com') } + let!(:agent) { create(:agent, email: 'foo@bar.com') } it 'sets article.sender to "Agent"' do described_class.new.process({}, raw_mail) @@ -141,7 +141,7 @@ RSpec.describe Channel::EmailParser, type: :model do end context 'when from address matches an existing customer' do - let!(:customer) { create(:customer_user, email: 'foo@bar.com') } + let!(:customer) { create(:customer, email: 'foo@bar.com') } it 'sets article.sender to "Customer"' do described_class.new.process({}, raw_mail) @@ -816,8 +816,8 @@ RSpec.describe Channel::EmailParser, type: :model do end describe 'assigning ticket.customer' do - let(:agent) { create(:agent_user) } - let(:customer) { create(:customer_user) } + let(:agent) { create(:agent) } + let(:customer) { create(:customer) } let(:raw_mail) { <<~RAW.chomp } From: #{agent.email} @@ -1195,7 +1195,7 @@ RSpec.describe Channel::EmailParser, type: :model do describe 'suppressing normal Ticket::Article callbacks' do context 'from sender: "Agent"' do - let(:agent) { create(:agent_user) } + let(:agent) { create(:agent) } it 'does not dispatch an email on article creation' do expect(TicketArticleCommunicateEmailJob).not_to receive(:perform_later) diff --git a/spec/models/concerns/has_history_examples.rb b/spec/models/concerns/has_history_examples.rb index 4e01283d5..a0eaf2382 100644 --- a/spec/models/concerns/has_history_examples.rb +++ b/spec/models/concerns/has_history_examples.rb @@ -91,7 +91,7 @@ RSpec.shared_examples 'HasHistory' do |history_relation_object: nil| describe 'of #owner' do let(:attribute) { 'owner' } - let(:new_value) { create(:customer_user) } # Ticket#owner is restricted to active agents of the same group + let(:new_value) { create(:customer) } # Ticket#owner is restricted to active agents of the same group include_examples 'failed attribute update' if described_class.attribute_names.include?('owner_id') end diff --git a/spec/models/cti/caller_id_spec.rb b/spec/models/cti/caller_id_spec.rb index 6332b4e82..cbb69eb66 100644 --- a/spec/models/cti/caller_id_spec.rb +++ b/spec/models/cti/caller_id_spec.rb @@ -146,7 +146,7 @@ RSpec.describe Cti::CallerId do describe '.rebuild' do context 'when a User record contains a valid phone number' do - let!(:user) { create(:agent_user, phone: '+49 123 456') } + let!(:user) { create(:agent, phone: '+49 123 456') } context 'and no corresponding CallerId exists' do it 'generates a CallerId record (with #level "known")' do @@ -173,7 +173,7 @@ RSpec.describe Cti::CallerId do end context 'when two User records contains the same valid phone number' do - let!(:users) { create_list(:agent_user, 2, phone: '+49 123 456') } + let!(:users) { create_list(:agent, 2, phone: '+49 123 456') } it 'generates two corresponding CallerId records (with #level "known")' do described_class.destroy_all # CallerId already generated in User callback @@ -251,17 +251,17 @@ RSpec.describe Cti::CallerId do describe '.known_agents_by_number' do context 'with known agent caller_id' do - let!(:agent_user1) { create(:agent_user, phone: '0123456') } - let!(:agent_user2) { create(:agent_user, phone: '0123457') } + let!(:agent1) { create(:agent, phone: '0123456') } + let!(:agent2) { create(:agent, phone: '0123457') } it 'gives matching agents' do expect(described_class.known_agents_by_number('49123456')) - .to match_array([agent_user1]) + .to match_array([agent1]) end end context 'with known customer caller_id' do - let!(:customer_user1) { create(:customer_user, phone: '0123456') } + let!(:customer1) { create(:customer, phone: '0123456') } it 'returns an empty array' do expect(described_class.known_agents_by_number('49123456')).to eq([]) @@ -270,11 +270,11 @@ RSpec.describe Cti::CallerId do context 'with maybe caller_id' do let(:ticket1) do - create(:ticket_article, created_by_id: customer_user2.id, body: 'some text 0123457') # create ticket + create(:ticket_article, created_by_id: customer2.id, body: 'some text 0123457') # create ticket Observer::Transaction.commit Scheduler.worker(true) end - let!(:customer_user2) { create(:customer_user) } + let!(:customer2) { create(:customer) } it 'returns an empty array' do expect(described_class.known_agents_by_number('49123457').count).to eq(0) diff --git a/spec/models/cti/driver/base_spec.rb b/spec/models/cti/driver/base_spec.rb index df3a4c5b8..15f5f7cc9 100644 --- a/spec/models/cti/driver/base_spec.rb +++ b/spec/models/cti/driver/base_spec.rb @@ -86,7 +86,7 @@ RSpec.describe Cti::Driver::Base do describe '.push_open_ticket_screen_recipient' do context 'with direct number in answeringNumber params' do let(:params) { { 'direction' => direction, 'event' => event, answeringNumber: user.phone } } - let!(:user) { create(:agent_user, phone: '1234567') } + let!(:user) { create(:agent, phone: '1234567') } it 'returns related user' do expect(driver.push_open_ticket_screen_recipient).to eq(user) @@ -95,7 +95,7 @@ RSpec.describe Cti::Driver::Base do context 'with not existing direct number in answeringNumber params' do let(:params) { { 'direction' => direction, 'event' => event, answeringNumber: '98765421' } } - let!(:user) { create(:agent_user, phone: '1234567') } + let!(:user) { create(:agent, phone: '1234567') } it 'returns nil' do expect(driver.push_open_ticket_screen_recipient).to be(nil) @@ -104,7 +104,7 @@ RSpec.describe Cti::Driver::Base do context 'with real phone number in answeringNumber params' do let(:params) { { 'direction' => direction, 'event' => event, answeringNumber: '491711000001' } } - let!(:user) { create(:agent_user, phone: '0171 1000001') } + let!(:user) { create(:agent, phone: '0171 1000001') } it 'returns related user' do expect(driver.push_open_ticket_screen_recipient).to eq(user) @@ -113,7 +113,7 @@ RSpec.describe Cti::Driver::Base do context 'with user in upcase in params' do let(:params) { { 'direction' => direction, 'event' => event, user: user.login.upcase } } - let!(:user) { create(:agent_user) } + let!(:user) { create(:agent) } it 'returns related user' do expect(driver.push_open_ticket_screen_recipient).to eq(user) @@ -122,7 +122,7 @@ RSpec.describe Cti::Driver::Base do context 'with user_id in params' do let(:params) { { 'direction' => direction, 'event' => event, user_id: user.id } } - let!(:user) { create(:agent_user) } + let!(:user) { create(:agent) } it 'returns related user' do expect(driver.push_open_ticket_screen_recipient).to eq(user) diff --git a/spec/models/cti/log_spec.rb b/spec/models/cti/log_spec.rb index 099e0a538..e6ae8bfb3 100644 --- a/spec/models/cti/log_spec.rb +++ b/spec/models/cti/log_spec.rb @@ -242,9 +242,9 @@ RSpec.describe Cti::Log do described_class.process(attributes) end - let(:customer_user_of_ticket) { create(:customer_user) } + let(:customer_of_ticket) { create(:customer) } let(:ticket_sample) do - create(:ticket_article, created_by_id: customer_user_of_ticket.id, body: 'some text 0123457') + create(:ticket_article, created_by_id: customer_of_ticket.id, body: 'some text 0123457') Observer::Transaction.commit Scheduler.worker(true) end @@ -268,28 +268,28 @@ RSpec.describe Cti::Log do end context 'with related known customer' do - let!(:customer_user) { create(:customer_user, phone: '0123456') } + let!(:customer) { create(:customer, phone: '0123456') } it 'gives caller information' do expect(log.preferences[:from].count).to eq(1) expect(log.preferences[:from].first) .to include( 'level' => 'known', - 'user_id' => customer_user.id, + 'user_id' => customer.id, ) end end context 'with related known customers' do - let!(:customer_user1) { create(:customer_user, phone: '0123456') } - let!(:customer_user2) { create(:customer_user, phone: '0123456') } + let!(:customer1) { create(:customer, phone: '0123456') } + let!(:customer2) { create(:customer, phone: '0123456') } it 'gives caller information' do expect(log.preferences[:from].count).to eq(2) expect(log.preferences[:from].first) .to include( 'level' => 'known', - 'user_id' => customer_user2.id, + 'user_id' => customer2.id, ) end end @@ -303,14 +303,14 @@ RSpec.describe Cti::Log do expect(log.preferences[:from].first) .to include( 'level' => 'maybe', - 'user_id' => customer_user_of_ticket.id, + 'user_id' => customer_of_ticket.id, ) end end context 'with related maybe and known customer' do let(:caller_id) { '0123457' } - let!(:customer) { create(:customer_user, phone: '0123457') } + let!(:customer) { create(:customer, phone: '0123457') } let!(:ticket) { ticket_sample } it 'gives caller information' do @@ -471,12 +471,12 @@ RSpec.describe Cti::Log do ) end - let!(:agent1) { create(:agent_user, phone: '01234599') } - let!(:customer2) { create(:customer_user, phone: '') } + let!(:agent1) { create(:agent, phone: '01234599') } + let!(:customer2) { create(:customer, phone: '') } let!(:ticket_article1) { create(:ticket_article, created_by_id: customer2.id, body: 'some text 01234599') } context 'with agent1 (known), customer1 (known) and customer2 (maybe)' do - let!(:customer1) { create(:customer_user, phone: '01234599') } + let!(:customer1) { create(:customer, phone: '01234599') } it 'gives customer1' do expect(log1.best_customer_id_of_log_entry).to eq(customer1.id) diff --git a/spec/models/job_spec.rb b/spec/models/job_spec.rb index fb7db89ab..8d3384cc7 100644 --- a/spec/models/job_spec.rb +++ b/spec/models/job_spec.rb @@ -204,7 +204,7 @@ RSpec.describe Job, type: :model do context 'when job has pre_condition:current_user.id in selector' do let!(:matching_ticket) { create(:ticket, owner_id: 1) } - let!(:nonmatching_ticket) { create(:ticket, owner_id: create(:agent_user).id) } + let!(:nonmatching_ticket) { create(:ticket, owner_id: create(:agent).id) } let(:condition) do { @@ -218,7 +218,7 @@ RSpec.describe Job, type: :model do end before do - UserInfo.current_user_id = create(:admin_user).id + UserInfo.current_user_id = create(:admin).id job UserInfo.current_user_id = nil end diff --git a/spec/models/knowledge_base/answer/translation/search_with_attachment_spec.rb b/spec/models/knowledge_base/answer/translation/search_with_attachment_spec.rb index bfa24bb3d..8cc097f2e 100644 --- a/spec/models/knowledge_base/answer/translation/search_with_attachment_spec.rb +++ b/spec/models/knowledge_base/answer/translation/search_with_attachment_spec.rb @@ -5,7 +5,7 @@ require 'models/contexts/factory_context' RSpec.describe KnowledgeBase::Answer::Translation, type: :model, current_user_id: 1, searchindex: 1 do include_context 'basic Knowledge Base' - let(:user) { create(:admin_user) } + let(:user) { create(:admin) } let(:filename) { 'test.rtf' } let(:query) { 'RTF document' } diff --git a/spec/models/knowledge_base_spec.rb b/spec/models/knowledge_base_spec.rb index ba9f482cc..f6da2f16e 100644 --- a/spec/models/knowledge_base_spec.rb +++ b/spec/models/knowledge_base_spec.rb @@ -48,12 +48,12 @@ RSpec.describe KnowledgeBase, type: :model do end it 'skip activity check for editors when filtering by activity' do - user = create(:admin_user) + user = create(:admin) expect(described_class.check_active_unless_editor(user).count).to eq(2) end it 'check activity if user is not editor when filtering by activity' do - user = create(:agent_user) + user = create(:agent) expect(described_class.check_active_unless_editor(user)).to contain_exactly(knowledge_base) end diff --git a/spec/models/object_manager/attribute/validation/required_spec.rb b/spec/models/object_manager/attribute/validation/required_spec.rb index 0aa07af0b..d881e1db0 100644 --- a/spec/models/object_manager/attribute/validation/required_spec.rb +++ b/spec/models/object_manager/attribute/validation/required_spec.rb @@ -23,7 +23,7 @@ RSpec.describe ::ObjectManager::Attribute::Validation::Required do shared_examples 'a permission based validator' do |permission:| - let(:performing_user) { create(:agent_user) } + let(:performing_user) { create(:agent) } before { UserInfo.current_user_id = performing_user.id } @@ -87,7 +87,7 @@ RSpec.describe ::ObjectManager::Attribute::Validation::Required do context 'for required => false' do - let(:performing_user) { create(:agent_user) } + let(:performing_user) { create(:agent) } before { UserInfo.current_user_id = performing_user.id } diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index 253b1c7fc..71bb0277a 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -28,11 +28,11 @@ RSpec.describe Organization, type: :model do describe 'Callbacks, Observers, & Async Transactions -' do describe 'Touching associations on update:' do - let!(:member) { create(:customer_user, organization: organization) } + let!(:member) { create(:customer, organization: organization) } let!(:member_ticket) { create(:ticket, customer: member) } context 'when member associations are added' do - let(:user) { create(:customer_user) } + let(:user) { create(:customer) } it 'is touched, and touches its other members (but not their tickets)' do expect { organization.members.push(user) } diff --git a/spec/models/recent_view_spec.rb b/spec/models/recent_view_spec.rb index 322bc0ce3..107fa13d0 100644 --- a/spec/models/recent_view_spec.rb +++ b/spec/models/recent_view_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' RSpec.describe RecentView, type: :model do - let(:admin) { create(:admin_user) } - let(:agent) { create(:agent_user) } - let(:customer) { create(:customer_user) } + let(:admin) { create(:admin) } + let(:agent) { create(:agent) } + let(:customer) { create(:customer) } let(:ticket) { create(:ticket, owner: owner, customer: customer) } let(:tickets) { create_list(:ticket, 15, owner: owner, customer: customer) } let(:owner) { admin } diff --git a/spec/models/taskbar_spec.rb b/spec/models/taskbar_spec.rb index 698060651..76c04b4fb 100644 --- a/spec/models/taskbar_spec.rb +++ b/spec/models/taskbar_spec.rb @@ -192,8 +192,8 @@ RSpec.describe Taskbar do expect(taskbar3.preferences[:tasks][0][:user_id]).to eq(2) expect(taskbar3.preferences[:tasks][0][:changed]).to eq(false) - agent_user_id = create(:agent_user).id - UserInfo.current_user_id = agent_user_id + agent_id = create(:agent).id + UserInfo.current_user_id = agent_id taskbar4 = described_class.create( client_id: 123, @@ -213,7 +213,7 @@ RSpec.describe Taskbar do expect(taskbar1.preferences[:tasks][0][:changed]).to eq(false) expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar1.preferences[:tasks][1][:changed]).to eq(false) - expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar1.preferences[:tasks][2][:changed]).to eq(false) taskbar2.reload @@ -222,7 +222,7 @@ RSpec.describe Taskbar do expect(taskbar2.preferences[:tasks][0][:changed]).to eq(false) expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar2.preferences[:tasks][1][:changed]).to eq(false) - expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar2.preferences[:tasks][2][:changed]).to eq(false) taskbar3.reload @@ -236,7 +236,7 @@ RSpec.describe Taskbar do expect(taskbar4.preferences[:tasks][0][:changed]).to eq(false) expect(taskbar4.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar4.preferences[:tasks][1][:changed]).to eq(false) - expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar4.preferences[:tasks][2][:changed]).to eq(false) UserInfo.current_user_id = 2 @@ -249,7 +249,7 @@ RSpec.describe Taskbar do expect(taskbar1.preferences[:tasks][0][:changed]).to eq(false) expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar1.preferences[:tasks][1][:changed]).to eq(false) - expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar1.preferences[:tasks][2][:changed]).to eq(false) taskbar2.reload @@ -258,7 +258,7 @@ RSpec.describe Taskbar do expect(taskbar2.preferences[:tasks][0][:changed]).to eq(false) expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar2.preferences[:tasks][1][:changed]).to eq(false) - expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar2.preferences[:tasks][2][:changed]).to eq(false) taskbar3.reload @@ -272,7 +272,7 @@ RSpec.describe Taskbar do expect(taskbar4.preferences[:tasks][0][:changed]).to eq(false) expect(taskbar4.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar4.preferences[:tasks][1][:changed]).to eq(false) - expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar4.preferences[:tasks][2][:changed]).to eq(false) UserInfo.current_user_id = 2 @@ -285,7 +285,7 @@ RSpec.describe Taskbar do expect(taskbar1.preferences[:tasks][0][:changed]).to eq(false) expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar1.preferences[:tasks][1][:changed]).to eq(true) - expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar1.preferences[:tasks][2][:changed]).to eq(false) taskbar2.reload @@ -294,7 +294,7 @@ RSpec.describe Taskbar do expect(taskbar2.preferences[:tasks][0][:changed]).to eq(false) expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar2.preferences[:tasks][1][:changed]).to eq(true) - expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar2.preferences[:tasks][2][:changed]).to eq(false) taskbar3.reload @@ -308,7 +308,7 @@ RSpec.describe Taskbar do expect(taskbar4.preferences[:tasks][0][:changed]).to eq(false) expect(taskbar4.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar4.preferences[:tasks][1][:changed]).to eq(true) - expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar4.preferences[:tasks][2][:changed]).to eq(false) UserInfo.current_user_id = 1 @@ -321,7 +321,7 @@ RSpec.describe Taskbar do expect(taskbar1.preferences[:tasks][0][:changed]).to eq(true) expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar1.preferences[:tasks][1][:changed]).to eq(true) - expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar1.preferences[:tasks][2][:changed]).to eq(false) taskbar2.reload @@ -330,7 +330,7 @@ RSpec.describe Taskbar do expect(taskbar2.preferences[:tasks][0][:changed]).to eq(true) expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar2.preferences[:tasks][1][:changed]).to eq(true) - expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar2.preferences[:tasks][2][:changed]).to eq(false) taskbar3.reload @@ -344,7 +344,7 @@ RSpec.describe Taskbar do expect(taskbar4.preferences[:tasks][0][:changed]).to eq(true) expect(taskbar4.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar4.preferences[:tasks][1][:changed]).to eq(true) - expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar4.preferences[:tasks][2][:changed]).to eq(false) taskbar1_last_contact = taskbar1.last_contact.to_s @@ -366,7 +366,7 @@ RSpec.describe Taskbar do expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar1.preferences[:tasks][1][:changed]).to eq(true) expect(taskbar1.preferences[:tasks][1][:last_contact].to_s).to eq(taskbar2_last_contact) - expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar1.preferences[:tasks][2][:changed]).to eq(false) expect(taskbar1.preferences[:tasks][2][:last_contact].to_s).to eq(taskbar4_last_contact) @@ -378,7 +378,7 @@ RSpec.describe Taskbar do expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar2.preferences[:tasks][1][:changed]).to eq(true) expect(taskbar2.preferences[:tasks][1][:last_contact].to_s).to eq(taskbar2_last_contact) - expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar2.preferences[:tasks][2][:changed]).to eq(false) expect(taskbar2.preferences[:tasks][2][:last_contact].to_s).to eq(taskbar4_last_contact) @@ -396,7 +396,7 @@ RSpec.describe Taskbar do expect(taskbar4.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar4.preferences[:tasks][1][:changed]).to eq(true) expect(taskbar4.preferences[:tasks][1][:last_contact].to_s).to eq(taskbar2_last_contact) - expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar4.preferences[:tasks][2][:changed]).to eq(false) expect(taskbar4.preferences[:tasks][2][:last_contact].to_s).to eq(taskbar4_last_contact) @@ -413,7 +413,7 @@ RSpec.describe Taskbar do expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar1.preferences[:tasks][1][:changed]).to eq(true) expect(taskbar1.preferences[:tasks][1][:last_contact].to_s).not_to eq(taskbar2_last_contact) - expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar1.preferences[:tasks][2][:changed]).to eq(false) expect(taskbar1.preferences[:tasks][2][:last_contact].to_s).to eq(taskbar4_last_contact) @@ -425,7 +425,7 @@ RSpec.describe Taskbar do expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar2.preferences[:tasks][1][:changed]).to eq(true) expect(taskbar2.preferences[:tasks][1][:last_contact].to_s).not_to eq(taskbar2_last_contact) - expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar2.preferences[:tasks][2][:changed]).to eq(false) expect(taskbar2.preferences[:tasks][2][:last_contact].to_s).to eq(taskbar4_last_contact) @@ -443,7 +443,7 @@ RSpec.describe Taskbar do expect(taskbar4.preferences[:tasks][1][:user_id]).to eq(2) expect(taskbar4.preferences[:tasks][1][:changed]).to eq(true) expect(taskbar4.preferences[:tasks][1][:last_contact].to_s).not_to eq(taskbar2_last_contact) - expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(agent_user_id) + expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(agent_id) expect(taskbar4.preferences[:tasks][2][:changed]).to eq(false) expect(taskbar4.preferences[:tasks][2][:last_contact].to_s).to eq(taskbar4_last_contact) diff --git a/spec/models/ticket_spec.rb b/spec/models/ticket_spec.rb index 176aac82b..44b205cb2 100644 --- a/spec/models/ticket_spec.rb +++ b/spec/models/ticket_spec.rb @@ -216,7 +216,7 @@ RSpec.describe Ticket, type: :model do # # Notification triggers should log notification as private or public # according to given configuration - let(:user) { create(:admin_user, mobile: '+37061010000') } + let(:user) { create(:admin, mobile: '+37061010000') } before { ticket.group.users << user } @@ -386,13 +386,13 @@ RSpec.describe Ticket, type: :model do describe 'Attributes:' do describe '#owner' do - let(:original_owner) { create(:agent_user, groups: [ticket.group]) } + let(:original_owner) { create(:agent, groups: [ticket.group]) } before { ticket.update(owner: original_owner) } context 'when assigned directly' do context 'to an active agent belonging to ticket.group' do - let(:agent) { create(:agent_user, groups: [ticket.group]) } + let(:agent) { create(:agent, groups: [ticket.group]) } it 'can be set' do expect { ticket.update(owner: agent) } @@ -401,7 +401,7 @@ RSpec.describe Ticket, type: :model do end context 'to an agent not belonging to ticket.group' do - let(:agent) { create(:agent_user, groups: [other_group]) } + let(:agent) { create(:agent, groups: [other_group]) } let(:other_group) { create(:group) } it 'resets to default user (id: 1) instead' do @@ -411,7 +411,7 @@ RSpec.describe Ticket, type: :model do end context 'to an inactive agent' do - let(:agent) { create(:agent_user, groups: [ticket.group], active: false) } + let(:agent) { create(:agent, groups: [ticket.group], active: false) } it 'resets to default user (id: 1) instead' do expect { ticket.update(owner: agent) } @@ -420,7 +420,7 @@ RSpec.describe Ticket, type: :model do end context 'to a non-agent' do - let(:agent) { create(:customer_user, groups: [ticket.group]) } + let(:agent) { create(:customer, groups: [ticket.group]) } it 'resets to default user (id: 1) instead' do expect { ticket.update(owner: agent) } @@ -763,9 +763,9 @@ 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(:customer) { create(:customer, organization: organization) } let(:organization) { create(:organization) } - let(:other_customer) { create(:customer_user, organization: other_organization) } + let(:other_customer) { create(:customer, organization: other_organization) } let(:other_organization) { create(:organization) } context 'on creation' do diff --git a/spec/models/token_spec.rb b/spec/models/token_spec.rb index cba373674..f499c59e6 100644 --- a/spec/models/token_spec.rb +++ b/spec/models/token_spec.rb @@ -80,7 +80,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(:agent) { create(:agent) } let(:preferences) { { permission: %w[admin ticket.agent] } } # agent has no access to admin.* context 'with a permission shared by both token.user and token.preferences' do diff --git a/spec/models/trigger/sms_spec.rb b/spec/models/trigger/sms_spec.rb index 7fb9e2dce..cd73c4df3 100644 --- a/spec/models/trigger/sms_spec.rb +++ b/spec/models/trigger/sms_spec.rb @@ -14,7 +14,7 @@ RSpec.describe Trigger do context 'sends interpolated, html-free SMS' do before do - another_agent = create(:admin_user, mobile: '+37061010000') + another_agent = create(:admin, mobile: '+37061010000') Group.lookup(id: 1).users << another_agent create(:channel, area: 'Sms::Notification') @@ -30,7 +30,7 @@ RSpec.describe Trigger do let(:message_body) { 'space between #{ticket.title} #{ticket.created_at}' } # rubocop:disable Lint/InterpolationCheck - let(:agent) { create(:agent_user) } + let(:agent) { create(:agent) } let(:ticket) do ticket = create(:ticket, group: Group.lookup(id: 1), created_by_id: agent.id) Observer::Transaction.commit @@ -64,14 +64,14 @@ RSpec.describe Trigger do context 'recipients' do - let(:recipient1) { create(:agent_user, mobile: '+37061010000', groups: [ticket_group]) } - let(:recipient2) { create(:agent_user, mobile: '+37061010001', groups: [ticket_group]) } - let(:recipient3) { create(:agent_user, mobile: '+37061010002', groups: [ticket_group]) } + let(:recipient1) { create(:agent, mobile: '+37061010000', groups: [ticket_group]) } + let(:recipient2) { create(:agent, mobile: '+37061010001', groups: [ticket_group]) } + let(:recipient3) { create(:agent, mobile: '+37061010002', groups: [ticket_group]) } let(:ticket_group) { create(:group) } let(:ticket) do - ticket = create(:ticket, group: ticket_group, created_by_id: create(:agent_user).id) + ticket = create(:ticket, group: ticket_group, created_by_id: create(:agent).id) Observer::Transaction.commit ticket end diff --git a/spec/models/trigger_spec.rb b/spec/models/trigger_spec.rb index 757a65b59..bfb57a834 100644 --- a/spec/models/trigger_spec.rb +++ b/spec/models/trigger_spec.rb @@ -197,7 +197,7 @@ RSpec.describe Trigger, type: :model do let(:email_address) { create(:email_address, email: system_email_address) } let(:group) { create(:group, email_address: email_address) } - let(:customer) { create(:customer_user, email: customer_email_address) } + let(:customer) { create(:customer, email: customer_email_address) } let(:security_preferences) { Ticket::Article.last.preferences[:security] } @@ -552,7 +552,7 @@ RSpec.describe Trigger, type: :model do end let(:user) do - user = create(:agent_user) + user = create(:agent) user.roles.first.groups << group user end diff --git a/spec/models/user/can_lookup_search_index_attributes_examples.rb b/spec/models/user/can_lookup_search_index_attributes_examples.rb index d4df02be4..9417f06fe 100644 --- a/spec/models/user/can_lookup_search_index_attributes_examples.rb +++ b/spec/models/user/can_lookup_search_index_attributes_examples.rb @@ -2,7 +2,7 @@ RSpec.shared_examples 'CanLookupSearchIndexAttributes' do describe '.search_index_value_by_attribute' do it 'returns search index value for attribute' do organization = create(:organization, name: 'Tomato42', note: 'special recipe') - user = create(:agent_user, organization: organization) + user = create(:agent, organization: organization) value = user.search_index_value_by_attribute('organization_id') expect(value).to eq('Tomato42') diff --git a/spec/models/user_device_spec.rb b/spec/models/user_device_spec.rb index 48b0d25c4..3d72ea114 100644 --- a/spec/models/user_device_spec.rb +++ b/spec/models/user_device_spec.rb @@ -4,7 +4,7 @@ RSpec.describe UserDevice, type: :model do describe '.add' do let(:existing_record) { described_class.add(user_agent, ip, agent.id, fingerprint, type) } let(:ip) { '91.115.248.231' } - let(:agent) { create(:agent_user) } + let(:agent) { create(:agent) } context 'with existing record of type: "session"' do before { existing_record } # create existing record @@ -184,7 +184,7 @@ RSpec.describe UserDevice, type: :model do let(:user_device) { described_class.add(user_agent, ip, agent.id, fingerprint, type) } let(:user_agent) { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36' } let(:ip) { '91.115.248.231' } - let(:agent) { create(:agent_user) } + let(:agent) { create(:agent) } let(:fingerprint) { 'fingerprint1234' } let(:type) { 'session' } @@ -228,7 +228,7 @@ RSpec.describe UserDevice, type: :model do let(:type) { 'session' } context 'user with email address' do - let(:agent) { create(:agent_user, email: 'somebody@example.com') } + let(:agent) { create(:agent, email: 'somebody@example.com') } it 'returns true' do expect(user_device.notification_send('user_device_new_location')) @@ -237,7 +237,7 @@ RSpec.describe UserDevice, type: :model do end context 'user without email address' do - let(:agent) { create(:agent_user, email: '') } + let(:agent) { create(:agent, email: '') } it 'returns false' do expect(user_device.notification_send('user_device_new_location')) diff --git a/spec/models/user_group_spec.rb b/spec/models/user_group_spec.rb index f9123fc59..5ee4d32ad 100644 --- a/spec/models/user_group_spec.rb +++ b/spec/models/user_group_spec.rb @@ -3,7 +3,7 @@ require 'models/concerns/has_group_relation_definition_examples' RSpec.describe UserGroup do - let!(:group_relation_instance) { create(:agent_user) } + let!(:group_relation_instance) { create(:agent) } it_behaves_like 'HasGroupRelationDefinition' end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 7c94508a1..784d3653a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -13,14 +13,14 @@ require 'models/user/can_lookup_search_index_attributes_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) } + let(:customer) { create(:customer) } + let(:agent) { create(:agent) } + let(:admin) { create(:admin) } it_behaves_like 'ApplicationModel', can_assets: { associations: :organization } - it_behaves_like 'HasGroups', group_access_factory: :agent_user + it_behaves_like 'HasGroups', group_access_factory: :agent it_behaves_like 'HasHistory' - it_behaves_like 'HasRoles', group_access_factory: :agent_user + it_behaves_like 'HasRoles', group_access_factory: :agent it_behaves_like 'HasXssSanitizedNote', model_factory: :user it_behaves_like 'HasGroups and Permissions', group_access_no_permission_factory: :user it_behaves_like 'CanBeImported' @@ -310,7 +310,7 @@ RSpec.describe User, type: :model do context 'when designated as the substitute' do let!(:agent_on_holiday) do create( - :agent_user, + :agent, out_of_office_start_at: Time.current.yesterday, out_of_office_end_at: Time.current.tomorrow, out_of_office_replacement_id: agent.id, @@ -867,19 +867,19 @@ RSpec.describe User, type: :model do before { Setting.set('system_agent_limit', current_agents.count + 1) } it 'grants agent creation' do - expect { create(:agent_user) } + expect { create(:agent) } .to change(current_agents, :count).by(1) end it 'grants role change' do - future_agent = create(:customer_user) + future_agent = create(:customer) expect { future_agent.roles = [agent_role] } .to change(current_agents, :count).by(1) end describe 'role updates' do - let(:agent) { create(:agent_user) } + let(:agent) { create(:agent) } it 'grants update by instances' do expect { agent.roles = [admin_role, agent_role] } @@ -902,9 +902,9 @@ RSpec.describe User, type: :model do it 'creation of new agents' do Setting.set('system_agent_limit', current_agents.count + 2) - create_list(:agent_user, 2) + create_list(:agent, 2) - expect { create(:agent_user) } + expect { create(:agent) } .to raise_error(Exceptions::UnprocessableEntity) .and change(current_agents, :count).by(0) end @@ -912,7 +912,7 @@ RSpec.describe User, type: :model do it 'prevents role change' do Setting.set('system_agent_limit', current_agents.count) - future_agent = create(:customer_user) + future_agent = create(:customer) expect { future_agent.roles = [agent_role] } .to raise_error(Exceptions::UnprocessableEntity) @@ -926,19 +926,19 @@ RSpec.describe User, type: :model do before { Setting.set('system_agent_limit', (current_agents.count + 1).to_s) } it 'grants agent creation' do - expect { create(:agent_user) } + expect { create(:agent) } .to change(current_agents, :count).by(1) end it 'grants role change' do - future_agent = create(:customer_user) + future_agent = create(:customer) expect { future_agent.roles = [agent_role] } .to change(current_agents, :count).by(1) end describe 'role updates' do - let(:agent) { create(:agent_user) } + let(:agent) { create(:agent) } it 'grants update by instances' do expect { agent.roles = [admin_role, agent_role] } @@ -961,9 +961,9 @@ RSpec.describe User, type: :model do it 'creation of new agents' do Setting.set('system_agent_limit', (current_agents.count + 2).to_s) - create_list(:agent_user, 2) + create_list(:agent, 2) - expect { create(:agent_user) } + expect { create(:agent) } .to raise_error(Exceptions::UnprocessableEntity) .and change(current_agents, :count).by(0) end @@ -971,7 +971,7 @@ RSpec.describe User, type: :model do it 'prevents role change' do Setting.set('system_agent_limit', current_agents.count.to_s) - future_agent = create(:customer_user) + future_agent = create(:customer) expect { future_agent.roles = [agent_role] } .to raise_error(Exceptions::UnprocessableEntity) @@ -987,7 +987,7 @@ RSpec.describe User, type: :model do context 'when exceeding the agent limit' do it 'prevents re-activation of agents' do - inactive_agent = create(:agent_user, active: false) + inactive_agent = create(:agent, active: false) expect { inactive_agent.update!(active: true) } .to raise_error(Exceptions::UnprocessableEntity) @@ -1001,7 +1001,7 @@ RSpec.describe User, type: :model do context 'when exceeding the agent limit' do it 'prevents re-activation of agents' do - inactive_agent = create(:agent_user, active: false) + inactive_agent = create(:agent, active: false) expect { inactive_agent.update!(active: true) } .to raise_error(Exceptions::UnprocessableEntity) @@ -1013,7 +1013,7 @@ RSpec.describe User, type: :model do end describe 'Touching associations on update:' do - subject!(:user) { create(:customer_user) } + subject!(:user) { create(:customer) } let!(:organization) { create(:organization) } diff --git a/spec/policies/ticket_policy_spec.rb b/spec/policies/ticket_policy_spec.rb index 19cd1b886..c96d0e0c6 100644 --- a/spec/policies/ticket_policy_spec.rb +++ b/spec/policies/ticket_policy_spec.rb @@ -12,7 +12,7 @@ describe TicketPolicy do end context 'when given a user that is neither owner nor customer' do - let(:user) { create(:agent_user) } + let(:user) { create(:agent) } it { is_expected.not_to permit_actions(%i[show full]) } @@ -24,8 +24,8 @@ describe TicketPolicy do context 'but the user is a customer from the same organization as ticket’s customer' do let(:record) { create(:ticket, customer: customer) } - let(:customer) { create(:customer_user, organization: create(:organization)) } - let(:user) { create(:customer_user, organization: customer.organization) } + let(:customer) { create(:customer, organization: create(:organization)) } + let(:user) { create(:customer, organization: customer.organization) } context 'and organization.shared is true (default)' do diff --git a/spec/policies/user_policy_spec.rb b/spec/policies/user_policy_spec.rb index 8b3a076eb..a3edc3cfc 100644 --- a/spec/policies/user_policy_spec.rb +++ b/spec/policies/user_policy_spec.rb @@ -14,19 +14,19 @@ describe UserPolicy do context 'wants to read, change, or delete any user' do context 'when record is an admin user' do - let(:record) { create(:admin_user) } + let(:record) { create(:admin) } it { is_expected.to permit_actions(%i[show update destroy]) } end context 'when record is an agent user' do - let(:record) { create(:agent_user) } + let(:record) { create(:agent) } it { is_expected.to permit_actions(%i[show update destroy]) } end context 'when record is a customer user' do - let(:record) { create(:customer_user) } + let(:record) { create(:customer) } it { is_expected.to permit_actions(%i[show update destroy]) } end @@ -51,21 +51,21 @@ describe UserPolicy do end context 'when record is an admin user' do - let(:record) { create(:admin_user) } + let(:record) { create(:admin) } it { is_expected.to permit_action(:show) } it { is_expected.not_to permit_actions(%i[update destroy]) } end context 'when record is an agent user' do - let(:record) { create(:agent_user) } + let(:record) { create(:agent) } it { is_expected.to permit_action(:show) } it { is_expected.not_to permit_actions(%i[update destroy]) } end context 'when record is a customer user' do - let(:record) { create(:customer_user) } + let(:record) { create(:customer) } it { is_expected.to permit_action(:show) } it { is_expected.not_to permit_actions(%i[update destroy]) } @@ -88,24 +88,24 @@ describe UserPolicy do end context 'when user is an agent' do - let(:user) { create(:agent_user) } + let(:user) { create(:agent) } context 'when record is an admin user' do - let(:record) { create(:admin_user) } + let(:record) { create(:admin) } it { is_expected.to permit_action(:show) } it { is_expected.not_to permit_actions(%i[update destroy]) } end context 'when record is an agent user' do - let(:record) { create(:agent_user) } + let(:record) { create(:agent) } it { is_expected.to permit_action(:show) } it { is_expected.not_to permit_actions(%i[update destroy]) } end context 'when record is a customer user' do - let(:record) { create(:customer_user) } + let(:record) { create(:customer) } it { is_expected.to permit_actions(%i[show update]) } it { is_expected.not_to permit_action(:destroy) } @@ -127,22 +127,22 @@ describe UserPolicy do end context 'when user is a customer' do - let(:user) { create(:customer_user) } + let(:user) { create(:customer) } context 'when record is an admin user' do - let(:record) { create(:admin_user) } + let(:record) { create(:admin) } it { is_expected.not_to permit_actions(%i[show update destroy]) } end context 'when record is an agent user' do - let(:record) { create(:agent_user) } + let(:record) { create(:agent) } it { is_expected.not_to permit_actions(%i[show update destroy]) } end context 'when record is a customer user' do - let(:record) { create(:customer_user) } + let(:record) { create(:customer) } it { is_expected.not_to permit_actions(%i[show update destroy]) } end @@ -154,8 +154,8 @@ describe UserPolicy do end context 'when record is a colleague' do - let(:user) { create(:customer_user, :with_org) } - let(:record) { create(:customer_user, organization: user.organization) } + let(:user) { create(:customer, :with_org) } + let(:record) { create(:customer, organization: user.organization) } it { is_expected.to permit_action(:show) } it { is_expected.not_to permit_actions(%i[update destroy]) } diff --git a/spec/requests/api_auth_on_behalf_of_spec.rb b/spec/requests/api_auth_on_behalf_of_spec.rb index 263883bb3..452da6db9 100644 --- a/spec/requests/api_auth_on_behalf_of_spec.rb +++ b/spec/requests/api_auth_on_behalf_of_spec.rb @@ -2,14 +2,14 @@ require 'rails_helper' RSpec.describe 'Api Auth On Behalf Of', type: :request do - let(:admin_user) do - create(:admin_user, groups: Group.all) + let(:admin) do + create(:admin, groups: Group.all) end - let(:agent_user) do - create(:agent_user) + let(:agent) do + create(:agent) end - let(:customer_user) do - create(:customer_user) + let(:customer) do + create(:customer) end describe 'request handling' do @@ -20,16 +20,16 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do group: 'Users', priority: '2 normal', state: 'new', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some test 123', }, } - authenticated_as(admin_user, on_behalf_of: customer_user.id) + authenticated_as(admin, on_behalf_of: customer.id) post '/api/v1/tickets', params: params, as: :json 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']) + expect(customer.id).to eq(json_response['created_by_id']) end it 'does X-On-Behalf-Of auth - ticket create admin for customer by login' do @@ -40,19 +40,19 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do group: 'Users', priority: '2 normal', state: 'new', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some test 123', }, } - authenticated_as(admin_user, on_behalf_of: customer_user.login) + authenticated_as(admin, on_behalf_of: customer.login) post '/api/v1/tickets', params: params, as: :json 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']) + expect(customer.id).to eq(json_response_ticket['created_by_id']) - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/activity_stream?full=true', params: {}, as: :json expect(response).to have_http_status(:ok) json_response_activity = json_response @@ -68,7 +68,7 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do end expect(ticket_created).to be_truthy - expect(customer_user.id).to eq(ticket_created.created_by_id) + expect(customer.id).to eq(ticket_created.created_by_id) get '/api/v1/activity_stream', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -85,7 +85,7 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do end expect(ticket_created).to be_truthy - expect(customer_user.id).to eq(ticket_created.created_by_id) + expect(customer.id).to eq(ticket_created.created_by_id) end it 'does X-On-Behalf-Of auth - ticket create admin for customer by email' do @@ -94,16 +94,16 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do group: 'Users', priority: '2 normal', state: 'new', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some test 123', }, } - authenticated_as(admin_user, on_behalf_of: customer_user.email) + authenticated_as(admin, on_behalf_of: customer.email) post '/api/v1/tickets', params: params, as: :json 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']) + expect(customer.id).to eq(json_response['created_by_id']) end it 'does X-On-Behalf-Of auth - ticket create admin for unknown' do @@ -112,12 +112,12 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do group: 'Users', priority: '2 normal', state: 'new', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some test 123', }, } - authenticated_as(admin_user, on_behalf_of: 99_449_494_949) + authenticated_as(admin, on_behalf_of: 99_449_494_949) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:unauthorized) expect(@response.header).not_to be_key('Access-Control-Allow-Origin') @@ -131,12 +131,12 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do group: 'Users', priority: '2 normal', state: 'new', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some test 123', }, } - authenticated_as(customer_user, on_behalf_of: admin_user.email) + authenticated_as(customer, on_behalf_of: admin.email) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:unauthorized) expect(@response.header).not_to be_key('Access-Control-Allow-Origin') @@ -150,12 +150,12 @@ RSpec.describe 'Api Auth On Behalf Of', type: :request do group: 'secret1234', priority: '2 normal', state: 'new', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some test 123', }, } - authenticated_as(admin_user, on_behalf_of: customer_user.email) + authenticated_as(admin, on_behalf_of: customer.email) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(@response.header).not_to be_key('Access-Control-Allow-Origin') diff --git a/spec/requests/api_auth_spec.rb b/spec/requests/api_auth_spec.rb index 23f3e7a46..6b14bf706 100644 --- a/spec/requests/api_auth_spec.rb +++ b/spec/requests/api_auth_spec.rb @@ -13,14 +13,14 @@ RSpec.describe 'Api Auth', type: :request do end end - let(:admin_user) do - create(:admin_user) + let(:admin) do + create(:admin) end - let(:agent_user) do - create(:agent_user) + let(:agent) do + create(:agent) end - let(:customer_user) do - create(:customer_user) + let(:customer) do + create(:customer) end describe 'request handling' do @@ -28,7 +28,7 @@ RSpec.describe 'Api Auth', type: :request do it 'does basic auth - admin' do Setting.set('api_password_access', false) - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/sessions', params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(response.header).not_to be_key('Access-Control-Allow-Origin') @@ -49,7 +49,7 @@ RSpec.describe 'Api Auth', type: :request do it 'does basic auth - agent' do Setting.set('api_password_access', false) - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/tickets', params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(response.header).not_to be_key('Access-Control-Allow-Origin') @@ -70,7 +70,7 @@ RSpec.describe 'Api Auth', type: :request do it 'does basic auth - customer' do Setting.set('api_password_access', false) - authenticated_as(customer_user) + authenticated_as(customer) get '/api/v1/tickets', params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(response.header).not_to be_key('Access-Control-Allow-Origin') @@ -94,13 +94,13 @@ RSpec.describe 'Api Auth', type: :request do :token, action: 'api', persistent: true, - user_id: admin_user.id, + user_id: admin.id, preferences: { permission: ['admin.session'], }, ) - authenticated_as(admin_user, token: admin_token) + authenticated_as(admin, token: admin_token) Setting.set('api_token_access', false) get '/api/v1/sessions', params: {}, as: :json @@ -136,8 +136,8 @@ RSpec.describe 'Api Auth', type: :request do expect(json_response).to be_a_kind_of(Hash) expect(json_response['error']).to eq('Not authorized (token)!') - admin_user.active = false - admin_user.save! + admin.active = false + admin.save! get '/api/v1/sessions', params: {}, as: :json expect(response).to have_http_status(:unauthorized) @@ -152,8 +152,8 @@ RSpec.describe 'Api Auth', type: :request do expect(json_response).to be_a_kind_of(Hash) expect(json_response['error']).to eq('User is inactive!') - admin_user.active = true - admin_user.save! + admin.active = true + admin.save! get '/api/v1/sessions', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -247,10 +247,10 @@ RSpec.describe 'Api Auth', type: :request do :token, action: 'api', persistent: true, - user_id: agent_user.id, + user_id: agent.id, ) - authenticated_as(agent_user, token: agent_token) + authenticated_as(agent, token: agent_token) Setting.set('api_token_access', false) get '/api/v1/tickets', params: {}, as: :json @@ -286,10 +286,10 @@ RSpec.describe 'Api Auth', type: :request do :token, action: 'api', persistent: true, - user_id: customer_user.id, + user_id: customer.id, ) - authenticated_as(customer_user, token: customer_token) + authenticated_as(customer, token: customer_token) Setting.set('api_token_access', false) get '/api/v1/tickets', params: {}, as: :json @@ -324,13 +324,13 @@ RSpec.describe 'Api Auth', type: :request do :token, action: 'api', persistent: true, - user_id: admin_user.id, + user_id: admin.id, ) - authenticated_as(admin_user, token: admin_token) + authenticated_as(admin, token: admin_token) - admin_user.active = false - admin_user.save! + admin.active = false + admin.save! Setting.set('api_token_access', false) get '/api/v1/sessions', params: {}, as: :json @@ -355,11 +355,11 @@ RSpec.describe 'Api Auth', type: :request do :token, action: 'api', persistent: true, - user_id: admin_user.id, + user_id: admin.id, expires_at: Time.zone.today ) - authenticated_as(admin_user, token: admin_token) + authenticated_as(admin, token: admin_token) get '/api/v1/tickets', params: {}, as: :json expect(response).to have_http_status(:unauthorized) @@ -379,11 +379,11 @@ RSpec.describe 'Api Auth', type: :request do :token, action: 'api', persistent: true, - user_id: admin_user.id, + user_id: admin.id, expires_at: Time.zone.tomorrow ) - authenticated_as(admin_user, token: admin_token) + authenticated_as(admin, token: admin_token) get '/api/v1/tickets', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -399,7 +399,7 @@ RSpec.describe 'Api Auth', type: :request do end it 'does session auth - admin' do - create(:admin_user, login: 'api-admin@example.com', password: 'adminpw') + create(:admin, login: 'api-admin@example.com', password: 'adminpw') get '/' token = response.headers['CSRF-TOKEN'] @@ -416,7 +416,7 @@ RSpec.describe 'Api Auth', type: :request do end it 'does session auth - admin - only with valid CSRF token' do - create(:admin_user, login: 'api-admin@example.com', password: 'adminpw') + create(:admin, login: 'api-admin@example.com', password: 'adminpw') post '/api/v1/signin', params: { username: 'api-admin@example.com', password: 'adminpw', fingerprint: '123456789' } expect(response).to have_http_status(:unauthorized) diff --git a/spec/requests/calendar_spec.rb b/spec/requests/calendar_spec.rb index d809db2f0..8446acf5d 100644 --- a/spec/requests/calendar_spec.rb +++ b/spec/requests/calendar_spec.rb @@ -2,8 +2,8 @@ require 'rails_helper' RSpec.describe 'Calendars', type: :request do - let(:admin_user) do - create(:admin_user) + let(:admin) do + create(:admin) end describe 'request handling' do @@ -29,7 +29,7 @@ RSpec.describe 'Calendars', type: :request do end it 'does calendar index with admin' do - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/calendars', as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) diff --git a/spec/requests/error_spec.rb b/spec/requests/error_spec.rb index e721cc277..75f849a79 100644 --- a/spec/requests/error_spec.rb +++ b/spec/requests/error_spec.rb @@ -43,7 +43,7 @@ RSpec.describe 'Error handling', type: :request do end context 'agent user' do - let(:requesting_user) { create(:agent_user, groups: Group.all) } + let(:requesting_user) { create(:agent, groups: Group.all) } let(:message) { 'Please contact your administrator' } context 'requesting JSON' do @@ -59,7 +59,7 @@ RSpec.describe 'Error handling', type: :request do end context 'admin user' do - let(:requesting_user) { create(:admin_user, groups: Group.all) } + let(:requesting_user) { create(:admin, groups: Group.all) } if ActiveRecord::Base.connection_config[:adapter] == 'mysql2' let(:message) { 'Mysql2::Error' } diff --git a/spec/requests/external_credentials_spec.rb b/spec/requests/external_credentials_spec.rb index cae98a3e7..600fbaace 100644 --- a/spec/requests/external_credentials_spec.rb +++ b/spec/requests/external_credentials_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' RSpec.describe 'External Credentials', type: :request do - let(:admin_user) { create(:admin_user) } + let(:admin) { create(:admin) } context 'without authentication' do describe '#index' do @@ -42,7 +42,7 @@ RSpec.describe 'External Credentials', type: :request do end context 'authenticated as admin' do - before { authenticated_as(admin_user, via: :browser) } + before { authenticated_as(admin, via: :browser) } describe '#index' do it 'responds with an array of ExternalCredential records' do diff --git a/spec/requests/integration/check_mk_spec.rb b/spec/requests/integration/check_mk_spec.rb index 86eb6ed83..beb701a32 100644 --- a/spec/requests/integration/check_mk_spec.rb +++ b/spec/requests/integration/check_mk_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' RSpec.describe 'Integration Check MK', type: :request do - let(:customer_user) do - create(:customer_user) + let(:customer) do + create(:customer) end let(:group) do create(:group) @@ -36,7 +36,7 @@ RSpec.describe 'Integration Check MK', type: :request do state: 'down', host: 'some host', service: 'some service', - customer: customer_user.email, + customer: customer.email, } post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params expect(response).to have_http_status(:ok) @@ -48,7 +48,7 @@ RSpec.describe 'Integration Check MK', type: :request do ticket = Ticket.find(json_response['ticket_id']) expect(ticket.state.name).to eq('new') - expect(ticket.customer.email).to eq(customer_user.email) + expect(ticket.customer.email).to eq(customer.email) expect(ticket.articles.count).to eq(1) end @@ -58,7 +58,7 @@ RSpec.describe 'Integration Check MK', type: :request do state: 'down', host: 'some host', service: 'some service', - customer: customer_user.login, + customer: customer.login, } post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params: params expect(response).to have_http_status(:ok) @@ -70,7 +70,7 @@ RSpec.describe 'Integration Check MK', type: :request do ticket = Ticket.find(json_response['ticket_id']) expect(ticket.state.name).to eq('new') - expect(ticket.customer.email).to eq(customer_user.email) + expect(ticket.customer.email).to eq(customer.email) expect(ticket.articles.count).to eq(1) end diff --git a/spec/requests/integration/cti_spec.rb b/spec/requests/integration/cti_spec.rb index 4aeeaa0d6..15a034300 100644 --- a/spec/requests/integration/cti_spec.rb +++ b/spec/requests/integration/cti_spec.rb @@ -2,12 +2,12 @@ require 'rails_helper' RSpec.describe 'Integration CTI', type: :request do - let(:agent_user) do - create(:agent_user) + let(:agent) do + create(:agent) end - let!(:customer_user1) do + let!(:customer1) do create( - :customer_user, + :customer, login: 'ticket-caller_id_cti-customer1@example.com', firstname: 'CallerId', lastname: 'Customer1', @@ -17,18 +17,18 @@ RSpec.describe 'Integration CTI', type: :request do note: 'Phone at home: +49 99999 222224', ) end - let!(:customer_user2) do + let!(:customer2) do create( - :customer_user, + :customer, login: 'ticket-caller_id_cti-customer2@example.com', firstname: 'CallerId', lastname: 'Customer2', phone: '+49 99999 222222 2', ) end - let!(:customer_user3) do + let!(:customer3) do create( - :customer_user, + :customer, login: 'ticket-caller_id_cti-customer3@example.com', firstname: 'CallerId', lastname: 'Customer3', @@ -615,15 +615,15 @@ RSpec.describe 'Integration CTI', type: :request do expect(response).to have_http_status(:unauthorized) # get caller list - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/cti/log', as: :json 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 expect(json_response['assets']['User']).to be_truthy - expect(json_response['assets']['User'][customer_user2.id.to_s]).to be_truthy - expect(json_response['assets']['User'][customer_user3.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer2.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer3.id.to_s]).to be_truthy expect(json_response['list'][0]['call_id']).to eq('1234567890-7') expect(json_response['list'][1]['call_id']).to eq('1234567890-6') expect(json_response['list'][2]['call_id']).to eq('1234567890-5') @@ -676,10 +676,10 @@ RSpec.describe 'Integration CTI', type: :request do # get caller list (with notify group with 2 log entries) cti_config = Setting.get('cti_config') - cti_config[:notify_map] = [{ queue: '4930777000000', user_ids: [agent_user.id.to_s] }] + cti_config[:notify_map] = [{ queue: '4930777000000', user_ids: [agent.id.to_s] }] Setting.set('cti_config', cti_config) - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/cti/log', as: :json expect(response).to have_http_status(:ok) @@ -723,10 +723,10 @@ RSpec.describe 'Integration CTI', type: :request do # get caller list (with notify group without a log entry) cti_config = Setting.get('cti_config') - cti_config[:notify_map] = [{ queue: '4912347114711', user_ids: [agent_user.to_s] }] + cti_config[:notify_map] = [{ queue: '4912347114711', user_ids: [agent.to_s] }] Setting.set('cti_config', cti_config) - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/cti/log', as: :json expect(response).to have_http_status(:ok) expect(json_response['list']).to eq([]) @@ -802,7 +802,7 @@ RSpec.describe 'Integration CTI', type: :request do log = Cti::Log.find(cti_log1.id) expect(log.done).to eq(false) - authenticated_as(agent_user) + authenticated_as(agent) post "/api/v1/cti/done/#{cti_log1.id}", params: { done: true } @@ -820,7 +820,7 @@ RSpec.describe 'Integration CTI', type: :request do log = Cti::Log.find(cti_log1.id) expect(log.done).to eq(false) - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/cti/done/bulk', params: { ids: [cti_log1.id, cti_log2.id] } diff --git a/spec/requests/integration/idoit_spec.rb b/spec/requests/integration/idoit_spec.rb index 850dbbc19..050582bf7 100644 --- a/spec/requests/integration/idoit_spec.rb +++ b/spec/requests/integration/idoit_spec.rb @@ -2,14 +2,14 @@ require 'rails_helper' RSpec.describe 'Idoit', type: :request do - let!(:admin_user) do - create(:admin_user, groups: Group.all) + let!(:admin) do + create(:admin, groups: Group.all) end - let!(:agent_user) do - create(:agent_user, groups: Group.all) + let!(:agent) do + create(:agent, groups: Group.all) end - let!(:customer_user) do - create(:customer_user) + let!(:customer) do + create(:customer) end let!(:token) do 'some_token' @@ -36,7 +36,7 @@ RSpec.describe 'Idoit', type: :request do endpoint: endpoint, client_id: '', } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/integration/idoit/verify', params: params, as: :json expect(response).to have_http_status(:unauthorized) expect(json_response).to be_a_kind_of(Hash) @@ -52,7 +52,7 @@ RSpec.describe 'Idoit', type: :request do endpoint: endpoint, client_id: '', } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/integration/idoit/verify', params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -87,7 +87,7 @@ RSpec.describe 'Idoit', type: :request do params = { method: 'cmdb.object_types', } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/integration/idoit', params: params, as: :json expect(response).to have_http_status(:ok) @@ -103,7 +103,7 @@ RSpec.describe 'Idoit', type: :request do params = { method: 'cmdb.object_types', } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/integration/idoit', params: params, as: :json expect(response).to have_http_status(:ok) @@ -130,7 +130,7 @@ RSpec.describe 'Idoit', type: :request do ids: ['33'] }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/integration/idoit', params: params, as: :json expect(response).to have_http_status(:ok) diff --git a/spec/requests/integration/monitoring_spec.rb b/spec/requests/integration/monitoring_spec.rb index f393c9291..2c3cb497b 100644 --- a/spec/requests/integration/monitoring_spec.rb +++ b/spec/requests/integration/monitoring_spec.rb @@ -2,14 +2,14 @@ require 'rails_helper' RSpec.describe 'Monitoring', type: :request do - let!(:admin_user) do - create(:admin_user, groups: Group.all) + let!(:admin) do + create(:admin, groups: Group.all) end - let!(:agent_user) do - create(:agent_user, groups: Group.all) + let!(:agent) do + create(:agent, groups: Group.all) end - let!(:customer_user) do - create(:customer_user) + let!(:customer) do + create(:customer) end let!(:token) do SecureRandom.urlsafe_base64(64) @@ -231,7 +231,7 @@ RSpec.describe 'Monitoring', type: :request do it 'does monitoring with admin user' do # health_check - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/monitoring/health_check', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -264,7 +264,7 @@ RSpec.describe 'Monitoring', type: :request do it 'does monitoring with agent user' do # health_check - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/monitoring/health_check', params: {}, as: :json expect(response).to have_http_status(:unauthorized) @@ -300,7 +300,7 @@ RSpec.describe 'Monitoring', type: :request do permission.save! # health_check - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/monitoring/health_check', params: {}, as: :json expect(response).to have_http_status(:unauthorized) @@ -512,7 +512,7 @@ RSpec.describe 'Monitoring', type: :request do end it 'does check restart_failed_jobs' do - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/monitoring/restart_failed_jobs', params: {}, as: :json expect(response).to have_http_status(:ok) end @@ -532,7 +532,7 @@ RSpec.describe 'Monitoring', type: :request do migration = ObjectManager::Attribute.migration_execute expect(true).to eq(migration) - authenticated_as(admin_user) + authenticated_as(admin) post "/api/v1/object_manager_attributes/#{object.id}", params: {}, as: :json token = @response.headers['CSRF-TOKEN'] diff --git a/spec/requests/integration/object_manager_attributes_spec.rb b/spec/requests/integration/object_manager_attributes_spec.rb index cd9e51c1f..d200a9d34 100644 --- a/spec/requests/integration/object_manager_attributes_spec.rb +++ b/spec/requests/integration/object_manager_attributes_spec.rb @@ -2,14 +2,14 @@ require 'rails_helper' RSpec.describe 'ObjectManager Attributes', type: :request do - let(:admin_user) do - create(:admin_user) + let(:admin) do + create(:admin) end describe 'request handling' do it 'does add new ticket text object' do - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/object_manager_attributes', params: {}, as: :json # token based on headers @@ -56,7 +56,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do end it 'does add new ticket text object - no default' do - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/object_manager_attributes', params: {}, as: :json # token based on headers @@ -109,7 +109,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do migration = ObjectManager::Attribute.migration_execute expect(migration).to eq(true) - authenticated_as(admin_user) + authenticated_as(admin) post "/api/v1/object_manager_attributes/#{object.id}", params: {}, as: :json # parameters for updating @@ -157,7 +157,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do end it 'does add new ticket boolean object' do - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/object_manager_attributes', params: {}, as: :json # token based on headers @@ -205,7 +205,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do end it 'does add new user select object' do - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/object_manager_attributes', params: {}, as: :json # token based on headers @@ -263,7 +263,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do expect(json_response['name']).to eq('test5') end - it 'does update user select object', authenticated_as: -> { admin_user }, db_strategy: :reset do + it 'does update user select object', authenticated_as: -> { admin }, db_strategy: :reset do # add a new object object = create(:object_manager_attribute_text, object_name: 'User') @@ -366,7 +366,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do 'id': 'c-201' } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/object_manager_attributes', params: params, as: :json migration = ObjectManager::Attribute.migration_execute @@ -416,7 +416,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do }, } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/object_manager_attributes', params: params, as: :json migration = ObjectManager::Attribute.migration_execute @@ -471,7 +471,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do }, } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/object_manager_attributes', params: params, as: :json migration = ObjectManager::Attribute.migration_execute @@ -566,7 +566,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do }, } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/object_manager_attributes', params: params, as: :json migration = ObjectManager::Attribute.migration_execute @@ -652,7 +652,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do }, } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/object_manager_attributes', params: params, as: :json migration = ObjectManager::Attribute.migration_execute @@ -785,7 +785,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do }, } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/object_manager_attributes', params: params, as: :json params = { @@ -926,7 +926,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do }, } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/object_manager_attributes', params: params, as: :json expect(response).to have_http_status(:created) # created @@ -988,7 +988,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do }, } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/object_manager_attributes', params: params, as: :json expect(response).to have_http_status(:created) # created @@ -1018,7 +1018,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do expect(json_response['data_type']).to eq('select') end - it "doesn't let to update item that doesn't exist", authenticated_as: -> { admin_user } do + it "doesn't let to update item that doesn't exist", authenticated_as: -> { admin } do params = { active: true, data_option: { @@ -1036,7 +1036,7 @@ RSpec.describe 'ObjectManager Attributes', type: :request do expect(response).to have_http_status(:unprocessable_entity) end - context 'position handling', authenticated_as: -> { admin_user } do + context 'position handling', authenticated_as: -> { admin } do let(:params) do { 'name': "customerdescription_#{rand(999_999_999)}", diff --git a/spec/requests/integration/placetel_spec.rb b/spec/requests/integration/placetel_spec.rb index e99695faf..9f9a2f14e 100644 --- a/spec/requests/integration/placetel_spec.rb +++ b/spec/requests/integration/placetel_spec.rb @@ -2,12 +2,12 @@ require 'rails_helper' RSpec.describe 'Integration Placetel', type: :request do - let(:agent_user) do - create(:agent_user) + let(:agent) do + create(:agent) end - let!(:customer_user1) do + let!(:customer1) do create( - :customer_user, + :customer, login: 'ticket-caller_id_cti-customer1@example.com', firstname: 'CallerId', lastname: 'Customer1', @@ -17,18 +17,18 @@ RSpec.describe 'Integration Placetel', type: :request do note: 'Phone at home: +49 99999 222224', ) end - let!(:customer_user2) do + let!(:customer2) do create( - :customer_user, + :customer, login: 'ticket-caller_id_cti-customer2@example.com', firstname: 'CallerId', lastname: 'Customer2', phone: '+49 99999 222222 2', ) end - let!(:customer_user3) do + let!(:customer3) do create( - :customer_user, + :customer, login: 'ticket-caller_id_cti-customer3@example.com', firstname: 'CallerId', lastname: 'Customer3', @@ -514,15 +514,15 @@ RSpec.describe 'Integration Placetel', type: :request do get '/api/v1/cti/log' expect(response).to have_http_status(:unauthorized) - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/cti/log', as: :json 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 expect(json_response['assets']['User']).to be_truthy - expect(json_response['assets']['User'][customer_user2.id.to_s]).to be_truthy - expect(json_response['assets']['User'][customer_user3.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer2.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer3.id.to_s]).to be_truthy expect(json_response['list'][0]['call_id']).to eq('1234567890-7') expect(json_response['list'][1]['call_id']).to eq('1234567890-6') expect(json_response['list'][2]['call_id']).to eq('1234567890-5') diff --git a/spec/requests/integration/sipgate_spec.rb b/spec/requests/integration/sipgate_spec.rb index 2c9c7c9b4..6a8f9cb52 100644 --- a/spec/requests/integration/sipgate_spec.rb +++ b/spec/requests/integration/sipgate_spec.rb @@ -2,12 +2,12 @@ require 'rails_helper' RSpec.describe 'Integration Sipgate', type: :request do - let(:agent_user) do - create(:agent_user) + let(:agent) do + create(:agent) end - let!(:customer_user1) do + let!(:customer1) do create( - :customer_user, + :customer, login: 'ticket-caller_id_cti-customer1@example.com', firstname: 'CallerId', lastname: 'Customer1', @@ -17,18 +17,18 @@ RSpec.describe 'Integration Sipgate', type: :request do note: 'Phone at home: +49 99999 222224', ) end - let!(:customer_user2) do + let!(:customer2) do create( - :customer_user, + :customer, login: 'ticket-caller_id_cti-customer2@example.com', firstname: 'CallerId', lastname: 'Customer2', phone: '+49 99999 222222 2', ) end - let!(:customer_user3) do + let!(:customer3) do create( - :customer_user, + :customer, login: 'ticket-caller_id_cti-customer3@example.com', firstname: 'CallerId', lastname: 'Customer3', @@ -444,15 +444,15 @@ RSpec.describe 'Integration Sipgate', type: :request do get '/api/v1/cti/log' expect(@response).to have_http_status(:unauthorized) - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/cti/log', as: :json 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 expect(json_response['assets']['User']).to be_truthy - expect(json_response['assets']['User'][customer_user2.id.to_s]).to be_truthy - expect(json_response['assets']['User'][customer_user3.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer2.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer3.id.to_s]).to be_truthy expect(json_response['list'][0]['call_id']).to eq('1234567890-6') expect(json_response['list'][1]['call_id']).to eq('1234567890-5') expect(json_response['list'][2]['call_id']).to eq('1234567890-4') diff --git a/spec/requests/integration/smime_spec.rb b/spec/requests/integration/smime_spec.rb index b79761a55..a61e70b31 100644 --- a/spec/requests/integration/smime_spec.rb +++ b/spec/requests/integration/smime_spec.rb @@ -2,11 +2,11 @@ require 'rails_helper' RSpec.describe 'Integration SMIME', type: :request do - let(:admin_user) { create(:admin_user) } + let(:admin) { create(:admin) } let(:email_address) { 'smime1@example.com' } before do - authenticated_as(admin_user) + authenticated_as(admin) end describe '/integration/smime/certificate' do diff --git a/spec/requests/integration/twilio_sms_spec.rb b/spec/requests/integration/twilio_sms_spec.rb index 955307591..e9be005c4 100644 --- a/spec/requests/integration/twilio_sms_spec.rb +++ b/spec/requests/integration/twilio_sms_spec.rb @@ -4,8 +4,8 @@ RSpec.describe 'Twilio SMS', type: :request do describe 'request handling' do - let(:agent_user) do - create(:agent_user, groups: Group.all) + let(:agent) do + create(:agent, groups: Group.all) end it 'does basic call' do @@ -131,15 +131,15 @@ RSpec.describe 'Twilio SMS', type: :request do body: 'some test', type: 'sms', } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/ticket_articles', params: params, as: :json 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') expect(json_response['content_type']).to eq('text/plain') - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) stub_request(:post, 'https://api.twilio.com/2010-04-01/Accounts/111/Messages.json') .with( @@ -171,7 +171,7 @@ RSpec.describe 'Twilio SMS', type: :request do it 'does customer based on already existing mobile attibute' do customer = create( - :customer_user, + :customer, email: 'me@example.com', mobile: '01710000000', ) diff --git a/spec/requests/integration/user_device_spec.rb b/spec/requests/integration/user_device_spec.rb index 1fef8e69f..54687b8b4 100644 --- a/spec/requests/integration/user_device_spec.rb +++ b/spec/requests/integration/user_device_spec.rb @@ -2,11 +2,11 @@ require 'rails_helper' RSpec.describe 'User Device', type: :request, sends_notification_emails: true do - let!(:admin_user) do - create(:admin_user, login: 'user-device-admin', password: 'adminpw', groups: Group.all) + let!(:admin) do + create(:admin, login: 'user-device-admin', password: 'adminpw', groups: Group.all) end - let!(:agent_user) do - create(:agent_user, login: 'user-device-agent', password: 'agentpw', groups: Group.all) + let!(:agent) do + create(:agent, login: 'user-device-agent', password: 'agentpw', groups: Group.all) end before do @@ -48,15 +48,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(0) + expect(UserDevice.where(user_id: admin.id).count).to eq(0) end it 'does login index with admin with fingerprint - I (03)' do @@ -74,15 +74,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(1) + expect(UserDevice.where(user_id: admin.id).count).to eq(1) user_device_first = UserDevice.last sleep 2 @@ -98,15 +98,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(1) + expect(UserDevice.where(user_id: admin.id).count).to eq(1) user_device_last = UserDevice.last expect(user_device_first.updated_at.to_s).to eq(user_device_last.updated_at.to_s) @@ -124,15 +124,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(1) + expect(UserDevice.where(user_id: admin.id).count).to eq(1) user_device_last = UserDevice.last expect(user_device_first.updated_at.to_s).to eq(user_device_last.updated_at.to_s) @@ -149,15 +149,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(1) + expect(UserDevice.where(user_id: admin.id).count).to eq(1) user_device_last = UserDevice.last expect(user_device_last.updated_at.to_s).not_to eq(user_device_first.updated_at.to_s) ENV['USER_DEVICE_UPDATED_AT'] = nil @@ -176,15 +176,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(2) + expect(UserDevice.where(user_id: admin.id).count).to eq(2) # ip reset ENV['TEST_REMOTE_IP'] = '5.9.62.170' # de @@ -195,7 +195,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do create( :user_device, - user_id: admin_user.id, + user_id: admin.id, fingerprint: 'fingerprintI', ) @@ -209,15 +209,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(2) + expect(UserDevice.where(user_id: admin.id).count).to eq(2) expect(json_response).to be_a_kind_of(Hash) expect(json_response['error']).to be_falsey expect(json_response['config']).to be_truthy @@ -233,15 +233,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(2) + expect(UserDevice.where(user_id: admin.id).count).to eq(2) params = { fingerprint: 'my_finger_print_II' } get '/api/v1/signshow', params: params, as: :json @@ -257,15 +257,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(2) + expect(UserDevice.where(user_id: admin.id).count).to eq(2) ENV['TEST_REMOTE_IP'] = '195.65.29.254' # ch @@ -279,15 +279,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(3) + expect(UserDevice.where(user_id: admin.id).count).to eq(3) # ip reset ENV['TEST_REMOTE_IP'] = '5.9.62.170' # de @@ -298,12 +298,12 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do UserDevice.add( ENV['HTTP_USER_AGENT'], ENV['TEST_REMOTE_IP'], - admin_user.id, + admin.id, 'my_finger_print_II', 'session', # session|basic_auth|token_auth|sso ) - expect(UserDevice.where(user_id: admin_user.id).count).to eq(1) + expect(UserDevice.where(user_id: admin.id).count).to eq(1) params = { fingerprint: 'my_finger_print_II', username: 'user-device-admin', password: 'adminpw' } post '/api/v1/signin', params: params, as: :json @@ -315,15 +315,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(1) + expect(UserDevice.where(user_id: admin.id).count).to eq(1) expect(json_response).to be_a_kind_of(Hash) expect(json_response['error']).to be_falsey expect(json_response['config']).to be_truthy @@ -336,15 +336,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do UserDevice.add( ENV['HTTP_USER_AGENT'], '127.0.0.1', - admin_user.id, + admin.id, '', 'basic_auth', # session|basic_auth|token_auth|sso ) - expect(UserDevice.where(user_id: admin_user.id).count).to eq(1) + expect(UserDevice.where(user_id: admin.id).count).to eq(1) ENV['HTTP_USER_AGENT'] = 'curl 1.2.3' params = {} - authenticated_as(admin_user, password: 'adminpw') + authenticated_as(admin, password: 'adminpw') get '/api/v1/users', params: params, as: :json expect(response).to have_http_status(:ok) @@ -354,15 +354,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(2) + expect(UserDevice.where(user_id: admin.id).count).to eq(2) expect(json_response).to be_a_kind_of(Array) user_device_first = UserDevice.last sleep 2 @@ -377,15 +377,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(2) + expect(UserDevice.where(user_id: admin.id).count).to eq(2) expect(json_response).to be_a_kind_of(Array) user_device_last = UserDevice.last expect(user_device_first.id).to eq(user_device_last.id) @@ -404,15 +404,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(2) + expect(UserDevice.where(user_id: admin.id).count).to eq(2) expect(json_response).to be_a_kind_of(Array) user_device_last = UserDevice.last expect(user_device_first.id).to eq(user_device_last.id) @@ -426,15 +426,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do UserDevice.add( ENV['HTTP_USER_AGENT'], ENV['TEST_REMOTE_IP'], - admin_user.id, + admin.id, '', 'basic_auth', # session|basic_auth|token_auth|sso ) - expect(UserDevice.where(user_id: admin_user.id).count).to eq(1) + expect(UserDevice.where(user_id: admin.id).count).to eq(1) params = {} - authenticated_as(admin_user, password: 'adminpw') + authenticated_as(admin, password: 'adminpw') get '/api/v1/users', params: params, as: :json expect(response).to have_http_status(:ok) @@ -444,15 +444,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(1) + expect(UserDevice.where(user_id: admin.id).count).to eq(1) expect(json_response).to be_a_kind_of(Array) end @@ -461,7 +461,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do ENV['HTTP_USER_AGENT'] = 'curl 1.2.3' params = {} - authenticated_as(agent_user, password: 'agentpw') + authenticated_as(agent, password: 'agentpw') get '/api/v1/users', params: params, as: :json expect(response).to have_http_status(:ok) @@ -471,15 +471,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: agent_user, + user: agent, ) not_sent( template: 'user_device_new_location', - user: agent_user, + user: agent, ) end - expect(UserDevice.where(user_id: agent_user.id).count).to eq(1) + expect(UserDevice.where(user_id: agent.id).count).to eq(1) expect(json_response).to be_a_kind_of(Array) end @@ -490,15 +490,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do UserDevice.add( ENV['HTTP_USER_AGENT'], ENV['TEST_REMOTE_IP'], - agent_user.id, + agent.id, '', 'basic_auth', # session|basic_auth|token_auth|sso ) - expect(UserDevice.where(user_id: agent_user.id).count).to eq(1) + expect(UserDevice.where(user_id: agent.id).count).to eq(1) params = {} - authenticated_as(agent_user, password: 'agentpw') + authenticated_as(agent, password: 'agentpw') get '/api/v1/users', params: params, as: :json expect(response).to have_http_status(:ok) @@ -508,23 +508,23 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: agent_user, + user: agent, ) not_sent( template: 'user_device_new_location', - user: agent_user, + user: agent, ) end - expect(UserDevice.where(user_id: agent_user.id).count).to eq(1) + expect(UserDevice.where(user_id: agent.id).count).to eq(1) expect(json_response).to be_a_kind_of(Array) end it 'does login with switched_from_user_id (10)' do - expect(UserDevice.where(user_id: agent_user.id).count).to eq(0) + expect(UserDevice.where(user_id: agent.id).count).to eq(0) - ENV['SWITCHED_FROM_USER_ID'] = admin_user.id.to_s + ENV['SWITCHED_FROM_USER_ID'] = admin.id.to_s params = { fingerprint: 'my_finger_print_II', username: 'user-device-agent', password: 'agentpw' } post '/api/v1/signin', params: params, as: :json @@ -536,15 +536,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: agent_user, + user: agent, ) not_sent( template: 'user_device_new_location', - user: agent_user, + user: agent, ) end - expect(UserDevice.where(user_id: agent_user.id).count).to eq(0) + expect(UserDevice.where(user_id: agent.id).count).to eq(0) expect(json_response).to be_a_kind_of(Hash) expect(json_response['error']).to be_falsey expect(json_response['config']).to be_truthy @@ -555,15 +555,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: agent_user, + user: agent, ) not_sent( template: 'user_device_new_location', - user: agent_user, + user: agent, ) end - expect(UserDevice.where(user_id: agent_user.id).count).to eq(0) + expect(UserDevice.where(user_id: agent.id).count).to eq(0) ENV['USER_DEVICE_UPDATED_AT'] = (Time.zone.now - 4.hours).to_s params = {} @@ -577,15 +577,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: agent_user, + user: agent, ) not_sent( template: 'user_device_new_location', - user: agent_user, + user: agent, ) end - expect(UserDevice.where(user_id: agent_user.id).count).to eq(0) + expect(UserDevice.where(user_id: agent.id).count).to eq(0) ENV['USER_DEVICE_UPDATED_AT'] = nil ENV['TEST_REMOTE_IP'] = '195.65.29.254' # ch @@ -599,18 +599,18 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: agent_user, + user: agent, ) not_sent( template: 'user_device_new_location', - user: agent_user, + user: agent, ) end # ip reset ENV['TEST_REMOTE_IP'] = '5.9.62.170' # de - expect(UserDevice.where(user_id: agent_user.id).count).to eq(0) + expect(UserDevice.where(user_id: agent.id).count).to eq(0) end it 'does login with invalid fingerprint (11)' do @@ -629,15 +629,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(0) + expect(UserDevice.where(user_id: admin.id).count).to eq(0) end it 'does login with integer as fingerprint (12)' do @@ -652,15 +652,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(1) + expect(UserDevice.where(user_id: admin.id).count).to eq(1) expect(json_response).to be_a_kind_of(Hash) expect(json_response['error']).to be_nil end @@ -671,7 +671,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do params = { fingerprint: 'long_1234567890long_1234567890long_1234567890long_1234567890long_1234567890long_1234567890long_1234567890long_1234567890long_1234567890long_1234567890long_1234567890' } - authenticated_as(admin_user, password: 'adminpw') + authenticated_as(admin, password: 'adminpw') post '/api/v1/form_config', params: params, as: :json expect(response).to have_http_status(:ok) @@ -686,15 +686,15 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do not_sent( template: 'user_device_new', - user: admin_user, + user: admin, ) not_sent( template: 'user_device_new_location', - user: admin_user, + user: admin, ) end - expect(UserDevice.where(user_id: admin_user.id).count).to eq(0) + expect(UserDevice.where(user_id: admin.id).count).to eq(0) end end end diff --git a/spec/requests/knowledge_base/translation_update_spec.rb b/spec/requests/knowledge_base/translation_update_spec.rb index c3ac94284..6ddb047fa 100644 --- a/spec/requests/knowledge_base/translation_update_spec.rb +++ b/spec/requests/knowledge_base/translation_update_spec.rb @@ -24,7 +24,7 @@ RSpec.describe 'KnowledgeBase translation update', type: :request, authenticated describe 'changes KB translation title' do describe 'as editor' do - let(:user_identifier) { :admin_user } + let(:user_identifier) { :admin } it 'updates title' do expect { request }.to change { knowledge_base.reload.translations.first.title }.to(new_title) @@ -32,7 +32,7 @@ RSpec.describe 'KnowledgeBase translation update', type: :request, authenticated end describe 'as reader' do - let(:user_identifier) { :agent_user } + let(:user_identifier) { :agent } it 'does not change title' do expect { request }.not_to change { knowledge_base.reload.translations.first.title } @@ -58,14 +58,14 @@ RSpec.describe 'KnowledgeBase translation update', type: :request, authenticated before { request } describe 'as editor' do - let(:user_identifier) { :admin_user } + let(:user_identifier) { :admin } it { expect(response).to have_http_status(:ok) } it { expect(json_response).to be_a_kind_of(Hash) } end describe 'as reader' do - let(:user_identifier) { :agent_user } + let(:user_identifier) { :agent } it { expect(response).to have_http_status(:unauthorized) } end diff --git a/spec/requests/long_polling_spec.rb b/spec/requests/long_polling_spec.rb index 14fd023a7..c6a1d4ec8 100644 --- a/spec/requests/long_polling_spec.rb +++ b/spec/requests/long_polling_spec.rb @@ -2,8 +2,8 @@ require 'rails_helper' RSpec.describe 'LongPolling', type: :request do - let(:agent_user) do - create(:agent_user) + let(:agent) do + create(:agent) end before do @@ -41,7 +41,7 @@ RSpec.describe 'LongPolling', type: :request do end it 'receive without client_id' do - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/message_receive', params: { data: {} }, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) @@ -49,7 +49,7 @@ RSpec.describe 'LongPolling', type: :request do end it 'receive without wrong client_id' do - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/message_receive', params: { client_id: 'not existing', data: {} }, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) @@ -57,7 +57,7 @@ RSpec.describe 'LongPolling', type: :request do end it 'send without client_id' do - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/message_send', params: { data: {} }, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -66,7 +66,7 @@ RSpec.describe 'LongPolling', type: :request do it 'send with client_id' do Sessions.create('123456', {}, { type: 'ajax' }) - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/message_send', params: { client_id: '123456', data: {} }, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -77,7 +77,7 @@ RSpec.describe 'LongPolling', type: :request do # here we use a token for the authentication because the basic auth way with username and password # 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) ) + authenticated_as(agent, token: create(:token, action: 'api', user_id: agent.id) ) get '/api/v1/message_send', params: { data: { event: 'login' } }, as: :json expect(response).to have_http_status(:ok) expect(json_response['client_id'].to_i).to be_between(1, 9_999_999_999) @@ -100,10 +100,10 @@ RSpec.describe 'LongPolling', type: :request do expect(json_response[0]['event']).to eq('spool:sent') expect(json_response.count).to eq(1) - spool_list = Sessions.spool_list(Time.now.utc.to_i, agent_user.id) + spool_list = Sessions.spool_list(Time.now.utc.to_i, agent.id) 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 + get '/api/v1/message_send', params: { client_id: client_id, data: { event: 'broadcast', spool: true, recipient: { user_id: [agent.id] }, data: { taskbar_id: 9_391_633 } } }, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response).to eq({}) @@ -115,10 +115,10 @@ RSpec.describe 'LongPolling', type: :request do travel 2.seconds - spool_list = Sessions.spool_list(Time.now.utc.to_i, agent_user.id) + spool_list = Sessions.spool_list(Time.now.utc.to_i, agent.id) expect(spool_list).to eq([]) - spool_list = Sessions.spool_list(nil, agent_user.id) + spool_list = Sessions.spool_list(nil, agent.id) expect(spool_list).to eq([{ message: { 'taskbar_id' => 9_391_633 }, type: 'direct' }]) end diff --git a/spec/requests/organization_spec.rb b/spec/requests/organization_spec.rb index 973b66c18..c91c2f8ed 100644 --- a/spec/requests/organization_spec.rb +++ b/spec/requests/organization_spec.rb @@ -2,14 +2,14 @@ require 'rails_helper' RSpec.describe 'Organization', type: :request, searchindex: true do - let!(:admin_user) do - create(:admin_user, groups: Group.all) + let!(:admin) do + create(:admin, groups: Group.all) end - let!(:agent_user) do - create(:agent_user, firstname: 'Search 1234', groups: Group.all) + let!(:agent) do + create(:agent, firstname: 'Search 1234', groups: Group.all) end - let!(:customer_user) do - create(:customer_user) + let!(:customer) do + create(:customer) end let!(:organization) do create( @@ -35,8 +35,8 @@ RSpec.describe 'Organization', type: :request, searchindex: true do created_at: '2017-09-05 12:00:00', ) end - let!(:customer_user2) do - create(:customer_user, organization: organization) + let!(:customer2) do + create(:customer, organization: organization) end before do @@ -58,7 +58,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do it 'does index with agent' do # index - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/organizations', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) @@ -132,7 +132,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do it 'does index with customer1' do # index - authenticated_as(customer_user) + authenticated_as(customer) get '/api/v1/organizations', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) @@ -158,7 +158,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do it 'does index with customer2' do # index - authenticated_as(customer_user2) + authenticated_as(customer2) get '/api/v1/organizations', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) @@ -182,7 +182,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do end it 'does organization search sortable' do - authenticated_as(admin_user) + authenticated_as(admin) get "/api/v1/organizations/search?query=#{CGI.escape('Rest Org')}", params: {}, as: :json expect(response).to have_http_status(:ok) result = json_response @@ -223,21 +223,21 @@ RSpec.describe 'Organization', type: :request, searchindex: true do organization = create( :organization, name: 'Rest Org NEW', - members: [customer_user], - updated_by_id: admin_user.id, - created_by_id: admin_user.id, + members: [customer], + updated_by_id: admin.id, + created_by_id: admin.id, ) - authenticated_as(admin_user) + authenticated_as(admin) get "/api/v1/organizations/#{organization.id}", params: {}, as: :json 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) expect(json_response['members']).to be_falsey - expect(json_response['member_ids']).to eq([customer_user.id]) - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['member_ids']).to eq([customer.id]) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) get "/api/v1/organizations/#{organization.id}?expand=true", params: {}, as: :json expect(response).to have_http_status(:ok) @@ -245,9 +245,9 @@ RSpec.describe 'Organization', type: :request, searchindex: true do expect(json_response['id']).to eq(organization.id) expect(json_response['name']).to eq(organization.name) expect(json_response['members']).to be_truthy - expect(json_response['member_ids']).to eq([customer_user.id]) - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['member_ids']).to eq([customer.id]) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) get "/api/v1/organizations/#{organization.id}?expand=false", params: {}, as: :json expect(response).to have_http_status(:ok) @@ -255,9 +255,9 @@ RSpec.describe 'Organization', type: :request, searchindex: true do expect(json_response['id']).to eq(organization.id) expect(json_response['name']).to eq(organization.name) expect(json_response['members']).to be_falsey - expect(json_response['member_ids']).to eq([customer_user.id]) - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['member_ids']).to eq([customer.id]) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) get "/api/v1/organizations/#{organization.id}?full=true", params: {}, as: :json expect(response).to have_http_status(:ok) @@ -278,21 +278,21 @@ RSpec.describe 'Organization', type: :request, searchindex: true do expect(json_response['id']).to eq(organization.id) expect(json_response['name']).to eq(organization.name) expect(json_response['members']).to be_falsey - expect(json_response['member_ids']).to eq([customer_user.id]) - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['member_ids']).to eq([customer.id]) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) end it 'does organization index and response format' do organization = create( :organization, name: 'Rest Org NEW', - members: [customer_user], - updated_by_id: admin_user.id, - created_by_id: admin_user.id, + members: [customer], + updated_by_id: admin.id, + created_by_id: admin.id, ) - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/organizations', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) @@ -301,8 +301,8 @@ RSpec.describe 'Organization', type: :request, searchindex: true do expect(json_response.last['name']).to eq(organization.name) expect(json_response.last['members']).to be_falsey expect(json_response.last['member_ids']).to eq(organization.member_ids) - expect(json_response.last['updated_by_id']).to eq(admin_user.id) - expect(json_response.last['created_by_id']).to eq(admin_user.id) + expect(json_response.last['updated_by_id']).to eq(admin.id) + expect(json_response.last['created_by_id']).to eq(admin.id) get '/api/v1/organizations?expand=true', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -311,9 +311,9 @@ RSpec.describe 'Organization', type: :request, searchindex: true do expect(json_response.last['id']).to eq(organization.id) expect(json_response.last['name']).to eq(organization.name) expect(json_response.last['member_ids']).to eq(organization.member_ids) - expect([customer_user.login]).to eq(organization.members.pluck(:login)) - expect(json_response.last['updated_by_id']).to eq(admin_user.id) - expect(json_response.last['created_by_id']).to eq(admin_user.id) + expect([customer.login]).to eq(organization.members.pluck(:login)) + expect(json_response.last['updated_by_id']).to eq(admin.id) + expect(json_response.last['created_by_id']).to eq(admin.id) get '/api/v1/organizations?expand=false', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -323,8 +323,8 @@ RSpec.describe 'Organization', type: :request, searchindex: true do expect(json_response.last['name']).to eq(organization.name) expect(json_response.last['members']).to be_falsey expect(json_response.last['member_ids']).to eq(organization.member_ids) - expect(json_response.last['updated_by_id']).to eq(admin_user.id) - expect(json_response.last['created_by_id']).to eq(admin_user.id) + expect(json_response.last['updated_by_id']).to eq(admin.id) + expect(json_response.last['created_by_id']).to eq(admin.id) get '/api/v1/organizations?full=true', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -349,17 +349,17 @@ RSpec.describe 'Organization', type: :request, searchindex: true do expect(json_response.last['name']).to eq(organization.name) expect(json_response.last['members']).to be_falsey expect(json_response.last['member_ids']).to eq(organization.member_ids) - expect(json_response.last['updated_by_id']).to eq(admin_user.id) - expect(json_response.last['created_by_id']).to eq(admin_user.id) + expect(json_response.last['updated_by_id']).to eq(admin.id) + expect(json_response.last['created_by_id']).to eq(admin.id) end it 'does ticket create and response format' do params = { name: 'Rest Org NEW', - members: [customer_user.login], + members: [customer.login], } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/organizations', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) @@ -368,8 +368,8 @@ RSpec.describe 'Organization', type: :request, searchindex: true do expect(json_response['name']).to eq(organization.name) expect(json_response['member_ids']).to eq(organization.member_ids) expect(json_response['members']).to be_falsey - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) params[:name] = 'Rest Org NEW #2' post '/api/v1/organizations?expand=true', params: params, as: :json @@ -380,8 +380,8 @@ RSpec.describe 'Organization', type: :request, searchindex: true do expect(json_response['name']).to eq(organization.name) expect(json_response['member_ids']).to eq(organization.member_ids) expect(json_response['members']).to eq(organization.members.pluck(:login)) - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) params[:name] = 'Rest Org NEW #3' post '/api/v1/organizations?full=true', params: params, as: :json @@ -403,15 +403,15 @@ RSpec.describe 'Organization', type: :request, searchindex: true do organization = create( :organization, name: 'Rest Org NEW', - members: [customer_user], - updated_by_id: admin_user.id, - created_by_id: admin_user.id, + members: [customer], + updated_by_id: admin.id, + created_by_id: admin.id, ) params = { name: 'a update name #1', } - authenticated_as(admin_user) + authenticated_as(admin) put "/api/v1/organizations/#{organization.id}", params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -420,8 +420,8 @@ RSpec.describe 'Organization', type: :request, searchindex: true do expect(json_response['name']).to eq(params[:name]) expect(json_response['member_ids']).to eq(organization.member_ids) expect(json_response['members']).to be_falsey - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) params = { name: 'a update name #2', @@ -433,9 +433,9 @@ RSpec.describe 'Organization', type: :request, searchindex: true do organization = Organization.find(json_response['id']) expect(json_response['name']).to eq(params[:name]) expect(json_response['member_ids']).to eq(organization.member_ids) - expect([customer_user.login]).to eq(organization.members.pluck(:login)) - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect([customer.login]).to eq(organization.members.pluck(:login)) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) params = { name: 'a update name #3', @@ -461,7 +461,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do name: 'some org', ) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/organizations/history/#{organization1.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -472,14 +472,14 @@ RSpec.describe 'Organization', type: :request, searchindex: true do end it 'does csv example - customer no access' do - authenticated_as(customer_user) + authenticated_as(customer) get '/api/v1/organizations/import_example', params: {}, as: :json 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) + authenticated_as(admin) get '/api/v1/organizations/import_example', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -500,7 +500,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do UserInfo.current_user_id = 1 customer1 = create( - :customer_user, + :customer, login: 'customer1-members@example.com', firstname: 'Member', lastname: 'Customer', @@ -509,7 +509,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do active: true, ) customer2 = create( - :customer_user, + :customer, login: 'customer2-members@example.com', firstname: 'Member', lastname: 'Customer', @@ -520,7 +520,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do UserInfo.current_user_id = nil # invalid file - authenticated_as(admin_user) + authenticated_as(admin) 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(:ok) diff --git a/spec/requests/overview_spec.rb b/spec/requests/overview_spec.rb index ff3f8814a..f77d8bb62 100644 --- a/spec/requests/overview_spec.rb +++ b/spec/requests/overview_spec.rb @@ -2,8 +2,8 @@ require 'rails_helper' RSpec.describe 'Overviews', type: :request do - let(:admin_user) do - create(:admin_user) + let(:admin) do + create(:admin) end describe 'request handling' do @@ -31,9 +31,9 @@ RSpec.describe 'Overviews', type: :request do }, } - agent_user = create(:agent_user, password: 'we need a password here') + agent = create(:agent, password: 'we need a password here') - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/overviews', params: params, as: :json expect(response).to have_http_status(:unauthorized) expect(json_response).to be_a_kind_of(Hash) @@ -63,7 +63,7 @@ RSpec.describe 'Overviews', type: :request do }, } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/overviews', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) @@ -134,7 +134,7 @@ RSpec.describe 'Overviews', type: :request do [overview1.id, 2], ] } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/overviews_prio', params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -173,7 +173,7 @@ RSpec.describe 'Overviews', type: :request do }, } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/overviews', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) diff --git a/spec/requests/package_spec.rb b/spec/requests/package_spec.rb index 0764b0255..bb8ff25b7 100644 --- a/spec/requests/package_spec.rb +++ b/spec/requests/package_spec.rb @@ -2,14 +2,14 @@ require 'rails_helper' RSpec.describe 'Packages', type: :request do - let(:admin_user) do - create(:admin_user) + let(:admin) do + create(:admin) end - let(:agent_user) do - create(:agent_user) + let(:agent) do + create(:agent) end - let(:customer_user) do - create(:customer_user) + let(:customer) do + create(:customer) end describe 'request handling' do @@ -24,7 +24,7 @@ RSpec.describe 'Packages', type: :request do end it 'does packages index with admin' do - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/packages', as: :json expect(response).to have_http_status(:ok) @@ -33,7 +33,7 @@ RSpec.describe 'Packages', type: :request do end it 'does packages index with admin and wrong pw' do - authenticated_as(admin_user, password: 'wrongadminpw') + authenticated_as(admin, password: 'wrongadminpw') get '/api/v1/packages', as: :json expect(response).to have_http_status(:unauthorized) @@ -42,9 +42,9 @@ RSpec.describe 'Packages', type: :request do end it 'does packages index with inactive admin' do - admin_user = create(:admin_user, active: false, password: 'we need a password here') + admin = create(:admin, active: false, password: 'we need a password here') - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/packages', as: :json expect(response).to have_http_status(:unauthorized) @@ -53,7 +53,7 @@ RSpec.describe 'Packages', type: :request do end it 'does packages index with agent' do - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/packages', as: :json expect(response).to have_http_status(:unauthorized) @@ -63,7 +63,7 @@ RSpec.describe 'Packages', type: :request do end it 'does packages index with customer' do - authenticated_as(customer_user) + authenticated_as(customer) get '/api/v1/packages', as: :json expect(response).to have_http_status(:unauthorized) diff --git a/spec/requests/report_spec.rb b/spec/requests/report_spec.rb index ae3532e7a..531ee8daa 100644 --- a/spec/requests/report_spec.rb +++ b/spec/requests/report_spec.rb @@ -2,8 +2,8 @@ require 'rails_helper' RSpec.describe 'Report', type: :request, searchindex: true do - let!(:admin_user) do - create(:admin_user) + let!(:admin) do + create(:admin) end let!(:year) do DateTime.now.utc.year @@ -72,7 +72,7 @@ RSpec.describe 'Report', type: :request, searchindex: true do describe 'request handling' do it 'does report example - admin access' do - authenticated_as(admin_user) + authenticated_as(admin) 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(:ok) @@ -84,7 +84,7 @@ RSpec.describe 'Report', type: :request, searchindex: true do it 'does report example - deliver result' do skip('No ES configured') if !SearchIndexBackend.enabled? - authenticated_as(admin_user) + authenticated_as(admin) # 2019-03-15 - day interval params = { diff --git a/spec/requests/search_spec.rb b/spec/requests/search_spec.rb index 5edd101ea..9f25eb2ad 100644 --- a/spec/requests/search_spec.rb +++ b/spec/requests/search_spec.rb @@ -3,14 +3,14 @@ require 'rails_helper' RSpec.describe 'Search', type: :request, searchindex: true do let(:group) { create(:group) } - let!(:admin_user) do - create(:admin_user, groups: [Group.lookup(name: 'Users'), group]) + let!(:admin) do + create(:admin, groups: [Group.lookup(name: 'Users'), group]) end - let!(:agent_user) do - create(:agent_user, firstname: 'Search 1234', groups: [Group.lookup(name: 'Users'), group]) + let!(:agent) do + create(:agent, firstname: 'Search 1234', groups: [Group.lookup(name: 'Users'), group]) end - let!(:customer_user) do - create(:customer_user) + let!(:customer) do + create(:customer) end let!(:organization1) do create(:organization, name: 'Rest Org') @@ -30,26 +30,26 @@ RSpec.describe 'Search', type: :request, searchindex: true do let!(:organization_nested) do create(:organization, name: 'Tomato42 Ltd.', note: 'Tomato42 Ltd.') end - let!(:customer_user_nested) do - create(:customer_user, organization: organization_nested) + let!(:customer_nested) do + create(:customer, organization: organization_nested) end - let!(:customer_user2) do - create(:customer_user, organization: organization1) + let!(:customer2) do + create(:customer, organization: organization1) end - let!(:customer_user3) do - create(:customer_user, organization: organization1) + let!(:customer3) do + create(:customer, organization: organization1) end let!(:ticket1) do - create(:ticket, title: 'test 1234-1', customer: customer_user, group: group) + create(:ticket, title: 'test 1234-1', customer: customer, group: group) end let!(:ticket2) do - create(:ticket, title: 'test 1234-2', customer: customer_user2, group: group) + create(:ticket, title: 'test 1234-2', customer: customer2, group: group) end let!(:ticket3) do - create(:ticket, title: 'test 1234-2', customer: customer_user3, group: group) + create(:ticket, title: 'test 1234-2', customer: customer3, group: group) end let!(:ticket_nested) do - create(:ticket, title: 'vegetable request', customer: customer_user_nested, group: group) + create(:ticket, title: 'vegetable request', customer: customer_nested, group: group) end let!(:article1) do create(:ticket_article, ticket_id: ticket1.id) @@ -121,7 +121,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do query: '1234*', limit: 1, } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/search', params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -129,7 +129,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do expect(json_response['result'][0]['type']).to eq('Ticket') expect(json_response['result'][0]['id']).to eq(ticket3.id) expect(json_response['result'][1]['type']).to eq('User') - expect(json_response['result'][1]['id']).to eq(agent_user.id) + expect(json_response['result'][1]['id']).to eq(agent.id) expect(json_response['result'][2]).to be_falsey params = { @@ -148,7 +148,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do expect(json_response['result'][2]['type']).to eq('Ticket') expect(json_response['result'][2]['id']).to eq(ticket1.id) expect(json_response['result'][3]['type']).to eq('User') - expect(json_response['result'][3]['id']).to eq(agent_user.id) + expect(json_response['result'][3]['id']).to eq(agent.id) expect(json_response['result'][4]).to be_falsey params = { @@ -177,7 +177,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do 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) + expect(json_response['result'][0]['id']).to eq(agent.id) expect(json_response['result'][1]).to be_falsey end @@ -187,7 +187,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do limit: 1, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/search', params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -195,7 +195,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do expect(json_response['result'][0]['type']).to eq('Ticket') expect(json_response['result'][0]['id']).to eq(ticket3.id) expect(json_response['result'][1]['type']).to eq('User') - expect(json_response['result'][1]['id']).to eq(agent_user.id) + expect(json_response['result'][1]['id']).to eq(agent.id) expect(json_response['result'][2]).to be_falsey params = { @@ -214,7 +214,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do expect(json_response['result'][2]['type']).to eq('Ticket') expect(json_response['result'][2]['id']).to eq(ticket1.id) expect(json_response['result'][3]['type']).to eq('User') - expect(json_response['result'][3]['id']).to eq(agent_user.id) + expect(json_response['result'][3]['id']).to eq(agent.id) expect(json_response['result'][4]).to be_falsey params = { @@ -243,7 +243,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do 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) + expect(json_response['result'][0]['id']).to eq(agent.id) expect(json_response['result'][1]).to be_falsey end @@ -253,7 +253,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do limit: 10, } - authenticated_as(customer_user) + authenticated_as(customer) post '/api/v1/search', params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -292,7 +292,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do limit: 10, } - authenticated_as(customer_user2) + authenticated_as(customer2) post '/api/v1/search', params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -331,7 +331,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do # Verify fix for Github issue #2058 - Autocomplete hangs on dot in the new user form it 'does searching for organization with a dot in its name' do - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/search/organization?query=tes.', as: :json expect(response).to have_http_status(:ok) expect(json_response['result'].size).to eq(1) @@ -342,7 +342,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do # Search query H& should correctly match H&M it 'does searching for organization with _ in its name' do - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/search/organization?query=abc_', as: :json expect(response).to have_http_status(:ok) expect(json_response['result'].size).to eq(1) @@ -355,20 +355,20 @@ RSpec.describe 'Search', type: :request, searchindex: true do # because of the initial relation between user and organization # both user and organization will be found as result - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/search/User', params: { query: 'Tomato42' }, as: :json 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['assets']['Organization'][organization_nested.id.to_s]).to be_truthy - expect(json_response['assets']['User'][customer_user_nested.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer_nested.id.to_s]).to be_truthy post '/api/v1/search/User', params: { query: 'organization:Tomato42' }, as: :json 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['assets']['Organization'][organization_nested.id.to_s]).to be_truthy - expect(json_response['assets']['User'][customer_user_nested.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer_nested.id.to_s]).to be_truthy organization_nested.update(name: 'Cucumber43 Ltd.') Scheduler.worker(true) @@ -381,18 +381,18 @@ RSpec.describe 'Search', type: :request, searchindex: true do expect(json_response).to be_a_kind_of(Hash) expect(json_response).to be_truthy expect(json_response['assets']['Organization'][organization_nested.id.to_s]).to be_truthy - expect(json_response['assets']['User'][customer_user_nested.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer_nested.id.to_s]).to be_truthy post '/api/v1/search/User', params: { query: 'organization:Cucumber43' }, as: :json 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['assets']['Organization'][organization_nested.id.to_s]).to be_truthy - expect(json_response['assets']['User'][customer_user_nested.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer_nested.id.to_s]).to be_truthy end it 'does find the ticket by organization name even if the organization name changes' do - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/search/Ticket', params: { query: 'Tomato42' }, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -432,7 +432,7 @@ RSpec.describe 'Search', type: :request, searchindex: true do limit: 10, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/search/Ticket', params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) diff --git a/spec/requests/session_spec.rb b/spec/requests/session_spec.rb index 84f560676..aec5c6f97 100644 --- a/spec/requests/session_spec.rb +++ b/spec/requests/session_spec.rb @@ -6,7 +6,7 @@ RSpec.describe 'Sessions endpoints', type: :request do context 'user logged in' do - subject(:user) { create(:agent_user, password: password) } + subject(:user) { create(:agent, password: password) } let(:password) { SecureRandom.urlsafe_base64(20) } let(:fingerprint) { SecureRandom.urlsafe_base64(40) } diff --git a/spec/requests/settings_spec.rb b/spec/requests/settings_spec.rb index cd2f86bd5..4031474e5 100644 --- a/spec/requests/settings_spec.rb +++ b/spec/requests/settings_spec.rb @@ -2,20 +2,20 @@ require 'rails_helper' RSpec.describe 'Settings', type: :request do - let(:admin_user) do - create(:admin_user) + let(:admin) do + create(:admin) end - let(:admin_api_user) do + let(:admin_api) do role_api = create(:role) role_api.permission_grant('admin.api') - create(:admin_user, roles: [role_api]) + create(:admin, roles: [role_api]) end - let(:agent_user) do - create(:agent_user) + let(:agent) do + create(:agent) end - let(:customer_user) do - create(:customer_user) + let(:customer) do + create(:customer) end describe 'request handling' do @@ -38,7 +38,7 @@ RSpec.describe 'Settings', type: :request do it 'does settings index with admin' do # index - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/settings', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) @@ -115,7 +115,7 @@ RSpec.describe 'Settings', type: :request do it 'does settings index with admin-api' do # index - authenticated_as(admin_api_user) + authenticated_as(admin_api) get '/api/v1/settings', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) @@ -187,7 +187,7 @@ RSpec.describe 'Settings', type: :request do it 'does settings index with agent' do # index - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/settings', params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(json_response).to be_a_kind_of(Hash) @@ -204,7 +204,7 @@ RSpec.describe 'Settings', type: :request do it 'does settings index with customer' do # index - authenticated_as(customer_user) + authenticated_as(customer) get '/api/v1/settings', params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(json_response).to be_a_kind_of(Hash) diff --git a/spec/requests/sla_spec.rb b/spec/requests/sla_spec.rb index 9dcb49e53..142dbe3b5 100644 --- a/spec/requests/sla_spec.rb +++ b/spec/requests/sla_spec.rb @@ -2,8 +2,8 @@ require 'rails_helper' RSpec.describe 'SLAs', type: :request do - let(:admin_user) do - create(:admin_user) + let(:admin) do + create(:admin) end describe 'request handling' do @@ -17,7 +17,7 @@ RSpec.describe 'SLAs', type: :request do end it 'does index sla with admin' do - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/slas', as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) diff --git a/spec/requests/tag_spec.rb b/spec/requests/tag_spec.rb index 21855facd..d81116841 100644 --- a/spec/requests/tag_spec.rb +++ b/spec/requests/tag_spec.rb @@ -4,7 +4,7 @@ RSpec.describe Tag, type: :request do describe 'request handling' do - let(:agent) { create(:agent_user) } + let(:agent) { create(:agent) } context 'tag search' do before do diff --git a/spec/requests/taskbar_spec.rb b/spec/requests/taskbar_spec.rb index e16fc26af..857527a1e 100644 --- a/spec/requests/taskbar_spec.rb +++ b/spec/requests/taskbar_spec.rb @@ -2,24 +2,24 @@ require 'rails_helper' RSpec.describe 'Taskbars', type: :request do - let(:agent_user) do - create(:agent_user) + let(:agent) do + create(:agent) end - let(:customer_user) do - create(:customer_user) + let(:customer) do + create(:customer) end describe 'request handling' do it 'does task ownership' do params = { - user_id: customer_user.id, + user_id: customer.id, client_id: '123', key: 'Ticket-5', callback: 'TicketZoom', state: { ticket: { - owner_id: agent_user.id, + owner_id: agent.id, }, article: {}, }, @@ -32,17 +32,17 @@ RSpec.describe 'Taskbars', type: :request do active: false, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/taskbar', params: params, as: :json 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) + expect(json_response['user_id']).to eq(agent.id) expect(json_response['params']['ticket_id']).to eq(5) expect(json_response['params']['shown']).to eq(true) taskbar_id = json_response['id'] - params[:user_id] = customer_user.id + params[:user_id] = customer.id params[:params] = { ticket_id: 5, shown: false, @@ -51,7 +51,7 @@ RSpec.describe 'Taskbars', type: :request do 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) + expect(json_response['user_id']).to eq(agent.id) expect(json_response['params']['ticket_id']).to eq(5) expect(json_response['params']['shown']).to eq(false) @@ -60,7 +60,7 @@ RSpec.describe 'Taskbars', type: :request do active: true, } - authenticated_as(customer_user) + authenticated_as(customer) put "/api/v1/taskbar/#{taskbar_id}", params: params, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) @@ -72,7 +72,7 @@ RSpec.describe 'Taskbars', type: :request do expect(json_response['error']).to eq('Not allowed to access this task.') # delete with correct user - authenticated_as(agent_user) + authenticated_as(agent) delete "/api/v1/taskbar/#{taskbar_id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) diff --git a/spec/requests/text_module_spec.rb b/spec/requests/text_module_spec.rb index 31552ab87..9e40fe45b 100644 --- a/spec/requests/text_module_spec.rb +++ b/spec/requests/text_module_spec.rb @@ -3,20 +3,20 @@ require 'byebug' RSpec.describe 'Text Module', type: :request do - let(:admin_user) do - create(:admin_user) + let(:admin) do + create(:admin) end - let(:agent_user) do - create(:agent_user) + let(:agent) do + create(:agent) end - let(:customer_user) do - create(:customer_user) + let(:customer) do + create(:customer) end describe 'request handling' do it 'does csv example - customer no access' do - authenticated_as(customer_user) + authenticated_as(customer) get '/api/v1/text_modules/import_example', as: :json expect(response).to have_http_status(:unauthorized) expect(json_response['error']).to eq('Not authorized (user)!') @@ -25,7 +25,7 @@ RSpec.describe 'Text Module', type: :request do it 'does csv example - admin access' do TextModule.load('en-en') - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/text_modules/import_example', as: :json expect(response).to have_http_status(:ok) rows = CSV.parse(@response.body) @@ -49,7 +49,7 @@ RSpec.describe 'Text Module', type: :request do # invalid file csv_file = fixture_file_upload('csv_import/text_module/simple_col_not_existing.csv', 'text/csv') - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/text_modules/import', params: { try: true, file: csv_file, col_sep: ';' } expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) diff --git a/spec/requests/ticket/article_attachments_spec.rb b/spec/requests/ticket/article_attachments_spec.rb index d58f3fa38..ff951371f 100644 --- a/spec/requests/ticket/article_attachments_spec.rb +++ b/spec/requests/ticket/article_attachments_spec.rb @@ -4,8 +4,8 @@ RSpec.describe 'Ticket Article Attachments', type: :request do let(:group) { create(:group) } - let(:agent_user) do - create(:agent_user, groups: [Group.lookup(name: 'Users'), group]) + let(:agent) do + create(:agent, groups: [Group.lookup(name: 'Users'), group]) end describe 'request handling' do @@ -26,12 +26,12 @@ RSpec.describe 'Ticket Article Attachments', type: :request do ) article2 = create(:ticket_article, ticket_id: ticket1.id) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/ticket_attachment/#{ticket1.id}/#{article1.id}/#{store1.id}", params: {} expect(response).to have_http_status(:ok) expect('some content').to eq(@response.body) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/ticket_attachment/#{ticket1.id}/#{article2.id}/#{store1.id}", params: {} expect(response).to have_http_status(:unauthorized) expect(@response.body).to match(/401: Unauthorized/) @@ -42,23 +42,23 @@ RSpec.describe 'Ticket Article Attachments', type: :request do user_id: 1, ) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/ticket_attachment/#{ticket2.id}/#{article1.id}/#{store1.id}", params: {} expect(response).to have_http_status(:ok) expect('some content').to eq(@response.body) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/ticket_attachment/#{ticket2.id}/#{article2.id}/#{store1.id}", params: {} expect(response).to have_http_status(:unauthorized) expect(@response.body).to match(/401: Unauthorized/) # allow access via merged ticket id also - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/ticket_attachment/#{ticket1.id}/#{article1.id}/#{store1.id}", params: {} expect(response).to have_http_status(:ok) expect('some content').to eq(@response.body) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/ticket_attachment/#{ticket1.id}/#{article2.id}/#{store1.id}", params: {} expect(response).to have_http_status(:unauthorized) expect(@response.body).to match(/401: Unauthorized/) @@ -70,7 +70,7 @@ RSpec.describe 'Ticket Article Attachments', type: :request do email_raw_string = File.read(email_file_path) ticket_p, article_p, _user_p = Channel::EmailParser.new.process({}, email_raw_string) - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/ticket_split', params: { form_id: '1234-2', ticket_id: ticket_p.id, article_id: article_p.id }, as: :json expect(response).to have_http_status(:ok) expect(json_response['assets']).to be_truthy @@ -85,7 +85,7 @@ RSpec.describe 'Ticket Article Attachments', type: :request do email_raw_string = File.read(email_file_path) _ticket_p, article_p, _user_p = Channel::EmailParser.new.process({}, email_raw_string) - authenticated_as(agent_user) + authenticated_as(agent) post "/api/v1/ticket_attachment_upload_clone_by_article/#{article_p.id}", params: {}, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) diff --git a/spec/requests/ticket/article_spec.rb b/spec/requests/ticket/article_spec.rb index d8ff5ecae..f88fd2e96 100644 --- a/spec/requests/ticket/article_spec.rb +++ b/spec/requests/ticket/article_spec.rb @@ -2,16 +2,16 @@ require 'rails_helper' RSpec.describe 'Ticket Article API endpoints', type: :request do - let(:admin_user) do - create(:admin_user, groups: Group.all) + let(:admin) do + create(:admin, groups: Group.all) end let!(:group) { create(:group) } - let(:agent_user) do - create(:agent_user, groups: Group.all) + let(:agent) do + create(:agent, groups: Group.all) end - let(:customer_user) do - create(:customer_user) + let(:customer) do + create(:customer) end describe 'request handling' do @@ -20,12 +20,12 @@ RSpec.describe 'Ticket Article API endpoints', type: :request do params = { title: 'a new ticket #1', group: 'Users', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some body', } } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) @@ -41,8 +41,8 @@ RSpec.describe 'Ticket Article API endpoints', type: :request do expect(json_response['subject']).to be_nil expect(json_response['body']).to eq('some body') expect(json_response['content_type']).to eq('text/plain') - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) ticket = Ticket.find(json_response['ticket_id']) expect(ticket.articles.count).to eq(2) @@ -64,8 +64,8 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO expect(json_response['body']).not_to match(/some body Red dot") + expect(article.origin_by_id).to eq(customer.id) + expect(article.from).to eq("#{customer.firstname} #{customer.lastname} <#{customer.email}>") end it 'does create phone ticket by customer and manipulate origin_by_id' do params = { title: 'a new ticket #1', group: 'Users', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some body', sender: 'Customer', @@ -301,7 +301,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO origin_by_id: 1, } } - authenticated_as(customer_user) + authenticated_as(customer) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) @@ -309,7 +309,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO expect(Ticket::Article.where(ticket_id: json_response['id']).count).to eq(1) # ony original article = Ticket::Article.where(ticket_id: json_response['id']).first - expect(article.origin_by_id).to eq(customer_user.id) + expect(article.origin_by_id).to eq(customer.id) end it 'does ticket split with html - check attachments' do @@ -390,7 +390,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO params = { form_id: 'new_form_id123', } - authenticated_as(agent_user) + authenticated_as(agent) post "/api/v1/ticket_attachment_upload_clone_by_article/#{article.id}", params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -408,8 +408,8 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ticket = create( :ticket, group: group, - updated_by_id: agent_user.id, - created_by_id: agent_user.id, + updated_by_id: agent.id, + created_by_id: agent.id, ) article = create( :ticket_article, @@ -465,7 +465,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO params = { form_id: 'new_form_id123', } - authenticated_as(agent_user) + authenticated_as(agent) post "/api/v1/ticket_attachment_upload_clone_by_article/#{article.id}", params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -488,19 +488,19 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO let(:article_communication) do create(:ticket_article, sender_name: 'Agent', type_name: 'email', ticket: ticket, - updated_by_id: agent_user.id, created_by_id: agent_user.id ) + updated_by_id: agent.id, created_by_id: agent.id ) end let(:article_note) do create(:ticket_article, sender_name: 'Agent', internal: true, type_name: 'note', ticket: ticket, - updated_by_id: agent_user.id, created_by_id: agent_user.id ) + updated_by_id: agent.id, created_by_id: agent.id ) end let(:article_note_customer) do create(:ticket_article, sender_name: 'Customer', internal: false, type_name: 'note', ticket: ticket, - updated_by_id: customer_user.id, created_by_id: customer_user.id ) + updated_by_id: customer.id, created_by_id: customer.id ) end let(:article_note_communication) do @@ -508,7 +508,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO create(:ticket_article, sender_name: 'Agent', internal: true, type_name: 'note_communication', ticket: ticket, - updated_by_id: agent_user.id, created_by_id: agent_user.id ) + updated_by_id: agent.id, created_by_id: agent.id ) end def delete_article_via_rest(article) @@ -548,7 +548,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO end context 'as admin' do - let(:user) { admin_user } + let(:user) { admin } include_examples 'deleting', item: 'article_communication', @@ -568,7 +568,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO end context 'as agent' do - let(:user) { agent_user } + let(:user) { agent } include_examples 'deleting', item: 'article_communication', @@ -589,7 +589,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO end context 'as customer' do - let(:user) { customer_user } + let(:user) { customer } include_examples 'deleting', item: 'article_communication', @@ -615,7 +615,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO let(:article) { article_note } context 'as admin' do - let(:user) { admin_user } + let(:user) { admin } context 'deleting after timeframe' do before { article && travel(8000.seconds) } @@ -625,7 +625,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO end context 'as agent' do - let(:user) { agent_user } + let(:user) { agent } context 'deleting before timeframe' do before { article && travel(5000.seconds) } @@ -647,7 +647,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO let(:article) { article_note } context 'as agent' do - let(:user) { agent_user } + let(:user) { agent } context 'deleting long after' do before { article && travel(99.days) } diff --git a/spec/requests/ticket/escalation_spec.rb b/spec/requests/ticket/escalation_spec.rb index 683745cbb..5a6d01686 100644 --- a/spec/requests/ticket/escalation_spec.rb +++ b/spec/requests/ticket/escalation_spec.rb @@ -2,11 +2,11 @@ require 'rails_helper' RSpec.describe 'Ticket Escalation', type: :request do - let!(:agent_user) do - create(:agent_user, groups: Group.all) + let!(:agent) do + create(:agent, groups: Group.all) end - let!(:customer_user) do - create(:customer_user) + let!(:customer) do + create(:customer) end let!(:calendar) do create( @@ -78,15 +78,15 @@ RSpec.describe 'Ticket Escalation', type: :request do }, } - authenticated_as(customer_user) + authenticated_as(customer) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('some value 123') - expect(json_response['updated_by_id']).to eq(customer_user.id) - expect(json_response['created_by_id']).to eq(customer_user.id) + expect(json_response['updated_by_id']).to eq(customer.id) + expect(json_response['created_by_id']).to eq(customer.id) ticket_p = Ticket.find(json_response['id']) @@ -128,14 +128,14 @@ Some Text" to: 'customer@example.com', }, } - authenticated_as(agent_user) + authenticated_as(agent) put "/api/v1/tickets/#{ticket_p.id}", params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'open').id) expect(json_response['title']).to eq('some value 123 - update') - expect(json_response['updated_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) expect(json_response['created_by_id']).to eq(user_p.id) ticket_p.reload diff --git a/spec/requests/ticket_spec.rb b/spec/requests/ticket_spec.rb index 7e7169675..c5fce702c 100644 --- a/spec/requests/ticket_spec.rb +++ b/spec/requests/ticket_spec.rb @@ -5,15 +5,15 @@ RSpec.describe 'Ticket', type: :request do let!(:ticket_group) do create(:group, email_address: create(:email_address) ) end - let(:admin_user) do - create(:admin_user, groups: Group.all, firstname: 'Tickets', lastname: 'Admin') + let(:admin) do + create(:admin, groups: Group.all, firstname: 'Tickets', lastname: 'Admin') end - let!(:agent_user) do - create(:agent_user, groups: Group.all, firstname: 'Tickets', lastname: 'Agent') + let!(:agent) do + create(:agent, groups: Group.all, firstname: 'Tickets', lastname: 'Agent') end - let!(:customer_user) do + let!(:customer) do create( - :customer_user, + :customer, login: 'tickets-customer1@example.com', firstname: 'Tickets', lastname: 'Customer1', @@ -33,7 +33,7 @@ RSpec.describe 'Ticket', type: :request do type: 'note', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) @@ -51,7 +51,7 @@ RSpec.describe 'Ticket', type: :request do type: 'note', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) @@ -64,10 +64,10 @@ RSpec.describe 'Ticket', type: :request do group: ticket_group.name, priority: '2 normal', state: 'new', - customer_id: customer_user.id, + customer_id: customer.id, article: {}, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) @@ -80,20 +80,20 @@ RSpec.describe 'Ticket', type: :request do group: ticket_group.name, priority: '2 normal', state: 'new', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some test 123', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #3') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) end it 'does ticket create with agent - minimal article and customer.email (01.04)' do @@ -102,20 +102,20 @@ RSpec.describe 'Ticket', type: :request do group: ticket_group.name, priority: '2 normal', state: 'new', - customer: customer_user.email, + customer: customer.email, article: { body: 'some test 123', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #3') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) end it 'does ticket create with agent - wrong owner_id - 0 (01.05)' do @@ -125,12 +125,12 @@ RSpec.describe 'Ticket', type: :request do priority: '2 normal', owner_id: 0, state: 'new', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some test 123', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) @@ -144,20 +144,20 @@ RSpec.describe 'Ticket', type: :request do priority: '2 normal', owner_id: '', state: 'new', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some test 123', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #5') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) end it 'does ticket create with agent - wrong owner_id - 99999 (01.07)' do @@ -167,12 +167,12 @@ RSpec.describe 'Ticket', type: :request do priority: '2 normal', owner_id: 99_999, state: 'new', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some test 123', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) @@ -186,20 +186,20 @@ RSpec.describe 'Ticket', type: :request do priority: '2 normal', owner_id: nil, state: 'new', - customer_id: customer_user.id, + customer_id: customer.id, article: { body: 'some test 123', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #7') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) end it 'does ticket create with agent - minimal article with guess customer (01.09)' do @@ -213,15 +213,15 @@ RSpec.describe 'Ticket', type: :request do body: 'some test 123', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #9') expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) end it 'does ticket create with agent - minimal article with guess customer (01.10)' do @@ -233,15 +233,15 @@ RSpec.describe 'Ticket', type: :request do body: 'some test 123', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #10') expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) end it 'does ticket create with agent - minimal article with customer hash (01.11)' do @@ -257,15 +257,15 @@ RSpec.describe 'Ticket', type: :request do body: 'some test 123', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #11') expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) end it 'does ticket create with agent - minimal article with customer hash with article.origin_by (01.11)' do @@ -282,19 +282,19 @@ RSpec.describe 'Ticket', type: :request do origin_by: 'some_new_customer@example.com', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #11.1') expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) ticket = Ticket.find(json_response['id']) article = ticket.articles.first - expect(article.updated_by_id).to eq(agent_user.id) - expect(article.created_by_id).to eq(agent_user.id) + expect(article.updated_by_id).to eq(agent.id) + expect(article.created_by_id).to eq(agent.id) expect(article.origin_by_id).to eq(User.lookup(email: 'some_new_customer@example.com').id) expect(article.sender.name).to eq('Customer') expect(article.type.name).to eq('note') @@ -316,19 +316,19 @@ RSpec.describe 'Ticket', type: :request do origin_by: 'some_new_customer@example.com', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #11.2') expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) ticket = Ticket.find(json_response['id']) article = ticket.articles.first - expect(article.updated_by_id).to eq(agent_user.id) - expect(article.created_by_id).to eq(agent_user.id) + expect(article.updated_by_id).to eq(agent.id) + expect(article.created_by_id).to eq(agent.id) expect(article.origin_by_id).to eq(User.lookup(email: 'some_new_customer@example.com').id) expect(article.sender.name).to eq('Customer') expect(article.type.name).to eq('note') @@ -351,19 +351,19 @@ RSpec.describe 'Ticket', type: :request do origin_by: 'some_new_customer@example.com', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #11.3') expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) ticket = Ticket.find(json_response['id']) article = ticket.articles.first - expect(article.updated_by_id).to eq(agent_user.id) - expect(article.created_by_id).to eq(agent_user.id) + expect(article.updated_by_id).to eq(agent.id) + expect(article.created_by_id).to eq(agent.id) expect(article.origin_by_id).to eq(User.lookup(email: 'some_new_customer@example.com').id) expect(article.sender.name).to eq('Customer') expect(article.type.name).to eq('note') @@ -382,23 +382,23 @@ RSpec.describe 'Ticket', type: :request do article: { sender: 'Customer', body: 'some test 123', - origin_by: customer_user.login, + origin_by: customer.login, }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #11.4') expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) ticket = Ticket.find(json_response['id']) article = ticket.articles.first - expect(article.updated_by_id).to eq(agent_user.id) - expect(article.created_by_id).to eq(agent_user.id) - expect(article.origin_by_id).to eq(customer_user.id) + expect(article.updated_by_id).to eq(agent.id) + expect(article.created_by_id).to eq(agent.id) + expect(article.origin_by_id).to eq(customer.id) expect(article.sender.name).to eq('Customer') expect(article.type.name).to eq('note') expect(article.from).to eq('Tickets Customer1') @@ -408,12 +408,12 @@ RSpec.describe 'Ticket', type: :request do params = { title: 'a new ticket #12', group: ticket_group.name, - customer_id: customer_user.id, + customer_id: customer.id, article: { subject: 'some test 123', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) @@ -424,7 +424,7 @@ RSpec.describe 'Ticket', type: :request do params = { title: 'a new ticket #13', group: ticket_group.name, - customer_id: customer_user.id, + customer_id: customer.id, article: { subject: 'some test 123', body: 'some test 123', @@ -435,15 +435,15 @@ RSpec.describe 'Ticket', type: :request do ], }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #13') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) ticket = Ticket.find(json_response['id']) expect(ticket.articles.count).to eq(1) @@ -459,7 +459,7 @@ RSpec.describe 'Ticket', type: :request do params = { title: 'a new ticket #14', group: ticket_group.name, - customer_id: customer_user.id, + customer_id: customer.id, article: { subject: 'some test 123', body: 'some test 123', @@ -477,15 +477,15 @@ RSpec.describe 'Ticket', type: :request do ], }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #14') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) ticket = Ticket.find(json_response['id']) expect(ticket.articles.count).to eq(1) @@ -501,7 +501,7 @@ RSpec.describe 'Ticket', type: :request do params = { title: 'a new ticket #15', group: ticket_group.name, - customer_id: customer_user.id, + customer_id: customer.id, article: { subject: 'some test 123', body: 'some test 123', @@ -512,7 +512,7 @@ RSpec.describe 'Ticket', type: :request do ], }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) @@ -523,7 +523,7 @@ RSpec.describe 'Ticket', type: :request do params = { title: 'a new ticket #15a', group: ticket_group.name, - customer_id: customer_user.id, + customer_id: customer.id, article: { subject: 'some test 123', body: 'some test 123', @@ -534,7 +534,7 @@ RSpec.describe 'Ticket', type: :request do ], }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) @@ -545,7 +545,7 @@ RSpec.describe 'Ticket', type: :request do params = { title: 'a new ticket #15b', group: ticket_group.name, - customer_id: customer_user.id, + customer_id: customer.id, article: { subject: 'some test 123', body: 'some test 123', @@ -556,7 +556,7 @@ RSpec.describe 'Ticket', type: :request do ], }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response['title']).to eq('a new ticket #15b') @@ -571,7 +571,7 @@ RSpec.describe 'Ticket', type: :request do params = { title: 'a new ticket #15c', group: ticket_group.name, - customer_id: customer_user.id, + customer_id: customer.id, article: { subject: 'some test 123', body: 'some test 123', @@ -582,7 +582,7 @@ RSpec.describe 'Ticket', type: :request do ], }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response['title']).to eq('a new ticket #15c') @@ -597,7 +597,7 @@ RSpec.describe 'Ticket', type: :request do params = { title: 'a new ticket #16', group: ticket_group.name, - customer_id: customer_user.id, + customer_id: customer.id, article: { subject: 'some test 123', body: 'some test 123', @@ -607,7 +607,7 @@ RSpec.describe 'Ticket', type: :request do ], }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:unprocessable_entity) expect(json_response).to be_a_kind_of(Hash) @@ -618,7 +618,7 @@ RSpec.describe 'Ticket', type: :request do params = { title: 'a new ticket #17', group: ticket_group.name, - customer_id: customer_user.id, + customer_id: customer.id, article: { content_type: 'text/html', subject: 'some test 123', @@ -627,15 +627,15 @@ RSpec.describe 'Ticket', type: :request do 9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" /> ', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #17') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) ticket = Ticket.find(json_response['id']) expect(ticket.articles.count).to eq(1) @@ -658,7 +658,7 @@ RSpec.describe 'Ticket', type: :request do params = { title: 'a new ticket #18', group: ticket_group.name, - customer_id: customer_user.id, + customer_id: customer.id, article: { content_type: 'text/html', subject: 'some test 123', @@ -671,15 +671,15 @@ RSpec.describe 'Ticket', type: :request do ], }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #18') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) ticket = Ticket.find(json_response['id']) expect(ticket.articles.count).to eq(1) @@ -714,14 +714,14 @@ RSpec.describe 'Ticket', type: :request do } } } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #1') - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) links = Link.list( link_object: 'Ticket', link_object_value: json_response['id'], @@ -737,9 +737,9 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: 'ticket with wrong ticket id', group_id: group.id, - customer_id: customer_user.id, + customer_id: customer.id, ) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/tickets/#{ticket.id}", params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(json_response).to be_a_kind_of(Hash) @@ -765,12 +765,12 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: title, group: ticket_group, - customer_id: customer_user.id, + customer_id: customer.id, preferences: { some_key1: 123, }, ) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/tickets/#{ticket.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -783,7 +783,7 @@ RSpec.describe 'Ticket', type: :request do params = { title: "#{title} - 2", - customer_id: agent_user.id, + customer_id: agent.id, preferences: { some_key2: 'abc', }, @@ -793,8 +793,8 @@ RSpec.describe 'Ticket', type: :request do expect(json_response).to be_a_kind_of(Hash) expect(json_response['id']).to eq(ticket.id) expect(json_response['title']).to eq("#{title} - 2") - expect(json_response['customer_id']).to eq(agent_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(agent.id) + expect(json_response['updated_by_id']).to eq(agent.id) expect(json_response['created_by_id']).to eq(1) expect(json_response['preferences']['some_key1']).to eq(123) expect(json_response['preferences']['some_key2']).to eq('abc') @@ -814,7 +814,7 @@ RSpec.describe 'Ticket', type: :request do expect(article_json_response['body']).to eq('some body') expect(article_json_response['content_type']).to eq('text/plain') expect(article_json_response['internal']).to eq(false) - expect(article_json_response['created_by_id']).to eq(agent_user.id) + expect(article_json_response['created_by_id']).to eq(agent.id) expect(article_json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Agent').id) expect(article_json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'note').id) @@ -859,7 +859,7 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['body']).to eq('some body') expect(json_response['content_type']).to eq('text/plain') expect(json_response['internal']).to eq(true) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['created_by_id']).to eq(agent.id) expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Agent').id) expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'email').id) @@ -875,7 +875,7 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['body']).to eq('some body') expect(json_response['content_type']).to eq('text/plain') expect(json_response['internal']).to eq(true) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['created_by_id']).to eq(agent.id) expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Agent').id) expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'email').id) @@ -907,9 +907,9 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: 'ticket with corret ticket id', group: ticket_group, - customer_id: customer_user.id, + customer_id: customer.id, ) - authenticated_as(admin_user) + authenticated_as(admin) get "/api/v1/tickets/#{ticket.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -921,15 +921,15 @@ RSpec.describe 'Ticket', type: :request do params = { title: 'ticket with corret ticket id - 2', - customer_id: agent_user.id, + customer_id: agent.id, } put "/api/v1/tickets/#{ticket.id}", params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response['id']).to eq(ticket.id) expect(json_response['title']).to eq('ticket with corret ticket id - 2') - expect(json_response['customer_id']).to eq(agent_user.id) - expect(json_response['updated_by_id']).to eq(admin_user.id) + expect(json_response['customer_id']).to eq(agent.id) + expect(json_response['updated_by_id']).to eq(admin.id) expect(json_response['created_by_id']).to eq(1) params = { @@ -947,7 +947,7 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['body']).to eq('some body') expect(json_response['content_type']).to eq('text/plain') expect(json_response['internal']).to eq(false) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['created_by_id']).to eq(admin.id) expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Agent').id) expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'note').id) @@ -964,7 +964,7 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['body']).to eq('some body') expect(json_response['content_type']).to eq('text/plain') expect(json_response['internal']).to eq(true) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['created_by_id']).to eq(admin.id) expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Agent').id) expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'note').id) @@ -986,7 +986,7 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['body']).to eq('some body') expect(json_response['content_type']).to eq('text/plain') expect(json_response['internal']).to eq(false) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['created_by_id']).to eq(admin.id) expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Agent').id) expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'email').id) @@ -1005,7 +1005,7 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: "#{title} - #{count}", group: ticket_group, - customer_id: customer_user.id, + customer_id: customer.id, ) create( :ticket_article, @@ -1017,7 +1017,7 @@ RSpec.describe 'Ticket', type: :request do travel 2.seconds end - authenticated_as(admin_user) + authenticated_as(admin) get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -1074,15 +1074,15 @@ RSpec.describe 'Ticket', type: :request do body: 'some body', }, } - authenticated_as(customer_user) + authenticated_as(customer) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #c1') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(customer_user.id) - expect(json_response['created_by_id']).to eq(customer_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(customer.id) + expect(json_response['created_by_id']).to eq(customer.id) end it 'does ticket create with customer with wrong customer (03.02)' do @@ -1091,22 +1091,22 @@ RSpec.describe 'Ticket', type: :request do state: 'new', priority: '2 normal', group: ticket_group.name, - customer_id: agent_user.id, + customer_id: agent.id, article: { content_type: 'text/plain', # or text/html body: 'some body', sender: 'System', }, } - authenticated_as(customer_user) + authenticated_as(customer) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #c2') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(customer_user.id) - expect(json_response['created_by_id']).to eq(customer_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(customer.id) + expect(json_response['created_by_id']).to eq(customer.id) end it 'does ticket create with customer with wrong customer hash (03.03)' do @@ -1116,9 +1116,9 @@ RSpec.describe 'Ticket', type: :request do priority: '2 normal', group: ticket_group.name, customer: { - firstname: agent_user.firstname, - lastname: agent_user.lastname, - email: agent_user.email, + firstname: agent.firstname, + lastname: agent.lastname, + email: agent.email, }, article: { content_type: 'text/plain', # or text/html @@ -1126,15 +1126,15 @@ RSpec.describe 'Ticket', type: :request do sender: 'System', }, } - authenticated_as(customer_user) + authenticated_as(customer) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #c2') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(customer_user.id) - expect(json_response['created_by_id']).to eq(customer_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(customer.id) + expect(json_response['created_by_id']).to eq(customer.id) end it 'does ticket with wrong ticket id (03.04)' do @@ -1142,9 +1142,9 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: 'ticket with wrong ticket id', group: ticket_group, - customer_id: agent_user.id, + customer_id: agent.id, ) - authenticated_as(customer_user) + authenticated_as(customer) get "/api/v1/tickets/#{ticket.id}", params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(json_response).to be_a_kind_of(Hash) @@ -1170,9 +1170,9 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: title, group: ticket_group, - customer_id: customer_user.id, + customer_id: customer.id, ) - authenticated_as(customer_user) + authenticated_as(customer) get "/api/v1/tickets/#{ticket.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -1184,7 +1184,7 @@ RSpec.describe 'Ticket', type: :request do params = { title: "#{title} - 2", - customer_id: agent_user.id, + customer_id: agent.id, } put "/api/v1/tickets/#{ticket.id}", params: params, as: :json expect(response).to have_http_status(:ok) @@ -1192,7 +1192,7 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['id']).to eq(ticket.id) expect(json_response['title']).to eq("#{title} - 2") expect(json_response['customer_id']).to eq(ticket.customer_id) - expect(json_response['updated_by_id']).to eq(customer_user.id) + expect(json_response['updated_by_id']).to eq(customer.id) expect(json_response['created_by_id']).to eq(1) params = { @@ -1209,7 +1209,7 @@ RSpec.describe 'Ticket', type: :request do expect(article_json_response['subject']).to eq('some subject') expect(article_json_response['body']).to eq('some body') expect(article_json_response['content_type']).to eq('text/plain') - expect(article_json_response['created_by_id']).to eq(customer_user.id) + expect(article_json_response['created_by_id']).to eq(customer.id) expect(article_json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Customer').id) expect(article_json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'note').id) @@ -1254,7 +1254,7 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['subject']).to eq('some subject') expect(json_response['body']).to eq('some body') expect(json_response['content_type']).to eq('text/plain') - expect(json_response['created_by_id']).to eq(customer_user.id) + expect(json_response['created_by_id']).to eq(customer.id) expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Customer').id) expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'note').id) @@ -1282,7 +1282,7 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['body']).to eq('some body') expect(json_response['content_type']).to eq('text/plain') expect(json_response['internal']).to eq(false) - expect(json_response['created_by_id']).to eq(customer_user.id) + expect(json_response['created_by_id']).to eq(customer.id) expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Customer').id) expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'web').id) @@ -1301,7 +1301,7 @@ RSpec.describe 'Ticket', type: :request do end it 'does ticket create with agent - minimal article with customer hash with article.origin_by (03.6)' do - authenticated_as(customer_user) + authenticated_as(customer) params = { title: 'a new ticket #3.6', group: ticket_group.name, @@ -1312,7 +1312,7 @@ RSpec.describe 'Ticket', type: :request do }, article: { body: 'some test 123', - origin_by: agent_user.login, + origin_by: agent.login, }, } @@ -1321,21 +1321,21 @@ RSpec.describe 'Ticket', type: :request do expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #3.6') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(customer_user.id) - expect(json_response['created_by_id']).to eq(customer_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(customer.id) + expect(json_response['created_by_id']).to eq(customer.id) ticket = Ticket.find(json_response['id']) article = ticket.articles.first - expect(article.updated_by_id).to eq(customer_user.id) - expect(article.created_by_id).to eq(customer_user.id) - expect(article.origin_by_id).to eq(customer_user.id) + expect(article.updated_by_id).to eq(customer.id) + expect(article.created_by_id).to eq(customer.id) + expect(article.origin_by_id).to eq(customer.id) expect(article.sender.name).to eq('Customer') expect(article.type.name).to eq('note') expect(article.from).to eq('Tickets Customer1') end it 'does ticket create with agent - minimal article with customer hash with article.origin_by (03.6)' do - authenticated_as(customer_user) + authenticated_as(customer) params = { title: 'a new ticket #3.6.1', group: ticket_group.name, @@ -1347,7 +1347,7 @@ RSpec.describe 'Ticket', type: :request do article: { sender: 'Agent', body: 'some test 123', - origin_by_id: agent_user.id, + origin_by_id: agent.id, }, } @@ -1356,14 +1356,14 @@ RSpec.describe 'Ticket', type: :request do expect(json_response).to be_a_kind_of(Hash) expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id) expect(json_response['title']).to eq('a new ticket #3.6.1') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(customer_user.id) - expect(json_response['created_by_id']).to eq(customer_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(customer.id) + expect(json_response['created_by_id']).to eq(customer.id) ticket = Ticket.find(json_response['id']) article = ticket.articles.first - expect(article.updated_by_id).to eq(customer_user.id) - expect(article.created_by_id).to eq(customer_user.id) - expect(article.origin_by_id).to eq(customer_user.id) + expect(article.updated_by_id).to eq(customer.id) + expect(article.created_by_id).to eq(customer.id) + expect(article.origin_by_id).to eq(customer.id) expect(article.sender.name).to eq('Customer') expect(article.type.name).to eq('note') expect(article.from).to eq('Tickets Customer1') @@ -1375,11 +1375,11 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: title, group: ticket_group, - customer_id: customer_user.id, - updated_by_id: agent_user.id, - created_by_id: agent_user.id, + customer_id: customer.id, + updated_by_id: agent.id, + created_by_id: agent.id, ) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/tickets/#{ticket.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -1389,8 +1389,8 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['priority']).to be_falsey expect(json_response['owner']).to be_falsey expect(json_response['customer_id']).to eq(ticket.customer_id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) get "/api/v1/tickets/#{ticket.id}?expand=true", params: {}, as: :json expect(response).to have_http_status(:ok) @@ -1401,8 +1401,8 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['group']).to eq(ticket.group.name) expect(json_response['priority']).to eq(ticket.priority.name) expect(json_response['owner']).to eq(ticket.owner.login) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) get "/api/v1/tickets/#{ticket.id}?expand=false", params: {}, as: :json expect(response).to have_http_status(:ok) @@ -1413,8 +1413,8 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['priority']).to be_falsey expect(json_response['owner']).to be_falsey expect(json_response['customer_id']).to eq(ticket.customer_id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) get "/api/v1/tickets/#{ticket.id}?full=true", params: {}, as: :json expect(response).to have_http_status(:ok) @@ -1429,16 +1429,16 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['assets']['Ticket'][ticket.id.to_s]['customer_id']).to eq(ticket.customer_id) expect(json_response['assets']['User']).to be_truthy - expect(json_response['assets']['User'][agent_user.id.to_s]).to be_truthy - expect(json_response['assets']['User'][agent_user.id.to_s]['id']).to eq(agent_user.id) - expect(json_response['assets']['User'][agent_user.id.to_s]['firstname']).to eq(agent_user.firstname) - expect(json_response['assets']['User'][agent_user.id.to_s]['lastname']).to eq(agent_user.lastname) + expect(json_response['assets']['User'][agent.id.to_s]).to be_truthy + expect(json_response['assets']['User'][agent.id.to_s]['id']).to eq(agent.id) + expect(json_response['assets']['User'][agent.id.to_s]['firstname']).to eq(agent.firstname) + expect(json_response['assets']['User'][agent.id.to_s]['lastname']).to eq(agent.lastname) expect(json_response['assets']['User']).to be_truthy - expect(json_response['assets']['User'][customer_user.id.to_s]).to be_truthy - expect(json_response['assets']['User'][customer_user.id.to_s]['id']).to eq(customer_user.id) - expect(json_response['assets']['User'][customer_user.id.to_s]['firstname']).to eq(customer_user.firstname) - expect(json_response['assets']['User'][customer_user.id.to_s]['lastname']).to eq(customer_user.lastname) + expect(json_response['assets']['User'][customer.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer.id.to_s]['id']).to eq(customer.id) + expect(json_response['assets']['User'][customer.id.to_s]['firstname']).to eq(customer.firstname) + expect(json_response['assets']['User'][customer.id.to_s]['lastname']).to eq(customer.lastname) get "/api/v1/tickets/#{ticket.id}?full=false", params: {}, as: :json expect(response).to have_http_status(:ok) @@ -1449,8 +1449,8 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['priority']).to be_falsey expect(json_response['owner']).to be_falsey expect(json_response['customer_id']).to eq(ticket.customer_id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) end it 'does ticket index and response format (04.02)' do @@ -1459,11 +1459,11 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: title, group: ticket_group, - customer_id: customer_user.id, - updated_by_id: agent_user.id, - created_by_id: agent_user.id, + customer_id: customer.id, + updated_by_id: agent.id, + created_by_id: agent.id, ) - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/tickets', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -1476,8 +1476,8 @@ RSpec.describe 'Ticket', type: :request do expect(json_response[1]['priority']).to be_falsey expect(json_response[1]['owner']).to be_falsey expect(json_response[1]['customer_id']).to eq(ticket.customer_id) - expect(json_response[1]['updated_by_id']).to eq(agent_user.id) - expect(json_response[1]['created_by_id']).to eq(agent_user.id) + expect(json_response[1]['updated_by_id']).to eq(agent.id) + expect(json_response[1]['created_by_id']).to eq(agent.id) get '/api/v1/tickets?expand=true', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -1490,8 +1490,8 @@ RSpec.describe 'Ticket', type: :request do expect(json_response[1]['group']).to eq(ticket.group.name) expect(json_response[1]['priority']).to eq(ticket.priority.name) expect(json_response[1]['owner']).to eq(ticket.owner.login) - expect(json_response[1]['updated_by_id']).to eq(agent_user.id) - expect(json_response[1]['created_by_id']).to eq(agent_user.id) + expect(json_response[1]['updated_by_id']).to eq(agent.id) + expect(json_response[1]['created_by_id']).to eq(agent.id) get '/api/v1/tickets?expand=false', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -1504,8 +1504,8 @@ RSpec.describe 'Ticket', type: :request do expect(json_response[1]['priority']).to be_falsey expect(json_response[1]['owner']).to be_falsey expect(json_response[1]['customer_id']).to eq(ticket.customer_id) - expect(json_response[1]['updated_by_id']).to eq(agent_user.id) - expect(json_response[1]['created_by_id']).to eq(agent_user.id) + expect(json_response[1]['updated_by_id']).to eq(agent.id) + expect(json_response[1]['created_by_id']).to eq(agent.id) get '/api/v1/tickets?full=true', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -1522,16 +1522,16 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['assets']['Ticket'][ticket.id.to_s]['customer_id']).to eq(ticket.customer_id) expect(json_response['assets']['User']).to be_truthy - expect(json_response['assets']['User'][agent_user.id.to_s]).to be_truthy - expect(json_response['assets']['User'][agent_user.id.to_s]['id']).to eq(agent_user.id) - expect(json_response['assets']['User'][agent_user.id.to_s]['firstname']).to eq(agent_user.firstname) - expect(json_response['assets']['User'][agent_user.id.to_s]['lastname']).to eq(agent_user.lastname) + expect(json_response['assets']['User'][agent.id.to_s]).to be_truthy + expect(json_response['assets']['User'][agent.id.to_s]['id']).to eq(agent.id) + expect(json_response['assets']['User'][agent.id.to_s]['firstname']).to eq(agent.firstname) + expect(json_response['assets']['User'][agent.id.to_s]['lastname']).to eq(agent.lastname) expect(json_response['assets']['User']).to be_truthy - expect(json_response['assets']['User'][customer_user.id.to_s]).to be_truthy - expect(json_response['assets']['User'][customer_user.id.to_s]['id']).to eq(customer_user.id) - expect(json_response['assets']['User'][customer_user.id.to_s]['firstname']).to eq(customer_user.firstname) - expect(json_response['assets']['User'][customer_user.id.to_s]['lastname']).to eq(customer_user.lastname) + expect(json_response['assets']['User'][customer.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer.id.to_s]['id']).to eq(customer.id) + expect(json_response['assets']['User'][customer.id.to_s]['firstname']).to eq(customer.firstname) + expect(json_response['assets']['User'][customer.id.to_s]['lastname']).to eq(customer.lastname) get '/api/v1/tickets?full=false', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -1544,8 +1544,8 @@ RSpec.describe 'Ticket', type: :request do expect(json_response[1]['priority']).to be_falsey expect(json_response[1]['owner']).to be_falsey expect(json_response[1]['customer_id']).to eq(ticket.customer_id) - expect(json_response[1]['updated_by_id']).to eq(agent_user.id) - expect(json_response[1]['created_by_id']).to eq(agent_user.id) + expect(json_response[1]['updated_by_id']).to eq(agent.id) + expect(json_response[1]['created_by_id']).to eq(agent.id) end it 'does ticket create and response format (04.03)' do @@ -1553,14 +1553,14 @@ RSpec.describe 'Ticket', type: :request do params = { title: title, group: ticket_group.name, - customer_id: customer_user.id, + customer_id: customer.id, state: 'new', priority: '2 normal', article: { body: 'some test 123', }, } - authenticated_as(agent_user) + authenticated_as(agent) post '/api/v1/tickets', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) @@ -1573,9 +1573,9 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['group_id']).to eq(ticket.group_id) expect(json_response['group']).to be_falsey expect(json_response['title']).to eq(title) - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) post '/api/v1/tickets?expand=true', params: params, as: :json expect(response).to have_http_status(:created) @@ -1589,9 +1589,9 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['group_id']).to eq(ticket.group_id) expect(json_response['group']).to eq(ticket.group.name) expect(json_response['title']).to eq(title) - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) post '/api/v1/tickets?full=true', params: params, as: :json expect(response).to have_http_status(:created) @@ -1606,16 +1606,16 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['assets']['Ticket'][ticket.id.to_s]['customer_id']).to eq(ticket.customer_id) expect(json_response['assets']['User']).to be_truthy - expect(json_response['assets']['User'][agent_user.id.to_s]).to be_truthy - expect(json_response['assets']['User'][agent_user.id.to_s]['id']).to eq(agent_user.id) - expect(json_response['assets']['User'][agent_user.id.to_s]['firstname']).to eq(agent_user.firstname) - expect(json_response['assets']['User'][agent_user.id.to_s]['lastname']).to eq(agent_user.lastname) + expect(json_response['assets']['User'][agent.id.to_s]).to be_truthy + expect(json_response['assets']['User'][agent.id.to_s]['id']).to eq(agent.id) + expect(json_response['assets']['User'][agent.id.to_s]['firstname']).to eq(agent.firstname) + expect(json_response['assets']['User'][agent.id.to_s]['lastname']).to eq(agent.lastname) expect(json_response['assets']['User']).to be_truthy - expect(json_response['assets']['User'][customer_user.id.to_s]).to be_truthy - expect(json_response['assets']['User'][customer_user.id.to_s]['id']).to eq(customer_user.id) - expect(json_response['assets']['User'][customer_user.id.to_s]['firstname']).to eq(customer_user.firstname) - expect(json_response['assets']['User'][customer_user.id.to_s]['lastname']).to eq(customer_user.lastname) + expect(json_response['assets']['User'][customer.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer.id.to_s]['id']).to eq(customer.id) + expect(json_response['assets']['User'][customer.id.to_s]['firstname']).to eq(customer.firstname) + expect(json_response['assets']['User'][customer.id.to_s]['lastname']).to eq(customer.lastname) end @@ -1625,15 +1625,15 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: title, group: ticket_group, - customer_id: customer_user.id, - updated_by_id: agent_user.id, - created_by_id: agent_user.id, + customer_id: customer.id, + updated_by_id: agent.id, + created_by_id: agent.id, ) params = { title: 'a update ticket #1', } - authenticated_as(agent_user) + authenticated_as(agent) put "/api/v1/tickets/#{ticket.id}", params: params, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -1646,9 +1646,9 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['group_id']).to eq(ticket.group_id) expect(json_response['group']).to be_falsey expect(json_response['title']).to eq('a update ticket #1') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) params = { title: 'a update ticket #2', @@ -1665,9 +1665,9 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['group_id']).to eq(ticket.group_id) expect(json_response['group']).to eq(ticket.group.name) expect(json_response['title']).to eq('a update ticket #2') - expect(json_response['customer_id']).to eq(customer_user.id) - expect(json_response['updated_by_id']).to eq(agent_user.id) - expect(json_response['created_by_id']).to eq(agent_user.id) + expect(json_response['customer_id']).to eq(customer.id) + expect(json_response['updated_by_id']).to eq(agent.id) + expect(json_response['created_by_id']).to eq(agent.id) params = { title: 'a update ticket #3', @@ -1685,16 +1685,16 @@ RSpec.describe 'Ticket', type: :request do expect(json_response['assets']['Ticket'][ticket.id.to_s]['customer_id']).to eq(ticket.customer_id) expect(json_response['assets']['User']).to be_truthy - expect(json_response['assets']['User'][agent_user.id.to_s]).to be_truthy - expect(json_response['assets']['User'][agent_user.id.to_s]['id']).to eq(agent_user.id) - expect(json_response['assets']['User'][agent_user.id.to_s]['firstname']).to eq(agent_user.firstname) - expect(json_response['assets']['User'][agent_user.id.to_s]['lastname']).to eq(agent_user.lastname) + expect(json_response['assets']['User'][agent.id.to_s]).to be_truthy + expect(json_response['assets']['User'][agent.id.to_s]['id']).to eq(agent.id) + expect(json_response['assets']['User'][agent.id.to_s]['firstname']).to eq(agent.firstname) + expect(json_response['assets']['User'][agent.id.to_s]['lastname']).to eq(agent.lastname) expect(json_response['assets']['User']).to be_truthy - expect(json_response['assets']['User'][customer_user.id.to_s]).to be_truthy - expect(json_response['assets']['User'][customer_user.id.to_s]['id']).to eq(customer_user.id) - expect(json_response['assets']['User'][customer_user.id.to_s]['firstname']).to eq(customer_user.firstname) - expect(json_response['assets']['User'][customer_user.id.to_s]['lastname']).to eq(customer_user.lastname) + expect(json_response['assets']['User'][customer.id.to_s]).to be_truthy + expect(json_response['assets']['User'][customer.id.to_s]['id']).to eq(customer.id) + expect(json_response['assets']['User'][customer.id.to_s]['firstname']).to eq(customer.firstname) + expect(json_response['assets']['User'][customer.id.to_s]['lastname']).to eq(customer.lastname) # it should be not possible to modify the ticket number expected_ticket_number = ticket.number @@ -1716,9 +1716,9 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: 'some title', group: ticket_group, - customer_id: customer_user.id, - updated_by_id: agent_user.id, - created_by_id: agent_user.id, + customer_id: customer.id, + updated_by_id: agent.id, + created_by_id: agent.id, ) article = create( :ticket_article, @@ -1793,11 +1793,11 @@ RSpec.describe 'Ticket', type: :request do created_by_id: 1, ) - authenticated_as(customer_user) + authenticated_as(customer) get "/api/v1/ticket_split?ticket_id=#{ticket.id}&article_id=#{article.id}&form_id=new_form_id123", params: {}, as: :json expect(response).to have_http_status(:unauthorized) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/ticket_split?ticket_id=#{ticket.id}&article_id=#{article.id}&form_id=new_form_id123", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -1825,9 +1825,9 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: 'some title', group: ticket_group, - customer_id: customer_user.id, - updated_by_id: agent_user.id, - created_by_id: agent_user.id, + customer_id: customer.id, + updated_by_id: agent.id, + created_by_id: agent.id, ) article = create( :ticket_article, @@ -1878,7 +1878,7 @@ RSpec.describe 'Ticket', type: :request do created_by_id: 1, ) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/ticket_split?ticket_id=#{ticket.id}&article_id=#{article.id}&form_id=new_form_id123", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -1907,26 +1907,26 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: 'ticket merge1', group: ticket_group, - customer_id: customer_user.id, + customer_id: customer.id, ) ticket2 = create( :ticket, title: 'ticket merge2', group: ticket_group, - customer_id: customer_user.id, + customer_id: customer.id, ) ticket3 = create( :ticket, title: 'ticket merge2', group: group_no_permission, - customer_id: customer_user.id, + customer_id: customer.id, ) - authenticated_as(customer_user) + authenticated_as(customer) get "/api/v1/ticket_merge/#{ticket2.id}/#{ticket1.id}", params: {}, as: :json expect(response).to have_http_status(:unauthorized) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/ticket_merge/#{ticket2.id}/#{ticket1.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -1963,18 +1963,18 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: 'ticket merge1', group: group_change_permission, - customer_id: customer_user.id, + customer_id: customer.id, ) ticket2 = create( :ticket, title: 'ticket merge2', group: group_change_permission, - customer_id: customer_user.id, + customer_id: customer.id, ) - agent_user.group_names_access_map = { group_change_permission.name => %w[read change] } + agent.group_names_access_map = { group_change_permission.name => %w[read change] } - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/ticket_merge/#{ticket1.id}/#{ticket2.number}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -1989,7 +1989,7 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: "#{title} A", group: ticket_group, - customer_id: customer_user.id, + customer_id: customer.id, created_at: '2018-02-05 17:42:00', updated_at: '2018-02-05 20:42:00', ) @@ -2004,7 +2004,7 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: "#{title} B", group: ticket_group, - customer_id: customer_user.id, + customer_id: customer.id, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '3 hoch'), created_at: '2018-02-05 19:42:00', @@ -2017,37 +2017,37 @@ RSpec.describe 'Ticket', type: :request do ticket_id: ticket2.id, ) - authenticated_as(admin_user) + authenticated_as(admin) get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response['tickets']).to eq([ticket2.id, ticket1.id]) - authenticated_as(admin_user) + authenticated_as(admin) get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: 'created_at', order_by: 'asc' }, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response['tickets']).to eq([ticket1.id, ticket2.id]) - authenticated_as(admin_user) + authenticated_as(admin) get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: 'title', order_by: 'asc' }, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response['tickets']).to eq([ticket1.id, ticket2.id]) - authenticated_as(admin_user) + authenticated_as(admin) get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: 'title', order_by: 'desc' }, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response['tickets']).to eq([ticket2.id, ticket1.id]) - authenticated_as(admin_user) + authenticated_as(admin) get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: %w[created_at updated_at], order_by: %w[asc asc] }, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) expect(json_response['tickets']).to eq([ticket1.id, ticket2.id]) - authenticated_as(admin_user) + authenticated_as(admin) get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: %w[created_at updated_at], order_by: %w[desc asc] }, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -2059,7 +2059,7 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: 'some title', group: ticket_group, - customer_id: customer_user.id, + customer_id: customer.id, ) create( :ticket_article, @@ -2068,16 +2068,16 @@ RSpec.describe 'Ticket', type: :request do ticket_id: ticket1.id, ) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/ticket_history/#{ticket1.id}", params: {}, as: :json 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) - expect(json_response['assets']['User'][customer_user.id.to_s]).not_to be_nil + expect(json_response['assets']['User'][customer.id.to_s]).not_to be_nil expect(json_response['assets']['Ticket'][ticket1.id.to_s]).not_to be_nil - authenticated_as(customer_user) + authenticated_as(customer) get "/api/v1/ticket_history/#{ticket1.id}", params: {}, as: :json expect(response).to have_http_status(:unauthorized) end @@ -2087,24 +2087,24 @@ RSpec.describe 'Ticket', type: :request do :ticket, title: 'some title', group: ticket_group, - customer_id: customer_user.id, + customer_id: customer.id, ) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/ticket_related/#{ticket1.id}", params: {}, as: :json expect(response).to have_http_status(:ok) - authenticated_as(customer_user) + authenticated_as(customer) get "/api/v1/ticket_related/#{ticket1.id}", params: {}, as: :json expect(response).to have_http_status(:unauthorized) end it 'does ticket recent' do - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/ticket_recent', params: {}, as: :json expect(response).to have_http_status(:ok) - authenticated_as(customer_user) + authenticated_as(customer) get '/api/v1/ticket_recent', params: {}, as: :json expect(response).to have_http_status(:unauthorized) end @@ -2115,11 +2115,11 @@ RSpec.describe 'Ticket', type: :request do let(:ticket1) { create(:ticket, customer: customer, organization: organization, group: ticket_group) } let(:ticket2) { create(:ticket, customer: customer, organization: organization, group: ticket_group) } let(:ticket3) { create(:ticket, customer: customer, organization: organization, group: ticket_group) } - let(:customer) { create(:customer_user, organization: organization) } + let(:customer) { create(:customer, organization: organization) } let(:organization) { create(:organization, shared: false) } before do - authenticated_as(admin_user) + authenticated_as(admin) ticket1 travel 2.minutes @@ -2146,8 +2146,8 @@ RSpec.describe 'Ticket', type: :request do describe '/api/v1/tickets' do subject(:ticket) { create(:ticket, state_name: 'closed') } - let(:admin) { create(:admin_user, groups: [ticket.group]) } - let(:agent) { create(:agent_user, groups: [ticket.group]) } + let(:admin) { create(:admin, groups: [ticket.group]) } + let(:agent) { create(:agent, groups: [ticket.group]) } let(:customer) { ticket.customer } describe 'reopening a ticket' do @@ -2212,12 +2212,12 @@ RSpec.describe 'Ticket', type: :request do subject(:ticket) { create(:ticket, customer: customer_authorized) } let(:organization_authorized) { create(:organization) } - let(:customer_authorized) { create(:customer_user, organization: organization_authorized) } + let(:customer_authorized) { create(:customer, organization: organization_authorized) } let(:organization_unauthorized) { create(:organization) } - let(:customer_unauthorized) { create(:customer_user, organization: organization_unauthorized) } + let(:customer_unauthorized) { create(:customer, organization: organization_unauthorized) } - let(:agent) { create(:agent_user, groups: [ticket.group]) } + let(:agent) { create(:agent, groups: [ticket.group]) } describe 'listing information' do diff --git a/spec/requests/time_accounting_spec.rb b/spec/requests/time_accounting_spec.rb index 42b21b1eb..ecd7dd216 100644 --- a/spec/requests/time_accounting_spec.rb +++ b/spec/requests/time_accounting_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' RSpec.describe 'Time Accounting API endpoints', type: :request do - let(:admin) { create(:admin_user) } - let(:customer) { create(:customer_user) } + let(:admin) { create(:admin) } + let(:customer) { create(:customer) } let(:year) { Time.current.year } let(:month) { Time.current.month } diff --git a/spec/requests/upload_cache_spec.rb b/spec/requests/upload_cache_spec.rb index 9af60b4fb..a0e196616 100644 --- a/spec/requests/upload_cache_spec.rb +++ b/spec/requests/upload_cache_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' RSpec.describe 'UploadCache', type: :request do - let(:user) { create(:customer_user) } + let(:user) { create(:customer) } let(:form_id) { 1337 } let(:upload_cache) { UploadCache.new(form_id) } diff --git a/spec/requests/user/organization_spec.rb b/spec/requests/user/organization_spec.rb index 1fef2117e..01d5ef49b 100644 --- a/spec/requests/user/organization_spec.rb +++ b/spec/requests/user/organization_spec.rb @@ -2,14 +2,14 @@ require 'rails_helper' RSpec.describe 'User Organization', type: :request, searchindex: true do - let!(:admin_user) do - create(:admin_user, groups: Group.all) + let!(:admin) do + create(:admin, groups: Group.all) end - let!(:agent_user) do - create(:agent_user, groups: Group.all) + let!(:agent) do + create(:agent, groups: Group.all) end - let!(:customer_user) do - create(:customer_user) + let!(:customer) do + create(:customer) end let!(:organization) do create(:organization, name: 'Rest Org', note: 'Rest Org A') @@ -20,8 +20,8 @@ RSpec.describe 'User Organization', type: :request, searchindex: true do let!(:organization3) do create(:organization, name: 'Rest Org #3', note: 'Rest Org C') end - let!(:customer_user2) do - create(:customer_user, organization: organization) + let!(:customer2) do + create(:customer, organization: organization) end before do @@ -41,7 +41,7 @@ RSpec.describe 'User Organization', type: :request, searchindex: true do describe 'request handling' do it 'does organization index with agent' do - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/organizations', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) @@ -113,7 +113,7 @@ RSpec.describe 'User Organization', type: :request, searchindex: true do end it 'does organization index with customer1' do - authenticated_as(customer_user) + authenticated_as(customer) get '/api/v1/organizations', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) @@ -137,7 +137,7 @@ RSpec.describe 'User Organization', type: :request, searchindex: true do end it 'does organization index with customer2' do - authenticated_as(customer_user2) + authenticated_as(customer2) get '/api/v1/organizations', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) diff --git a/spec/requests/user/permission_spec.rb b/spec/requests/user/permission_spec.rb index 9ba59d76f..63ea2e047 100644 --- a/spec/requests/user/permission_spec.rb +++ b/spec/requests/user/permission_spec.rb @@ -21,7 +21,7 @@ RSpec.describe 'User endpoint', type: :request do let(:attributes) { attributes_params_for(:user) } it 'responds unauthorized for customer' do - requester = create(:customer_user) + requester = create(:customer) authenticated_as(requester) expect do @@ -71,7 +71,7 @@ RSpec.describe 'User endpoint', type: :request do end it 'responds successful for agent but removes assignment' do - requester = create(:agent_user) + requester = create(:agent) authenticated_as(requester) expect do @@ -144,7 +144,7 @@ RSpec.describe 'User endpoint', type: :request do end it 'responds successful for agent but removes assignment' do - requester = create(:agent_user) + requester = create(:agent) authenticated_as(requester) expect do @@ -228,21 +228,21 @@ RSpec.describe 'User endpoint', type: :request do it 'is successful for other admin' do authorized_update_request( requester: requester, - requested: create(:admin_user), + requested: create(:admin), ) end it 'is successful for agent' do authorized_update_request( requester: requester, - requested: create(:agent_user), + requested: create(:agent), ) end it 'is successful for customer' do authorized_update_request( requester: requester, - requested: create(:customer_user), + requested: create(:customer), ) end end @@ -261,33 +261,33 @@ RSpec.describe 'User endpoint', type: :request do it 'is unauthorized for other admin' do unauthorized_update_request( requester: requester, - requested: create(:admin_user), + requested: create(:admin), ) end it 'is unauthorized for agent' do unauthorized_update_request( requester: requester, - requested: create(:agent_user), + requested: create(:agent), ) end it 'is unauthorized for customer' do unauthorized_update_request( requester: requester, - requested: create(:customer_user), + requested: create(:customer), ) end end context 'request by agent' do - let(:requester) { create(:agent_user) } + let(:requester) { create(:agent) } it 'is unauthorized for admin' do unauthorized_update_request( requester: requester, - requested: create(:admin_user), + requested: create(:admin), ) end @@ -301,33 +301,33 @@ RSpec.describe 'User endpoint', type: :request do it 'is unauthorized for other agent' do unauthorized_update_request( requester: requester, - requested: create(:agent_user), + requested: create(:agent), ) end it 'is successful for customer' do authorized_update_request( requester: requester, - requested: create(:customer_user), + requested: create(:customer), ) end end context 'request by customer' do - let(:requester) { create(:customer_user) } + let(:requester) { create(:customer) } it 'is unauthorized for admin' do unauthorized_update_request( requester: requester, - requested: create(:admin_user), + requested: create(:admin), ) end it 'is unauthorized for agent' do unauthorized_update_request( requester: requester, - requested: create(:agent_user), + requested: create(:agent), ) end @@ -341,7 +341,7 @@ RSpec.describe 'User endpoint', type: :request do it 'is unauthorized for other customer' do unauthorized_update_request( requester: requester, - requested: create(:customer_user), + requested: create(:customer), ) end @@ -352,7 +352,7 @@ RSpec.describe 'User endpoint', type: :request do unauthorized_update_request( requester: requester, - requested: create(:customer_user, organization: same_organization), + requested: create(:customer, organization: same_organization), ) end end @@ -399,7 +399,7 @@ RSpec.describe 'User endpoint', type: :request do shared_examples 'permitted agent update' do it 'responds successful for agent but removes assignment' do - requester = create(:agent_user) + requester = create(:agent) authenticated_as(requester) expect do @@ -415,7 +415,7 @@ RSpec.describe 'User endpoint', type: :request do shared_examples 'forbidden agent update' do it 'responds successful for agent but removes assignment' do - requester = create(:agent_user) + requester = create(:agent) authenticated_as(requester) expect do @@ -545,21 +545,21 @@ RSpec.describe 'User endpoint', type: :request do it 'is successful for other admin' do authorized_destroy_request( requester: requester, - requested: create(:admin_user), + requested: create(:admin), ) end it 'is successful for agent' do authorized_destroy_request( requester: requester, - requested: create(:agent_user), + requested: create(:agent), ) end it 'is successful for customer' do authorized_destroy_request( requester: requester, - requested: create(:customer_user), + requested: create(:customer), ) end end @@ -578,33 +578,33 @@ RSpec.describe 'User endpoint', type: :request do it 'is unauthorized for other admin' do unauthorized_destroy_request( requester: requester, - requested: create(:admin_user), + requested: create(:admin), ) end it 'is unauthorized for agent' do unauthorized_destroy_request( requester: requester, - requested: create(:agent_user), + requested: create(:agent), ) end it 'is unauthorized for customer' do unauthorized_destroy_request( requester: requester, - requested: create(:customer_user), + requested: create(:customer), ) end end context 'request by agent' do - let(:requester) { create(:agent_user) } + let(:requester) { create(:agent) } it 'is unauthorized for admin' do unauthorized_destroy_request( requester: requester, - requested: create(:admin_user), + requested: create(:admin), ) end @@ -618,33 +618,33 @@ RSpec.describe 'User endpoint', type: :request do it 'is unauthorized for other agent' do unauthorized_destroy_request( requester: requester, - requested: create(:agent_user), + requested: create(:agent), ) end it 'is unauthorized for customer' do unauthorized_destroy_request( requester: requester, - requested: create(:customer_user), + requested: create(:customer), ) end end context 'request by customer' do - let(:requester) { create(:customer_user) } + let(:requester) { create(:customer) } it 'is unauthorized for admin' do unauthorized_destroy_request( requester: requester, - requested: create(:admin_user), + requested: create(:admin), ) end it 'is unauthorized for agent' do unauthorized_destroy_request( requester: requester, - requested: create(:agent_user), + requested: create(:agent), ) end @@ -658,7 +658,7 @@ RSpec.describe 'User endpoint', type: :request do it 'is unauthorized for other customer' do unauthorized_destroy_request( requester: requester, - requested: create(:customer_user), + requested: create(:customer), ) end @@ -669,7 +669,7 @@ RSpec.describe 'User endpoint', type: :request do unauthorized_destroy_request( requester: requester, - requested: create(:customer_user, organization: same_organization), + requested: create(:customer, organization: same_organization), ) end end diff --git a/spec/requests/user_spec.rb b/spec/requests/user_spec.rb index 20109950f..7223798c2 100644 --- a/spec/requests/user_spec.rb +++ b/spec/requests/user_spec.rb @@ -2,9 +2,9 @@ require 'rails_helper' RSpec.describe 'User', type: :request, searchindex: true do - let!(:admin_user) do + let!(:admin) do create( - :admin_user, + :admin, groups: Group.all, login: 'rest-admin', firstname: 'Rest', @@ -12,9 +12,9 @@ RSpec.describe 'User', type: :request, searchindex: true do email: 'rest-admin@example.com', ) end - let!(:admin_user_pw) do + let!(:admin_with_pw) do create( - :admin_user, + :admin, groups: Group.all, login: 'rest-admin-pw', firstname: 'Rest', @@ -23,9 +23,9 @@ RSpec.describe 'User', type: :request, searchindex: true do password: 'adminpw', ) end - let!(:agent_user) do + let!(:agent) do create( - :agent_user, + :agent, groups: Group.all, login: 'rest-agent@example.com', firstname: 'Rest', @@ -33,9 +33,9 @@ RSpec.describe 'User', type: :request, searchindex: true do email: 'rest-agent@example.com', ) end - let!(:customer_user) do + let!(:customer) do create( - :customer_user, + :customer, login: 'rest-customer1@example.com', firstname: 'Rest', lastname: 'Customer1', @@ -51,9 +51,9 @@ RSpec.describe 'User', type: :request, searchindex: true do let!(:organization3) do create(:organization, name: 'Rest Org #3') end - let!(:customer_user2) do + let!(:customer2) do create( - :customer_user, + :customer, organization: organization, login: 'rest-customer2@example.com', firstname: 'Rest', @@ -191,7 +191,7 @@ RSpec.describe 'User', type: :request, searchindex: true do end it 'does auth tests - username auth, wrong pw' do - authenticated_as(admin_user, password: 'not_existing') + authenticated_as(admin, password: 'not_existing') get '/api/v1/users', params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(json_response['error']).to eq('authentication failed') @@ -219,7 +219,7 @@ RSpec.describe 'User', type: :request, searchindex: true do end it 'does user index and create with admin' do - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/users/me', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_truthy @@ -238,13 +238,13 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response.length >= 3).to be_truthy # show/:id - get "/api/v1/users/#{agent_user.id}", params: {}, as: :json + get "/api/v1/users/#{agent.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_truthy expect(Hash).to eq(json_response.class) expect('rest-agent@example.com').to eq(json_response['email']) - get "/api/v1/users/#{customer_user.id}", params: {}, as: :json + get "/api/v1/users/#{customer.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_truthy expect(Hash).to eq(json_response.class) @@ -327,7 +327,7 @@ RSpec.describe 'User', type: :request, searchindex: true do end it 'does user index and create with agent' do - authenticated_as(agent_user) + authenticated_as(agent) get '/api/v1/users/me', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_truthy @@ -367,42 +367,42 @@ RSpec.describe 'User', type: :request, searchindex: true do params = { firstname: "Admin#{firstname}", lastname: 'Admin Last', email: 'new_admin_by_agent@example.com', role_ids: [ role.id ] } post '/api/v1/users', params: params, as: :json expect(response).to have_http_status(:created) - json_response_user1 = JSON.parse(@response.body) - expect(json_response_user1).to be_truthy - user = User.find(json_response_user1['id']) + json_response1 = JSON.parse(@response.body) + expect(json_response1).to be_truthy + user = User.find(json_response1['id']) expect(user).not_to be_role('Admin') expect(user).not_to be_role('Agent') expect(user).to be_role('Customer') - expect(json_response_user1['login']).to eq('new_admin_by_agent@example.com') - expect(json_response_user1['email']).to eq('new_admin_by_agent@example.com') + expect(json_response1['login']).to eq('new_admin_by_agent@example.com') + expect(json_response1['email']).to eq('new_admin_by_agent@example.com') # create user with agent role role = Role.lookup(name: 'Agent') params = { firstname: "Agent#{firstname}", lastname: 'Agent Last', email: 'new_agent_by_agent@example.com', role_ids: [ role.id ] } post '/api/v1/users', params: params, as: :json expect(response).to have_http_status(:created) - json_response_user1 = JSON.parse(@response.body) - expect(json_response_user1).to be_truthy - user = User.find(json_response_user1['id']) + json_response1 = JSON.parse(@response.body) + expect(json_response1).to be_truthy + user = User.find(json_response1['id']) expect(user).not_to be_role('Admin') expect(user).not_to be_role('Agent') expect(user).to be_role('Customer') - expect(json_response_user1['login']).to eq('new_agent_by_agent@example.com') - expect(json_response_user1['email']).to eq('new_agent_by_agent@example.com') + expect(json_response1['login']).to eq('new_agent_by_agent@example.com') + expect(json_response1['email']).to eq('new_agent_by_agent@example.com') # create user with customer role role = Role.lookup(name: 'Customer') params = { firstname: "Customer#{firstname}", lastname: 'Customer Last', email: 'new_customer_by_agent@example.com', role_ids: [ role.id ] } post '/api/v1/users', params: params, as: :json expect(response).to have_http_status(:created) - json_response_user1 = JSON.parse(@response.body) - expect(json_response_user1).to be_truthy - user = User.find(json_response_user1['id']) + json_response1 = JSON.parse(@response.body) + expect(json_response1).to be_truthy + user = User.find(json_response1['id']) expect(user).not_to be_role('Admin') expect(user).not_to be_role('Agent') expect(user).to be_role('Customer') - expect(json_response_user1['login']).to eq('new_customer_by_agent@example.com') - expect(json_response_user1['email']).to eq('new_customer_by_agent@example.com') + expect(json_response1['login']).to eq('new_customer_by_agent@example.com') + expect(json_response1['email']).to eq('new_customer_by_agent@example.com') # search as agent Scheduler.worker(true) @@ -411,7 +411,7 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) - expect(json_response[0]['id']).to eq(json_response_user1['id']) + expect(json_response[0]['id']).to eq(json_response1['id']) expect(json_response[0]['firstname']).to eq("Customer#{firstname}") expect(json_response[0]['lastname']).to eq('Customer Last') expect(json_response[0]['role_ids']).to be_truthy @@ -420,7 +420,7 @@ RSpec.describe 'User', type: :request, searchindex: true do get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&expand=true", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) - expect(json_response[0]['id']).to eq(json_response_user1['id']) + expect(json_response[0]['id']).to eq(json_response1['id']) expect(json_response[0]['firstname']).to eq("Customer#{firstname}") expect(json_response[0]['lastname']).to eq('Customer Last') expect(json_response[0]['role_ids']).to be_truthy @@ -429,7 +429,7 @@ RSpec.describe 'User', type: :request, searchindex: true do get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&label=true", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) - expect(json_response[0]['id']).to eq(json_response_user1['id']) + expect(json_response[0]['id']).to eq(json_response1['id']) expect(json_response[0]['label']).to eq("Customer#{firstname} Customer Last ") expect(json_response[0]['value']).to eq("Customer#{firstname} Customer Last ") expect(json_response[0]['role_ids']).to be_falsey @@ -438,7 +438,7 @@ RSpec.describe 'User', type: :request, searchindex: true do get "/api/v1/users/search?term=#{CGI.escape("Customer#{firstname}")}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) - expect(json_response[0]['id']).to eq(json_response_user1['id']) + expect(json_response[0]['id']).to eq(json_response1['id']) expect(json_response[0]['label']).to eq("Customer#{firstname} Customer Last ") expect(json_response[0]['value']).to eq('new_customer_by_agent@example.com') expect(json_response[0]['role_ids']).to be_falsey @@ -447,12 +447,12 @@ RSpec.describe 'User', type: :request, searchindex: true do # Regression test for issue #2539 - search pagination broken in users_controller.rb # Get the total number of users N, then search with one result per page, so there should N pages with one result each get '/api/v1/users/search', params: { query: '*' }, as: :json - total_user_number = json_response.count - (1..total_user_number).each do |i| + total_number = json_response.count + (1..total_number).each do |i| get '/api/v1/users/search', params: { query: '*', per_page: 1, page: i }, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) - expect(json_response.count).to eq(1), "Page #{i}/#{total_user_number} of the user search pagination test have the wrong result!" + expect(json_response.count).to eq(1), "Page #{i}/#{total_number} of the user search pagination test have the wrong result!" end role = Role.find_by(name: 'Agent') @@ -465,7 +465,7 @@ RSpec.describe 'User', type: :request, searchindex: true do get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&role_ids=#{role.id}&label=true", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) - expect(json_response[0]['id']).to eq(json_response_user1['id']) + expect(json_response[0]['id']).to eq(json_response1['id']) expect(json_response[0]['label']).to eq("Customer#{firstname} Customer Last ") expect(json_response[0]['value']).to eq("Customer#{firstname} Customer Last ") expect(json_response[0]['role_ids']).to be_falsey @@ -481,7 +481,7 @@ RSpec.describe 'User', type: :request, searchindex: true do get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&permissions=#{permission.name}&label=true", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) - expect(json_response[0]['id']).to eq(json_response_user1['id']) + expect(json_response[0]['id']).to eq(json_response1['id']) expect(json_response[0]['label']).to eq("Customer#{firstname} Customer Last ") expect(json_response[0]['value']).to eq("Customer#{firstname} Customer Last ") expect(json_response[0]['role_ids']).to be_falsey @@ -489,7 +489,7 @@ RSpec.describe 'User', type: :request, searchindex: true do end it 'does user index and create with customer1' do - authenticated_as(customer_user) + authenticated_as(customer) get '/api/v1/users/me', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_truthy @@ -502,12 +502,12 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(1).to eq(json_response.length) # show/:id - get "/api/v1/users/#{customer_user.id}", params: {}, as: :json + get "/api/v1/users/#{customer.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(Hash).to eq(json_response.class) expect('rest-customer1@example.com').to eq(json_response['email']) - get "/api/v1/users/#{customer_user2.id}", params: {}, as: :json + get "/api/v1/users/#{customer2.id}", params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(Hash).to eq(json_response.class) expect(json_response['error']).to be_truthy @@ -531,7 +531,7 @@ RSpec.describe 'User', type: :request, searchindex: true do end it 'does user index with customer2' do - authenticated_as(customer_user2) + authenticated_as(customer2) get '/api/v1/users/me', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_truthy @@ -544,12 +544,12 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(1).to eq(json_response.length) # show/:id - get "/api/v1/users/#{customer_user2.id}", params: {}, as: :json + get "/api/v1/users/#{customer2.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(Hash).to eq(json_response.class) expect('rest-customer2@example.com').to eq(json_response['email']) - get "/api/v1/users/#{customer_user.id}", params: {}, as: :json + get "/api/v1/users/#{customer.id}", params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(Hash).to eq(json_response.class) expect(json_response['error']).to be_truthy @@ -562,7 +562,7 @@ RSpec.describe 'User', type: :request, searchindex: true do it 'does users show and response format (04.01)' do user = create( - :customer_user, + :customer, login: 'rest-customer3@example.com', firstname: 'Rest', lastname: 'Customer3', @@ -570,11 +570,11 @@ RSpec.describe 'User', type: :request, searchindex: true do password: 'customer3pw', active: true, organization: organization, - updated_by_id: admin_user.id, - created_by_id: admin_user.id, + updated_by_id: admin.id, + created_by_id: admin.id, ) - authenticated_as(admin_user) + authenticated_as(admin) get "/api/v1/users/#{user.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -584,8 +584,8 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response['organization_id']).to eq(user.organization_id) expect(json_response['password']).to be_falsey expect(json_response['role_ids']).to eq(user.role_ids) - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) get "/api/v1/users/#{user.id}?expand=true", params: {}, as: :json expect(response).to have_http_status(:ok) @@ -596,8 +596,8 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response['organization']).to eq(user.organization.name) expect(json_response['role_ids']).to eq(user.role_ids) expect(json_response['password']).to be_falsey - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) get "/api/v1/users/#{user.id}?expand=false", params: {}, as: :json expect(response).to have_http_status(:ok) @@ -608,8 +608,8 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response['organization_id']).to eq(user.organization_id) expect(json_response['password']).to be_falsey expect(json_response['role_ids']).to eq(user.role_ids) - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) get "/api/v1/users/#{user.id}?full=true", params: {}, as: :json expect(response).to have_http_status(:ok) @@ -633,13 +633,13 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response['organization_id']).to eq(user.organization_id) expect(json_response['password']).to be_falsey expect(json_response['role_ids']).to eq(user.role_ids) - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) end it 'does user index and response format (04.02)' do user = create( - :customer_user, + :customer, login: 'rest-customer3@example.com', firstname: 'Rest', lastname: 'Customer3', @@ -647,11 +647,11 @@ RSpec.describe 'User', type: :request, searchindex: true do password: 'customer3pw', active: true, organization: organization, - updated_by_id: admin_user.id, - created_by_id: admin_user.id, + updated_by_id: admin.id, + created_by_id: admin.id, ) - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/users', params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) @@ -662,8 +662,8 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response.last['role_ids']).to eq(user.role_ids) expect(json_response.last['organization_id']).to eq(user.organization_id) expect(json_response.last['password']).to be_falsey - expect(json_response.last['updated_by_id']).to eq(admin_user.id) - expect(json_response.last['created_by_id']).to eq(admin_user.id) + expect(json_response.last['updated_by_id']).to eq(admin.id) + expect(json_response.last['created_by_id']).to eq(admin.id) get '/api/v1/users?expand=true', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -674,8 +674,8 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response.last['organization_id']).to eq(user.organization_id) expect(json_response.last['organization']).to eq(user.organization.name) expect(json_response.last['password']).to be_falsey - expect(json_response.last['updated_by_id']).to eq(admin_user.id) - expect(json_response.last['created_by_id']).to eq(admin_user.id) + expect(json_response.last['updated_by_id']).to eq(admin.id) + expect(json_response.last['created_by_id']).to eq(admin.id) get '/api/v1/users?expand=false', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -687,8 +687,8 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response.last['role_ids']).to eq(user.role_ids) expect(json_response.last['organization_id']).to eq(user.organization_id) expect(json_response.last['password']).to be_falsey - expect(json_response.last['updated_by_id']).to eq(admin_user.id) - expect(json_response.last['created_by_id']).to eq(admin_user.id) + expect(json_response.last['updated_by_id']).to eq(admin.id) + expect(json_response.last['created_by_id']).to eq(admin.id) get '/api/v1/users?full=true', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -715,8 +715,8 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response.last['role_ids']).to eq(user.role_ids) expect(json_response.last['organization_id']).to eq(user.organization_id) expect(json_response.last['password']).to be_falsey - expect(json_response.last['updated_by_id']).to eq(admin_user.id) - expect(json_response.last['created_by_id']).to eq(admin_user.id) + expect(json_response.last['updated_by_id']).to eq(admin.id) + expect(json_response.last['created_by_id']).to eq(admin.id) end it 'does ticket create and response format (04.03)' do @@ -727,7 +727,7 @@ RSpec.describe 'User', type: :request, searchindex: true do organization: organization.name, } - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/users', params: params, as: :json expect(response).to have_http_status(:created) expect(json_response).to be_a_kind_of(Hash) @@ -737,8 +737,8 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response['organization_id']).to eq(user.organization_id) expect(json_response['organization']).to be_falsey expect(json_response['password']).to be_falsey - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) post '/api/v1/users?expand=true', params: params, as: :json expect(response).to have_http_status(:created) @@ -749,8 +749,8 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response['organization_id']).to eq(user.organization_id) expect(json_response['organization']).to eq(user.organization.name) expect(json_response['password']).to be_falsey - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) post '/api/v1/users?full=true', params: params, as: :json expect(response).to have_http_status(:created) @@ -765,17 +765,17 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response['assets']['User'][user.id.to_s]['lastname']).to eq(user.lastname) expect(json_response['assets']['User'][user.id.to_s]['password']).to be_falsey - expect(json_response['assets']['User'][admin_user.id.to_s]).to be_truthy - expect(json_response['assets']['User'][admin_user.id.to_s]['id']).to eq(admin_user.id) - expect(json_response['assets']['User'][admin_user.id.to_s]['firstname']).to eq(admin_user.firstname) - expect(json_response['assets']['User'][admin_user.id.to_s]['lastname']).to eq(admin_user.lastname) - expect(json_response['assets']['User'][admin_user.id.to_s]['password']).to be_falsey + expect(json_response['assets']['User'][admin.id.to_s]).to be_truthy + expect(json_response['assets']['User'][admin.id.to_s]['id']).to eq(admin.id) + expect(json_response['assets']['User'][admin.id.to_s]['firstname']).to eq(admin.firstname) + expect(json_response['assets']['User'][admin.id.to_s]['lastname']).to eq(admin.lastname) + expect(json_response['assets']['User'][admin.id.to_s]['password']).to be_falsey end it 'does ticket update and response formats (04.04)' do user = create( - :customer_user, + :customer, login: 'rest-customer3@example.com', firstname: 'Rest', lastname: 'Customer3', @@ -783,11 +783,11 @@ RSpec.describe 'User', type: :request, searchindex: true do password: 'customer3pw', active: true, organization: organization, - updated_by_id: admin_user.id, - created_by_id: admin_user.id, + updated_by_id: admin.id, + created_by_id: admin.id, ) - authenticated_as(admin_user) + authenticated_as(admin) params = { firstname: 'a update firstname #1', } @@ -801,8 +801,8 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response['organization_id']).to eq(user.organization_id) expect(json_response['organization']).to be_falsey expect(json_response['password']).to be_falsey - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) params = { firstname: 'a update firstname #2', @@ -817,8 +817,8 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response['organization_id']).to eq(user.organization_id) expect(json_response['organization']).to eq(user.organization.name) expect(json_response['password']).to be_falsey - expect(json_response['updated_by_id']).to eq(admin_user.id) - expect(json_response['created_by_id']).to eq(admin_user.id) + expect(json_response['updated_by_id']).to eq(admin.id) + expect(json_response['created_by_id']).to eq(admin.id) params = { firstname: 'a update firstname #3', @@ -836,17 +836,17 @@ RSpec.describe 'User', type: :request, searchindex: true do expect(json_response['assets']['User'][user.id.to_s]['lastname']).to eq(user.lastname) expect(json_response['assets']['User'][user.id.to_s]['password']).to be_falsey - expect(json_response['assets']['User'][admin_user.id.to_s]).to be_truthy - expect(json_response['assets']['User'][admin_user.id.to_s]['id']).to eq(admin_user.id) - expect(json_response['assets']['User'][admin_user.id.to_s]['firstname']).to eq(admin_user.firstname) - expect(json_response['assets']['User'][admin_user.id.to_s]['lastname']).to eq(admin_user.lastname) - expect(json_response['assets']['User'][admin_user.id.to_s]['password']).to be_falsey + expect(json_response['assets']['User'][admin.id.to_s]).to be_truthy + expect(json_response['assets']['User'][admin.id.to_s]['id']).to eq(admin.id) + expect(json_response['assets']['User'][admin.id.to_s]['firstname']).to eq(admin.firstname) + expect(json_response['assets']['User'][admin.id.to_s]['lastname']).to eq(admin.lastname) + expect(json_response['assets']['User'][admin.id.to_s]['password']).to be_falsey end it 'does csv example - customer no access (05.01)' do - authenticated_as(customer_user) + authenticated_as(customer) get '/api/v1/users/import_example', params: {}, as: :json expect(response).to have_http_status(:unauthorized) expect(json_response['error']).to eq('Not authorized (user)!') @@ -854,7 +854,7 @@ RSpec.describe 'User', type: :request, searchindex: true do it 'does csv example - admin access (05.02)' do - authenticated_as(admin_user) + authenticated_as(admin) get '/api/v1/users/import_example', params: {}, as: :json expect(response).to have_http_status(:ok) @@ -873,7 +873,7 @@ RSpec.describe 'User', type: :request, searchindex: true do # invalid file csv_file = fixture_file_upload('csv_import/user/simple_col_not_existing.csv', 'text/csv') - authenticated_as(admin_user) + authenticated_as(admin) post '/api/v1/users/import?try=true', params: { file: csv_file, col_sep: ';' } expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -929,14 +929,14 @@ RSpec.describe 'User', type: :request, searchindex: true do it 'does user history' do user1 = create( - :customer_user, + :customer, login: 'history@example.com', firstname: 'History', lastname: 'Customer1', email: 'history@example.com', ) - authenticated_as(agent_user) + authenticated_as(agent) get "/api/v1/users/history/#{user1.id}", params: {}, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Hash) @@ -950,7 +950,7 @@ RSpec.describe 'User', type: :request, searchindex: true do firstname = "user_search_sortable #{rand(999_999_999)}" user1 = create( - :customer_user, + :customer, login: 'rest-user_search_sortableA@example.com', firstname: "#{firstname} A", lastname: 'user_search_sortableA', @@ -962,7 +962,7 @@ RSpec.describe 'User', type: :request, searchindex: true do created_at: '2016-02-05 17:42:00', ) user2 = create( - :customer_user, + :customer, login: 'rest-user_search_sortableB@example.com', firstname: "#{firstname} B", lastname: 'user_search_sortableB', @@ -979,7 +979,7 @@ RSpec.describe 'User', type: :request, searchindex: true do Scheduler.worker(true) sleep 2 # let es time to come ready - authenticated_as(admin_user) + authenticated_as(admin) get "/api/v1/users/search?query=#{CGI.escape(firstname)}", params: { sort_by: 'created_at', order_by: 'asc' }, as: :json expect(response).to have_http_status(:ok) expect(json_response).to be_a_kind_of(Array) @@ -1038,10 +1038,10 @@ RSpec.describe 'User', type: :request, searchindex: true do end context 'does password reset send work' do - let(:user) { create(:customer_user, login: 'somebody', email: 'somebody@example.com') } + let(:user) { create(:customer, login: 'somebody', email: 'somebody@example.com') } context 'for user without email address' do - let(:user) { create(:customer_user, login: 'somebody', email: '') } + let(:user) { create(:customer, login: 'somebody', email: '') } it 'return failed' do post '/api/v1/users/password_reset', params: { username: user.login }, as: :json @@ -1076,11 +1076,11 @@ RSpec.describe 'User', type: :request, searchindex: true do end context 'does password reset by token work' do - let(:user) { create(:customer_user, login: 'somebody', email: 'somebody@example.com') } + let(:user) { create(:customer, login: 'somebody', email: 'somebody@example.com') } let(:token) { create(:token, action: 'PasswordReset', user_id: user.id) } context 'for user without email address' do - let(:user) { create(:customer_user, login: 'somebody', email: '') } + let(:user) { create(:customer, login: 'somebody', email: '') } it 'return failed' do post '/api/v1/users/password_reset_verify', params: { username: user.login, token: token.name, password: 'Test1234#.' }, as: :json @@ -1115,12 +1115,12 @@ RSpec.describe 'User', type: :request, searchindex: true do end context 'password change' do - let(:user) { create(:customer_user, login: 'somebody', email: 'somebody@example.com', password: 'Test1234#.') } + let(:user) { create(:customer, login: 'somebody', email: 'somebody@example.com', password: 'Test1234#.') } before { authenticated_as(user, login: 'somebody', password: 'Test1234#.') } context 'user without email address' do - let(:user) { create(:customer_user, login: 'somebody', email: '', password: 'Test1234#.') } + let(:user) { create(:customer, login: 'somebody', email: '', password: 'Test1234#.') } it 'return ok' do post '/api/v1/users/password_change', params: { password_old: 'Test1234#.', password_new: 'Test12345#.' }, as: :json diff --git a/spec/support/request.rb b/spec/support/request.rb index 032f017dc..034a2aa7d 100644 --- a/spec/support/request.rb +++ b/spec/support/request.rb @@ -98,7 +98,7 @@ module ZammadSpecSupportRequest # @see FactoryBot#attributes_for # # @example - # attributes_params_for(:admin_user, email: 'custom@example.com') + # attributes_params_for(:admin, email: 'custom@example.com') # # => {firstname: 'Nicole', email: 'custom@example.com', ...} # # @return [Hash{Symbol => }] request cleaned attributes @@ -145,7 +145,7 @@ RSpec.configure do |config| # # In order for this to work, you must define the user in a `let` block first: # - # let(:user) { create(:customer_user) } + # let(:user) { create(:customer) } # config.before(:each, :authenticated_as, type: :request) do |example| user = authenticated_as_get_user example.metadata[:authenticated_as], return_type: :user diff --git a/spec/support/sends_notification_emails.rb b/spec/support/sends_notification_emails.rb index 5cb48fcd9..693085a16 100644 --- a/spec/support/sends_notification_emails.rb +++ b/spec/support/sends_notification_emails.rb @@ -11,7 +11,7 @@ module SendsNotificationEmailsHelper # # sent( # template: 'user_device_new', - # user: admin_user, + # user: admin, # ) # end # @@ -31,7 +31,7 @@ module SendsNotificationEmailsHelper # @example # not_sent( # template: 'user_device_new_location', - # user: admin_user, + # user: admin, # ) # # @return [nil] @@ -50,7 +50,7 @@ module SendsNotificationEmailsHelper # @example # sent( # template: 'user_device_new_location', - # user: admin_user, + # user: admin, # ) # # @return [nil] diff --git a/spec/system/ticket/create_spec.rb b/spec/system/ticket/create_spec.rb index 6862923f0..70f773341 100644 --- a/spec/system/ticket/create_spec.rb +++ b/spec/system/ticket/create_spec.rb @@ -4,7 +4,7 @@ require 'system/examples/text_modules_examples' RSpec.describe 'Ticket Create', type: :system do context 'when applying ticket templates' do - let(:agent) { create(:agent_user, groups: [permitted_group]) } + let(:agent) { create(:agent, groups: [permitted_group]) } let(:permitted_group) { create(:group) } let(:unpermitted_group) { create(:group) } let!(:template) { create(:template, :dummy_data, group: unpermitted_group, owner: agent) } @@ -64,7 +64,7 @@ RSpec.describe 'Ticket Create', type: :system do let(:email_address) { create(:email_address, email: system_email_address) } let(:group) { create(:group, email_address: email_address) } let(:agent_groups) { [group] } - let(:agent) { create(:agent_user, groups: agent_groups) } + let(:agent) { create(:agent, groups: agent_groups) } before do create(:smime_certificate, :with_private, fixture: system_email_address) @@ -73,7 +73,7 @@ RSpec.describe 'Ticket Create', type: :system do context 'recipient certificate present' do let(:recipient_email_address) { 'smime2@example.com' } - let(:customer) { create(:customer_user, email: recipient_email_address) } + let(:customer) { create(:customer, email: recipient_email_address) } before do create(:smime_certificate, fixture: recipient_email_address) diff --git a/spec/system/ticket/zoom_spec.rb b/spec/system/ticket/zoom_spec.rb index ab3d28971..1e4dba77b 100644 --- a/spec/system/ticket/zoom_spec.rb +++ b/spec/system/ticket/zoom_spec.rb @@ -178,7 +178,7 @@ RSpec.describe 'Ticket zoom', type: :system do context 'Group without signature' do let(:ticket) { create(:ticket) } - let(:current_user) { create(:agent_user, password: 'test', groups: [ticket.group]) } + let(:current_user) { create(:agent, password: 'test', groups: [ticket.group]) } before do # initial article to reply to @@ -208,28 +208,28 @@ RSpec.describe 'Ticket zoom', type: :system do end describe 'delete article', authenticated_as: :user do - let(:admin_user) { create :admin, groups: [Group.first] } - let(:agent_user) { create :agent, groups: [Group.first] } - let(:customer_user) { create :customer } - let(:ticket) { create :ticket, group: agent_user.groups.first, customer: customer_user } + let(:admin) { create :admin, groups: [Group.first] } + let(:agent) { create :agent, groups: [Group.first] } + let(:customer) { create :customer } + let(:ticket) { create :ticket, group: agent.groups.first, customer: customer } let(:article) { send(item) } def article_communication - create_ticket_article(sender_name: 'Agent', internal: false, type_name: 'email', updated_by: customer_user) + create_ticket_article(sender_name: 'Agent', internal: false, type_name: 'email', updated_by: customer) end def article_note - create_ticket_article(sender_name: 'Agent', internal: true, type_name: 'note', updated_by: agent_user) + create_ticket_article(sender_name: 'Agent', internal: true, type_name: 'note', updated_by: agent) end def article_note_customer - create_ticket_article(sender_name: 'Customer', internal: false, type_name: 'note', updated_by: customer_user) + create_ticket_article(sender_name: 'Customer', internal: false, type_name: 'note', updated_by: customer) end def article_note_communication create(:ticket_article_type, name: 'note_communication', communication: true) - create_ticket_article(sender_name: 'Agent', internal: true, type_name: 'note_communication', updated_by: agent_user) + create_ticket_article(sender_name: 'Agent', internal: true, type_name: 'note_communication', updated_by: agent) end def create_ticket_article(sender_name:, internal:, type_name:, updated_by:) @@ -242,7 +242,7 @@ RSpec.describe 'Ticket zoom', type: :system do context 'going through full stack' do context 'as admin' do - let(:user) { admin_user } + let(:user) { admin } let(:item) { 'article_communication' } let(:offset) { 0.minutes } @@ -294,7 +294,7 @@ RSpec.describe 'Ticket zoom', type: :system do end context 'as admin' do - let(:user) { admin_user } + let(:user) { admin } include_examples 'deleting ticket article', item: 'article_communication', @@ -314,7 +314,7 @@ RSpec.describe 'Ticket zoom', type: :system do end context 'as agent' do - let(:user) { agent_user } + let(:user) { agent } include_examples 'deleting ticket article', item: 'article_communication', @@ -334,7 +334,7 @@ RSpec.describe 'Ticket zoom', type: :system do end context 'as customer' do - let(:user) { customer_user } + let(:user) { customer } include_examples 'deleting ticket article', item: 'article_communication', @@ -350,13 +350,13 @@ RSpec.describe 'Ticket zoom', type: :system do before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 6000 } context 'as admin' do - let(:user) { admin_user } + let(:user) { admin } include_examples 'according to permission matrix', item: 'article_note', expects_visible: true, offset: 8000.seconds, description: 'outside of delete timeframe' end context 'as agent' do - let(:user) { agent_user } + let(:user) { agent } include_examples 'according to permission matrix', item: 'article_note', expects_visible: true, offset: 5000.seconds, description: 'outside of delete timeframe' include_examples 'according to permission matrix', item: 'article_note', expects_visible: false, offset: 8000.seconds, description: 'outside of delete timeframe' @@ -367,7 +367,7 @@ RSpec.describe 'Ticket zoom', type: :system do before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 0 } context 'as agent' do - let(:user) { agent_user } + let(:user) { agent } include_examples 'according to permission matrix', item: 'article_note', expects_visible: true, offset: 99.days, description: 'long after' end @@ -377,7 +377,7 @@ RSpec.describe 'Ticket zoom', type: :system do context 'button is hidden on the go' do before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 5 } - let(:user) { agent_user } + let(:user) { agent } let(:item) { 'article_note' } let!(:article) { send(item) } let(:offset) { 0.seconds } @@ -400,10 +400,10 @@ RSpec.describe 'Ticket zoom', type: :system do let(:email_address) { create(:email_address, email: system_email_address) } let(:group) { create(:group, email_address: email_address) } let(:agent_groups) { [group] } - let(:agent) { create(:agent_user, groups: agent_groups) } + let(:agent) { create(:agent, groups: agent_groups) } let(:sender_email_address) { 'smime2@example.com' } - let(:customer) { create(:customer_user, email: sender_email_address) } + let(:customer) { create(:customer, email: sender_email_address) } let!(:ticket) { create(:ticket, group: group, owner: agent, customer: customer) }