@talkpilot/core-db 1.1.6 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (331) hide show
  1. package/dist/connection.d.ts +1 -1
  2. package/dist/connection.d.ts.map +1 -1
  3. package/dist/connection.js +24 -21
  4. package/dist/connection.js.map +1 -1
  5. package/dist/index.d.ts +9 -9
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/municipal/cities/cities.getters.d.ts +2 -2
  9. package/dist/municipal/cities/cities.getters.d.ts.map +1 -1
  10. package/dist/municipal/cities/cities.getters.js +4 -8
  11. package/dist/municipal/cities/cities.getters.js.map +1 -1
  12. package/dist/municipal/cities/cities.types.d.ts +1 -1
  13. package/dist/municipal/cities/index.d.ts +2 -2
  14. package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts +3 -3
  15. package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts.map +1 -1
  16. package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js +22 -30
  17. package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js.map +1 -1
  18. package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts +4 -4
  19. package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts.map +1 -1
  20. package/dist/municipal/departmentsSubjects/index.d.ts +2 -2
  21. package/dist/municipal/index.d.ts +8 -8
  22. package/dist/municipal/index.d.ts.map +1 -1
  23. package/dist/municipal/index.js +1 -1
  24. package/dist/municipal/mongodb-client.d.ts +1 -1
  25. package/dist/municipal/mongodb-client.d.ts.map +1 -1
  26. package/dist/municipal/mongodb-client.js +25 -13
  27. package/dist/municipal/mongodb-client.js.map +1 -1
  28. package/dist/municipal/streets/index.d.ts +2 -2
  29. package/dist/municipal/streets/streets.getters.d.ts +3 -3
  30. package/dist/municipal/streets/streets.getters.d.ts.map +1 -1
  31. package/dist/municipal/streets/streets.getters.js +9 -19
  32. package/dist/municipal/streets/streets.getters.js.map +1 -1
  33. package/dist/municipal/streets/streets.types.d.ts +1 -1
  34. package/dist/municipal/systemInstructions/index.d.ts +3 -3
  35. package/dist/municipal/systemInstructions/index.d.ts.map +1 -1
  36. package/dist/municipal/systemInstructions/instructions.getters.d.ts +3 -3
  37. package/dist/municipal/systemInstructions/instructions.getters.d.ts.map +1 -1
  38. package/dist/municipal/systemInstructions/instructions.getters.js +4 -10
  39. package/dist/municipal/systemInstructions/instructions.getters.js.map +1 -1
  40. package/dist/municipal/systemInstructions/instructions.setters.d.ts +2 -2
  41. package/dist/municipal/systemInstructions/instructions.setters.d.ts.map +1 -1
  42. package/dist/municipal/systemInstructions/instructions.setters.js +8 -13
  43. package/dist/municipal/systemInstructions/instructions.setters.js.map +1 -1
  44. package/dist/municipal/systemInstructions/instructions.types.d.ts +3 -3
  45. package/dist/municipal/systemInstructions/instructions.types.d.ts.map +1 -1
  46. package/dist/municipal/systemInstructions/instructions.types.js +6 -6
  47. package/dist/municipal/tickets/index.d.ts +2 -2
  48. package/dist/municipal/tickets/tickets.getters.d.ts +3 -3
  49. package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -1
  50. package/dist/municipal/tickets/tickets.getters.js +29 -50
  51. package/dist/municipal/tickets/tickets.getters.js.map +1 -1
  52. package/dist/municipal/tickets/tickets.types.d.ts +1 -1
  53. package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
  54. package/dist/municipal/utils/types.d.ts +1 -1
  55. package/dist/municipal/utils/types.d.ts.map +1 -1
  56. package/dist/talkpilot/agents/agents.getters.d.ts +1 -1
  57. package/dist/talkpilot/agents/agents.getters.js +2 -2
  58. package/dist/talkpilot/agents/agents.types.d.ts +2 -2
  59. package/dist/talkpilot/agents/index.d.ts +2 -2
  60. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.d.ts +2 -2
  61. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.d.ts.map +1 -1
  62. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.js +1 -1
  63. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.js.map +1 -1
  64. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.types.d.ts +2 -2
  65. package/dist/talkpilot/backgroundToolResults/index.d.ts +2 -2
  66. package/dist/talkpilot/calls/calls.getters.d.ts +3 -3
  67. package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
  68. package/dist/talkpilot/calls/calls.getters.js +15 -19
  69. package/dist/talkpilot/calls/calls.getters.js.map +1 -1
  70. package/dist/talkpilot/calls/calls.types.d.ts +3 -3
  71. package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
  72. package/dist/talkpilot/calls/calls.types.js +2 -2
  73. package/dist/talkpilot/calls/index.d.ts +2 -2
  74. package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts +2 -2
  75. package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts.map +1 -1
  76. package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js +2 -2
  77. package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js.map +1 -1
  78. package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.d.ts +2 -2
  79. package/dist/talkpilot/clientAudioBuffers/index.d.ts +2 -2
  80. package/dist/talkpilot/clients/clients.getters.d.ts +2 -2
  81. package/dist/talkpilot/clients/clients.getters.d.ts.map +1 -1
  82. package/dist/talkpilot/clients/clients.getters.js +2 -5
  83. package/dist/talkpilot/clients/clients.getters.js.map +1 -1
  84. package/dist/talkpilot/clients/clients.types.d.ts +1 -1
  85. package/dist/talkpilot/clients/index.d.ts +2 -2
  86. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +2 -2
  87. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
  88. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +1 -1
  89. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
  90. package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +3 -3
  91. package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
  92. package/dist/talkpilot/clientsConfig/index.d.ts +2 -2
  93. package/dist/talkpilot/flows/flows.getter.d.ts +2 -2
  94. package/dist/talkpilot/flows/flows.getter.d.ts.map +1 -1
  95. package/dist/talkpilot/flows/flows.getter.js +1 -1
  96. package/dist/talkpilot/flows/flows.getter.js.map +1 -1
  97. package/dist/talkpilot/flows/flows.schema.d.ts +3 -0
  98. package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
  99. package/dist/talkpilot/flows/flows.schema.js +80 -87
  100. package/dist/talkpilot/flows/flows.schema.js.map +1 -1
  101. package/dist/talkpilot/flows/flows.types.d.ts +17 -16
  102. package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
  103. package/dist/talkpilot/flows/index.d.ts +2 -2
  104. package/dist/talkpilot/groups/groups.getters.d.ts +2 -2
  105. package/dist/talkpilot/groups/groups.getters.d.ts.map +1 -1
  106. package/dist/talkpilot/groups/groups.getters.js +2 -2
  107. package/dist/talkpilot/groups/groups.getters.js.map +1 -1
  108. package/dist/talkpilot/groups/groups.types.d.ts +1 -1
  109. package/dist/talkpilot/groups/index.d.ts +3 -3
  110. package/dist/talkpilot/groups/phone.utils.d.ts +1 -1
  111. package/dist/talkpilot/groups/phone.utils.d.ts.map +1 -1
  112. package/dist/talkpilot/groups/phone.utils.js +2 -2
  113. package/dist/talkpilot/groups/phone.utils.js.map +1 -1
  114. package/dist/talkpilot/index.d.ts +16 -16
  115. package/dist/talkpilot/index.js +1 -1
  116. package/dist/talkpilot/leads/index.d.ts +2 -2
  117. package/dist/talkpilot/leads/leads.getter.d.ts +2 -2
  118. package/dist/talkpilot/leads/leads.getter.d.ts.map +1 -1
  119. package/dist/talkpilot/leads/leads.getter.js +1 -1
  120. package/dist/talkpilot/leads/leads.getter.js.map +1 -1
  121. package/dist/talkpilot/leads/leads.schema.js +16 -16
  122. package/dist/talkpilot/leads/leads.types.d.ts +1 -1
  123. package/dist/talkpilot/mongodb-client.d.ts +1 -1
  124. package/dist/talkpilot/mongodb-client.d.ts.map +1 -1
  125. package/dist/talkpilot/mongodb-client.js +29 -16
  126. package/dist/talkpilot/mongodb-client.js.map +1 -1
  127. package/dist/talkpilot/phone_numbers/index.d.ts +2 -2
  128. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +3 -3
  129. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
  130. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +13 -28
  131. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
  132. package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +9 -9
  133. package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +1 -1
  134. package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts.map +1 -1
  135. package/dist/talkpilot/plans/index.d.ts +2 -2
  136. package/dist/talkpilot/plans/plans.getters.d.ts +2 -2
  137. package/dist/talkpilot/plans/plans.getters.d.ts.map +1 -1
  138. package/dist/talkpilot/plans/plans.getters.js +3 -3
  139. package/dist/talkpilot/plans/plans.getters.js.map +1 -1
  140. package/dist/talkpilot/plans/plans.types.d.ts +4 -4
  141. package/dist/talkpilot/plans/plans.types.d.ts.map +1 -1
  142. package/dist/talkpilot/plans/plans.types.js +19 -19
  143. package/dist/talkpilot/results/index.d.ts +2 -2
  144. package/dist/talkpilot/results/index.d.ts.map +1 -1
  145. package/dist/talkpilot/results/index.js.map +1 -1
  146. package/dist/talkpilot/results/results.getter.d.ts +3 -3
  147. package/dist/talkpilot/results/results.getter.d.ts.map +1 -1
  148. package/dist/talkpilot/results/results.getter.js +4 -4
  149. package/dist/talkpilot/results/results.getter.js.map +1 -1
  150. package/dist/talkpilot/results/results.schema.js +18 -18
  151. package/dist/talkpilot/results/results.types.d.ts +1 -1
  152. package/dist/talkpilot/sessions/index.d.ts +2 -2
  153. package/dist/talkpilot/sessions/sessions.getter.d.ts +3 -3
  154. package/dist/talkpilot/sessions/sessions.getter.d.ts.map +1 -1
  155. package/dist/talkpilot/sessions/sessions.getter.js +10 -13
  156. package/dist/talkpilot/sessions/sessions.getter.js.map +1 -1
  157. package/dist/talkpilot/sessions/sessions.schema.js +17 -17
  158. package/dist/talkpilot/sessions/sessions.types.d.ts +2 -2
  159. package/dist/talkpilot/subscriptions/index.d.ts +3 -3
  160. package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts +2 -2
  161. package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts.map +1 -1
  162. package/dist/talkpilot/subscriptions/subscriptions.getters.js +11 -11
  163. package/dist/talkpilot/subscriptions/subscriptions.getters.js.map +1 -1
  164. package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts +2 -2
  165. package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts.map +1 -1
  166. package/dist/talkpilot/subscriptions/subscriptions.getters.utils.js.map +1 -1
  167. package/dist/talkpilot/subscriptions/subscriptions.types.d.ts +2 -2
  168. package/dist/talkpilot/subscriptions/subscriptions.types.d.ts.map +1 -1
  169. package/dist/talkpilot/subscriptions/subscriptions.types.js +7 -7
  170. package/dist/talkpilot/utils/query.utils.d.ts +1 -1
  171. package/dist/test-utils/db-utils.d.ts +1 -1
  172. package/dist/test-utils/db-utils.js +2 -2
  173. package/dist/test-utils/factories/index.d.ts +12 -12
  174. package/dist/test-utils/factories/municipal/cities.d.ts +2 -2
  175. package/dist/test-utils/factories/municipal/cities.d.ts.map +1 -1
  176. package/dist/test-utils/factories/municipal/cities.js +1 -1
  177. package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts +2 -2
  178. package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts.map +1 -1
  179. package/dist/test-utils/factories/municipal/departmentsSubjects.js +1 -7
  180. package/dist/test-utils/factories/municipal/departmentsSubjects.js.map +1 -1
  181. package/dist/test-utils/factories/municipal/streets.d.ts +2 -2
  182. package/dist/test-utils/factories/municipal/streets.d.ts.map +1 -1
  183. package/dist/test-utils/factories/municipal/streets.js +1 -6
  184. package/dist/test-utils/factories/municipal/streets.js.map +1 -1
  185. package/dist/test-utils/factories/municipal/tickets.d.ts +2 -2
  186. package/dist/test-utils/factories/municipal/tickets.d.ts.map +1 -1
  187. package/dist/test-utils/factories/municipal/tickets.js +1 -7
  188. package/dist/test-utils/factories/municipal/tickets.js.map +1 -1
  189. package/dist/test-utils/factories/talkpilot/agents.d.ts +2 -2
  190. package/dist/test-utils/factories/talkpilot/agents.d.ts.map +1 -1
  191. package/dist/test-utils/factories/talkpilot/agents.js +4 -4
  192. package/dist/test-utils/factories/talkpilot/calls.d.ts +2 -2
  193. package/dist/test-utils/factories/talkpilot/calls.d.ts.map +1 -1
  194. package/dist/test-utils/factories/talkpilot/calls.js +1 -1
  195. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts +2 -2
  196. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts.map +1 -1
  197. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js +1 -1
  198. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js.map +1 -1
  199. package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts +2 -2
  200. package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts.map +1 -1
  201. package/dist/test-utils/factories/talkpilot/clientsConfig.js.map +1 -1
  202. package/dist/test-utils/factories/talkpilot/flows.d.ts +3 -3
  203. package/dist/test-utils/factories/talkpilot/flows.d.ts.map +1 -1
  204. package/dist/test-utils/factories/talkpilot/flows.js.map +1 -1
  205. package/dist/test-utils/factories/talkpilot/groups.d.ts +2 -2
  206. package/dist/test-utils/factories/talkpilot/groups.d.ts.map +1 -1
  207. package/dist/test-utils/factories/talkpilot/groups.js +9 -9
  208. package/dist/test-utils/factories/talkpilot/groups.js.map +1 -1
  209. package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts +3 -3
  210. package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts.map +1 -1
  211. package/dist/test-utils/factories/talkpilot/phone_numbers.js.map +1 -1
  212. package/dist/test-utils/factories/talkpilot/sessions.d.ts +2 -2
  213. package/dist/test-utils/factories/talkpilot/sessions.d.ts.map +1 -1
  214. package/dist/test-utils/factories/talkpilot/sessions.js +1 -1
  215. package/dist/utils/validation.js +2 -2
  216. package/dist/utils/validation.js.map +1 -1
  217. package/package.json +1 -3
  218. package/src/__tests__/setup.ts +3 -3
  219. package/src/connection.ts +25 -27
  220. package/src/index.ts +9 -9
  221. package/src/municipal/__tests__/validation.spec.ts +23 -35
  222. package/src/municipal/cities/cities.getters.ts +10 -16
  223. package/src/municipal/cities/cities.types.ts +1 -1
  224. package/src/municipal/cities/index.ts +2 -2
  225. package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +44 -53
  226. package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +5 -5
  227. package/src/municipal/departmentsSubjects/index.ts +3 -2
  228. package/src/municipal/index.ts +10 -10
  229. package/src/municipal/mongodb-client.ts +26 -19
  230. package/src/municipal/streets/index.ts +2 -2
  231. package/src/municipal/streets/streets.getters.ts +23 -43
  232. package/src/municipal/streets/streets.types.ts +1 -1
  233. package/src/municipal/systemInstructions/__tests__/getters.spec.ts +52 -67
  234. package/src/municipal/systemInstructions/__tests__/setters.spec.ts +238 -271
  235. package/src/municipal/systemInstructions/index.ts +3 -7
  236. package/src/municipal/systemInstructions/instructions.getters.ts +18 -30
  237. package/src/municipal/systemInstructions/instructions.setters.ts +19 -43
  238. package/src/municipal/systemInstructions/instructions.types.ts +10 -10
  239. package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +12 -12
  240. package/src/municipal/tickets/index.ts +2 -2
  241. package/src/municipal/tickets/tickets.getters.ts +42 -69
  242. package/src/municipal/tickets/tickets.types.ts +2 -2
  243. package/src/municipal/utils/types.ts +3 -8
  244. package/src/talkpilot/__tests__/db.spec.ts +12 -12
  245. package/src/talkpilot/__tests__/mongodb-client.spec.ts +8 -7
  246. package/src/talkpilot/__tests__/validation.spec.ts +24 -30
  247. package/src/talkpilot/agents/__tests__/agents.getters.spec.ts +10 -10
  248. package/src/talkpilot/agents/agents.getters.ts +3 -3
  249. package/src/talkpilot/agents/agents.types.ts +2 -2
  250. package/src/talkpilot/agents/index.ts +2 -2
  251. package/src/talkpilot/backgroundToolResults/__tests__/backgroundToolResults.getters.spec.ts +31 -42
  252. package/src/talkpilot/backgroundToolResults/backgroundToolResults.getters.ts +11 -11
  253. package/src/talkpilot/backgroundToolResults/backgroundToolResults.types.ts +3 -2
  254. package/src/talkpilot/backgroundToolResults/index.ts +2 -2
  255. package/src/talkpilot/calls/__tests__/callStats.utils.spec.ts +27 -27
  256. package/src/talkpilot/calls/__tests__/calls.spec.ts +39 -79
  257. package/src/talkpilot/calls/calls.getters.ts +28 -48
  258. package/src/talkpilot/calls/calls.types.ts +16 -16
  259. package/src/talkpilot/calls/index.ts +2 -2
  260. package/src/talkpilot/clientAudioBuffers/__tests__/clientAudioBuffer.getters.spec.ts +39 -73
  261. package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +11 -18
  262. package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +2 -2
  263. package/src/talkpilot/clientAudioBuffers/index.ts +2 -2
  264. package/src/talkpilot/clients/clients.getters.ts +5 -10
  265. package/src/talkpilot/clients/clients.types.ts +1 -1
  266. package/src/talkpilot/clients/index.ts +2 -2
  267. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +18 -21
  268. package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +4 -6
  269. package/src/talkpilot/clientsConfig/clientsConfig.types.ts +8 -10
  270. package/src/talkpilot/clientsConfig/index.ts +2 -2
  271. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +37 -38
  272. package/src/talkpilot/flows/flows.getter.ts +5 -8
  273. package/src/talkpilot/flows/flows.schema.ts +80 -87
  274. package/src/talkpilot/flows/flows.types.ts +24 -23
  275. package/src/talkpilot/flows/index.ts +2 -2
  276. package/src/talkpilot/groups/__tests__/groups.spec.ts +27 -34
  277. package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +20 -20
  278. package/src/talkpilot/groups/groups.getters.ts +5 -8
  279. package/src/talkpilot/groups/groups.types.ts +1 -1
  280. package/src/talkpilot/groups/index.ts +3 -3
  281. package/src/talkpilot/groups/phone.utils.ts +6 -12
  282. package/src/talkpilot/index.ts +17 -17
  283. package/src/talkpilot/leads/index.ts +2 -2
  284. package/src/talkpilot/leads/leads.getter.ts +4 -5
  285. package/src/talkpilot/leads/leads.schema.ts +16 -16
  286. package/src/talkpilot/leads/leads.types.ts +1 -1
  287. package/src/talkpilot/mongodb-client.ts +33 -23
  288. package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +44 -84
  289. package/src/talkpilot/phone_numbers/index.ts +2 -2
  290. package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +22 -44
  291. package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +9 -9
  292. package/src/talkpilot/phone_numbers/phone_numbers.types.ts +1 -1
  293. package/src/talkpilot/plans/__tests__/plans.spec.ts +26 -30
  294. package/src/talkpilot/plans/index.ts +2 -2
  295. package/src/talkpilot/plans/plans.getters.ts +18 -25
  296. package/src/talkpilot/plans/plans.types.ts +23 -27
  297. package/src/talkpilot/results/index.ts +2 -5
  298. package/src/talkpilot/results/results.getter.ts +8 -9
  299. package/src/talkpilot/results/results.schema.ts +18 -18
  300. package/src/talkpilot/results/results.types.ts +1 -1
  301. package/src/talkpilot/sessions/__tests__/sessions.spec.ts +41 -65
  302. package/src/talkpilot/sessions/index.ts +2 -2
  303. package/src/talkpilot/sessions/sessions.getter.ts +16 -21
  304. package/src/talkpilot/sessions/sessions.schema.ts +17 -17
  305. package/src/talkpilot/sessions/sessions.types.ts +2 -2
  306. package/src/talkpilot/subscriptions/__tests__/subscriptions.getters.utils.spec.ts +15 -18
  307. package/src/talkpilot/subscriptions/index.ts +3 -3
  308. package/src/talkpilot/subscriptions/subscriptions.getters.ts +33 -36
  309. package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +3 -10
  310. package/src/talkpilot/subscriptions/subscriptions.types.ts +9 -9
  311. package/src/talkpilot/utils/__tests__/query.utils.spec.ts +8 -8
  312. package/src/talkpilot/utils/query.utils.ts +2 -2
  313. package/src/test-utils/db-utils.ts +5 -5
  314. package/src/test-utils/factories/index.ts +12 -12
  315. package/src/test-utils/factories/municipal/cities.ts +5 -5
  316. package/src/test-utils/factories/municipal/departmentsSubjects.ts +25 -32
  317. package/src/test-utils/factories/municipal/streets.ts +5 -10
  318. package/src/test-utils/factories/municipal/tickets.ts +6 -12
  319. package/src/test-utils/factories/talkpilot/agents.ts +8 -8
  320. package/src/test-utils/factories/talkpilot/calls.ts +5 -5
  321. package/src/test-utils/factories/talkpilot/clientAudioBuffers.ts +12 -14
  322. package/src/test-utils/factories/talkpilot/clientsConfig.ts +8 -7
  323. package/src/test-utils/factories/talkpilot/flows.ts +5 -7
  324. package/src/test-utils/factories/talkpilot/groups.ts +13 -13
  325. package/src/test-utils/factories/talkpilot/phone_numbers.ts +6 -8
  326. package/src/test-utils/factories/talkpilot/sessions.ts +5 -5
  327. package/src/utils/validation.ts +4 -4
  328. package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts +0 -4
  329. package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts.map +0 -1
  330. package/dist/talkpilot/subscriptions/subscriptions.utils.js +0 -20
  331. package/dist/talkpilot/subscriptions/subscriptions.utils.js.map +0 -1
@@ -1,11 +1,7 @@
1
- import { ObjectId } from "../index";
2
- import { ObjectId as MongoObjectId } from "mongodb";
3
- import {
4
- MIS_SystemInstruction,
5
- MIS_TOOLS,
6
- QUERY_TYPES,
7
- } from "./instructions.types";
8
- import { getSystemInstructionsCollection } from "./instructions.getters";
1
+ import { ObjectId } from '../index';
2
+ import { ObjectId as MongoObjectId } from 'mongodb';
3
+ import { MIS_SystemInstruction, MIS_TOOLS, QUERY_TYPES } from './instructions.types';
4
+ import { getSystemInstructionsCollection } from './instructions.getters';
9
5
 
10
6
  /**
11
7
  * Validate system instruction data
@@ -13,21 +9,11 @@ import { getSystemInstructionsCollection } from "./instructions.getters";
13
9
  * @throws Error if tool or queryType is invalid
14
10
  */
15
11
  const validateInstructionData = (data: Partial<MIS_SystemInstruction>) => {
16
- if (
17
- data.tool &&
18
- !(Object.values(MIS_TOOLS) as string[]).includes(data.tool)
19
- ) {
20
- throw new Error(
21
- `Invalid tool value: ${data.tool}. Allowed values are: ${Object.values(MIS_TOOLS).join(", ")}`,
22
- );
12
+ if (data.tool && !(Object.values(MIS_TOOLS) as string[]).includes(data.tool)) {
13
+ throw new Error(`Invalid tool value: ${data.tool}. Allowed values are: ${Object.values(MIS_TOOLS).join(', ')}`);
23
14
  }
24
- if (
25
- data.queryType &&
26
- !(Object.values(QUERY_TYPES) as string[]).includes(data.queryType)
27
- ) {
28
- throw new Error(
29
- `Invalid queryType value: ${data.queryType}. Allowed values are: ${Object.values(QUERY_TYPES).join(", ")}`,
30
- );
15
+ if (data.queryType && !(Object.values(QUERY_TYPES) as string[]).includes(data.queryType)) {
16
+ throw new Error(`Invalid queryType value: ${data.queryType}. Allowed values are: ${Object.values(QUERY_TYPES).join(', ')}`);
31
17
  }
32
18
  };
33
19
 
@@ -37,20 +23,16 @@ const validateInstructionData = (data: Partial<MIS_SystemInstruction>) => {
37
23
  * @returns inserted system instruction id
38
24
  */
39
25
  export const createSystemInstruction = async (
40
- instructionData: Omit<
41
- MIS_SystemInstruction,
42
- "_id" | "createdAt" | "updatedAt"
43
- >,
26
+ instructionData: Omit<MIS_SystemInstruction, '_id' | 'createdAt' | 'updatedAt'>
44
27
  ): Promise<MongoObjectId> => {
45
28
  validateInstructionData(instructionData as Partial<MIS_SystemInstruction>);
46
- const instruction: Omit<MIS_SystemInstruction, "_id"> = {
47
- //append doc metadata to user provided data
29
+ const instruction: Omit<MIS_SystemInstruction, '_id'> = { //append doc metadata to user provided data
48
30
  ...instructionData,
49
31
  createdAt: new Date(),
50
32
  updatedAt: new Date(),
51
33
  };
52
34
  const { insertedId } = await getSystemInstructionsCollection().insertOne(
53
- instruction as MIS_SystemInstruction,
35
+ instruction as MIS_SystemInstruction
54
36
  );
55
37
  return insertedId;
56
38
  };
@@ -63,13 +45,13 @@ export const createSystemInstruction = async (
63
45
  */
64
46
  export const updateSystemInstruction = async (
65
47
  id: string,
66
- data: Partial<Omit<MIS_SystemInstruction, "_id" | "createdAt" | "updatedAt">>,
48
+ data: Partial<Omit<MIS_SystemInstruction, '_id' | 'createdAt' | 'updatedAt'>>
67
49
  ): Promise<MIS_SystemInstruction | null> => {
68
50
  validateInstructionData(data as Partial<MIS_SystemInstruction>);
69
51
  const result = await getSystemInstructionsCollection().findOneAndUpdate(
70
52
  { _id: new ObjectId(id) },
71
53
  { $set: { ...data, updatedAt: new Date() } },
72
- { returnDocument: "after" },
54
+ { returnDocument: 'after' }
73
55
  );
74
56
  return result || null;
75
57
  };
@@ -80,9 +62,7 @@ export const updateSystemInstruction = async (
80
62
  * @returns true if deleted, false otherwise
81
63
  */
82
64
  export const deleteSystemInstruction = async (id: string): Promise<boolean> => {
83
- const result = await getSystemInstructionsCollection().deleteOne({
84
- _id: new ObjectId(id),
85
- });
65
+ const result = await getSystemInstructionsCollection().deleteOne({ _id: new ObjectId(id) });
86
66
  return result.deletedCount > 0;
87
67
  };
88
68
  /**
@@ -91,13 +71,11 @@ export const deleteSystemInstruction = async (id: string): Promise<boolean> => {
91
71
  * @param id system instruction id
92
72
  * @returns true on success, false otherwise
93
73
  */
94
- export const activateSystemInstruction = async (
95
- id: string,
96
- ): Promise<boolean> => {
74
+ export const activateSystemInstruction = async (id: string): Promise<boolean> => {
97
75
  const result = await getSystemInstructionsCollection().findOneAndUpdate(
98
76
  { _id: new ObjectId(id) },
99
77
  { $set: { isActive: true } },
100
- { returnDocument: "after" },
78
+ { returnDocument: 'after' }
101
79
  );
102
80
  return Boolean(result);
103
81
  };
@@ -107,13 +85,11 @@ export const activateSystemInstruction = async (
107
85
  * @param id system instruction id
108
86
  * @returns true on success, false otherwise
109
87
  */
110
- export const deactivateSystemInstruction = async (
111
- id: string,
112
- ): Promise<boolean> => {
88
+ export const deactivateSystemInstruction = async (id: string): Promise<boolean> => {
113
89
  const result = await getSystemInstructionsCollection().findOneAndUpdate(
114
90
  { _id: new ObjectId(id) },
115
91
  { $set: { isActive: false } },
116
- { returnDocument: "after" },
92
+ {returnDocument: 'after'}
117
93
  );
118
94
  return Boolean(result);
119
- };
95
+ }
@@ -1,21 +1,21 @@
1
- import { ObjectId } from "mongodb";
1
+ import { ObjectId } from 'mongodb';
2
2
 
3
- import { CityName } from "../utils/types";
3
+ import {CityName} from "../utils/types";
4
4
 
5
5
  export const MIS_TOOLS = {
6
- findStreet: "findStreet",
7
- findSubject: "findSubject",
6
+ findStreet: 'findStreet',
7
+ findSubject: 'findSubject'
8
8
  } as const;
9
9
 
10
10
  export const QUERY_TYPES = {
11
- exactlyOne: "exactlyOne",
12
- any: "any",
13
- all: "all",
14
- none: "none",
11
+ exactlyOne: 'exactlyOne',
12
+ any: 'any',
13
+ all: 'all',
14
+ none: 'none'
15
15
  } as const;
16
16
 
17
- export type MIS_Tool = (typeof MIS_TOOLS)[keyof typeof MIS_TOOLS];
18
- export type QueryType = (typeof QUERY_TYPES)[keyof typeof QUERY_TYPES];
17
+ export type MIS_Tool = typeof MIS_TOOLS[keyof typeof MIS_TOOLS];
18
+ export type QueryType = typeof QUERY_TYPES[keyof typeof QUERY_TYPES];
19
19
 
20
20
  export type MIS_SystemInstruction = {
21
21
  _id: ObjectId;
@@ -1,14 +1,14 @@
1
- import { findTicketsByCallSid } from "../tickets.getters";
2
- import { setDb } from "../../index";
3
- import { Db, Collection } from "mongodb";
4
- import { createTicket } from "../../../test-utils/factories";
1
+ import { findTicketsByCallSid } from '../tickets.getters';
2
+ import { setDb } from '../../index';
3
+ import { Db, Collection } from 'mongodb';
4
+ import { createTicket } from '../../../test-utils/factories';
5
5
 
6
- describe("tickets getters", () => {
6
+ describe('tickets getters', () => {
7
7
  let mockDb: Partial<Db>;
8
8
  let mockCollection: Partial<Collection>;
9
9
 
10
10
  beforeEach(() => {
11
- const mockTicket = createTicket({ callSid: "123" });
11
+ const mockTicket = createTicket({ callSid: '123' });
12
12
  mockCollection = {
13
13
  find: jest.fn().mockReturnValue({
14
14
  toArray: jest.fn().mockResolvedValue([mockTicket]),
@@ -20,11 +20,11 @@ describe("tickets getters", () => {
20
20
  setDb(mockDb as Db);
21
21
  });
22
22
 
23
- it("findTicketsByCallSid should return tickets for the given callSid", async () => {
24
- const result = await findTicketsByCallSid("123");
25
-
26
- expect(mockDb.collection).toHaveBeenCalledWith("tickets");
27
- expect(mockCollection.find).toHaveBeenCalledWith({ callSid: "123" });
28
- expect(result[0].callSid).toBe("123");
23
+ it('findTicketsByCallSid should return tickets for the given callSid', async () => {
24
+ const result = await findTicketsByCallSid('123');
25
+
26
+ expect(mockDb.collection).toHaveBeenCalledWith('tickets');
27
+ expect(mockCollection.find).toHaveBeenCalledWith({ callSid: '123' });
28
+ expect(result[0].callSid).toBe('123');
29
29
  });
30
30
  });
@@ -1,2 +1,2 @@
1
- export * from "./tickets.getters";
2
- export type { Ticket, TicketDoc, SubjectStatsItem } from "./tickets.types";
1
+ export * from './tickets.getters';
2
+ export type { Ticket, TicketDoc, SubjectStatsItem } from './tickets.types';
@@ -1,6 +1,6 @@
1
- import { CityName, getDb, ObjectId, Ticket } from "../index";
2
- import type { SubjectStatsItem } from "./tickets.types";
3
- import { Collection, Filter, ObjectId as MongoObjectId } from "mongodb";
1
+ import {CityName, getDb, ObjectId, Ticket} from '../index';
2
+ import type { SubjectStatsItem } from './tickets.types';
3
+ import { Collection, Filter, ObjectId as MongoObjectId } from 'mongodb';
4
4
 
5
5
  /**
6
6
  * Generate a new ticket ID as a string
@@ -11,33 +11,25 @@ export const generateTicketId = (): string => {
11
11
  };
12
12
 
13
13
  export const getTicketsCollection = (): Collection<Ticket> => {
14
- return getDb().collection<Ticket>("tickets");
14
+ return getDb().collection<Ticket>('tickets');
15
15
  };
16
16
 
17
- export const findTickets = async (
18
- filter: Filter<Ticket> = {},
19
- ): Promise<Ticket[]> => {
17
+ export const findTickets = async (filter: Filter<Ticket> = {}): Promise<Ticket[]> => {
20
18
  return await getTicketsCollection().find(filter).toArray();
21
19
  };
22
20
 
23
- export const findTicketsByCallSid = async (
24
- callSid: string,
25
- ): Promise<Ticket[]> => {
21
+ export const findTicketsByCallSid = async (callSid: string): Promise<Ticket[]> => {
26
22
  return await getTicketsCollection().find({ callSid }).toArray();
27
23
  };
28
24
 
29
- export const getTicketById = async (
30
- ticketId: string,
31
- ): Promise<Ticket | null> => {
32
- const ticket = await getTicketsCollection().findOne({
33
- _id: new ObjectId(ticketId),
34
- });
25
+ export const getTicketById = async (ticketId: string): Promise<Ticket | null> => {
26
+ const ticket = await getTicketsCollection().findOne({ _id: new ObjectId(ticketId) });
35
27
  return ticket ? ticket : null;
36
28
  };
37
29
 
38
30
  export const createTicket = async (
39
- ticketData: Omit<Ticket, "_id" | "createdAt" | "updatedAt">,
40
- ticketId?: string,
31
+ ticketData: Omit<Ticket, '_id' | 'createdAt' | 'updatedAt'>,
32
+ ticketId?: string
41
33
  ): Promise<MongoObjectId> => {
42
34
  const ticket: Ticket = {
43
35
  _id: ticketId ? new ObjectId(ticketId) : new ObjectId(),
@@ -51,20 +43,18 @@ export const createTicket = async (
51
43
 
52
44
  export const updateTicket = async (
53
45
  ticketId: string,
54
- data: Partial<Omit<Ticket, "_id" | "createdAt" | "updatedAt">>,
46
+ data: Partial<Omit<Ticket, '_id' | 'createdAt' | 'updatedAt'>>
55
47
  ): Promise<Ticket | null> => {
56
48
  const result = await getTicketsCollection().findOneAndUpdate(
57
49
  { _id: new ObjectId(ticketId) },
58
50
  { $set: { ...data, updatedAt: new Date() } },
59
- { returnDocument: "after" },
51
+ { returnDocument: 'after' }
60
52
  );
61
53
  return result || null;
62
54
  };
63
55
 
64
56
  export const deleteTicket = async (ticketId: string): Promise<boolean> => {
65
- const result = await getTicketsCollection().deleteOne({
66
- _id: new ObjectId(ticketId),
67
- });
57
+ const result = await getTicketsCollection().deleteOne({ _id: new ObjectId(ticketId) });
68
58
  return result.deletedCount > 0;
69
59
  };
70
60
 
@@ -76,7 +66,7 @@ export async function getTicketsCountByCityAndDateRange(
76
66
  cityName: string,
77
67
  startStr: string,
78
68
  endStr: string,
79
- timezone: string,
69
+ timezone: string
80
70
  ): Promise<number> {
81
71
  const doc = await getTicketsCollection()
82
72
  .aggregate<{ n: number }>([
@@ -84,12 +74,12 @@ export async function getTicketsCountByCityAndDateRange(
84
74
  {
85
75
  $addFields: {
86
76
  dateLocal: {
87
- $dateToString: { format: "%Y-%m-%d", date: "$createdAt", timezone },
77
+ $dateToString: { format: '%Y-%m-%d', date: '$createdAt', timezone },
88
78
  },
89
79
  },
90
80
  },
91
81
  { $match: { dateLocal: { $gte: startStr, $lte: endStr } } },
92
- { $count: "n" },
82
+ { $count: 'n' },
93
83
  ])
94
84
  .next();
95
85
  return doc?.n ?? 0;
@@ -103,7 +93,7 @@ export async function getTicketsSubjectStats(
103
93
  cityName: string,
104
94
  startStr: string,
105
95
  endStr: string,
106
- timezone: string,
96
+ timezone: string
107
97
  ): Promise<SubjectStatsItem[]> {
108
98
  const coll = getTicketsCollection();
109
99
  const rows = await coll
@@ -112,7 +102,7 @@ export async function getTicketsSubjectStats(
112
102
  {
113
103
  $addFields: {
114
104
  dateLocal: {
115
- $dateToString: { format: "%Y-%m-%d", date: "$createdAt", timezone },
105
+ $dateToString: { format: '%Y-%m-%d', date: '$createdAt', timezone },
116
106
  },
117
107
  },
118
108
  },
@@ -121,11 +111,11 @@ export async function getTicketsSubjectStats(
121
111
  $addFields: {
122
112
  effectiveSubjectId: {
123
113
  $ifNull: [
124
- "$externalCallFields.event_subject_id",
114
+ '$externalCallFields.event_subject_id',
125
115
  {
126
116
  $ifNull: [
127
- "$externalCallFields.event_sub_subject_id",
128
- "$externalCallFields.event_sub_subject_id2",
117
+ '$externalCallFields.event_sub_subject_id',
118
+ '$externalCallFields.event_sub_subject_id2',
129
119
  ],
130
120
  },
131
121
  ],
@@ -134,23 +124,19 @@ export async function getTicketsSubjectStats(
134
124
  },
135
125
  {
136
126
  $lookup: {
137
- from: "departmentsSubjects",
138
- let: { sid: "$effectiveSubjectId", c: cityName },
127
+ from: 'departmentsSubjects',
128
+ let: { sid: '$effectiveSubjectId', c: cityName },
139
129
  pipeline: [
140
130
  {
141
131
  $match: {
142
132
  $expr: {
143
133
  $and: [
144
- { $eq: ["$cityName", "$$c"] },
134
+ { $eq: ['$cityName', '$$c'] },
145
135
  {
146
136
  $or: [
147
- { $eq: ["$subject_id", { $ifNull: ["$$sid", ""] }] },
148
- {
149
- $eq: ["$sub_subject_id", { $ifNull: ["$$sid", ""] }],
150
- },
151
- {
152
- $eq: ["$sub_subject_id2", { $ifNull: ["$$sid", ""] }],
153
- },
137
+ { $eq: ['$subject_id', { $ifNull: ['$$sid', ''] }] },
138
+ { $eq: ['$sub_subject_id', { $ifNull: ['$$sid', ''] }] },
139
+ { $eq: ['$sub_subject_id2', { $ifNull: ['$$sid', ''] }] },
154
140
  ],
155
141
  },
156
142
  ],
@@ -159,41 +145,28 @@ export async function getTicketsSubjectStats(
159
145
  },
160
146
  { $limit: 1 },
161
147
  ],
162
- as: "subj",
148
+ as: 'subj',
163
149
  },
164
150
  },
165
151
  {
166
152
  $addFields: {
167
153
  subject_id: {
168
154
  $cond: {
169
- if: { $gt: [{ $size: "$subj" }, 0] },
170
- then: {
171
- $ifNull: [{ $arrayElemAt: ["$subj.subject_id", 0] }, ""],
172
- },
173
- else: "",
155
+ if: { $gt: [{ $size: '$subj' }, 0] },
156
+ then: { $ifNull: [{ $arrayElemAt: ['$subj.subject_id', 0] }, ''] },
157
+ else: '',
174
158
  },
175
159
  },
176
160
  subject: {
177
161
  $cond: {
178
- if: { $gt: [{ $size: "$subj" }, 0] },
179
- then: {
180
- $ifNull: [
181
- { $arrayElemAt: ["$subj.subjectName", 0] },
182
- "Unclassified",
183
- ],
184
- },
185
- else: "Unclassified",
162
+ if: { $gt: [{ $size: '$subj' }, 0] },
163
+ then: { $ifNull: [{ $arrayElemAt: ['$subj.subjectName', 0] }, 'Unclassified'] },
164
+ else: 'Unclassified',
186
165
  },
187
166
  },
188
167
  },
189
168
  },
190
- {
191
- $group: {
192
- _id: "$subject_id",
193
- subject: { $first: "$subject" },
194
- count: { $sum: 1 },
195
- },
196
- },
169
+ { $group: { _id: '$subject_id', subject: { $first: '$subject' }, count: { $sum: 1 } } },
197
170
  { $sort: { count: -1 } },
198
171
  ])
199
172
  .toArray();
@@ -223,21 +196,21 @@ export const updateTicketFilesByCallNumber = async (params: {
223
196
  const { cityName, callNumber, image1, image2, image3 } = params;
224
197
 
225
198
  const update: any = {};
226
- if (image1) update["externalCallFields.image1"] = image1;
227
- if (image2) update["externalCallFields.image2"] = image2;
228
- if (image3) update["externalCallFields.image3"] = image3;
199
+ if (image1) update['externalCallFields.image1'] = image1;
200
+ if (image2) update['externalCallFields.image2'] = image2;
201
+ if (image3) update['externalCallFields.image3'] = image3;
229
202
 
230
203
  const result = await getTicketsCollection().updateOne(
231
204
  {
232
205
  cityName: cityName,
233
- "externalCallFields.call_number": callNumber,
206
+ 'externalCallFields.call_number': callNumber,
234
207
  },
235
208
  {
236
209
  $set: {
237
210
  ...update,
238
211
  updatedAt: new Date(),
239
212
  },
240
- },
213
+ }
241
214
  );
242
215
 
243
216
  return result.matchedCount > 0;
@@ -253,8 +226,8 @@ export const clearGuestJwtByCallNumber = async (params: {
253
226
  const { cityName, callNumber } = params;
254
227
 
255
228
  const result = await getTicketsCollection().updateOne(
256
- { cityName, "externalCallFields.call_number": callNumber },
257
- { $unset: { guestJwt: "" }, $set: { updatedAt: new Date() } },
229
+ { cityName, 'externalCallFields.call_number': callNumber },
230
+ { $unset: { guestJwt: '' }, $set: { updatedAt: new Date() } }
258
231
  );
259
232
 
260
233
  return result.matchedCount > 0;
@@ -1,6 +1,6 @@
1
- import { ObjectId, WithId } from "mongodb";
1
+ import { ObjectId, WithId } from 'mongodb';
2
2
 
3
- import { CityName } from "../utils/types";
3
+ import {CityName} from "../utils/types";
4
4
 
5
5
  export type Ticket = {
6
6
  _id: ObjectId;
@@ -1,11 +1,6 @@
1
+
2
+
1
3
  /**
2
4
  * City name type for municipal data
3
5
  */
4
- export type CityName =
5
- | "ashdod"
6
- | "maltar"
7
- | "billit"
8
- | "hashkelon"
9
- | "eilat"
10
- | "tests"
11
- | string;
6
+ export type CityName = 'ashdod' | 'maltar' | 'billit' | 'hashkelon' | 'eilat' | 'tests' | string;
@@ -8,25 +8,25 @@ import {
8
8
  ObjectId,
9
9
  getPlansCollection,
10
10
  getSubscriptionsCollection,
11
- } from "../index";
11
+ } from '../index';
12
12
 
13
- import { ObjectId as MongoObjectId } from "mongodb";
13
+ import { ObjectId as MongoObjectId } from 'mongodb';
14
14
 
15
- describe("talkpilot core/db", () => {
15
+ describe('talkpilot core/db', () => {
16
16
  it.each([
17
- ["flows", getFlowsCollection],
18
- ["sessions", getSessionsCollection],
19
- ["results", getResultsCollection],
20
- ["leads", getLeadsCollection],
21
- ["phone_numbers", getPhoneNumbersCollection],
22
- ["clients", getClientsCollection],
23
- ["plans", getPlansCollection],
24
- ["subscriptions", getSubscriptionsCollection],
17
+ ['flows', getFlowsCollection],
18
+ ['sessions', getSessionsCollection],
19
+ ['results', getResultsCollection],
20
+ ['leads', getLeadsCollection],
21
+ ['phone_numbers', getPhoneNumbersCollection],
22
+ ['clients', getClientsCollection],
23
+ ['plans', getPlansCollection],
24
+ ['subscriptions', getSubscriptionsCollection],
25
25
  ])('%s collection helper returns a "%s" collection', (name, getter) => {
26
26
  expect(getter().collectionName).toBe(name);
27
27
  });
28
28
 
29
- it("ObjectId re-export behaves like mongodb.ObjectId", () => {
29
+ it('ObjectId re-export behaves like mongodb.ObjectId', () => {
30
30
  expect(ObjectId).toBe(MongoObjectId);
31
31
 
32
32
  const id = new ObjectId();
@@ -1,18 +1,19 @@
1
- import { getDb } from "../index";
1
+ import { mongodbClient } from '../mongodb-client';
2
+ import { getDb } from '../index';
2
3
 
3
- describe("MongoDBClient", () => {
4
- it("should have a connected database instance from global setup", () => {
4
+ describe('MongoDBClient', () => {
5
+ it('should have a connected database instance from global setup', () => {
5
6
  const db = getDb();
6
7
  expect(db).toBeDefined();
7
- expect(db.databaseName).toBe("test"); // Based on our setup.ts
8
+ expect(db.databaseName).toBe('test'); // Based on our setup.ts
8
9
  });
9
10
 
10
- it("should report as connected", async () => {
11
+ it('should report as connected', async () => {
11
12
  // Note: mongodbClient.connect() was called in global setup
12
13
  // but through setDb, not necessarily through the client singleton instance
13
14
  // since initTestDb calls setDb directly.
14
-
15
+
15
16
  // In a real scenario, you'd use the client.
16
- expect(true).toBe(true);
17
+ expect(true).toBe(true);
17
18
  });
18
19
  });
@@ -1,7 +1,7 @@
1
- import { mongodbClient } from "../mongodb-client";
2
- import { MongoClient } from "mongodb";
1
+ import { mongodbClient } from '../mongodb-client';
2
+ import { MongoClient } from 'mongodb';
3
3
 
4
- describe("MongoDBClient Validation", () => {
4
+ describe('MongoDBClient Validation', () => {
5
5
  const originalEnv = process.env;
6
6
 
7
7
  beforeEach(() => {
@@ -9,7 +9,7 @@ describe("MongoDBClient Validation", () => {
9
9
  delete process.env.MONGO_URI;
10
10
  delete process.env.MONGODB_URI;
11
11
  delete process.env.MONGODB_DB_NAME;
12
-
12
+
13
13
  // Force reset singleton state
14
14
  (mongodbClient as any).client = null;
15
15
  (mongodbClient as any).db = null;
@@ -21,47 +21,41 @@ describe("MongoDBClient Validation", () => {
21
21
  await mongodbClient.disconnect();
22
22
  });
23
23
 
24
- it("should throw error if no URI is provided", async () => {
24
+ it('should throw error if no URI is provided', async () => {
25
25
  await expect(mongodbClient.connect()).rejects.toThrow(
26
- "[core-db] Configuration Error: 'MONGO_URI' is missing",
26
+ "[core-db] Configuration Error: 'MONGO_URI' is missing"
27
27
  );
28
28
  });
29
29
 
30
- it("should throw error if an invalid URI format is provided", async () => {
31
- await expect(mongodbClient.connect("not-a-mongo-uri")).rejects.toThrow(
32
- "[core-db] Connection Error: The provided MongoDB URI is invalid",
30
+ it('should throw error if an invalid URI format is provided', async () => {
31
+ await expect(mongodbClient.connect('not-a-mongo-uri')).rejects.toThrow(
32
+ "[core-db] Connection Error: The provided MongoDB URI is invalid"
33
33
  );
34
34
  });
35
35
 
36
- it("should throw error if URI is valid but database name is missing", async () => {
36
+ it('should throw error if URI is valid but database name is missing', async () => {
37
37
  // We mock the actual MongoClient connection so it doesn't try to hit a real network
38
- const connectSpy = jest
39
- .spyOn(MongoClient.prototype, "connect")
40
- .mockResolvedValue({} as any);
41
-
42
- const uriWithoutDb = "mongodb://127.0.0.1:27017";
38
+ const connectSpy = jest.spyOn(MongoClient.prototype, 'connect').mockResolvedValue({} as any);
39
+
40
+ const uriWithoutDb = 'mongodb://127.0.0.1:27017';
43
41
  await expect(mongodbClient.connect(uriWithoutDb)).rejects.toThrow(
44
- "[core-db] Database name not specified",
42
+ "[core-db] Database name not specified"
45
43
  );
46
-
44
+
47
45
  connectSpy.mockRestore();
48
46
  });
49
47
 
50
- it("should succeed when valid URI and DB name are provided", async () => {
51
- const mockDb = { databaseName: "my-db" };
52
- const connectSpy = jest
53
- .spyOn(MongoClient.prototype, "connect")
54
- .mockResolvedValue({} as any);
55
- const dbSpy = jest
56
- .spyOn(MongoClient.prototype, "db")
57
- .mockReturnValue(mockDb as any);
58
-
59
- const validUri = "mongodb://127.0.0.1:27017/my-db";
48
+ it('should succeed when valid URI and DB name are provided', async () => {
49
+ const mockDb = { databaseName: 'my-db' };
50
+ const connectSpy = jest.spyOn(MongoClient.prototype, 'connect').mockResolvedValue({} as any);
51
+ const dbSpy = jest.spyOn(MongoClient.prototype, 'db').mockReturnValue(mockDb as any);
52
+
53
+ const validUri = 'mongodb://127.0.0.1:27017/my-db';
60
54
  await mongodbClient.connect(validUri);
61
-
55
+
62
56
  expect(mongodbClient.getDb()).toBeDefined();
63
- expect(mongodbClient.getDb().databaseName).toBe("my-db");
64
-
57
+ expect(mongodbClient.getDb().databaseName).toBe('my-db');
58
+
65
59
  connectSpy.mockRestore();
66
60
  dbSpy.mockRestore();
67
61
  });