test4.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. */
  3. import { Observable, Subject, of } from "rxjs"
  4. import { ObservableStorage, SearchService } from "../services/query.service"
  5. import { Conditions, Storage } from "../services/query.service"
  6. import _ = require("lodash")
  7. import { DataPrepService } from "../services/dataprep.service"
  8. let query = new SearchService()
  9. let dataPrepService = new DataPrepService()
  10. let mongoStorage: Storage = {
  11. type: `MongoDB`,
  12. url: `mongodb://192.168.100.59:27017/default`
  13. }
  14. // Array inquiry: should return mutiple data
  15. let conditions1: Conditions[] = [
  16. { 'msgTag': ['Incoming'] }
  17. ]
  18. // Basic inquiry, but with multi search: should return one data
  19. let conditions2: Conditions[] = [
  20. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  21. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" },
  22. ]
  23. // Value only argument! : should return one data
  24. let conditions3: Conditions[] = [
  25. { "$regex": "cum incidunt maxime voluptatibus" }
  26. ]
  27. // Date Range inquiry: Should return 1 data
  28. let conditions4: Conditions[] = [
  29. {
  30. "$dateRange": {
  31. "startDate": "2022-04-29T00:00:00.000Z",
  32. 'endDate': "2022-04-30T00:00:00.000Z",
  33. 'column': "data.data.appData.msgDateTime"
  34. }
  35. },
  36. ]
  37. // Multi conditions except for regex search: Should return at least 1 data
  38. let conditions5: Conditions[] = [
  39. {
  40. "$dateRange": {
  41. "startDate": "2022-04-29T00:00:00.000Z",
  42. 'endDate': "2022-04-30T00:00:00.000Z",
  43. 'column': "data.data.appData.msgDateTime"
  44. }
  45. },
  46. { 'msgTag': ['basic'] },
  47. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  48. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  49. ]
  50. // Ultimate search. With all conditions piling at once: Should at least returns 1 data
  51. let conditions6: Conditions[] = [
  52. {
  53. "$dateRange": {
  54. "startDate": "2022-04-29T00:00:00.000Z",
  55. 'endDate': "2022-04-30T00:00:00.000Z",
  56. 'column': "data.data.appData.msgDateTime"
  57. }
  58. },
  59. { "$regex": "maxime voluptatibus ad quasi eveniet" },
  60. { 'msgTag': ['basic'] },
  61. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  62. ]
  63. // should return 1 data
  64. let conditions7: Conditions[] = [
  65. {
  66. "$dateRange": {
  67. "startDate": "2022-04-29T00:00:00.000Z",
  68. 'endDate': "2022-04-30T00:00:00.000Z",
  69. 'column': "data.data.appData.msgDateTime"
  70. }
  71. },
  72. { "$regex": "maxime voluptatibus ad quasi eveniet" },
  73. // { 'data.data.appData.msgTag': ['basic'] },
  74. { "data.data.appData.msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  75. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  76. ]
  77. // should not return anything
  78. let conditions8: Conditions[] = [
  79. {
  80. "$dateRange": {
  81. "startDate": "2022-04-29T00:00:00.000Z",
  82. 'endDate': "2022-04-30T00:00:00.000Z",
  83. 'column': "data.data.appData.msgDateTime"
  84. }
  85. },
  86. { "$regex": "maxime voluptatibus ad quasi eveniet" },
  87. { 'msgTag': ['basic'] },
  88. { "data.data.appDatamsgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  89. { "header.msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  90. ]
  91. let obsStorage : Subject<any> = new Subject()
  92. dataPrepService.loadObsData(mongoStorage, obsStorage)
  93. const testObs: ObservableStorage = {
  94. type: "observable",
  95. ref: obsStorage
  96. }
  97. query.query(testObs, ...conditions1).subscribe((element) => {
  98. console.log(element.appData.msgId)
  99. })