123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979 |
- require 'test_helper'
- class TicketOverviewTest < ActiveSupport::TestCase
- setup do
- group = Group.create_or_update(
- name: 'OverviewTest',
- updated_at: '2015-02-05 16:37:00',
- updated_by_id: 1,
- created_by_id: 1,
- )
- roles = Role.where(name: 'Agent')
- @agent1 = User.create_or_update(
- login: 'ticket-overview-agent1@example.com',
- firstname: 'Overview',
- lastname: 'Agent1',
- email: 'ticket-overview-agent1@example.com',
- password: 'agentpw',
- active: true,
- roles: roles,
- groups: [group],
- updated_at: '2015-02-05 16:37:00',
- updated_by_id: 1,
- created_by_id: 1,
- )
- @agent2 = User.create_or_update(
- login: 'ticket-overview-agent2@example.com',
- firstname: 'Overview',
- lastname: 'Agent2',
- email: 'ticket-overview-agent2@example.com',
- password: 'agentpw',
- active: true,
- roles: roles,
- #groups: groups,
- updated_at: '2015-02-05 16:38:00',
- updated_by_id: 1,
- created_by_id: 1,
- )
- roles = Role.where(name: 'Customer')
- organization1 = Organization.create_or_update(
- name: 'Overview Org',
- updated_at: '2015-02-05 16:37:00',
- updated_by_id: 1,
- created_by_id: 1,
- )
- @customer1 = User.create_or_update(
- login: 'ticket-overview-customer1@example.com',
- firstname: 'Overview',
- lastname: 'Customer1',
- email: 'ticket-overview-customer1@example.com',
- password: 'customerpw',
- active: true,
- organization_id: organization1.id,
- roles: roles,
- updated_at: '2015-02-05 16:37:00',
- updated_by_id: 1,
- created_by_id: 1,
- )
- @customer2 = User.create_or_update(
- login: 'ticket-overview-customer2@example.com',
- firstname: 'Overview',
- lastname: 'Customer2',
- email: 'ticket-overview-customer2@example.com',
- password: 'customerpw',
- active: true,
- organization_id: organization1.id,
- roles: roles,
- updated_at: '2015-02-05 16:37:00',
- updated_by_id: 1,
- created_by_id: 1,
- )
- @customer3 = User.create_or_update(
- login: 'ticket-overview-customer3@example.com',
- firstname: 'Overview',
- lastname: 'Customer3',
- email: 'ticket-overview-customer3@example.com',
- password: 'customerpw',
- active: true,
- organization_id: nil,
- roles: roles,
- updated_at: '2015-02-05 16:37:00',
- updated_by_id: 1,
- created_by_id: 1,
- )
- Overview.destroy_all
- UserInfo.current_user_id = 1
- overview_role = Role.find_by(name: 'Agent')
- @overview1 = Overview.create_or_update(
- name: 'My assigned Tickets',
- link: 'my_assigned',
- prio: 1000,
- role_ids: [overview_role.id],
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3, 7],
- },
- 'ticket.owner_id' => {
- operator: 'is',
- pre_condition: 'current_user.id',
- },
- },
- order: {
- by: 'created_at',
- direction: 'ASC',
- },
- view: {
- d: %w[title customer group created_at],
- s: %w[title customer group created_at],
- m: %w[number title customer group created_at],
- view_mode_default: 's',
- },
- )
- @overview2 = Overview.create_or_update(
- name: 'Unassigned & Open',
- link: 'all_unassigned',
- prio: 1010,
- role_ids: [overview_role.id],
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- 'ticket.owner_id' => {
- operator: 'is',
- value: 1,
- },
- },
- order: {
- by: 'created_at',
- direction: 'ASC',
- },
- view: {
- d: %w[title customer group created_at],
- s: %w[title customer group created_at],
- m: %w[number title customer group created_at],
- view_mode_default: 's',
- },
- )
- @overview3 = Overview.create_or_update(
- name: 'My Tickets 2',
- link: 'my_tickets_2',
- prio: 1020,
- role_ids: [overview_role.id],
- user_ids: [@agent2.id],
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3, 7],
- },
- 'ticket.owner_id' => {
- operator: 'is',
- pre_condition: 'current_user.id',
- },
- },
- order: {
- by: 'created_at',
- direction: 'ASC',
- },
- view: {
- d: %w[title customer group created_at],
- s: %w[title customer group created_at],
- m: %w[number title customer group created_at],
- view_mode_default: 's',
- },
- )
- @overview4 = Overview.create_or_update(
- name: 'My Tickets only with Note',
- link: 'my_tickets_onyl_with_note',
- prio: 1030,
- role_ids: [overview_role.id],
- user_ids: [@agent1.id],
- condition: {
- 'article.type_id' => {
- operator: 'is',
- value: Ticket::Article::Type.find_by(name: 'note').id,
- },
- 'ticket.owner_id' => {
- operator: 'is',
- pre_condition: 'current_user.id',
- },
- },
- order: {
- by: 'created_at',
- direction: 'ASC',
- },
- view: {
- d: %w[title customer group created_at],
- s: %w[title customer group created_at],
- m: %w[number title customer group created_at],
- view_mode_default: 's',
- },
- )
- overview_role = Role.find_by(name: 'Customer')
- @overview5 = Overview.create_or_update(
- name: 'My Tickets',
- link: 'my_tickets',
- prio: 1100,
- role_ids: [overview_role.id],
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3, 4, 6, 7],
- },
- 'ticket.customer_id' => {
- operator: 'is',
- pre_condition: 'current_user.id',
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title state created_at],
- m: %w[number title state created_at],
- view_mode_default: 's',
- },
- )
- @overview6 = Overview.create_or_update(
- name: 'My Organization Tickets',
- link: 'my_organization_tickets',
- prio: 1200,
- role_ids: [overview_role.id],
- organization_shared: true,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3, 4, 6, 7],
- },
- 'ticket.organization_id' => {
- operator: 'is',
- pre_condition: 'current_user.organization_id',
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- @overview7 = Overview.create_or_update(
- name: 'My Organization Tickets (open)',
- link: 'my_organization_tickets_open',
- prio: 1200,
- role_ids: [overview_role.id],
- user_ids: [@customer2.id],
- organization_shared: true,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- 'ticket.organization_id' => {
- operator: 'is',
- pre_condition: 'current_user.organization_id',
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- overview_role = Role.find_by(name: 'Admin')
- @overview8 = Overview.create_or_update(
- name: 'Not Shown Admin',
- link: 'not_shown_admin',
- prio: 9900,
- role_ids: [overview_role.id],
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- end
- test 'overview index' do
- result = Ticket::Overviews.all(
- current_user: @agent1,
- )
- assert_equal(3, result.count)
- assert_equal('My assigned Tickets', result[0].name)
- assert_equal('Unassigned & Open', result[1].name)
- assert_equal('My Tickets only with Note', result[2].name)
- result = Ticket::Overviews.all(
- current_user: @agent2,
- )
- assert_equal(3, result.count)
- assert_equal('My assigned Tickets', result[0].name)
- assert_equal('Unassigned & Open', result[1].name)
- assert_equal('My Tickets 2', result[2].name)
- result = Ticket::Overviews.all(
- current_user: @customer1,
- )
- assert_equal(2, result.count)
- assert_equal('My Tickets', result[0].name)
- assert_equal('My Organization Tickets', result[1].name)
- result = Ticket::Overviews.all(
- current_user: @customer2,
- )
- assert_equal(3, result.count)
- assert_equal('My Tickets', result[0].name)
- assert_equal('My Organization Tickets', result[1].name)
- assert_equal('My Organization Tickets (open)', result[2].name)
- result = Ticket::Overviews.all(
- current_user: @customer3,
- )
- assert_equal(1, result.count)
- assert_equal('My Tickets', result[0].name)
- end
- test 'missing role' do
- Ticket.destroy_all
- assert_raises(Exception) do
- Overview.create!(
- name: 'new overview',
- link: 'new_overview',
- prio: 1200,
- user_ids: [@customer2.id],
- organization_shared: true,
- condition: {
- 'ticket.state_id' => {
- operator: 'is',
- value: [1, 2, 3],
- },
- 'ticket.organization_id' => {
- operator: 'is',
- pre_condition: 'current_user.organization_id',
- },
- },
- order: {
- by: 'created_at',
- direction: 'DESC',
- },
- view: {
- d: %w[title customer state created_at],
- s: %w[number title customer state created_at],
- m: %w[number title customer state created_at],
- view_mode_default: 's',
- },
- )
- end
- end
- test 'overview content' do
- Ticket.destroy_all
- result = Ticket::Overviews.index(@agent1)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert(result[1][:tickets].blank?)
- assert_equal(result[1][:count], 0)
- assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
- assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- assert_equal(result[2][:count], 0)
- result = Ticket::Overviews.index(@agent2)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert(result[1][:tickets].blank?)
- assert_equal(result[1][:count], 0)
- assert_equal(result[2][:overview][:name], 'My Tickets 2')
- assert_equal(result[2][:overview][:view], 'my_tickets_2')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- ticket1 = Ticket.create!(
- title: 'overview test 1',
- group: Group.lookup(name: 'OverviewTest'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- 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... 123',
- 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::Overviews.index(@agent1)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert_not(result[1][:tickets].blank?)
- assert_equal(result[1][:tickets][0][:id], ticket1.id)
- assert_equal(result[1][:count], 1)
- assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
- assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- assert_equal(result[2][:count], 0)
- result = Ticket::Overviews.index(@agent2)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert(result[1][:tickets].blank?)
- assert_equal(result[1][:count], 0)
- assert_equal(result[2][:overview][:name], 'My Tickets 2')
- assert_equal(result[2][:overview][:view], 'my_tickets_2')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- travel 1.second # because of mysql millitime issues
- ticket2 = Ticket.create!(
- title: 'overview test 2',
- group: Group.lookup(name: 'OverviewTest'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '3 high'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- 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... 123',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Agent'),
- type: Ticket::Article::Type.find_by(name: 'note'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- result = Ticket::Overviews.index(@agent1)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert_not(result[1][:tickets].blank?)
- assert_equal(result[1][:tickets][0][:id], ticket1.id)
- assert_equal(result[1][:tickets][1][:id], ticket2.id)
- assert_equal(result[1][:count], 2)
- assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
- assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- assert_equal(result[2][:count], 0)
- result = Ticket::Overviews.index(@agent2)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert(result[1][:tickets].blank?)
- assert_equal(result[1][:count], 0)
- assert_equal(result[2][:overview][:name], 'My Tickets 2')
- assert_equal(result[2][:overview][:view], 'my_tickets_2')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- ticket2.owner_id = @agent1.id
- ticket2.save!
- result = Ticket::Overviews.index(@agent1)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[0][:tickets][0][:id], ticket2.id)
- assert_equal(result[0][:count], 1)
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert_not(result[1][:tickets].blank?)
- assert_equal(result[1][:tickets][0][:id], ticket1.id)
- assert_equal(result[1][:count], 1)
- assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
- assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
- assert_equal(result[2][:tickets].class, Array)
- assert_equal(result[2][:tickets][0][:id], ticket2.id)
- assert_equal(result[2][:count], 1)
- result = Ticket::Overviews.index(@agent2)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert(result[1][:tickets].blank?)
- assert_equal(result[1][:count], 0)
- assert_equal(result[2][:overview][:name], 'My Tickets 2')
- assert_equal(result[2][:overview][:view], 'my_tickets_2')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- travel 1.second # because of mysql millitime issues
- ticket3 = Ticket.create!(
- title: 'overview test 3',
- group: Group.lookup(name: 'OverviewTest'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '1 low'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- Ticket::Article.create!(
- ticket_id: ticket3.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message... 123',
- 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,
- )
- travel_back
- result = Ticket::Overviews.index(@agent1)
- assert_equal(result[0][:overview][:id], @overview1.id)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[0][:tickets][0][:id], ticket2.id)
- assert_equal(result[0][:count], 1)
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[1][:overview][:id], @overview2.id)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert_not(result[1][:tickets].blank?)
- assert_equal(result[1][:tickets][0][:id], ticket1.id)
- assert_equal(result[1][:tickets][1][:id], ticket3.id)
- assert_equal(result[1][:count], 2)
- assert_equal(result[2][:overview][:id], @overview4.id)
- assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
- assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
- assert_equal(result[2][:tickets].class, Array)
- assert_equal(result[2][:tickets][0][:id], ticket2.id)
- assert_equal(result[2][:count], 1)
- result = Ticket::Overviews.index(@agent2)
- assert_equal(result[0][:overview][:id], @overview1.id)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:id], @overview2.id)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert(result[1][:tickets].blank?)
- assert_equal(result[1][:count], 0)
- assert_equal(result[2][:overview][:id], @overview3.id)
- assert_equal(result[2][:overview][:name], 'My Tickets 2')
- assert_equal(result[2][:overview][:view], 'my_tickets_2')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- @overview2.order = {
- by: 'created_at',
- direction: 'DESC',
- }
- @overview2.save!
- result = Ticket::Overviews.index(@agent1)
- assert_equal(result[0][:overview][:id], @overview1.id)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[0][:tickets][0][:id], ticket2.id)
- assert_equal(result[0][:count], 1)
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[1][:overview][:id], @overview2.id)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert_not(result[1][:tickets].blank?)
- assert_equal(result[1][:tickets][0][:id], ticket3.id)
- assert_equal(result[1][:tickets][1][:id], ticket1.id)
- assert_equal(result[1][:count], 2)
- assert_equal(result[2][:overview][:id], @overview4.id)
- assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
- assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
- assert_equal(result[2][:tickets].class, Array)
- assert_equal(result[2][:tickets][0][:id], ticket2.id)
- assert_equal(result[2][:count], 1)
- result = Ticket::Overviews.index(@agent2)
- assert_equal(result[0][:overview][:id], @overview1.id)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:id], @overview2.id)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert(result[1][:tickets].blank?)
- assert_equal(result[1][:count], 0)
- assert_equal(result[2][:overview][:id], @overview3.id)
- assert_equal(result[2][:overview][:name], 'My Tickets 2')
- assert_equal(result[2][:overview][:view], 'my_tickets_2')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- @overview2.order = {
- by: 'priority_id',
- direction: 'DESC',
- }
- @overview2.save!
- result = Ticket::Overviews.index(@agent1)
- assert_equal(result[0][:overview][:id], @overview1.id)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[0][:tickets][0][:id], ticket2.id)
- assert_equal(result[0][:count], 1)
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[1][:overview][:id], @overview2.id)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert_not(result[1][:tickets].blank?)
- assert_equal(result[1][:tickets][0][:id], ticket1.id)
- assert_equal(result[1][:tickets][1][:id], ticket3.id)
- assert_equal(result[1][:count], 2)
- assert_equal(result[2][:overview][:id], @overview4.id)
- assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
- assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
- assert_equal(result[2][:tickets].class, Array)
- assert_equal(result[2][:tickets][0][:id], ticket2.id)
- assert_equal(result[2][:count], 1)
- result = Ticket::Overviews.index(@agent2)
- assert_equal(result[0][:overview][:id], @overview1.id)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:id], @overview2.id)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert(result[1][:tickets].blank?)
- assert_equal(result[1][:count], 0)
- assert_equal(result[2][:overview][:id], @overview3.id)
- assert_equal(result[2][:overview][:name], 'My Tickets 2')
- assert_equal(result[2][:overview][:view], 'my_tickets_2')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- @overview2.order = {
- by: 'priority_id',
- direction: 'ASC',
- }
- @overview2.save!
- result = Ticket::Overviews.index(@agent1)
- assert_equal(result[0][:overview][:id], @overview1.id)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[0][:tickets][0][:id], ticket2.id)
- assert_equal(result[0][:count], 1)
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[1][:overview][:id], @overview2.id)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert_not(result[1][:tickets].blank?)
- assert_equal(result[1][:tickets][0][:id], ticket3.id)
- assert_equal(result[1][:tickets][1][:id], ticket1.id)
- assert_equal(result[1][:count], 2)
- assert_equal(result[2][:overview][:id], @overview4.id)
- assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
- assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
- assert_equal(result[2][:tickets].class, Array)
- assert_equal(result[2][:tickets][0][:id], ticket2.id)
- assert_equal(result[2][:count], 1)
- result = Ticket::Overviews.index(@agent2)
- assert_equal(result[0][:overview][:id], @overview1.id)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:id], @overview2.id)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert(result[1][:tickets].blank?)
- assert_equal(result[1][:count], 0)
- assert_equal(result[2][:overview][:id], @overview3.id)
- assert_equal(result[2][:overview][:name], 'My Tickets 2')
- assert_equal(result[2][:overview][:view], 'my_tickets_2')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- @overview2.order = {
- by: 'priority',
- direction: 'DESC',
- }
- @overview2.save!
- result = Ticket::Overviews.index(@agent1)
- assert_equal(result[0][:overview][:id], @overview1.id)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[0][:tickets][0][:id], ticket2.id)
- assert_equal(result[0][:count], 1)
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[1][:overview][:id], @overview2.id)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert_not(result[1][:tickets].blank?)
- assert_equal(result[1][:tickets][0][:id], ticket1.id)
- assert_equal(result[1][:tickets][1][:id], ticket3.id)
- assert_equal(result[1][:count], 2)
- assert_equal(result[2][:overview][:id], @overview4.id)
- assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
- assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
- assert_equal(result[2][:tickets].class, Array)
- assert_equal(result[2][:tickets][0][:id], ticket2.id)
- assert_equal(result[2][:count], 1)
- result = Ticket::Overviews.index(@agent2)
- assert_equal(result[0][:overview][:id], @overview1.id)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:id], @overview2.id)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert(result[1][:tickets].blank?)
- assert_equal(result[1][:count], 0)
- assert_equal(result[2][:overview][:id], @overview3.id)
- assert_equal(result[2][:overview][:name], 'My Tickets 2')
- assert_equal(result[2][:overview][:view], 'my_tickets_2')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- @overview2.order = {
- by: 'priority',
- direction: 'ASC',
- }
- @overview2.save!
- result = Ticket::Overviews.index(@agent1)
- assert_equal(result[0][:overview][:id], @overview1.id)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[0][:tickets][0][:id], ticket2.id)
- assert_equal(result[0][:count], 1)
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[1][:overview][:id], @overview2.id)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert_not(result[1][:tickets].blank?)
- assert_equal(result[1][:tickets][0][:id], ticket3.id)
- assert_equal(result[1][:tickets][1][:id], ticket1.id)
- assert_equal(result[1][:count], 2)
- assert_equal(result[2][:overview][:id], @overview4.id)
- assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
- assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
- assert_equal(result[2][:tickets].class, Array)
- assert_equal(result[2][:tickets][0][:id], ticket2.id)
- assert_equal(result[2][:count], 1)
- result = Ticket::Overviews.index(@agent2)
- assert_equal(result[0][:overview][:id], @overview1.id)
- assert_equal(result[0][:overview][:name], 'My assigned Tickets')
- assert_equal(result[0][:overview][:view], 'my_assigned')
- assert_equal(result[0][:count], 0)
- assert_equal(result[0][:tickets].class, Array)
- assert(result[0][:tickets].blank?)
- assert_equal(result[1][:overview][:id], @overview2.id)
- assert_equal(result[1][:overview][:name], 'Unassigned & Open')
- assert_equal(result[1][:overview][:view], 'all_unassigned')
- assert_equal(result[1][:tickets].class, Array)
- assert(result[1][:tickets].blank?)
- assert_equal(result[1][:count], 0)
- assert_equal(result[2][:overview][:id], @overview3.id)
- assert_equal(result[2][:overview][:name], 'My Tickets 2')
- assert_equal(result[2][:overview][:view], 'my_tickets_2')
- assert_equal(result[2][:tickets].class, Array)
- assert(result[2][:tickets].blank?)
- end
- test 'overview any owner / no owner is set' do
- Ticket.destroy_all
- Overview.destroy_all
- UserInfo.current_user_id = 1
- overview_role = Role.find_by(name: 'Agent')
- overview1 = Overview.create_or_update(
- name: 'not owned',
- prio: 1000,
- role_ids: [overview_role.id],
- condition: {
- 'ticket.owner_id' => {
- operator: 'is',
- pre_condition: 'not_set',
- },
- },
- order: {
- by: 'created_at',
- direction: 'ASC',
- },
- view: {
- d: %w[title customer group created_at],
- s: %w[title customer group created_at],
- m: %w[number title customer group created_at],
- view_mode_default: 's',
- },
- )
- overview2 = Overview.create_or_update(
- name: 'not owned by somebody',
- prio: 2000,
- role_ids: [overview_role.id],
- condition: {
- 'ticket.owner_id' => {
- operator: 'is not',
- pre_condition: 'not_set',
- },
- },
- order: {
- by: 'created_at',
- direction: 'ASC',
- },
- view: {
- d: %w[title customer group created_at],
- s: %w[title customer group created_at],
- m: %w[number title customer group created_at],
- view_mode_default: 's',
- },
- )
- ticket1 = Ticket.create!(
- title: 'overview test 1',
- group: Group.lookup(name: 'OverviewTest'),
- customer_id: 2,
- owner_id: 1,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- )
- travel 2.seconds
- ticket2 = Ticket.create!(
- title: 'overview test 2',
- group: Group.lookup(name: 'OverviewTest'),
- customer_id: 2,
- owner_id: nil,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- )
- travel 2.seconds
- ticket3 = Ticket.create!(
- title: 'overview test 3',
- group: Group.lookup(name: 'OverviewTest'),
- customer_id: 2,
- owner_id: @agent1.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- )
- result = Ticket::Overviews.index(@agent1)
- assert_equal(result[0][:overview][:id], overview1.id)
- assert_equal(result[0][:overview][:name], 'not owned')
- assert_equal(result[0][:overview][:view], 'not_owned')
- assert_equal(result[0][:tickets].class, Array)
- assert_equal(result[0][:tickets][0][:id], ticket1.id)
- assert_equal(result[0][:tickets][1][:id], ticket2.id)
- assert_equal(result[0][:count], 2)
- assert_equal(result[1][:overview][:id], overview2.id)
- assert_equal(result[1][:overview][:name], 'not owned by somebody')
- assert_equal(result[1][:overview][:view], 'not_owned_by_somebody')
- assert_equal(result[1][:tickets].class, Array)
- assert_equal(result[1][:tickets][0][:id], ticket3.id)
- assert_equal(result[1][:count], 1)
- end
- end
|