123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- require 'integration_test_helper'
- class CalendarSubscriptionsTicketsTest < ActiveSupport::TestCase
- user = User.create(
- firstname: 'CalendarSubscriptions',
- lastname: 'Testuser',
- email: 'calendar_subscriptions_testuser@example.com',
- updated_by_id: 1,
- created_by_id: 1,
- )
- user_not_assigned = User.find(1)
- sla = Sla.create(
- name: 'sla 1',
- condition: {},
- data: {
- 'Mon' => 'Mon', 'Tue' => 'Tue', 'Wed' => 'Wed', 'Thu' => 'Thu', 'Fri' => 'Fri', 'Sat' => 'Sat', 'Sun' => 'Sun',
- 'beginning_of_workday' => '9:00',
- 'end_of_workday' => '18:00',
- },
- timezone: 'Europe/Berlin',
- first_response_time: 10,
- update_time: 10,
- close_time: 10,
- active: true,
- updated_by_id: 1,
- created_by_id: 1,
- )
- tickets = [
- {
- owner: user,
- title: 'new 1',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'new' ),
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user_not_assigned,
- title: 'new 2',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'new' ),
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user,
- title: 'open 1',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'open' ),
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user_not_assigned,
- title: 'open 2',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'open' ),
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user,
- title: 'pending reminder 1',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'pending reminder' ),
- pending_time: Time.zone.parse('1977-10-27 22:00:00 +0000'),
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user,
- title: 'pending reminder 2',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'pending reminder' ),
- pending_time: DateTime.tomorrow,
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user_not_assigned,
- title: 'pending reminder 3',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'pending reminder' ),
- pending_time: Time.zone.parse('1977-10-27 22:00:00 +0000'),
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user_not_assigned,
- title: 'pending reminder 4',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'pending reminder' ),
- pending_time: DateTime.tomorrow,
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user,
- title: 'pending close 1',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'pending close' ),
- pending_time: Time.zone.parse('1977-10-27 22:00:00 +0000'),
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user,
- title: 'pending close 2',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'pending close' ),
- pending_time: DateTime.tomorrow,
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user_not_assigned,
- title: 'pending close 3',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'pending close' ),
- pending_time: Time.zone.parse('1977-10-27 22:00:00 +0000'),
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user_not_assigned,
- title: 'pending close 4',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'pending close' ),
- pending_time: DateTime.tomorrow,
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user,
- title: 'escalation 1',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'open' ),
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- created_at: '2013-03-21 09:30:00 UTC',
- updated_at: '2013-03-21 09:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- },
- {
- owner: user_not_assigned,
- title: 'escalation 2',
- group: Group.lookup( name: 'Users'),
- customer_id: user.id,
- state: Ticket::State.lookup( name: 'open' ),
- priority: Ticket::Priority.lookup( name: '2 normal' ),
- created_at: '2013-03-21 09:30:00 UTC',
- updated_at: '2013-03-21 09:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- },
- ]
- tickets.each do |ticket|
- Ticket.create( ticket )
- end
- defaults_disabled = {
- escalation: {
- own: false,
- not_assigned: false,
- },
- new_open: {
- own: false,
- not_assigned: false,
- },
- pending: {
- own: false,
- not_assigned: false,
- }
- }
- test 'new_open' do
- tests = [
- {
- count: 0,
- name: 'none',
- preferences: {
- new_open: {
- own: false,
- not_assigned: false,
- }
- },
- owner_ids: []
- },
- {
- count: 3,
- name: 'owner',
- preferences: {
- new_open: {
- own: true,
- not_assigned: false,
- }
- },
- owner_ids: [user.id]
- },
- {
- count: 3,
- name: 'not_assigned',
- preferences: {
- new_open: {
- own: false,
- not_assigned: true,
- }
- },
- owner_ids: [user_not_assigned.id]
- },
- {
- count: 6,
- name: 'owner+not_assigned',
- preferences: {
- new_open: {
- own: true,
- not_assigned: true,
- }
- },
- owner_ids: [user.id, user_not_assigned.id]
- },
- ]
- tests.each do |test_data|
- preferences = defaults_disabled.merge( test_data[:preferences] )
- user.preferences[:calendar_subscriptions] = {}
- user.preferences[:calendar_subscriptions][:tickets] = preferences
- calendar_subscriptions_ticket = CalendarSubscriptions::Tickets.new( user, preferences )
- event_data = calendar_subscriptions_ticket.new_open
- assert_equal( test_data[:count], event_data.length, "#{test_data[:name]} event count" )
- calendar_subscriptions = CalendarSubscriptions.new( user )
- ical = calendar_subscriptions.all
- event_data.each do |event|
- contained = false
- if ical.match?(/#{event[:summary]}/)
- contained = true
- end
- assert( contained, "#{test_data[:name]} new_open ical contains '#{event[:summary]}'" )
- end
- end
- end
- test 'pending' do
- tests = [
- {
- count: 0,
- name: 'none',
- preferences: {
- pending: {
- own: false,
- not_assigned: false,
- }
- },
- owner_ids: []
- },
- {
- count: 4,
- name: 'owner',
- preferences: {
- pending: {
- own: true,
- not_assigned: false,
- }
- },
- owner_ids: [user.id]
- },
- {
- count: 4,
- name: 'not_assigned',
- preferences: {
- pending: {
- own: false,
- not_assigned: true,
- }
- },
- owner_ids: [user_not_assigned.id]
- },
- {
- count: 8,
- name: 'owner+not_assigned',
- preferences: {
- pending: {
- own: true,
- not_assigned: true,
- }
- },
- owner_ids: [user.id, user_not_assigned.id]
- },
- ]
- tests.each do |test_data|
- preferences = defaults_disabled.merge( test_data[:preferences] )
- user.preferences[:calendar_subscriptions] = {}
- user.preferences[:calendar_subscriptions][:tickets] = preferences
- calendar_subscriptions_ticket = CalendarSubscriptions::Tickets.new( user, preferences )
- event_data = calendar_subscriptions_ticket.pending
- assert_equal( test_data[:count], event_data.length, "#{test_data[:name]} event count" )
- calendar_subscriptions = CalendarSubscriptions.new( user )
- ical = calendar_subscriptions.all
- event_data.each do |event|
- contained = false
- if ical.match?(/#{event[:summary]}/)
- contained = true
- end
- assert( contained, "#{test_data[:name]} pending ical contains '#{event[:summary]}'" )
- end
- end
- end
- test 'escalation' do
- tests = [
- {
- count: 0,
- name: 'none',
- preferences: {
- escalation: {
- own: false,
- not_assigned: false,
- }
- },
- owner_ids: []
- },
- {
- count: 7,
- name: 'owner',
- preferences: {
- escalation: {
- own: true,
- not_assigned: false,
- }
- },
- owner_ids: [user.id]
- },
- {
- count: 7,
- name: 'not_assigned',
- preferences: {
- escalation: {
- own: false,
- not_assigned: true,
- }
- },
- owner_ids: [user_not_assigned.id]
- },
- {
- count: 12,
- name: 'owner+not_assigned',
- preferences: {
- escalation: {
- own: true,
- not_assigned: true,
- }
- },
- owner_ids: [user.id, user_not_assigned.id]
- },
- ]
- tests.each do |test_data|
- preferences = defaults_disabled.merge( test_data[:preferences] )
- user.preferences[:calendar_subscriptions] = {}
- user.preferences[:calendar_subscriptions][:tickets] = preferences
- calendar_subscriptions_ticket = CalendarSubscriptions::Tickets.new( user, preferences )
- event_data = calendar_subscriptions_ticket.escalation
- assert_equal( test_data[:count], event_data.length, "#{test_data[:name]} event count" )
- calendar_subscriptions = CalendarSubscriptions.new( user )
- ical = calendar_subscriptions.all
- event_data.each do |event|
- contained = false
- if ical.match?(/#{event[:summary]}/)
- contained = true
- end
- assert( contained, "#{test_data[:name]} escalation ical contains '#{event[:summary]}'" )
- end
- end
- end
- end
|