base_spec.rb 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Selector::Base, searchindex: true do
  4. let(:agent) { create(:agent, groups: [Group.first]) }
  5. let(:ticket_1) { create(:ticket, title: 'bli', group: Group.first) }
  6. let(:ticket_2) { create(:ticket, title: 'bla', group: Group.first) }
  7. let(:ticket_3) { create(:ticket, title: 'blub', group: Group.first) }
  8. before do
  9. Ticket.destroy_all
  10. ticket_1 && ticket_2 && ticket_3
  11. searchindex_model_reload([Ticket])
  12. end
  13. it 'does support AND conditions', :aggregate_failures do
  14. condition = {
  15. operator: 'AND',
  16. conditions: [
  17. {
  18. name: 'ticket.title',
  19. operator: 'contains',
  20. value: 'b',
  21. },
  22. {
  23. name: 'ticket.title',
  24. operator: 'contains',
  25. value: 'l',
  26. },
  27. {
  28. name: 'ticket.title',
  29. operator: 'contains',
  30. value: 'b',
  31. },
  32. ]
  33. }
  34. count, = Ticket.selectors(condition, { current_user: agent })
  35. expect(count).to eq(3)
  36. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  37. expect(result[:count]).to eq(3)
  38. end
  39. it 'does support NOT conditions', :aggregate_failures do
  40. condition = {
  41. operator: 'NOT',
  42. conditions: [
  43. {
  44. name: 'ticket.title',
  45. operator: 'contains',
  46. value: 'b',
  47. },
  48. {
  49. name: 'ticket.title',
  50. operator: 'contains',
  51. value: 'l',
  52. },
  53. {
  54. name: 'ticket.title',
  55. operator: 'contains',
  56. value: 'b',
  57. },
  58. ]
  59. }
  60. count, = Ticket.selectors(condition, { current_user: agent })
  61. expect(count).to eq(0)
  62. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  63. expect(result[:count]).to eq(0)
  64. end
  65. it 'does support OR conditions', :aggregate_failures do
  66. condition = {
  67. operator: 'OR',
  68. conditions: [
  69. {
  70. name: 'ticket.title',
  71. operator: 'is',
  72. value: 'bli',
  73. },
  74. {
  75. name: 'ticket.title',
  76. operator: 'is',
  77. value: 'bla',
  78. },
  79. {
  80. name: 'ticket.title',
  81. operator: 'is',
  82. value: 'blub',
  83. },
  84. ]
  85. }
  86. count, = Ticket.selectors(condition, { current_user: agent })
  87. expect(count).to eq(3)
  88. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  89. expect(result[:count]).to eq(3)
  90. end
  91. it 'does support OR conditions (one missing)', :aggregate_failures do
  92. condition = {
  93. operator: 'OR',
  94. conditions: [
  95. {
  96. name: 'ticket.title',
  97. operator: 'is',
  98. value: 'xxx',
  99. },
  100. {
  101. name: 'ticket.title',
  102. operator: 'is',
  103. value: 'bla',
  104. },
  105. {
  106. name: 'ticket.title',
  107. operator: 'is',
  108. value: 'blub',
  109. },
  110. ]
  111. }
  112. count, = Ticket.selectors(condition, { current_user: agent })
  113. expect(count).to eq(2)
  114. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  115. expect(result[:count]).to eq(2)
  116. end
  117. it 'does support OR conditions (all missing)', :aggregate_failures do
  118. condition = {
  119. operator: 'AND',
  120. conditions: [
  121. {
  122. name: 'ticket.title',
  123. operator: 'is',
  124. value: 'bli',
  125. },
  126. {
  127. name: 'ticket.title',
  128. operator: 'is',
  129. value: 'bla',
  130. },
  131. {
  132. name: 'ticket.title',
  133. operator: 'is',
  134. value: 'blub',
  135. },
  136. ]
  137. }
  138. count, = Ticket.selectors(condition, { current_user: agent })
  139. expect(count).to eq(0)
  140. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  141. expect(result[:count]).to eq(0)
  142. end
  143. it 'does support sub level conditions', :aggregate_failures do
  144. condition = {
  145. operator: 'OR',
  146. conditions: [
  147. {
  148. name: 'ticket.title',
  149. operator: 'is',
  150. value: 'bli',
  151. },
  152. {
  153. operator: 'OR',
  154. conditions: [
  155. {
  156. name: 'ticket.title',
  157. operator: 'is',
  158. value: 'bla',
  159. },
  160. {
  161. name: 'ticket.title',
  162. operator: 'is',
  163. value: 'blub',
  164. },
  165. ],
  166. }
  167. ]
  168. }
  169. count, = Ticket.selectors(condition, { current_user: agent })
  170. expect(count).to eq(3)
  171. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  172. expect(result[:count]).to eq(3)
  173. end
  174. it 'does support sub level conditions (one missing)', :aggregate_failures do
  175. condition = {
  176. operator: 'OR',
  177. conditions: [
  178. {
  179. name: 'ticket.title',
  180. operator: 'is',
  181. value: 'bli',
  182. },
  183. {
  184. operator: 'OR',
  185. conditions: [
  186. {
  187. name: 'ticket.title',
  188. operator: 'is',
  189. value: 'xxx',
  190. },
  191. {
  192. name: 'ticket.title',
  193. operator: 'is',
  194. value: 'blub',
  195. },
  196. ],
  197. }
  198. ]
  199. }
  200. count, = Ticket.selectors(condition, { current_user: agent })
  201. expect(count).to eq(2)
  202. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  203. expect(result[:count]).to eq(2)
  204. end
  205. it 'does support sub level conditions (all missing)', :aggregate_failures do
  206. condition = {
  207. operator: 'AND',
  208. conditions: [
  209. {
  210. name: 'ticket.title',
  211. operator: 'is',
  212. value: 'bli',
  213. },
  214. {
  215. operator: 'AND',
  216. conditions: [
  217. {
  218. name: 'ticket.title',
  219. operator: 'is',
  220. value: 'bla',
  221. },
  222. {
  223. name: 'ticket.title',
  224. operator: 'is',
  225. value: 'blub',
  226. },
  227. ],
  228. }
  229. ]
  230. }
  231. count, = Ticket.selectors(condition, { current_user: agent })
  232. expect(count).to eq(0)
  233. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  234. expect(result[:count]).to eq(0)
  235. end
  236. it 'does return all 3 results on empty condition', :aggregate_failures do
  237. condition = {
  238. operator: 'AND',
  239. conditions: []
  240. }
  241. count, = Ticket.selectors(condition, { current_user: agent })
  242. expect(count).to eq(3)
  243. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  244. expect(result[:count]).to eq(3)
  245. end
  246. it 'does return all 3 results on empty sub condition', :aggregate_failures do
  247. condition = {
  248. operator: 'AND',
  249. conditions: [
  250. {
  251. name: 'ticket.title',
  252. operator: 'contains',
  253. value: 'b',
  254. },
  255. {
  256. name: 'ticket.title',
  257. operator: 'contains',
  258. value: 'l',
  259. },
  260. {
  261. name: 'ticket.title',
  262. operator: 'contains',
  263. value: 'b',
  264. },
  265. {
  266. operator: 'AND',
  267. conditions: [
  268. ],
  269. }
  270. ]
  271. }
  272. count, = Ticket.selectors(condition, { current_user: agent })
  273. expect(count).to eq(3)
  274. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  275. expect(result[:count]).to eq(3)
  276. end
  277. it 'does return all 3 results on empty sub sub condition', :aggregate_failures do
  278. condition = {
  279. operator: 'AND',
  280. conditions: [
  281. {
  282. name: 'ticket.title',
  283. operator: 'contains',
  284. value: 'b',
  285. },
  286. {
  287. name: 'ticket.title',
  288. operator: 'contains',
  289. value: 'l',
  290. },
  291. {
  292. name: 'ticket.title',
  293. operator: 'contains',
  294. value: 'b',
  295. },
  296. {
  297. operator: 'AND',
  298. conditions: [
  299. {
  300. operator: 'AND',
  301. conditions: [
  302. ],
  303. }
  304. ],
  305. }
  306. ]
  307. }
  308. count, = Ticket.selectors(condition, { current_user: agent })
  309. expect(count).to eq(3)
  310. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  311. expect(result[:count]).to eq(3)
  312. end
  313. describe 'Report profile terminates with error if today is used as timestamp for condition #4901' do
  314. before do
  315. ticket_1.update(created_at: 1.day.ago)
  316. searchindex_model_reload([Ticket])
  317. end
  318. it 'does support today operator', :aggregate_failures do
  319. condition = {
  320. operator: 'AND',
  321. conditions: [
  322. {
  323. name: 'ticket.created_at',
  324. operator: 'today',
  325. },
  326. ]
  327. }
  328. count, = Ticket.selectors(condition, { current_user: agent })
  329. expect(count).to eq(2)
  330. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  331. expect(result[:count]).to eq(2)
  332. end
  333. end
  334. describe 'Trigger do not allow "Multi-Tree-Select" Fields on Organization and User Level as If Condition #4504', db_strategy: :reset do
  335. let(:field_name) { SecureRandom.uuid }
  336. let(:organization) { create(:organization, field_name => ['Incident', 'Incident::Hardware']) }
  337. let(:customer) { create(:customer, organization: organization, field_name => ['Incident', 'Incident::Hardware']) }
  338. let(:ticket) { create(:ticket, title: 'bli', group: Group.first, customer: customer, field_name => ['Incident', 'Incident::Hardware']) }
  339. def check_condition(attribute)
  340. condition = {
  341. operator: 'AND',
  342. conditions: [
  343. {
  344. name: attribute.to_s,
  345. operator: 'contains all',
  346. value: ['Incident', 'Incident::Hardware'],
  347. }
  348. ]
  349. }
  350. count, = Ticket.selectors(condition, { current_user: agent })
  351. expect(count).to eq(1)
  352. count, = Ticket.selectors(condition, { current_user: agent })
  353. expect(count).to eq(1)
  354. end
  355. before do
  356. create(:object_manager_attribute_multi_tree_select, object_name: 'Ticket', name: field_name)
  357. create(:object_manager_attribute_multi_tree_select, object_name: 'User', name: field_name)
  358. create(:object_manager_attribute_multi_tree_select, object_name: 'Organization', name: field_name)
  359. ObjectManager::Attribute.migration_execute
  360. ticket
  361. searchindex_model_reload([Ticket, User, Organization])
  362. end
  363. it 'does support contains one for all objects' do # rubocop:disable RSpec/NoExpectationExample
  364. check_condition("ticket.#{field_name}")
  365. check_condition("customer.#{field_name}")
  366. check_condition("organization.#{field_name}")
  367. end
  368. end
  369. describe 'Reporting profiles do not work with multi tree select #4546' do
  370. context 'when value is a string' do
  371. before do
  372. create(:tag, tag_item: create(:'tag/item', name: 'AAA'), o: ticket_1)
  373. create(:tag, tag_item: create(:'tag/item', name: 'BBB'), o: ticket_1)
  374. searchindex_model_reload([Ticket])
  375. end
  376. it 'does return ticket by contains all string value', :aggregate_failures do
  377. condition = {
  378. operator: 'AND',
  379. conditions: [
  380. {
  381. name: 'ticket.tags',
  382. operator: 'contains all',
  383. value: 'AAA, BBB',
  384. }
  385. ]
  386. }
  387. count, = Ticket.selectors(condition, { current_user: agent })
  388. expect(count).to eq(1)
  389. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  390. expect(result[:count]).to eq(1)
  391. end
  392. end
  393. context 'when value is an array', db_strategy: :reset do
  394. let(:field_name) { SecureRandom.uuid }
  395. before do
  396. create(:object_manager_attribute_multi_tree_select, name: field_name)
  397. ObjectManager::Attribute.migration_execute
  398. ticket_1.reload.update(field_name => ['Incident', 'Incident::Hardware'])
  399. searchindex_model_reload([Ticket])
  400. end
  401. it 'does return ticket by contains all array value', :aggregate_failures do
  402. condition = {
  403. operator: 'AND',
  404. conditions: [
  405. {
  406. name: "ticket.#{field_name}",
  407. operator: 'contains all',
  408. value: ['Incident', 'Incident::Hardware'],
  409. }
  410. ]
  411. }
  412. count, = Ticket.selectors(condition, { current_user: agent })
  413. expect(count).to eq(1)
  414. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  415. expect(result[:count]).to eq(1)
  416. end
  417. end
  418. end
  419. describe 'Report profiles: Problem with some conditions (starts with, ends with, is any, is none) #4798' do
  420. context 'when operator is any of' do
  421. it 'does match', :aggregate_failures do
  422. condition = {
  423. operator: 'OR',
  424. conditions: [
  425. {
  426. name: 'ticket.title',
  427. operator: 'is any of',
  428. value: %w[bli bla],
  429. },
  430. {
  431. name: 'ticket.title',
  432. operator: 'is any of',
  433. value: ['blub'],
  434. },
  435. ]
  436. }
  437. count, = Ticket.selectors(condition, { current_user: agent })
  438. expect(count).to eq(3)
  439. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  440. expect(result[:count]).to eq(3)
  441. end
  442. it 'does not match', :aggregate_failures do
  443. condition = {
  444. operator: 'OR',
  445. conditions: [
  446. {
  447. name: 'ticket.title',
  448. operator: 'is any of',
  449. value: %w[blix blax],
  450. },
  451. {
  452. name: 'ticket.title',
  453. operator: 'is any of',
  454. value: ['blubx'],
  455. },
  456. ]
  457. }
  458. count, = Ticket.selectors(condition, { current_user: agent })
  459. expect(count).to eq(0)
  460. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  461. expect(result[:count]).to eq(0)
  462. end
  463. end
  464. context 'when operator is none of' do
  465. it 'does match', :aggregate_failures do
  466. condition = {
  467. operator: 'OR',
  468. conditions: [
  469. {
  470. name: 'ticket.title',
  471. operator: 'is none of',
  472. value: %w[blix blax],
  473. },
  474. {
  475. name: 'ticket.title',
  476. operator: 'is none of',
  477. value: ['blubx'],
  478. },
  479. ]
  480. }
  481. count, = Ticket.selectors(condition, { current_user: agent })
  482. expect(count).to eq(3)
  483. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  484. expect(result[:count]).to eq(3)
  485. end
  486. it 'does not match', :aggregate_failures do
  487. condition = {
  488. operator: 'AND',
  489. conditions: [
  490. {
  491. name: 'ticket.title',
  492. operator: 'is none of',
  493. value: %w[bli bla],
  494. },
  495. {
  496. name: 'ticket.title',
  497. operator: 'is none of',
  498. value: ['blub'],
  499. },
  500. ]
  501. }
  502. count, = Ticket.selectors(condition, { current_user: agent })
  503. expect(count).to eq(0)
  504. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  505. expect(result[:count]).to eq(0)
  506. end
  507. end
  508. context 'when operator starts with one of' do
  509. it 'does match', :aggregate_failures do
  510. condition = {
  511. operator: 'AND',
  512. conditions: [
  513. {
  514. name: 'ticket.title',
  515. operator: 'starts with one of',
  516. value: ['bl'],
  517. },
  518. ]
  519. }
  520. count, = Ticket.selectors(condition, { current_user: agent })
  521. expect(count).to eq(3)
  522. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  523. expect(result[:count]).to eq(3)
  524. end
  525. it 'does not match', :aggregate_failures do
  526. condition = {
  527. operator: 'AND',
  528. conditions: [
  529. {
  530. name: 'ticket.title',
  531. operator: 'starts with one of',
  532. value: ['aaa'],
  533. },
  534. ]
  535. }
  536. count, = Ticket.selectors(condition, { current_user: agent })
  537. expect(count).to eq(0)
  538. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  539. expect(result[:count]).to eq(0)
  540. end
  541. end
  542. context 'when operator ends with one of' do
  543. it 'does match', :aggregate_failures do
  544. condition = {
  545. operator: 'OR',
  546. conditions: [
  547. {
  548. name: 'ticket.title',
  549. operator: 'ends with one of',
  550. value: %w[li la],
  551. },
  552. {
  553. name: 'ticket.title',
  554. operator: 'ends with one of',
  555. value: ['ub'],
  556. },
  557. ]
  558. }
  559. count, = Ticket.selectors(condition, { current_user: agent })
  560. expect(count).to eq(3)
  561. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  562. expect(result[:count]).to eq(3)
  563. end
  564. it 'does not match', :aggregate_failures do
  565. condition = {
  566. operator: 'AND',
  567. conditions: [
  568. {
  569. name: 'ticket.title',
  570. operator: 'ends with one of',
  571. value: ['ubx'],
  572. },
  573. ]
  574. }
  575. count, = Ticket.selectors(condition, { current_user: agent })
  576. expect(count).to eq(0)
  577. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  578. expect(result[:count]).to eq(0)
  579. end
  580. end
  581. end
  582. describe 'Tags' do
  583. let(:ta) { create(:'tag/item', name: 'a') }
  584. let(:tb) { create(:'tag/item', name: 'b') }
  585. let(:tc) { create(:'tag/item', name: 'c') }
  586. let(:td) { create(:'tag/item', name: 'd') }
  587. let(:ticket_a) do
  588. create(:ticket, group: Group.first).tap do |ticket|
  589. create(:tag, o: ticket, tag_item: ta)
  590. end
  591. end
  592. let(:ticket_a_b) do
  593. create(:ticket, group: Group.first).tap do |ticket|
  594. create(:tag, o: ticket, tag_item: ta)
  595. create(:tag, o: ticket, tag_item: tb)
  596. end
  597. end
  598. let(:ticket_none) { create(:ticket, group: Group.first) }
  599. before do
  600. Ticket.destroy_all
  601. ta && tb && tc && td
  602. ticket_a && ticket_a_b && ticket_none
  603. searchindex_model_reload([Ticket])
  604. end
  605. describe 'contains all' do
  606. it 'checks tags a = 2', :aggregate_failures do
  607. condition = {
  608. operator: 'AND',
  609. conditions: [
  610. {
  611. name: 'ticket.tags',
  612. operator: 'contains all',
  613. value: 'a',
  614. },
  615. ]
  616. }
  617. count, = Ticket.selectors(condition, { current_user: agent })
  618. expect(count).to eq(2)
  619. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  620. expect(result[:count]).to eq(2)
  621. end
  622. it 'checks tags a, b = 1', :aggregate_failures do
  623. condition = {
  624. operator: 'AND',
  625. conditions: [
  626. {
  627. name: 'ticket.tags',
  628. operator: 'contains all',
  629. value: 'a,b',
  630. },
  631. ]
  632. }
  633. count, = Ticket.selectors(condition, { current_user: agent })
  634. expect(count).to eq(1)
  635. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  636. expect(result[:count]).to eq(1)
  637. end
  638. it 'checks tags a, c = 0', :aggregate_failures do
  639. condition = {
  640. operator: 'AND',
  641. conditions: [
  642. {
  643. name: 'ticket.tags',
  644. operator: 'contains all',
  645. value: 'a,c',
  646. },
  647. ]
  648. }
  649. count, = Ticket.selectors(condition, { current_user: agent })
  650. expect(count).to eq(0)
  651. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  652. expect(result[:count]).to eq(0)
  653. end
  654. it 'checks tags a, b, c = 0', :aggregate_failures do
  655. condition = {
  656. operator: 'AND',
  657. conditions: [
  658. {
  659. name: 'ticket.tags',
  660. operator: 'contains all',
  661. value: 'a,b,c',
  662. },
  663. ]
  664. }
  665. count, = Ticket.selectors(condition, { current_user: agent })
  666. expect(count).to eq(0)
  667. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  668. expect(result[:count]).to eq(0)
  669. end
  670. it 'checks tags c, d = 0', :aggregate_failures do
  671. condition = {
  672. operator: 'AND',
  673. conditions: [
  674. {
  675. name: 'ticket.tags',
  676. operator: 'contains all',
  677. value: 'c,d',
  678. },
  679. ]
  680. }
  681. count, = Ticket.selectors(condition, { current_user: agent })
  682. expect(count).to eq(0)
  683. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  684. expect(result[:count]).to eq(0)
  685. end
  686. it 'checks tags d = 0', :aggregate_failures do
  687. condition = {
  688. operator: 'AND',
  689. conditions: [
  690. {
  691. name: 'ticket.tags',
  692. operator: 'contains all',
  693. value: 'd',
  694. },
  695. ]
  696. }
  697. count, = Ticket.selectors(condition, { current_user: agent })
  698. expect(count).to eq(0)
  699. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  700. expect(result[:count]).to eq(0)
  701. end
  702. end
  703. describe 'contains one' do
  704. it 'checks tags a = 2', :aggregate_failures do
  705. condition = {
  706. operator: 'AND',
  707. conditions: [
  708. {
  709. name: 'ticket.tags',
  710. operator: 'contains one',
  711. value: 'a',
  712. },
  713. ]
  714. }
  715. count, = Ticket.selectors(condition, { current_user: agent })
  716. expect(count).to eq(2)
  717. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  718. expect(result[:count]).to eq(2)
  719. end
  720. it 'checks tags a, b = 2', :aggregate_failures do
  721. condition = {
  722. operator: 'AND',
  723. conditions: [
  724. {
  725. name: 'ticket.tags',
  726. operator: 'contains one',
  727. value: 'a,b',
  728. },
  729. ]
  730. }
  731. count, = Ticket.selectors(condition, { current_user: agent })
  732. expect(count).to eq(2)
  733. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  734. expect(result[:count]).to eq(2)
  735. end
  736. it 'checks tags a, c = 2', :aggregate_failures do
  737. condition = {
  738. operator: 'AND',
  739. conditions: [
  740. {
  741. name: 'ticket.tags',
  742. operator: 'contains one',
  743. value: 'a,c',
  744. },
  745. ]
  746. }
  747. count, = Ticket.selectors(condition, { current_user: agent })
  748. expect(count).to eq(2)
  749. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  750. expect(result[:count]).to eq(2)
  751. end
  752. it 'checks tags a, b, c = 2', :aggregate_failures do
  753. condition = {
  754. operator: 'AND',
  755. conditions: [
  756. {
  757. name: 'ticket.tags',
  758. operator: 'contains one',
  759. value: 'a,b,c',
  760. },
  761. ]
  762. }
  763. count, = Ticket.selectors(condition, { current_user: agent })
  764. expect(count).to eq(2)
  765. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  766. expect(result[:count]).to eq(2)
  767. end
  768. it 'checks tags c, d = 0', :aggregate_failures do
  769. condition = {
  770. operator: 'AND',
  771. conditions: [
  772. {
  773. name: 'ticket.tags',
  774. operator: 'contains one',
  775. value: 'c,d',
  776. },
  777. ]
  778. }
  779. count, = Ticket.selectors(condition, { current_user: agent })
  780. expect(count).to eq(0)
  781. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  782. expect(result[:count]).to eq(0)
  783. end
  784. it 'checks tags d = 0', :aggregate_failures do
  785. condition = {
  786. operator: 'AND',
  787. conditions: [
  788. {
  789. name: 'ticket.tags',
  790. operator: 'contains one',
  791. value: 'd',
  792. },
  793. ]
  794. }
  795. count, = Ticket.selectors(condition, { current_user: agent })
  796. expect(count).to eq(0)
  797. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  798. expect(result[:count]).to eq(0)
  799. end
  800. end
  801. describe 'contains all not' do
  802. it 'checks tags a = 1', :aggregate_failures do
  803. condition = {
  804. operator: 'AND',
  805. conditions: [
  806. {
  807. name: 'ticket.tags',
  808. operator: 'contains all not',
  809. value: 'a',
  810. },
  811. ]
  812. }
  813. count, = Ticket.selectors(condition, { current_user: agent })
  814. expect(count).to eq(1)
  815. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  816. expect(result[:count]).to eq(1)
  817. end
  818. it 'checks tags a, b = 2', :aggregate_failures do
  819. condition = {
  820. operator: 'AND',
  821. conditions: [
  822. {
  823. name: 'ticket.tags',
  824. operator: 'contains all not',
  825. value: 'a,b',
  826. },
  827. ]
  828. }
  829. count, = Ticket.selectors(condition, { current_user: agent })
  830. expect(count).to eq(2)
  831. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  832. expect(result[:count]).to eq(2)
  833. end
  834. it 'checks tags a, c = 3', :aggregate_failures do
  835. condition = {
  836. operator: 'AND',
  837. conditions: [
  838. {
  839. name: 'ticket.tags',
  840. operator: 'contains all not',
  841. value: 'a,c',
  842. },
  843. ]
  844. }
  845. count, = Ticket.selectors(condition, { current_user: agent })
  846. expect(count).to eq(3)
  847. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  848. expect(result[:count]).to eq(3)
  849. end
  850. it 'checks tags a, b, c = 3', :aggregate_failures do
  851. condition = {
  852. operator: 'AND',
  853. conditions: [
  854. {
  855. name: 'ticket.tags',
  856. operator: 'contains all not',
  857. value: 'a,b,c',
  858. },
  859. ]
  860. }
  861. count, = Ticket.selectors(condition, { current_user: agent })
  862. expect(count).to eq(3)
  863. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  864. expect(result[:count]).to eq(3)
  865. end
  866. it 'checks tags c, d = 3', :aggregate_failures do
  867. condition = {
  868. operator: 'AND',
  869. conditions: [
  870. {
  871. name: 'ticket.tags',
  872. operator: 'contains all not',
  873. value: 'c,d',
  874. },
  875. ]
  876. }
  877. count, = Ticket.selectors(condition, { current_user: agent })
  878. expect(count).to eq(3)
  879. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  880. expect(result[:count]).to eq(3)
  881. end
  882. it 'checks tags d = 3', :aggregate_failures do
  883. condition = {
  884. operator: 'AND',
  885. conditions: [
  886. {
  887. name: 'ticket.tags',
  888. operator: 'contains all not',
  889. value: 'd',
  890. },
  891. ]
  892. }
  893. count, = Ticket.selectors(condition, { current_user: agent })
  894. expect(count).to eq(3)
  895. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  896. expect(result[:count]).to eq(3)
  897. end
  898. end
  899. describe 'contains one not' do
  900. it 'checks tags a = 1', :aggregate_failures do
  901. condition = {
  902. operator: 'AND',
  903. conditions: [
  904. {
  905. name: 'ticket.tags',
  906. operator: 'contains one not',
  907. value: 'a',
  908. },
  909. ]
  910. }
  911. count, = Ticket.selectors(condition, { current_user: agent })
  912. expect(count).to eq(1)
  913. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  914. expect(result[:count]).to eq(1)
  915. end
  916. it 'checks tags a, b = 1', :aggregate_failures do
  917. condition = {
  918. operator: 'AND',
  919. conditions: [
  920. {
  921. name: 'ticket.tags',
  922. operator: 'contains one not',
  923. value: 'a,b',
  924. },
  925. ]
  926. }
  927. count, = Ticket.selectors(condition, { current_user: agent })
  928. expect(count).to eq(1)
  929. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  930. expect(result[:count]).to eq(1)
  931. end
  932. it 'checks tags a, c = 1', :aggregate_failures do
  933. condition = {
  934. operator: 'AND',
  935. conditions: [
  936. {
  937. name: 'ticket.tags',
  938. operator: 'contains one not',
  939. value: 'a,c',
  940. },
  941. ]
  942. }
  943. count, = Ticket.selectors(condition, { current_user: agent })
  944. expect(count).to eq(1)
  945. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  946. expect(result[:count]).to eq(1)
  947. end
  948. it 'checks tags a, b, c = 1', :aggregate_failures do
  949. condition = {
  950. operator: 'AND',
  951. conditions: [
  952. {
  953. name: 'ticket.tags',
  954. operator: 'contains one not',
  955. value: 'a,b,c',
  956. },
  957. ]
  958. }
  959. count, = Ticket.selectors(condition, { current_user: agent })
  960. expect(count).to eq(1)
  961. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  962. expect(result[:count]).to eq(1)
  963. end
  964. it 'checks tags c, d = 3', :aggregate_failures do
  965. condition = {
  966. operator: 'AND',
  967. conditions: [
  968. {
  969. name: 'ticket.tags',
  970. operator: 'contains one not',
  971. value: 'c,d',
  972. },
  973. ]
  974. }
  975. count, = Ticket.selectors(condition, { current_user: agent })
  976. expect(count).to eq(3)
  977. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  978. expect(result[:count]).to eq(3)
  979. end
  980. it 'checks tags d = 3', :aggregate_failures do
  981. condition = {
  982. operator: 'AND',
  983. conditions: [
  984. {
  985. name: 'ticket.tags',
  986. operator: 'contains one not',
  987. value: 'd',
  988. },
  989. ]
  990. }
  991. count, = Ticket.selectors(condition, { current_user: agent })
  992. expect(count).to eq(3)
  993. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  994. expect(result[:count]).to eq(3)
  995. end
  996. end
  997. end
  998. end