Fixed issue #1723 - Wrong ticket number count in preview.

This commit is contained in:
Martin Edenhofer 2017-12-20 10:55:54 +01:00
parent 9805fa176a
commit aef865a916
2 changed files with 107 additions and 1 deletions

View file

@ -42,7 +42,7 @@ class App.SettingsAreaTicketNumber extends App.Controller
number = "#{App.Config.get('ticket_hook')}#{App.Config.get('system_id')}" number = "#{App.Config.get('ticket_hook')}#{App.Config.get('system_id')}"
counter = '1' counter = '1'
if paramsItem.min_size if paramsItem.min_size
minSize = parseInt(paramsItem.min_size) minSize = parseInt(paramsItem.min_size) - "#{App.Config.get('system_id')}".length
if paramsItem.checksum if paramsItem.checksum
minSize -= 1 minSize -= 1
if minSize > 1 if minSize > 1

View file

@ -0,0 +1,106 @@
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 '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
end