has_ticket_contact_attributes_impact_examples.rb 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. RSpec.shared_examples 'Ticket::Article::HasTicketContactAttributesImpact' do
  2. describe '#update_ticket_article_attributes callback' do
  3. subject(:ticket) { create(:ticket, created_at: '2013-03-28 23:49:00 UTC', updated_at: '2013-03-28 23:49:00 UTC') }
  4. let(:calendar) do
  5. create(:calendar,
  6. business_hours: {
  7. mon: {
  8. active: true,
  9. timeframes: [ ['08:00', '18:00'] ]
  10. },
  11. tue: {
  12. active: true,
  13. timeframes: [ ['08:00', '18:00'] ]
  14. },
  15. wed: {
  16. active: true,
  17. timeframes: [ ['08:00', '18:00'] ]
  18. },
  19. thu: {
  20. active: true,
  21. timeframes: [ ['08:00', '18:00'] ]
  22. },
  23. fri: {
  24. active: true,
  25. timeframes: [ ['08:00', '18:00'] ]
  26. },
  27. sat: {
  28. active: false,
  29. timeframes: [ ['08:00', '17:00'] ]
  30. },
  31. sun: {
  32. active: false,
  33. timeframes: [ ['08:00', '17:00'] ]
  34. },
  35. })
  36. end
  37. let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 120, solution_time: 180) }
  38. before do
  39. sla
  40. ticket
  41. end
  42. context 'when inbound email Article is created' do
  43. it 'updates ticket article attributes' do
  44. article_inbound = create(:'ticket/article', :inbound_email, ticket: ticket, created_at: '2013-03-28 23:49:00 UTC', updated_at: '2013-03-28 23:49:00 UTC')
  45. ticket.reload
  46. expect(ticket.last_contact_at.to_s).to eq(article_inbound.created_at.to_s)
  47. expect(ticket.last_contact_customer_at.to_s).to eq(article_inbound.created_at.to_s)
  48. expect(ticket.last_contact_agent_at).to be_nil
  49. expect(ticket.first_response_at).to be_nil
  50. expect(ticket.close_at).to be_nil
  51. end
  52. end
  53. context 'when outbound email Article is created in response to inbound email Article' do
  54. it 'updates ticket article attributes' do
  55. article_inbound = create(:'ticket/article', :inbound_email, ticket: ticket, created_at: '2013-03-28 23:49:00 UTC', updated_at: '2013-03-28 23:49:00 UTC')
  56. ticket.reload
  57. article_outbound = create(:'ticket/article', :outbound_email, ticket: ticket, created_at: '2013-03-29 07:00:03 UTC', updated_at: '2013-03-29 07:00:03 UTC')
  58. ticket.reload
  59. expect(ticket.last_contact_at.to_s).to eq(article_outbound.created_at.to_s)
  60. expect(ticket.last_contact_customer_at.to_s).to eq(article_inbound.created_at.to_s)
  61. expect(ticket.last_contact_agent_at.to_s).to eq(article_outbound.created_at.to_s)
  62. expect(ticket.first_response_at.to_s).to eq(article_outbound.created_at.to_s)
  63. expect(ticket.first_response_in_min).to eq(0)
  64. expect(ticket.first_response_diff_in_min).to eq(60)
  65. expect(ticket.close_at).to be_nil
  66. end
  67. end
  68. context 'when inbound phone Article is created' do
  69. it 'updates ticket article attributes' do
  70. article_inbound = create(:'ticket/article', :inbound_phone, ticket: ticket, created_at: '2013-03-28 23:49:00 UTC', updated_at: '2013-03-28 23:49:00 UTC')
  71. ticket.reload
  72. expect(ticket.last_contact_at.to_s).to eq(article_inbound.created_at.to_s)
  73. expect(ticket.last_contact_customer_at.to_s).to eq(article_inbound.created_at.to_s)
  74. expect(ticket.last_contact_agent_at).to be_nil
  75. expect(ticket.first_response_at).to be_nil
  76. expect(ticket.close_at).to be_nil
  77. end
  78. end
  79. context 'when outbound note Article is created in response to inbound phone Article' do
  80. it 'updates ticket article attributes' do
  81. article_inbound = create(:'ticket/article', :inbound_phone, ticket: ticket, created_at: '2013-03-28 23:49:00 UTC', updated_at: '2013-03-28 23:49:00 UTC')
  82. ticket.reload
  83. create(:'ticket/article', :outbound_note, ticket: ticket, created_at: '2013-03-28 23:52:00 UTC', updated_at: '2013-03-28 23:52:00 UTC')
  84. ticket.reload
  85. expect(ticket.last_contact_at.to_s).to eq(article_inbound.created_at.to_s)
  86. expect(ticket.last_contact_customer_at.to_s).to eq(article_inbound.created_at.to_s)
  87. expect(ticket.last_contact_agent_at).to be_nil
  88. expect(ticket.first_response_at).to be_nil
  89. expect(ticket.close_at).to be_nil
  90. end
  91. end
  92. context 'when outbound phone Article is created after outbound note Article is created in response to inbound phone Article' do
  93. it 'updates ticket article attributes' do
  94. article_inbound = create(:'ticket/article', :inbound_phone, ticket: ticket, created_at: '2013-03-28 23:49:00 UTC', updated_at: '2013-03-28 23:49:00 UTC')
  95. ticket.reload
  96. create(:'ticket/article', :outbound_note, ticket: ticket, created_at: '2013-03-28 23:52:00 UTC', updated_at: '2013-03-28 23:52:00 UTC')
  97. ticket.reload
  98. article_outbound = create(:'ticket/article', :outbound_phone, ticket: ticket, created_at: '2013-03-28 23:55:00 UTC', updated_at: '2013-03-28 23:55:00 UTC')
  99. ticket.reload
  100. expect(ticket.last_contact_at.to_s).to eq(article_outbound.created_at.to_s)
  101. expect(ticket.last_contact_customer_at.to_s).to eq(article_inbound.created_at.to_s)
  102. expect(ticket.last_contact_agent_at.to_s).to eq(article_outbound.created_at.to_s)
  103. expect(ticket.first_response_at.to_s).to eq(article_outbound.created_at.to_s)
  104. expect(ticket.close_at).to be_nil
  105. end
  106. end
  107. context 'when inbound web Article is created' do
  108. subject(:ticket) { create(:ticket, created_at: '2016-11-01 13:56:21 UTC', updated_at: '2016-11-01 13:56:21 UTC') }
  109. let(:calendar) do
  110. create(:calendar,
  111. business_hours: {
  112. mon: {
  113. active: true,
  114. timeframes: [ ['08:00', '20:00'] ]
  115. },
  116. tue: {
  117. active: true,
  118. timeframes: [ ['08:00', '20:00'] ]
  119. },
  120. wed: {
  121. active: true,
  122. timeframes: [ ['08:00', '20:00'] ]
  123. },
  124. thu: {
  125. active: true,
  126. timeframes: [ ['08:00', '20:00'] ]
  127. },
  128. fri: {
  129. active: true,
  130. timeframes: [ ['08:00', '20:00'] ]
  131. },
  132. sat: {
  133. active: false,
  134. timeframes: [ ['08:00', '17:00'] ]
  135. },
  136. sun: {
  137. active: false,
  138. timeframes: [ ['08:00', '17:00'] ]
  139. },
  140. },
  141. public_holidays: {
  142. '2016-11-01' => {
  143. 'active' => true,
  144. 'summary' => 'test 1',
  145. },
  146. })
  147. end
  148. let(:sla) { create(:sla, condition: {}, calendar: calendar, first_response_time: 60, update_time: 120, solution_time: nil) }
  149. before do
  150. sla
  151. ticket
  152. create(:'ticket/article', :inbound_web, ticket: ticket, created_at: '2016-11-01 13:56:21 UTC', updated_at: '2016-11-01 13:56:21 UTC')
  153. ticket.reload
  154. end
  155. it 'calculates escalation_at attributes' do
  156. expect(ticket.escalation_at.gmtime.to_s).to eq('2016-11-02 08:00:00 UTC')
  157. expect(ticket.first_response_escalation_at.gmtime.to_s).to eq('2016-11-02 08:00:00 UTC')
  158. expect(ticket.update_escalation_at.gmtime.to_s).to eq('2016-11-02 09:00:00 UTC')
  159. expect(ticket.close_escalation_at).to be_nil
  160. end
  161. context 'when replied via outbound email' do
  162. before do
  163. create(:'ticket/article', :outbound_email, ticket: ticket, created_at: '2016-11-07 13:26:36 UTC', updated_at: '2016-11-07 13:26:36 UTC')
  164. ticket.reload
  165. end
  166. it 'calculates escalation_at attributes' do
  167. expect(ticket.escalation_at).to be_nil
  168. expect(ticket.first_response_escalation_at).to be_nil
  169. expect(ticket.update_escalation_at).to be_nil
  170. expect(ticket.close_escalation_at).to be_nil
  171. end
  172. end
  173. end
  174. context "when Setting 'ticket_last_contact_behaviour' is set to 'based_on_customer_reaction'" do
  175. subject(:ticket) { create(:ticket, created_at: '2018-05-01 13:56:21 UTC', updated_at: '2018-05-01 13:56:21 UTC') }
  176. let(:calendar) do
  177. create(:calendar,
  178. business_hours: {
  179. mon: {
  180. active: true,
  181. timeframes: [ ['08:00', '20:00'] ]
  182. },
  183. tue: {
  184. active: true,
  185. timeframes: [ ['08:00', '20:00'] ]
  186. },
  187. wed: {
  188. active: true,
  189. timeframes: [ ['08:00', '20:00'] ]
  190. },
  191. thu: {
  192. active: true,
  193. timeframes: [ ['08:00', '20:00'] ]
  194. },
  195. fri: {
  196. active: true,
  197. timeframes: [ ['08:00', '20:00'] ]
  198. },
  199. sat: {
  200. active: false,
  201. timeframes: [ ['08:00', '17:00'] ]
  202. },
  203. sun: {
  204. active: false,
  205. timeframes: [ ['08:00', '17:00'] ]
  206. },
  207. },
  208. public_holidays: {
  209. '2016-11-01' => {
  210. 'active' => true,
  211. 'summary' => 'test 1',
  212. },
  213. })
  214. end
  215. let(:sla) { create(:sla, condition: {}, calendar: calendar, first_response_time: 60, update_time: 120, solution_time: nil) }
  216. before do
  217. Setting.set('ticket_last_contact_behaviour', 'based_on_customer_reaction')
  218. sla
  219. end
  220. it 'updates ticket article attributes' do
  221. ticket
  222. article = create(:'ticket/article', :inbound_phone, ticket: ticket, created_at: '2018-05-01 13:56:21 UTC', updated_at: '2018-05-01 13:56:21 UTC')
  223. ticket.reload
  224. expect(ticket.last_contact_at.to_s).to eq(article.created_at.to_s)
  225. expect(ticket.last_contact_customer_at.to_s).to eq(article.created_at.to_s)
  226. expect(ticket.last_contact_agent_at).to be_nil
  227. expect(ticket.first_response_at).to be_nil
  228. expect(ticket.close_at).to be_nil
  229. article = create(:'ticket/article', :inbound_phone, ticket: ticket, created_at: '2018-05-01 14:56:21 UTC', updated_at: '2018-05-01 14:56:21 UTC')
  230. ticket.reload
  231. expect(ticket.last_contact_at.to_s).to eq(article.created_at.to_s)
  232. expect(ticket.last_contact_customer_at.to_s).to eq(article.created_at.to_s)
  233. expect(ticket.last_contact_agent_at).to be_nil
  234. expect(ticket.first_response_at).to be_nil
  235. expect(ticket.close_at).to be_nil
  236. article_customer = create(:'ticket/article', :inbound_phone, ticket: ticket, created_at: '2018-05-01 15:56:21 UTC', updated_at: '2018-05-01 15:56:21 UTC')
  237. ticket.reload
  238. expect(ticket.last_contact_at.to_s).to eq(article_customer.created_at.to_s)
  239. expect(ticket.last_contact_customer_at.to_s).to eq(article_customer.created_at.to_s)
  240. expect(ticket.last_contact_agent_at).to be_nil
  241. expect(ticket.first_response_at).to be_nil
  242. expect(ticket.close_at).to be_nil
  243. article_agent = create(:'ticket/article', :outbound_phone, ticket: ticket, created_at: '2018-05-01 16:56:21 UTC', updated_at: '2018-05-01 16:56:21 UTC')
  244. ticket.reload
  245. expect(ticket.last_contact_at.to_s).to eq(article_agent.created_at.to_s)
  246. expect(ticket.last_contact_customer_at.to_s).to eq(article_customer.created_at.to_s)
  247. expect(ticket.last_contact_agent_at.to_s).to eq(article_agent.created_at.to_s)
  248. expect(ticket.first_response_at.to_s).to eq(article_agent.created_at.to_s)
  249. expect(ticket.close_at).to be_nil
  250. end
  251. end
  252. end
  253. end