@talkpilot/core-db 1.1.3 → 1.1.5
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.
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +21 -24
- package/dist/connection.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/municipal/cities/cities.getters.d.ts +2 -2
- package/dist/municipal/cities/cities.getters.d.ts.map +1 -1
- package/dist/municipal/cities/cities.getters.js +8 -4
- package/dist/municipal/cities/cities.getters.js.map +1 -1
- package/dist/municipal/cities/cities.types.d.ts +1 -1
- package/dist/municipal/cities/index.d.ts +2 -2
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts +3 -3
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts.map +1 -1
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js +30 -22
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js.map +1 -1
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts +4 -4
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts.map +1 -1
- package/dist/municipal/departmentsSubjects/index.d.ts +2 -2
- package/dist/municipal/index.d.ts +8 -8
- package/dist/municipal/index.d.ts.map +1 -1
- package/dist/municipal/index.js +1 -1
- package/dist/municipal/mongodb-client.d.ts +1 -1
- package/dist/municipal/mongodb-client.d.ts.map +1 -1
- package/dist/municipal/mongodb-client.js +13 -25
- package/dist/municipal/mongodb-client.js.map +1 -1
- package/dist/municipal/streets/index.d.ts +2 -2
- package/dist/municipal/streets/streets.getters.d.ts +3 -3
- package/dist/municipal/streets/streets.getters.d.ts.map +1 -1
- package/dist/municipal/streets/streets.getters.js +19 -9
- package/dist/municipal/streets/streets.getters.js.map +1 -1
- package/dist/municipal/streets/streets.types.d.ts +1 -1
- package/dist/municipal/systemInstructions/index.d.ts +3 -3
- package/dist/municipal/systemInstructions/index.d.ts.map +1 -1
- package/dist/municipal/systemInstructions/instructions.getters.d.ts +3 -3
- package/dist/municipal/systemInstructions/instructions.getters.d.ts.map +1 -1
- package/dist/municipal/systemInstructions/instructions.getters.js +10 -4
- package/dist/municipal/systemInstructions/instructions.getters.js.map +1 -1
- package/dist/municipal/systemInstructions/instructions.setters.d.ts +2 -2
- package/dist/municipal/systemInstructions/instructions.setters.d.ts.map +1 -1
- package/dist/municipal/systemInstructions/instructions.setters.js +13 -8
- package/dist/municipal/systemInstructions/instructions.setters.js.map +1 -1
- package/dist/municipal/systemInstructions/instructions.types.d.ts +3 -3
- package/dist/municipal/systemInstructions/instructions.types.d.ts.map +1 -1
- package/dist/municipal/systemInstructions/instructions.types.js +6 -6
- package/dist/municipal/tickets/index.d.ts +2 -2
- package/dist/municipal/tickets/tickets.getters.d.ts +3 -3
- package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -1
- package/dist/municipal/tickets/tickets.getters.js +50 -29
- package/dist/municipal/tickets/tickets.getters.js.map +1 -1
- package/dist/municipal/tickets/tickets.types.d.ts +1 -1
- package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
- package/dist/municipal/utils/types.d.ts +1 -1
- package/dist/municipal/utils/types.d.ts.map +1 -1
- package/dist/talkpilot/agents/agents.getters.d.ts +1 -1
- package/dist/talkpilot/agents/agents.getters.js +2 -2
- package/dist/talkpilot/agents/agents.types.d.ts +2 -2
- package/dist/talkpilot/agents/index.d.ts +2 -2
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.d.ts +2 -2
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.d.ts.map +1 -1
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.js +1 -1
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.js.map +1 -1
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.types.d.ts +2 -2
- package/dist/talkpilot/backgroundToolResults/index.d.ts +2 -2
- package/dist/talkpilot/calls/calls.getters.d.ts +3 -3
- package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.getters.js +19 -15
- package/dist/talkpilot/calls/calls.getters.js.map +1 -1
- package/dist/talkpilot/calls/calls.types.d.ts +3 -3
- package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.types.js +2 -2
- package/dist/talkpilot/calls/index.d.ts +2 -2
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts +2 -2
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts.map +1 -1
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js +2 -2
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js.map +1 -1
- package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.d.ts +2 -2
- package/dist/talkpilot/clientAudioBuffers/index.d.ts +2 -2
- package/dist/talkpilot/clients/clients.getters.d.ts +2 -2
- package/dist/talkpilot/clients/clients.getters.d.ts.map +1 -1
- package/dist/talkpilot/clients/clients.getters.js +5 -2
- package/dist/talkpilot/clients/clients.getters.js.map +1 -1
- package/dist/talkpilot/clients/clients.types.d.ts +1 -1
- package/dist/talkpilot/clients/index.d.ts +2 -2
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +2 -2
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +9 -2
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/index.d.ts +2 -2
- package/dist/talkpilot/flows/flows.getter.d.ts +2 -2
- package/dist/talkpilot/flows/flows.getter.d.ts.map +1 -1
- package/dist/talkpilot/flows/flows.getter.js +1 -1
- package/dist/talkpilot/flows/flows.getter.js.map +1 -1
- package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
- package/dist/talkpilot/flows/flows.schema.js +87 -79
- package/dist/talkpilot/flows/flows.schema.js.map +1 -1
- package/dist/talkpilot/flows/flows.types.d.ts +16 -16
- package/dist/talkpilot/flows/index.d.ts +2 -2
- package/dist/talkpilot/groups/groups.getters.d.ts +2 -2
- package/dist/talkpilot/groups/groups.getters.d.ts.map +1 -1
- package/dist/talkpilot/groups/groups.getters.js +2 -2
- package/dist/talkpilot/groups/groups.getters.js.map +1 -1
- package/dist/talkpilot/groups/groups.types.d.ts +1 -1
- package/dist/talkpilot/groups/index.d.ts +3 -3
- package/dist/talkpilot/groups/phone.utils.d.ts +1 -1
- package/dist/talkpilot/groups/phone.utils.d.ts.map +1 -1
- package/dist/talkpilot/groups/phone.utils.js +2 -2
- package/dist/talkpilot/groups/phone.utils.js.map +1 -1
- package/dist/talkpilot/index.d.ts +16 -16
- package/dist/talkpilot/index.js +1 -1
- package/dist/talkpilot/leads/index.d.ts +2 -2
- package/dist/talkpilot/leads/leads.getter.d.ts +2 -2
- package/dist/talkpilot/leads/leads.getter.d.ts.map +1 -1
- package/dist/talkpilot/leads/leads.getter.js +1 -1
- package/dist/talkpilot/leads/leads.getter.js.map +1 -1
- package/dist/talkpilot/leads/leads.schema.js +16 -16
- package/dist/talkpilot/leads/leads.types.d.ts +1 -1
- package/dist/talkpilot/mongodb-client.d.ts +1 -1
- package/dist/talkpilot/mongodb-client.d.ts.map +1 -1
- package/dist/talkpilot/mongodb-client.js +16 -29
- package/dist/talkpilot/mongodb-client.js.map +1 -1
- package/dist/talkpilot/phone_numbers/index.d.ts +2 -2
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +3 -3
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +28 -13
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +9 -9
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts.map +1 -1
- package/dist/talkpilot/plans/index.d.ts +2 -2
- package/dist/talkpilot/plans/plans.getters.d.ts +2 -2
- package/dist/talkpilot/plans/plans.getters.d.ts.map +1 -1
- package/dist/talkpilot/plans/plans.getters.js +3 -3
- package/dist/talkpilot/plans/plans.getters.js.map +1 -1
- package/dist/talkpilot/plans/plans.types.d.ts +4 -4
- package/dist/talkpilot/plans/plans.types.d.ts.map +1 -1
- package/dist/talkpilot/plans/plans.types.js +19 -19
- package/dist/talkpilot/results/index.d.ts +2 -2
- package/dist/talkpilot/results/index.d.ts.map +1 -1
- package/dist/talkpilot/results/index.js.map +1 -1
- package/dist/talkpilot/results/results.getter.d.ts +3 -3
- package/dist/talkpilot/results/results.getter.d.ts.map +1 -1
- package/dist/talkpilot/results/results.getter.js +4 -4
- package/dist/talkpilot/results/results.getter.js.map +1 -1
- package/dist/talkpilot/results/results.schema.js +18 -18
- package/dist/talkpilot/results/results.types.d.ts +1 -1
- package/dist/talkpilot/sessions/index.d.ts +2 -2
- package/dist/talkpilot/sessions/sessions.getter.d.ts +3 -3
- package/dist/talkpilot/sessions/sessions.getter.d.ts.map +1 -1
- package/dist/talkpilot/sessions/sessions.getter.js +13 -10
- package/dist/talkpilot/sessions/sessions.getter.js.map +1 -1
- package/dist/talkpilot/sessions/sessions.schema.js +17 -17
- package/dist/talkpilot/sessions/sessions.types.d.ts +2 -2
- package/dist/talkpilot/subscriptions/index.d.ts +3 -3
- package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts +2 -2
- package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.getters.js +11 -11
- package/dist/talkpilot/subscriptions/subscriptions.getters.js.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts +2 -2
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.js.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.types.d.ts +2 -2
- package/dist/talkpilot/subscriptions/subscriptions.types.d.ts.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.types.js +7 -7
- package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts +4 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.js +20 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.js.map +1 -0
- package/dist/talkpilot/utils/query.utils.d.ts +1 -1
- package/dist/test-utils/db-utils.d.ts +1 -1
- package/dist/test-utils/db-utils.js +2 -2
- package/dist/test-utils/factories/index.d.ts +12 -12
- package/dist/test-utils/factories/municipal/cities.d.ts +2 -2
- package/dist/test-utils/factories/municipal/cities.d.ts.map +1 -1
- package/dist/test-utils/factories/municipal/cities.js +1 -1
- package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts +2 -2
- package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts.map +1 -1
- package/dist/test-utils/factories/municipal/departmentsSubjects.js +7 -1
- package/dist/test-utils/factories/municipal/departmentsSubjects.js.map +1 -1
- package/dist/test-utils/factories/municipal/streets.d.ts +2 -2
- package/dist/test-utils/factories/municipal/streets.d.ts.map +1 -1
- package/dist/test-utils/factories/municipal/streets.js +6 -1
- package/dist/test-utils/factories/municipal/streets.js.map +1 -1
- package/dist/test-utils/factories/municipal/tickets.d.ts +2 -2
- package/dist/test-utils/factories/municipal/tickets.d.ts.map +1 -1
- package/dist/test-utils/factories/municipal/tickets.js +7 -1
- package/dist/test-utils/factories/municipal/tickets.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/agents.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/agents.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/agents.js +4 -4
- package/dist/test-utils/factories/talkpilot/calls.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/calls.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/calls.js +1 -1
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js +1 -1
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/clientsConfig.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/flows.d.ts +3 -3
- package/dist/test-utils/factories/talkpilot/flows.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/flows.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/groups.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/groups.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/groups.js +9 -9
- package/dist/test-utils/factories/talkpilot/groups.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts +3 -3
- package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/phone_numbers.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/sessions.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/sessions.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/sessions.js +1 -1
- package/dist/utils/validation.js +2 -2
- package/dist/utils/validation.js.map +1 -1
- package/package.json +3 -1
- package/src/__tests__/setup.ts +3 -3
- package/src/connection.ts +27 -25
- package/src/index.ts +9 -9
- package/src/municipal/__tests__/validation.spec.ts +35 -23
- package/src/municipal/cities/cities.getters.ts +16 -10
- package/src/municipal/cities/cities.types.ts +1 -1
- package/src/municipal/cities/index.ts +2 -2
- package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +53 -44
- package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +5 -5
- package/src/municipal/departmentsSubjects/index.ts +2 -3
- package/src/municipal/index.ts +10 -10
- package/src/municipal/mongodb-client.ts +19 -26
- package/src/municipal/streets/index.ts +2 -2
- package/src/municipal/streets/streets.getters.ts +43 -23
- package/src/municipal/streets/streets.types.ts +1 -1
- package/src/municipal/systemInstructions/__tests__/getters.spec.ts +67 -52
- package/src/municipal/systemInstructions/__tests__/setters.spec.ts +271 -238
- package/src/municipal/systemInstructions/index.ts +7 -3
- package/src/municipal/systemInstructions/instructions.getters.ts +30 -18
- package/src/municipal/systemInstructions/instructions.setters.ts +43 -19
- package/src/municipal/systemInstructions/instructions.types.ts +10 -10
- package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +12 -12
- package/src/municipal/tickets/index.ts +2 -2
- package/src/municipal/tickets/tickets.getters.ts +69 -42
- package/src/municipal/tickets/tickets.types.ts +2 -2
- package/src/municipal/utils/types.ts +8 -3
- package/src/talkpilot/__tests__/db.spec.ts +12 -12
- package/src/talkpilot/__tests__/mongodb-client.spec.ts +7 -8
- package/src/talkpilot/__tests__/validation.spec.ts +30 -24
- package/src/talkpilot/agents/__tests__/agents.getters.spec.ts +10 -10
- package/src/talkpilot/agents/agents.getters.ts +3 -3
- package/src/talkpilot/agents/agents.types.ts +2 -2
- package/src/talkpilot/agents/index.ts +2 -2
- package/src/talkpilot/backgroundToolResults/__tests__/backgroundToolResults.getters.spec.ts +42 -31
- package/src/talkpilot/backgroundToolResults/backgroundToolResults.getters.ts +11 -11
- package/src/talkpilot/backgroundToolResults/backgroundToolResults.types.ts +2 -3
- package/src/talkpilot/backgroundToolResults/index.ts +2 -2
- package/src/talkpilot/calls/__tests__/callStats.utils.spec.ts +27 -27
- package/src/talkpilot/calls/__tests__/calls.spec.ts +79 -39
- package/src/talkpilot/calls/calls.getters.ts +48 -28
- package/src/talkpilot/calls/calls.types.ts +16 -16
- package/src/talkpilot/calls/index.ts +2 -2
- package/src/talkpilot/clientAudioBuffers/__tests__/clientAudioBuffer.getters.spec.ts +73 -39
- package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +18 -11
- package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +2 -2
- package/src/talkpilot/clientAudioBuffers/index.ts +2 -2
- package/src/talkpilot/clients/clients.getters.ts +10 -5
- package/src/talkpilot/clients/clients.types.ts +1 -1
- package/src/talkpilot/clients/index.ts +2 -2
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +21 -18
- package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +6 -4
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +17 -7
- package/src/talkpilot/clientsConfig/index.ts +2 -2
- package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +38 -34
- package/src/talkpilot/flows/flows.getter.ts +8 -5
- package/src/talkpilot/flows/flows.schema.ts +87 -79
- package/src/talkpilot/flows/flows.types.ts +23 -23
- package/src/talkpilot/flows/index.ts +2 -2
- package/src/talkpilot/groups/__tests__/groups.spec.ts +34 -27
- package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +20 -20
- package/src/talkpilot/groups/groups.getters.ts +8 -5
- package/src/talkpilot/groups/groups.types.ts +1 -1
- package/src/talkpilot/groups/index.ts +3 -3
- package/src/talkpilot/groups/phone.utils.ts +12 -6
- package/src/talkpilot/index.ts +17 -17
- package/src/talkpilot/leads/index.ts +2 -2
- package/src/talkpilot/leads/leads.getter.ts +5 -4
- package/src/talkpilot/leads/leads.schema.ts +16 -16
- package/src/talkpilot/leads/leads.types.ts +1 -1
- package/src/talkpilot/mongodb-client.ts +23 -33
- package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +84 -44
- package/src/talkpilot/phone_numbers/index.ts +2 -2
- package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +44 -22
- package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +9 -9
- package/src/talkpilot/phone_numbers/phone_numbers.types.ts +1 -1
- package/src/talkpilot/plans/__tests__/plans.spec.ts +30 -26
- package/src/talkpilot/plans/index.ts +2 -2
- package/src/talkpilot/plans/plans.getters.ts +25 -18
- package/src/talkpilot/plans/plans.types.ts +27 -23
- package/src/talkpilot/results/index.ts +5 -2
- package/src/talkpilot/results/results.getter.ts +9 -8
- package/src/talkpilot/results/results.schema.ts +18 -18
- package/src/talkpilot/results/results.types.ts +1 -1
- package/src/talkpilot/sessions/__tests__/sessions.spec.ts +65 -41
- package/src/talkpilot/sessions/index.ts +2 -2
- package/src/talkpilot/sessions/sessions.getter.ts +21 -16
- package/src/talkpilot/sessions/sessions.schema.ts +17 -17
- package/src/talkpilot/sessions/sessions.types.ts +2 -2
- package/src/talkpilot/subscriptions/__tests__/subscriptions.getters.utils.spec.ts +18 -15
- package/src/talkpilot/subscriptions/index.ts +3 -3
- package/src/talkpilot/subscriptions/subscriptions.getters.ts +36 -33
- package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +10 -3
- package/src/talkpilot/subscriptions/subscriptions.types.ts +9 -9
- package/src/talkpilot/utils/__tests__/query.utils.spec.ts +8 -8
- package/src/talkpilot/utils/query.utils.ts +2 -2
- package/src/test-utils/db-utils.ts +5 -5
- package/src/test-utils/factories/index.ts +12 -12
- package/src/test-utils/factories/municipal/cities.ts +5 -5
- package/src/test-utils/factories/municipal/departmentsSubjects.ts +32 -25
- package/src/test-utils/factories/municipal/streets.ts +10 -5
- package/src/test-utils/factories/municipal/tickets.ts +12 -6
- package/src/test-utils/factories/talkpilot/agents.ts +8 -8
- package/src/test-utils/factories/talkpilot/calls.ts +5 -5
- package/src/test-utils/factories/talkpilot/clientAudioBuffers.ts +14 -12
- package/src/test-utils/factories/talkpilot/clientsConfig.ts +7 -8
- package/src/test-utils/factories/talkpilot/flows.ts +7 -5
- package/src/test-utils/factories/talkpilot/groups.ts +13 -13
- package/src/test-utils/factories/talkpilot/phone_numbers.ts +8 -6
- package/src/test-utils/factories/talkpilot/sessions.ts +5 -5
- package/src/utils/validation.ts +4 -4
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { ObjectId } from
|
|
2
|
-
import { ObjectId as MongoObjectId } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
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";
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* Validate system instruction data
|
|
@@ -9,11 +13,21 @@ import { getSystemInstructionsCollection } from './instructions.getters';
|
|
|
9
13
|
* @throws Error if tool or queryType is invalid
|
|
10
14
|
*/
|
|
11
15
|
const validateInstructionData = (data: Partial<MIS_SystemInstruction>) => {
|
|
12
|
-
if (
|
|
13
|
-
|
|
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
|
+
);
|
|
14
23
|
}
|
|
15
|
-
if (
|
|
16
|
-
|
|
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
|
+
);
|
|
17
31
|
}
|
|
18
32
|
};
|
|
19
33
|
|
|
@@ -23,16 +37,20 @@ const validateInstructionData = (data: Partial<MIS_SystemInstruction>) => {
|
|
|
23
37
|
* @returns inserted system instruction id
|
|
24
38
|
*/
|
|
25
39
|
export const createSystemInstruction = async (
|
|
26
|
-
instructionData: Omit<
|
|
40
|
+
instructionData: Omit<
|
|
41
|
+
MIS_SystemInstruction,
|
|
42
|
+
"_id" | "createdAt" | "updatedAt"
|
|
43
|
+
>,
|
|
27
44
|
): Promise<MongoObjectId> => {
|
|
28
45
|
validateInstructionData(instructionData as Partial<MIS_SystemInstruction>);
|
|
29
|
-
const instruction: Omit<MIS_SystemInstruction,
|
|
46
|
+
const instruction: Omit<MIS_SystemInstruction, "_id"> = {
|
|
47
|
+
//append doc metadata to user provided data
|
|
30
48
|
...instructionData,
|
|
31
49
|
createdAt: new Date(),
|
|
32
50
|
updatedAt: new Date(),
|
|
33
51
|
};
|
|
34
52
|
const { insertedId } = await getSystemInstructionsCollection().insertOne(
|
|
35
|
-
instruction as MIS_SystemInstruction
|
|
53
|
+
instruction as MIS_SystemInstruction,
|
|
36
54
|
);
|
|
37
55
|
return insertedId;
|
|
38
56
|
};
|
|
@@ -45,13 +63,13 @@ export const createSystemInstruction = async (
|
|
|
45
63
|
*/
|
|
46
64
|
export const updateSystemInstruction = async (
|
|
47
65
|
id: string,
|
|
48
|
-
data: Partial<Omit<MIS_SystemInstruction,
|
|
66
|
+
data: Partial<Omit<MIS_SystemInstruction, "_id" | "createdAt" | "updatedAt">>,
|
|
49
67
|
): Promise<MIS_SystemInstruction | null> => {
|
|
50
68
|
validateInstructionData(data as Partial<MIS_SystemInstruction>);
|
|
51
69
|
const result = await getSystemInstructionsCollection().findOneAndUpdate(
|
|
52
70
|
{ _id: new ObjectId(id) },
|
|
53
71
|
{ $set: { ...data, updatedAt: new Date() } },
|
|
54
|
-
{ returnDocument:
|
|
72
|
+
{ returnDocument: "after" },
|
|
55
73
|
);
|
|
56
74
|
return result || null;
|
|
57
75
|
};
|
|
@@ -62,7 +80,9 @@ export const updateSystemInstruction = async (
|
|
|
62
80
|
* @returns true if deleted, false otherwise
|
|
63
81
|
*/
|
|
64
82
|
export const deleteSystemInstruction = async (id: string): Promise<boolean> => {
|
|
65
|
-
const result = await getSystemInstructionsCollection().deleteOne({
|
|
83
|
+
const result = await getSystemInstructionsCollection().deleteOne({
|
|
84
|
+
_id: new ObjectId(id),
|
|
85
|
+
});
|
|
66
86
|
return result.deletedCount > 0;
|
|
67
87
|
};
|
|
68
88
|
/**
|
|
@@ -71,11 +91,13 @@ export const deleteSystemInstruction = async (id: string): Promise<boolean> => {
|
|
|
71
91
|
* @param id system instruction id
|
|
72
92
|
* @returns true on success, false otherwise
|
|
73
93
|
*/
|
|
74
|
-
export const activateSystemInstruction = async (
|
|
94
|
+
export const activateSystemInstruction = async (
|
|
95
|
+
id: string,
|
|
96
|
+
): Promise<boolean> => {
|
|
75
97
|
const result = await getSystemInstructionsCollection().findOneAndUpdate(
|
|
76
98
|
{ _id: new ObjectId(id) },
|
|
77
99
|
{ $set: { isActive: true } },
|
|
78
|
-
{ returnDocument:
|
|
100
|
+
{ returnDocument: "after" },
|
|
79
101
|
);
|
|
80
102
|
return Boolean(result);
|
|
81
103
|
};
|
|
@@ -85,11 +107,13 @@ export const activateSystemInstruction = async (id: string): Promise<boolean> =>
|
|
|
85
107
|
* @param id system instruction id
|
|
86
108
|
* @returns true on success, false otherwise
|
|
87
109
|
*/
|
|
88
|
-
export const deactivateSystemInstruction = async (
|
|
110
|
+
export const deactivateSystemInstruction = async (
|
|
111
|
+
id: string,
|
|
112
|
+
): Promise<boolean> => {
|
|
89
113
|
const result = await getSystemInstructionsCollection().findOneAndUpdate(
|
|
90
114
|
{ _id: new ObjectId(id) },
|
|
91
115
|
{ $set: { isActive: false } },
|
|
92
|
-
|
|
116
|
+
{ returnDocument: "after" },
|
|
93
117
|
);
|
|
94
118
|
return Boolean(result);
|
|
95
|
-
}
|
|
119
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { ObjectId } from
|
|
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:
|
|
7
|
-
findSubject:
|
|
6
|
+
findStreet: "findStreet",
|
|
7
|
+
findSubject: "findSubject",
|
|
8
8
|
} as const;
|
|
9
9
|
|
|
10
10
|
export const QUERY_TYPES = {
|
|
11
|
-
exactlyOne:
|
|
12
|
-
any:
|
|
13
|
-
all:
|
|
14
|
-
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
|
|
2
|
-
import { setDb } from
|
|
3
|
-
import { Db, Collection } from
|
|
4
|
-
import { createTicket } from
|
|
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(
|
|
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:
|
|
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(
|
|
24
|
-
const result = await findTicketsByCallSid(
|
|
25
|
-
|
|
26
|
-
expect(mockDb.collection).toHaveBeenCalledWith(
|
|
27
|
-
expect(mockCollection.find).toHaveBeenCalledWith({ callSid:
|
|
28
|
-
expect(result[0].callSid).toBe(
|
|
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
|
|
2
|
-
export type { Ticket, TicketDoc, SubjectStatsItem } from
|
|
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
|
|
2
|
-
import type { SubjectStatsItem } from
|
|
3
|
-
import { Collection, Filter, ObjectId as MongoObjectId } from
|
|
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,25 +11,33 @@ export const generateTicketId = (): string => {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export const getTicketsCollection = (): Collection<Ticket> => {
|
|
14
|
-
return getDb().collection<Ticket>(
|
|
14
|
+
return getDb().collection<Ticket>("tickets");
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export const findTickets = async (
|
|
17
|
+
export const findTickets = async (
|
|
18
|
+
filter: Filter<Ticket> = {},
|
|
19
|
+
): Promise<Ticket[]> => {
|
|
18
20
|
return await getTicketsCollection().find(filter).toArray();
|
|
19
21
|
};
|
|
20
22
|
|
|
21
|
-
export const findTicketsByCallSid = async (
|
|
23
|
+
export const findTicketsByCallSid = async (
|
|
24
|
+
callSid: string,
|
|
25
|
+
): Promise<Ticket[]> => {
|
|
22
26
|
return await getTicketsCollection().find({ callSid }).toArray();
|
|
23
27
|
};
|
|
24
28
|
|
|
25
|
-
export const getTicketById = async (
|
|
26
|
-
|
|
29
|
+
export const getTicketById = async (
|
|
30
|
+
ticketId: string,
|
|
31
|
+
): Promise<Ticket | null> => {
|
|
32
|
+
const ticket = await getTicketsCollection().findOne({
|
|
33
|
+
_id: new ObjectId(ticketId),
|
|
34
|
+
});
|
|
27
35
|
return ticket ? ticket : null;
|
|
28
36
|
};
|
|
29
37
|
|
|
30
38
|
export const createTicket = async (
|
|
31
|
-
ticketData: Omit<Ticket,
|
|
32
|
-
ticketId?: string
|
|
39
|
+
ticketData: Omit<Ticket, "_id" | "createdAt" | "updatedAt">,
|
|
40
|
+
ticketId?: string,
|
|
33
41
|
): Promise<MongoObjectId> => {
|
|
34
42
|
const ticket: Ticket = {
|
|
35
43
|
_id: ticketId ? new ObjectId(ticketId) : new ObjectId(),
|
|
@@ -43,18 +51,20 @@ export const createTicket = async (
|
|
|
43
51
|
|
|
44
52
|
export const updateTicket = async (
|
|
45
53
|
ticketId: string,
|
|
46
|
-
data: Partial<Omit<Ticket,
|
|
54
|
+
data: Partial<Omit<Ticket, "_id" | "createdAt" | "updatedAt">>,
|
|
47
55
|
): Promise<Ticket | null> => {
|
|
48
56
|
const result = await getTicketsCollection().findOneAndUpdate(
|
|
49
57
|
{ _id: new ObjectId(ticketId) },
|
|
50
58
|
{ $set: { ...data, updatedAt: new Date() } },
|
|
51
|
-
{ returnDocument:
|
|
59
|
+
{ returnDocument: "after" },
|
|
52
60
|
);
|
|
53
61
|
return result || null;
|
|
54
62
|
};
|
|
55
63
|
|
|
56
64
|
export const deleteTicket = async (ticketId: string): Promise<boolean> => {
|
|
57
|
-
const result = await getTicketsCollection().deleteOne({
|
|
65
|
+
const result = await getTicketsCollection().deleteOne({
|
|
66
|
+
_id: new ObjectId(ticketId),
|
|
67
|
+
});
|
|
58
68
|
return result.deletedCount > 0;
|
|
59
69
|
};
|
|
60
70
|
|
|
@@ -66,7 +76,7 @@ export async function getTicketsCountByCityAndDateRange(
|
|
|
66
76
|
cityName: string,
|
|
67
77
|
startStr: string,
|
|
68
78
|
endStr: string,
|
|
69
|
-
timezone: string
|
|
79
|
+
timezone: string,
|
|
70
80
|
): Promise<number> {
|
|
71
81
|
const doc = await getTicketsCollection()
|
|
72
82
|
.aggregate<{ n: number }>([
|
|
@@ -74,12 +84,12 @@ export async function getTicketsCountByCityAndDateRange(
|
|
|
74
84
|
{
|
|
75
85
|
$addFields: {
|
|
76
86
|
dateLocal: {
|
|
77
|
-
$dateToString: { format:
|
|
87
|
+
$dateToString: { format: "%Y-%m-%d", date: "$createdAt", timezone },
|
|
78
88
|
},
|
|
79
89
|
},
|
|
80
90
|
},
|
|
81
91
|
{ $match: { dateLocal: { $gte: startStr, $lte: endStr } } },
|
|
82
|
-
{ $count:
|
|
92
|
+
{ $count: "n" },
|
|
83
93
|
])
|
|
84
94
|
.next();
|
|
85
95
|
return doc?.n ?? 0;
|
|
@@ -93,7 +103,7 @@ export async function getTicketsSubjectStats(
|
|
|
93
103
|
cityName: string,
|
|
94
104
|
startStr: string,
|
|
95
105
|
endStr: string,
|
|
96
|
-
timezone: string
|
|
106
|
+
timezone: string,
|
|
97
107
|
): Promise<SubjectStatsItem[]> {
|
|
98
108
|
const coll = getTicketsCollection();
|
|
99
109
|
const rows = await coll
|
|
@@ -102,7 +112,7 @@ export async function getTicketsSubjectStats(
|
|
|
102
112
|
{
|
|
103
113
|
$addFields: {
|
|
104
114
|
dateLocal: {
|
|
105
|
-
$dateToString: { format:
|
|
115
|
+
$dateToString: { format: "%Y-%m-%d", date: "$createdAt", timezone },
|
|
106
116
|
},
|
|
107
117
|
},
|
|
108
118
|
},
|
|
@@ -111,11 +121,11 @@ export async function getTicketsSubjectStats(
|
|
|
111
121
|
$addFields: {
|
|
112
122
|
effectiveSubjectId: {
|
|
113
123
|
$ifNull: [
|
|
114
|
-
|
|
124
|
+
"$externalCallFields.event_subject_id",
|
|
115
125
|
{
|
|
116
126
|
$ifNull: [
|
|
117
|
-
|
|
118
|
-
|
|
127
|
+
"$externalCallFields.event_sub_subject_id",
|
|
128
|
+
"$externalCallFields.event_sub_subject_id2",
|
|
119
129
|
],
|
|
120
130
|
},
|
|
121
131
|
],
|
|
@@ -124,19 +134,23 @@ export async function getTicketsSubjectStats(
|
|
|
124
134
|
},
|
|
125
135
|
{
|
|
126
136
|
$lookup: {
|
|
127
|
-
from:
|
|
128
|
-
let: { sid:
|
|
137
|
+
from: "departmentsSubjects",
|
|
138
|
+
let: { sid: "$effectiveSubjectId", c: cityName },
|
|
129
139
|
pipeline: [
|
|
130
140
|
{
|
|
131
141
|
$match: {
|
|
132
142
|
$expr: {
|
|
133
143
|
$and: [
|
|
134
|
-
{ $eq: [
|
|
144
|
+
{ $eq: ["$cityName", "$$c"] },
|
|
135
145
|
{
|
|
136
146
|
$or: [
|
|
137
|
-
{ $eq: [
|
|
138
|
-
{
|
|
139
|
-
|
|
147
|
+
{ $eq: ["$subject_id", { $ifNull: ["$$sid", ""] }] },
|
|
148
|
+
{
|
|
149
|
+
$eq: ["$sub_subject_id", { $ifNull: ["$$sid", ""] }],
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
$eq: ["$sub_subject_id2", { $ifNull: ["$$sid", ""] }],
|
|
153
|
+
},
|
|
140
154
|
],
|
|
141
155
|
},
|
|
142
156
|
],
|
|
@@ -145,28 +159,41 @@ export async function getTicketsSubjectStats(
|
|
|
145
159
|
},
|
|
146
160
|
{ $limit: 1 },
|
|
147
161
|
],
|
|
148
|
-
as:
|
|
162
|
+
as: "subj",
|
|
149
163
|
},
|
|
150
164
|
},
|
|
151
165
|
{
|
|
152
166
|
$addFields: {
|
|
153
167
|
subject_id: {
|
|
154
168
|
$cond: {
|
|
155
|
-
if: { $gt: [{ $size:
|
|
156
|
-
then: {
|
|
157
|
-
|
|
169
|
+
if: { $gt: [{ $size: "$subj" }, 0] },
|
|
170
|
+
then: {
|
|
171
|
+
$ifNull: [{ $arrayElemAt: ["$subj.subject_id", 0] }, ""],
|
|
172
|
+
},
|
|
173
|
+
else: "",
|
|
158
174
|
},
|
|
159
175
|
},
|
|
160
176
|
subject: {
|
|
161
177
|
$cond: {
|
|
162
|
-
if: { $gt: [{ $size:
|
|
163
|
-
then: {
|
|
164
|
-
|
|
178
|
+
if: { $gt: [{ $size: "$subj" }, 0] },
|
|
179
|
+
then: {
|
|
180
|
+
$ifNull: [
|
|
181
|
+
{ $arrayElemAt: ["$subj.subjectName", 0] },
|
|
182
|
+
"Unclassified",
|
|
183
|
+
],
|
|
184
|
+
},
|
|
185
|
+
else: "Unclassified",
|
|
165
186
|
},
|
|
166
187
|
},
|
|
167
188
|
},
|
|
168
189
|
},
|
|
169
|
-
{
|
|
190
|
+
{
|
|
191
|
+
$group: {
|
|
192
|
+
_id: "$subject_id",
|
|
193
|
+
subject: { $first: "$subject" },
|
|
194
|
+
count: { $sum: 1 },
|
|
195
|
+
},
|
|
196
|
+
},
|
|
170
197
|
{ $sort: { count: -1 } },
|
|
171
198
|
])
|
|
172
199
|
.toArray();
|
|
@@ -196,21 +223,21 @@ export const updateTicketFilesByCallNumber = async (params: {
|
|
|
196
223
|
const { cityName, callNumber, image1, image2, image3 } = params;
|
|
197
224
|
|
|
198
225
|
const update: any = {};
|
|
199
|
-
if (image1) update[
|
|
200
|
-
if (image2) update[
|
|
201
|
-
if (image3) update[
|
|
226
|
+
if (image1) update["externalCallFields.image1"] = image1;
|
|
227
|
+
if (image2) update["externalCallFields.image2"] = image2;
|
|
228
|
+
if (image3) update["externalCallFields.image3"] = image3;
|
|
202
229
|
|
|
203
230
|
const result = await getTicketsCollection().updateOne(
|
|
204
231
|
{
|
|
205
232
|
cityName: cityName,
|
|
206
|
-
|
|
233
|
+
"externalCallFields.call_number": callNumber,
|
|
207
234
|
},
|
|
208
235
|
{
|
|
209
236
|
$set: {
|
|
210
237
|
...update,
|
|
211
238
|
updatedAt: new Date(),
|
|
212
239
|
},
|
|
213
|
-
}
|
|
240
|
+
},
|
|
214
241
|
);
|
|
215
242
|
|
|
216
243
|
return result.matchedCount > 0;
|
|
@@ -226,8 +253,8 @@ export const clearGuestJwtByCallNumber = async (params: {
|
|
|
226
253
|
const { cityName, callNumber } = params;
|
|
227
254
|
|
|
228
255
|
const result = await getTicketsCollection().updateOne(
|
|
229
|
-
{ cityName,
|
|
230
|
-
{ $unset: { guestJwt:
|
|
256
|
+
{ cityName, "externalCallFields.call_number": callNumber },
|
|
257
|
+
{ $unset: { guestJwt: "" }, $set: { updatedAt: new Date() } },
|
|
231
258
|
);
|
|
232
259
|
|
|
233
260
|
return result.matchedCount > 0;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* City name type for municipal data
|
|
5
3
|
*/
|
|
6
|
-
export type CityName =
|
|
4
|
+
export type CityName =
|
|
5
|
+
| "ashdod"
|
|
6
|
+
| "maltar"
|
|
7
|
+
| "billit"
|
|
8
|
+
| "hashkelon"
|
|
9
|
+
| "eilat"
|
|
10
|
+
| "tests"
|
|
11
|
+
| string;
|
|
@@ -8,25 +8,25 @@ import {
|
|
|
8
8
|
ObjectId,
|
|
9
9
|
getPlansCollection,
|
|
10
10
|
getSubscriptionsCollection,
|
|
11
|
-
} from
|
|
11
|
+
} from "../index";
|
|
12
12
|
|
|
13
|
-
import { ObjectId as MongoObjectId } from
|
|
13
|
+
import { ObjectId as MongoObjectId } from "mongodb";
|
|
14
14
|
|
|
15
|
-
describe(
|
|
15
|
+
describe("talkpilot core/db", () => {
|
|
16
16
|
it.each([
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
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(
|
|
29
|
+
it("ObjectId re-export behaves like mongodb.ObjectId", () => {
|
|
30
30
|
expect(ObjectId).toBe(MongoObjectId);
|
|
31
31
|
|
|
32
32
|
const id = new ObjectId();
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getDb } from '../index';
|
|
1
|
+
import { getDb } from "../index";
|
|
3
2
|
|
|
4
|
-
describe(
|
|
5
|
-
it(
|
|
3
|
+
describe("MongoDBClient", () => {
|
|
4
|
+
it("should have a connected database instance from global setup", () => {
|
|
6
5
|
const db = getDb();
|
|
7
6
|
expect(db).toBeDefined();
|
|
8
|
-
expect(db.databaseName).toBe(
|
|
7
|
+
expect(db.databaseName).toBe("test"); // Based on our setup.ts
|
|
9
8
|
});
|
|
10
9
|
|
|
11
|
-
it(
|
|
10
|
+
it("should report as connected", async () => {
|
|
12
11
|
// Note: mongodbClient.connect() was called in global setup
|
|
13
12
|
// but through setDb, not necessarily through the client singleton instance
|
|
14
13
|
// since initTestDb calls setDb directly.
|
|
15
|
-
|
|
14
|
+
|
|
16
15
|
// In a real scenario, you'd use the client.
|
|
17
|
-
expect(true).toBe(true);
|
|
16
|
+
expect(true).toBe(true);
|
|
18
17
|
});
|
|
19
18
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { mongodbClient } from
|
|
2
|
-
import { MongoClient } from
|
|
1
|
+
import { mongodbClient } from "../mongodb-client";
|
|
2
|
+
import { MongoClient } from "mongodb";
|
|
3
3
|
|
|
4
|
-
describe(
|
|
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,41 +21,47 @@ describe('MongoDBClient Validation', () => {
|
|
|
21
21
|
await mongodbClient.disconnect();
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
it(
|
|
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(
|
|
31
|
-
await expect(mongodbClient.connect(
|
|
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(
|
|
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
|
-
|
|
40
|
-
|
|
38
|
+
const connectSpy = jest
|
|
39
|
+
.spyOn(MongoClient.prototype, "connect")
|
|
40
|
+
.mockResolvedValue({} as any);
|
|
41
|
+
|
|
42
|
+
const uriWithoutDb = "mongodb://127.0.0.1:27017";
|
|
41
43
|
await expect(mongodbClient.connect(uriWithoutDb)).rejects.toThrow(
|
|
42
|
-
"[core-db] Database name not specified"
|
|
44
|
+
"[core-db] Database name not specified",
|
|
43
45
|
);
|
|
44
|
-
|
|
46
|
+
|
|
45
47
|
connectSpy.mockRestore();
|
|
46
48
|
});
|
|
47
49
|
|
|
48
|
-
it(
|
|
49
|
-
const mockDb = { databaseName:
|
|
50
|
-
const connectSpy = jest
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
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";
|
|
54
60
|
await mongodbClient.connect(validUri);
|
|
55
|
-
|
|
61
|
+
|
|
56
62
|
expect(mongodbClient.getDb()).toBeDefined();
|
|
57
|
-
expect(mongodbClient.getDb().databaseName).toBe(
|
|
58
|
-
|
|
63
|
+
expect(mongodbClient.getDb().databaseName).toBe("my-db");
|
|
64
|
+
|
|
59
65
|
connectSpy.mockRestore();
|
|
60
66
|
dbSpy.mockRestore();
|
|
61
67
|
});
|