123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- require 'test_helper'
- class TicketNumberTest < ActiveSupport::TestCase
- test 'number' do
- Setting.set('ticket_number_increment', { checksum: false, min_size: 5 })
- Setting.set('system_id', 1)
- number = Ticket::Number.generate
- assert_equal(number.to_s.length, 5)
- Setting.set('ticket_number_increment', { checksum: false, min_size: 10 })
- Setting.set('system_id', 1)
- number = Ticket::Number.generate
- assert_equal(number.to_s.length, 10)
- Setting.set('ticket_number_increment', { checksum: true, min_size: 5 })
- Setting.set('system_id', 1)
- number = Ticket::Number.generate
- assert_equal(number.to_s.length, 5)
- Setting.set('ticket_number_increment', { checksum: true, min_size: 10 })
- Setting.set('system_id', 1)
- number = Ticket::Number.generate
- assert_equal(number.to_s.length, 10)
- Setting.set('ticket_number_increment', { checksum: false, min_size: 5 })
- Setting.set('system_id', 88)
- number = Ticket::Number.generate
- assert_equal(number.to_s.length, 5)
- Setting.set('ticket_number_increment', { checksum: false, min_size: 10 })
- Setting.set('system_id', 88)
- number = Ticket::Number.generate
- assert_equal(number.to_s.length, 10)
- Setting.set('ticket_number_increment', { checksum: true, min_size: 5 })
- Setting.set('system_id', 88)
- number = Ticket::Number.generate
- assert_equal(number.to_s.length, 5)
- Setting.set('ticket_number_increment', { checksum: true, min_size: 10 })
- Setting.set('system_id', 88)
- number = Ticket::Number.generate
- assert_equal(number.to_s.length, 10)
- 150.times do
- number = Ticket::Number.generate
- assert_equal(number.to_s.length, 10)
- end
- end
- test 'number check' do
- Setting.set('ticket_number_increment', { checksum: false, min_size: 5 })
- Setting.set('system_id', 1)
- ticket = Ticket.create!(
- title: 'test 1',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- subject = ticket.subject_build(ticket.title)
- ticket_check = Ticket::Number.check(subject)
- assert_equal(ticket.id, ticket_check.id)
- Setting.set('system_id', 999)
- ticket_check = Ticket::Number.check(subject)
- assert_not(ticket_check)
- Setting.set('ticket_number_ignore_system_id', true)
- ticket_check = Ticket::Number.check(subject)
- assert_equal(ticket.id, ticket_check.id)
- end
- test 'date' do
- Setting.set('ticket_number', 'Ticket::Number::Date')
- Setting.set('ticket_number_date', { checksum: false })
- Setting.set('system_id', 1)
- system_id = Setting.get('system_id')
- number_prefix = "#{Time.zone.now.strftime('%Y%m%d')}#{system_id}"
- number = Ticket::Number.generate
- assert_equal(number.to_s.length, 13)
- assert_match(/#{number_prefix}/, number.to_s)
- Setting.set('ticket_number_date', { checksum: false })
- Setting.set('system_id', 88)
- number = Ticket::Number.generate
- system_id = Setting.get('system_id')
- number_prefix = "#{Time.zone.now.strftime('%Y%m%d')}#{system_id}"
- assert_equal(number.to_s.length, 14)
- assert_match(/#{number_prefix}/, number.to_s)
- Setting.set('ticket_number_date', { checksum: true })
- Setting.set('system_id', 1)
- number = Ticket::Number.generate
- system_id = Setting.get('system_id')
- number_prefix = "#{Time.zone.now.strftime('%Y%m%d')}#{system_id}"
- assert_equal(number.to_s.length, 14)
- assert_match(/#{number_prefix}/, number.to_s)
- Setting.set('ticket_number_date', { checksum: true })
- Setting.set('system_id', 88)
- number = Ticket::Number.generate
- system_id = Setting.get('system_id')
- number_prefix = "#{Time.zone.now.strftime('%Y%m%d')}#{system_id}"
- assert_equal(number.to_s.length, 15)
- assert_match(/#{number_prefix}/, number.to_s)
- 150.times do
- number = Ticket::Number.generate
- assert_equal(number.to_s.length, 15)
- end
- end
- test 'date check' do
- Setting.set('ticket_number', 'Ticket::Number::Date')
- Setting.set('ticket_number_date', { checksum: false })
- Setting.set('system_id', 1)
- ticket = Ticket.create!(
- title: 'test 1',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- subject = ticket.subject_build(ticket.title)
- ticket_check = Ticket::Number.check(subject)
- assert_equal(ticket.id, ticket_check.id)
- Setting.set('system_id', 999)
- ticket_check = Ticket::Number.check(subject)
- assert_not(ticket_check)
- Setting.set('ticket_number_ignore_system_id', true)
- ticket_check = Ticket::Number.check(subject)
- assert_equal(ticket.id, ticket_check.id)
- end
- end
|