ticket_article_time_accouting_test.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. require 'test_helper'
  2. class TicketArticleTimeAccoutingTest < ActiveSupport::TestCase
  3. test 'destroy dependent time accounting for ticket and article' do
  4. ticket_test = Ticket.create(
  5. title: 'com test 1',
  6. group: Group.lookup(name: 'Users'),
  7. customer_id: 2,
  8. state: Ticket::State.lookup(name: 'new'),
  9. priority: Ticket::Priority.lookup(name: '2 normal'),
  10. updated_by_id: 1,
  11. created_by_id: 1,
  12. )
  13. assert(ticket_test, 'ticket created')
  14. article_test1 = Ticket::Article.create(
  15. ticket_id: ticket_test.id,
  16. from: 'some_customer_com-1@example.com',
  17. to: 'some_zammad_com-1@example.com',
  18. subject: 'com test 1',
  19. message_id: 'some@id_com_1',
  20. body: 'some message 123',
  21. internal: false,
  22. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  23. type: Ticket::Article::Type.find_by(name: 'email'),
  24. updated_by_id: 1,
  25. created_by_id: 1,
  26. )
  27. Ticket::TimeAccounting.create!(
  28. ticket_id: ticket_test.id,
  29. ticket_article_id: article_test1.id,
  30. time_unit: 10,
  31. created_by_id: 1,
  32. )
  33. article_test2 = Ticket::Article.create(
  34. ticket_id: ticket_test.id,
  35. from: 'some_customer_com-1@example.com',
  36. to: 'some_zammad_com-1@example.com',
  37. subject: 'com test 1',
  38. message_id: 'some@id_com_1',
  39. body: 'some message 123',
  40. internal: false,
  41. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  42. type: Ticket::Article::Type.find_by(name: 'email'),
  43. updated_by_id: 1,
  44. created_by_id: 1,
  45. )
  46. Ticket::TimeAccounting.create!(
  47. ticket_id: ticket_test.id,
  48. ticket_article_id: article_test2.id,
  49. time_unit: 10,
  50. created_by_id: 1,
  51. )
  52. article_test3 = Ticket::Article.create(
  53. ticket_id: ticket_test.id,
  54. from: 'some_customer_com-1@example.com',
  55. to: 'some_zammad_com-1@example.com',
  56. subject: 'com test 1',
  57. message_id: 'some@id_com_1',
  58. body: 'some message 123',
  59. internal: false,
  60. sender: Ticket::Article::Sender.find_by(name: 'Customer'),
  61. type: Ticket::Article::Type.find_by(name: 'email'),
  62. updated_by_id: 1,
  63. created_by_id: 1,
  64. )
  65. Ticket::TimeAccounting.create!(
  66. ticket_id: ticket_test.id,
  67. ticket_article_id: article_test3.id,
  68. time_unit: 10,
  69. created_by_id: 1,
  70. )
  71. Ticket::TimeAccounting.create!(
  72. ticket_id: ticket_test.id,
  73. time_unit: 10,
  74. created_by_id: 1,
  75. )
  76. time_accouting_list = Ticket::TimeAccounting.where(
  77. ticket_id: ticket_test.id,
  78. )
  79. found = time_accouting_list.select { |t| t.ticket_article_id.in?([article_test1.id, article_test2.id, article_test3.id]) }
  80. assert_equal(3, found.count)
  81. article_test1.destroy
  82. time_accouting_list.reload
  83. found = time_accouting_list.select { |t| t.ticket_article_id.in?([article_test1.id, article_test2.id, article_test3.id]) }
  84. assert_equal(2, found.count)
  85. article_test2.destroy
  86. time_accouting_list.reload
  87. found = time_accouting_list.select { |t| t.ticket_article_id.in?([article_test1.id, article_test2.id, article_test3.id]) }
  88. assert_equal(1, found.count)
  89. article_test3.destroy
  90. time_accouting_list.reload
  91. found = time_accouting_list.select { |t| t.ticket_article_id.in?([article_test1.id, article_test2.id, article_test3.id]) }
  92. assert_equal(0, found.count)
  93. # one accouting left for the ticket only
  94. assert_equal(1, time_accouting_list.count)
  95. ticket_test.destroy
  96. time_accouting_list.reload
  97. assert_equal(0, time_accouting_list.count)
  98. end
  99. end