<commit_before><commit_msg>Added integration tests for iCal feature.<commit_after># encoding: utf-8
require 'integration_test_helper'

class ICalTicketTest < ActiveSupport::TestCase

  user = User.create(
    firstname: 'iCal',
    lastname: 'Testuser',
    email: '<EMAIL>',
    updated_by_id: 1,
    created_by_id: 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,
      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,
      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,
      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,
      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,
    },
  ]

  tickets.each { |ticket|

    Ticket.create( ticket )
  }

  test 'new_open' do

    event_data = ICal::Ticket.new_open( user )

    assert_equal( 3, event_data.length, 'event count' )

    ical = ICal.to_ical( event_data )

    event_data.each{ |event|

      contained = false
      if ical =~ /#{event[:summary]}/
        contained = true
      end

      assert( contained, "ical contains '#{event[:summary]}'" )
    }
  end

  test 'pending' do

    event_data = ICal::Ticket.pending( user )

    assert_equal( 4, event_data.length, 'event count' )

    ical = ICal.to_ical( event_data )

    event_data.each{ |event|

      contained = false
      if ical =~ /#{event[:summary]}/
        contained = true
      end

      assert( contained, "ical contains '#{event[:summary]}'" )
    }
  end

  test 'escalation' do

    event_data = ICal::Ticket.escalation( user )

    assert_equal( 7, event_data.length, 'event count' )

    ical = ICal.to_ical( event_data )

    event_data.each{ |event|

      contained = false
      if ical =~ /#{event[:summary]}/
        contained = true
      end

      assert( contained, "ical contains '#{event[:summary]}'" )
    }
  end
end
{'fraction_non_alphanumeric': 0.14921946740128558, 'fraction_numerical': 0.026170798898071626, 'mean_word_length': 2.5279352226720646, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2633443', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1497, 'n_words': 356}