123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625 |
- require 'test_helper'
- class TicketScreenOptionsTest < ActiveSupport::TestCase
- test 'base' do
- group1 = Group.create!(
- name: 'Group 1',
- active: true,
- email_address: EmailAddress.first,
- created_by_id: 1,
- updated_by_id: 1,
- )
- group2 = Group.create!(
- name: 'Group 2',
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- group3 = Group.create!(
- name: 'Group 3',
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- agent1 = User.create!(
- login: 'agent1@example.com',
- firstname: 'Role',
- lastname: 'Agent1',
- email: 'agent1@example.com',
- password: 'agentpw',
- active: true,
- roles: Role.where(name: %w[Admin Agent]),
- updated_by_id: 1,
- created_by_id: 1,
- )
- agent1.group_names_access_map = {
- group1.name => 'full',
- group2.name => %w[read change],
- group3.name => 'full',
- }
- agent2 = User.create!(
- login: 'agent2@example.com',
- firstname: 'Role',
- lastname: 'Agent2',
- email: 'agent2@example.com',
- password: 'agentpw',
- active: true,
- roles: Role.where(name: %w[Admin Agent]),
- updated_by_id: 1,
- created_by_id: 1,
- )
- agent2.group_names_access_map = {
- group1.name => 'full',
- group2.name => %w[read change],
- group3.name => ['create'],
- }
- agent3 = User.create!(
- login: 'agent3@example.com',
- firstname: 'Role',
- lastname: 'Agent3',
- email: 'agent3@example.com',
- password: 'agentpw',
- active: true,
- roles: Role.where(name: %w[Admin Agent]),
- updated_by_id: 1,
- created_by_id: 1,
- )
- agent3.group_names_access_map = {
- group1.name => 'full',
- group2.name => ['full'],
- }
- agent4 = User.create!(
- login: 'agent4@example.com',
- firstname: 'Role',
- lastname: 'Agent4',
- email: 'agent4@example.com',
- password: 'agentpw',
- active: true,
- roles: Role.where(name: %w[Admin Agent]),
- updated_by_id: 1,
- created_by_id: 1,
- )
- agent4.group_names_access_map = {
- group1.name => 'full',
- group2.name => %w[read overview change],
- }
- agent5 = User.create!(
- login: 'agent5@example.com',
- firstname: 'Role',
- lastname: 'Agent5',
- email: 'agent5@example.com',
- password: 'agentpw',
- active: true,
- roles: Role.where(name: %w[Admin Agent]),
- updated_by_id: 1,
- created_by_id: 1,
- )
- agent5.group_names_access_map = {
- group3.name => 'full',
- }
- agent6 = User.create!(
- login: 'agent6@example.com',
- firstname: 'Role',
- lastname: 'Agent6',
- email: 'agent6@example.com',
- password: 'agentpw',
- active: true,
- roles: Role.where(name: %w[Admin Agent]),
- updated_by_id: 1,
- created_by_id: 1,
- )
- result = Ticket::ScreenOptions.attributes_to_change(
- current_user: agent1,
- )
- assert(result[:form_meta])
- assert(result[:form_meta][:filter])
- assert(result[:form_meta][:filter][:state_id])
- assert_equal([
- Ticket::State.lookup(name: 'open').id,
- Ticket::State.lookup(name: 'pending reminder').id,
- Ticket::State.lookup(name: 'closed').id,
- Ticket::State.lookup(name: 'pending close').id,
- ], result[:form_meta][:filter][:state_id].sort)
- assert(result[:form_meta][:filter][:priority_id])
- assert_equal([
- Ticket::Priority.lookup(name: '1 low').id,
- Ticket::Priority.lookup(name: '2 normal').id,
- Ticket::Priority.lookup(name: '3 high').id,
- ], result[:form_meta][:filter][:priority_id].sort)
- assert(result[:form_meta][:filter][:type_id])
- assert_equal([], result[:form_meta][:filter][:type_id].sort)
- assert(result[:form_meta][:filter][:group_id])
- assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
- assert(result[:form_meta][:dependencies])
- assert(result[:form_meta][:dependencies][:group_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
- assert(result[:form_meta][:dependencies][:group_id][''])
- assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
- assert(result[:form_meta][:dependencies][:group_id][group3.id])
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id])
- assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent5.id))
- result = Ticket::ScreenOptions.attributes_to_change(
- current_user: agent2,
- )
- assert(result[:form_meta])
- assert(result[:form_meta][:filter])
- assert(result[:form_meta][:filter][:state_id])
- assert_equal([
- Ticket::State.lookup(name: 'open').id,
- Ticket::State.lookup(name: 'pending reminder').id,
- Ticket::State.lookup(name: 'closed').id,
- Ticket::State.lookup(name: 'pending close').id,
- ], result[:form_meta][:filter][:state_id].sort)
- assert(result[:form_meta][:filter][:priority_id])
- assert_equal([
- Ticket::Priority.lookup(name: '1 low').id,
- Ticket::Priority.lookup(name: '2 normal').id,
- Ticket::Priority.lookup(name: '3 high').id,
- ], result[:form_meta][:filter][:priority_id].sort)
- assert(result[:form_meta][:filter][:type_id])
- assert_equal([], result[:form_meta][:filter][:type_id].sort)
- assert(result[:form_meta][:filter][:group_id])
- assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
- assert(result[:form_meta][:dependencies])
- assert(result[:form_meta][:dependencies][:group_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
- assert(result[:form_meta][:dependencies][:group_id][''])
- assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
- assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent5.id))
- result = Ticket::ScreenOptions.attributes_to_change(
- current_user: agent3,
- )
- assert(result[:form_meta])
- assert(result[:form_meta][:filter])
- assert(result[:form_meta][:filter][:state_id])
- assert_equal([
- Ticket::State.lookup(name: 'open').id,
- Ticket::State.lookup(name: 'pending reminder').id,
- Ticket::State.lookup(name: 'closed').id,
- Ticket::State.lookup(name: 'pending close').id,
- ], result[:form_meta][:filter][:state_id].sort)
- assert(result[:form_meta][:filter][:priority_id])
- assert_equal([
- Ticket::Priority.lookup(name: '1 low').id,
- Ticket::Priority.lookup(name: '2 normal').id,
- Ticket::Priority.lookup(name: '3 high').id,
- ], result[:form_meta][:filter][:priority_id].sort)
- assert(result[:form_meta][:filter][:type_id])
- assert_equal([], result[:form_meta][:filter][:type_id].sort)
- assert(result[:form_meta][:filter][:group_id])
- assert_equal([group1.id, group2.id], result[:form_meta][:filter][:group_id].sort)
- assert(result[:form_meta][:dependencies])
- assert(result[:form_meta][:dependencies][:group_id])
- assert_equal(3, result[:form_meta][:dependencies][:group_id].count)
- assert(result[:form_meta][:dependencies][:group_id][''])
- assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
- assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
- ticket1 = Ticket.create!(
- title: 'some title 1',
- group: group1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- article1 = Ticket::Article.create!(
- ticket_id: ticket1.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Customer'),
- type: Ticket::Article::Type.find_by(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket2 = Ticket.create!(
- title: 'some title 2',
- group: group2,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- article2 = Ticket::Article.create!(
- ticket_id: ticket2.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Customer'),
- type: Ticket::Article::Type.find_by(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- result = Ticket::ScreenOptions.attributes_to_change(
- ticket_id: ticket1.id,
- current_user: agent1,
- )
- assert(result[:form_meta])
- assert(result[:form_meta][:filter])
- assert(result[:form_meta][:filter][:state_id])
- assert_equal([
- Ticket::State.lookup(name: 'new').id,
- Ticket::State.lookup(name: 'open').id,
- Ticket::State.lookup(name: 'pending reminder').id,
- Ticket::State.lookup(name: 'closed').id,
- Ticket::State.lookup(name: 'pending close').id,
- ], result[:form_meta][:filter][:state_id].sort)
- assert(result[:form_meta][:filter][:priority_id])
- assert_equal([
- Ticket::Priority.lookup(name: '1 low').id,
- Ticket::Priority.lookup(name: '2 normal').id,
- Ticket::Priority.lookup(name: '3 high').id,
- ], result[:form_meta][:filter][:priority_id].sort)
- assert(result[:form_meta][:filter][:type_id])
- assert_equal([
- Ticket::Article::Type.lookup(name: 'email').id,
- Ticket::Article::Type.lookup(name: 'phone').id,
- Ticket::Article::Type.lookup(name: 'note').id,
- ], result[:form_meta][:filter][:type_id].sort)
- assert(result[:form_meta][:filter][:group_id])
- assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
- assert(result[:form_meta][:dependencies])
- assert(result[:form_meta][:dependencies][:group_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
- assert(result[:form_meta][:dependencies][:group_id][''])
- assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
- assert(result[:form_meta][:dependencies][:group_id][group2.id])
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
- assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group3.id])
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id])
- assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent5.id))
- result = Ticket::ScreenOptions.attributes_to_change(
- ticket_id: ticket2.id,
- current_user: agent1,
- )
- assert(result[:form_meta])
- assert(result[:form_meta][:filter])
- assert(result[:form_meta][:filter][:state_id])
- assert_equal([
- Ticket::State.lookup(name: 'new').id,
- Ticket::State.lookup(name: 'open').id,
- Ticket::State.lookup(name: 'pending reminder').id,
- Ticket::State.lookup(name: 'closed').id,
- Ticket::State.lookup(name: 'pending close').id,
- ], result[:form_meta][:filter][:state_id].sort)
- assert(result[:form_meta][:filter][:priority_id])
- assert_equal([
- Ticket::Priority.lookup(name: '1 low').id,
- Ticket::Priority.lookup(name: '2 normal').id,
- Ticket::Priority.lookup(name: '3 high').id,
- ], result[:form_meta][:filter][:priority_id].sort)
- assert(result[:form_meta][:filter][:type_id])
- assert_equal([
- Ticket::Article::Type.lookup(name: 'phone').id,
- Ticket::Article::Type.lookup(name: 'note').id,
- ], result[:form_meta][:filter][:type_id].sort)
- assert(result[:form_meta][:filter][:group_id])
- assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
- assert(result[:form_meta][:dependencies])
- assert(result[:form_meta][:dependencies][:group_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
- assert(result[:form_meta][:dependencies][:group_id][''])
- assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
- assert(result[:form_meta][:dependencies][:group_id][group2.id])
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
- assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group3.id])
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id])
- assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent5.id))
- result = Ticket::ScreenOptions.attributes_to_change(
- ticket_id: ticket2.id,
- current_user: agent1,
- )
- assert(result[:form_meta])
- assert(result[:form_meta][:filter])
- assert(result[:form_meta][:filter][:state_id])
- assert_equal([
- Ticket::State.lookup(name: 'new').id,
- Ticket::State.lookup(name: 'open').id,
- Ticket::State.lookup(name: 'pending reminder').id,
- Ticket::State.lookup(name: 'closed').id,
- Ticket::State.lookup(name: 'pending close').id,
- ], result[:form_meta][:filter][:state_id].sort)
- assert(result[:form_meta][:filter][:priority_id])
- assert_equal([
- Ticket::Priority.lookup(name: '1 low').id,
- Ticket::Priority.lookup(name: '2 normal').id,
- Ticket::Priority.lookup(name: '3 high').id,
- ], result[:form_meta][:filter][:priority_id].sort)
- assert(result[:form_meta][:filter][:type_id])
- assert_equal([
- Ticket::Article::Type.lookup(name: 'phone').id,
- Ticket::Article::Type.lookup(name: 'note').id,
- ], result[:form_meta][:filter][:type_id].sort)
- assert(result[:form_meta][:filter][:group_id])
- assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
- assert(result[:form_meta][:dependencies])
- assert(result[:form_meta][:dependencies][:group_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
- assert(result[:form_meta][:dependencies][:group_id][''])
- assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
- assert(result[:form_meta][:dependencies][:group_id][group2.id])
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
- assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group3.id])
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id])
- assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].include?(agent5.id))
- result = Ticket::ScreenOptions.attributes_to_change(
- ticket_id: ticket1.id,
- current_user: agent2,
- )
- assert(result[:form_meta])
- assert(result[:form_meta][:filter])
- assert(result[:form_meta][:filter][:state_id])
- assert_equal([
- Ticket::State.lookup(name: 'new').id,
- Ticket::State.lookup(name: 'open').id,
- Ticket::State.lookup(name: 'pending reminder').id,
- Ticket::State.lookup(name: 'closed').id,
- Ticket::State.lookup(name: 'pending close').id,
- ], result[:form_meta][:filter][:state_id].sort)
- assert(result[:form_meta][:filter][:priority_id])
- assert_equal([
- Ticket::Priority.lookup(name: '1 low').id,
- Ticket::Priority.lookup(name: '2 normal').id,
- Ticket::Priority.lookup(name: '3 high').id,
- ], result[:form_meta][:filter][:priority_id].sort)
- assert(result[:form_meta][:filter][:type_id])
- assert_equal([
- Ticket::Article::Type.lookup(name: 'email').id,
- Ticket::Article::Type.lookup(name: 'phone').id,
- Ticket::Article::Type.lookup(name: 'note').id,
- ], result[:form_meta][:filter][:type_id].sort)
- assert(result[:form_meta][:filter][:group_id])
- assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
- assert(result[:form_meta][:dependencies])
- assert(result[:form_meta][:dependencies][:group_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
- assert(result[:form_meta][:dependencies][:group_id][''])
- assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
- assert(result[:form_meta][:dependencies][:group_id][group2.id])
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
- assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
- result = Ticket::ScreenOptions.attributes_to_change(
- ticket_id: ticket2.id,
- current_user: agent2,
- )
- assert(result[:form_meta])
- assert(result[:form_meta][:filter])
- assert(result[:form_meta][:filter][:state_id])
- assert_equal([
- Ticket::State.lookup(name: 'new').id,
- Ticket::State.lookup(name: 'open').id,
- Ticket::State.lookup(name: 'pending reminder').id,
- Ticket::State.lookup(name: 'closed').id,
- Ticket::State.lookup(name: 'pending close').id,
- ], result[:form_meta][:filter][:state_id].sort)
- assert(result[:form_meta][:filter][:priority_id])
- assert_equal([
- Ticket::Priority.lookup(name: '1 low').id,
- Ticket::Priority.lookup(name: '2 normal').id,
- Ticket::Priority.lookup(name: '3 high').id,
- ], result[:form_meta][:filter][:priority_id].sort)
- assert(result[:form_meta][:filter][:type_id])
- assert_equal([
- Ticket::Article::Type.lookup(name: 'phone').id,
- Ticket::Article::Type.lookup(name: 'note').id,
- ], result[:form_meta][:filter][:type_id].sort)
- assert(result[:form_meta][:filter][:group_id])
- assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
- assert(result[:form_meta][:dependencies])
- assert(result[:form_meta][:dependencies][:group_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
- assert(result[:form_meta][:dependencies][:group_id][''])
- assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
- assert(result[:form_meta][:dependencies][:group_id][group2.id])
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
- assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
- result = Ticket::ScreenOptions.attributes_to_change(
- ticket_id: ticket1.id,
- current_user: agent3,
- )
- assert(result[:form_meta])
- assert(result[:form_meta][:filter])
- assert(result[:form_meta][:filter][:state_id])
- assert_equal([
- Ticket::State.lookup(name: 'new').id,
- Ticket::State.lookup(name: 'open').id,
- Ticket::State.lookup(name: 'pending reminder').id,
- Ticket::State.lookup(name: 'closed').id,
- Ticket::State.lookup(name: 'pending close').id,
- ], result[:form_meta][:filter][:state_id].sort)
- assert(result[:form_meta][:filter][:priority_id])
- assert_equal([
- Ticket::Priority.lookup(name: '1 low').id,
- Ticket::Priority.lookup(name: '2 normal').id,
- Ticket::Priority.lookup(name: '3 high').id,
- ], result[:form_meta][:filter][:priority_id].sort)
- assert(result[:form_meta][:filter][:type_id])
- assert_equal([
- Ticket::Article::Type.lookup(name: 'email').id,
- Ticket::Article::Type.lookup(name: 'phone').id,
- Ticket::Article::Type.lookup(name: 'note').id,
- ], result[:form_meta][:filter][:type_id].sort)
- assert(result[:form_meta][:filter][:group_id])
- assert_equal([group1.id, group2.id], result[:form_meta][:filter][:group_id].sort)
- assert(result[:form_meta][:dependencies])
- assert(result[:form_meta][:dependencies][:group_id])
- assert_equal(3, result[:form_meta][:dependencies][:group_id].count)
- assert(result[:form_meta][:dependencies][:group_id][''])
- assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
- assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
- result = Ticket::ScreenOptions.attributes_to_change(
- ticket_id: ticket2.id,
- current_user: agent3,
- )
- assert(result[:form_meta])
- assert(result[:form_meta][:filter])
- assert(result[:form_meta][:filter][:state_id])
- assert_equal([
- Ticket::State.lookup(name: 'new').id,
- Ticket::State.lookup(name: 'open').id,
- Ticket::State.lookup(name: 'pending reminder').id,
- Ticket::State.lookup(name: 'closed').id,
- Ticket::State.lookup(name: 'pending close').id,
- ], result[:form_meta][:filter][:state_id].sort)
- assert(result[:form_meta][:filter][:priority_id])
- assert_equal([
- Ticket::Priority.lookup(name: '1 low').id,
- Ticket::Priority.lookup(name: '2 normal').id,
- Ticket::Priority.lookup(name: '3 high').id,
- ], result[:form_meta][:filter][:priority_id].sort)
- assert(result[:form_meta][:filter][:type_id])
- assert_equal([
- Ticket::Article::Type.lookup(name: 'phone').id,
- Ticket::Article::Type.lookup(name: 'note').id,
- ], result[:form_meta][:filter][:type_id].sort)
- assert(result[:form_meta][:filter][:group_id])
- assert_equal([group1.id, group2.id], result[:form_meta][:filter][:group_id].sort)
- assert(result[:form_meta][:dependencies])
- assert(result[:form_meta][:dependencies][:group_id])
- assert_equal(3, result[:form_meta][:dependencies][:group_id].count)
- assert(result[:form_meta][:dependencies][:group_id][''])
- assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id])
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id])
- assert_equal(4, result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent1.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
- assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
- assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
- assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
- end
- end
|