@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,14 +1,14 @@
|
|
|
1
|
-
import { findAgents } from
|
|
2
|
-
import { setDb } from
|
|
3
|
-
import { Db, Collection } from
|
|
4
|
-
import { createAgent } from
|
|
1
|
+
import { findAgents } from "../agents.getters";
|
|
2
|
+
import { setDb } from "../../index";
|
|
3
|
+
import { Db, Collection } from "mongodb";
|
|
4
|
+
import { createAgent } from "../../../test-utils/factories";
|
|
5
5
|
|
|
6
|
-
describe(
|
|
6
|
+
describe("agents getters", () => {
|
|
7
7
|
let mockDb: Partial<Db>;
|
|
8
8
|
let mockCollection: Partial<Collection>;
|
|
9
9
|
|
|
10
10
|
beforeEach(() => {
|
|
11
|
-
const mockAgent = createAgent({ name:
|
|
11
|
+
const mockAgent = createAgent({ name: "Agent Smith" });
|
|
12
12
|
mockCollection = {
|
|
13
13
|
find: jest.fn().mockReturnValue({
|
|
14
14
|
toArray: jest.fn().mockResolvedValue([mockAgent]),
|
|
@@ -20,10 +20,10 @@ describe('agents getters', () => {
|
|
|
20
20
|
setDb(mockDb as Db);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
it(
|
|
23
|
+
it("findAgents should return agents", async () => {
|
|
24
24
|
const result = await findAgents();
|
|
25
|
-
|
|
26
|
-
expect(mockDb.collection).toHaveBeenCalledWith(
|
|
27
|
-
expect(result[0].name).toBe(
|
|
25
|
+
|
|
26
|
+
expect(mockDb.collection).toHaveBeenCalledWith("agents");
|
|
27
|
+
expect(result[0].name).toBe("Agent Smith");
|
|
28
28
|
});
|
|
29
29
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getDb, Agent, ObjectId } from
|
|
1
|
+
import { getDb, Agent, ObjectId } from "../index";
|
|
2
2
|
|
|
3
3
|
export const getAgentsCollection = () => {
|
|
4
|
-
return getDb().collection<Agent>(
|
|
4
|
+
return getDb().collection<Agent>("agents");
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export const findAgents = async (filter: any = {}) => {
|
|
@@ -25,7 +25,7 @@ export const updateAgent = (agentId: string, data: Partial<Agent>) => {
|
|
|
25
25
|
return getAgentsCollection().findOneAndUpdate(
|
|
26
26
|
{ _id: new ObjectId(agentId) },
|
|
27
27
|
{ $set: data },
|
|
28
|
-
{ returnDocument:
|
|
28
|
+
{ returnDocument: "after" },
|
|
29
29
|
);
|
|
30
30
|
};
|
|
31
31
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WithId } from
|
|
1
|
+
import { WithId } from "mongodb";
|
|
2
2
|
|
|
3
3
|
export type Agent = {
|
|
4
4
|
name: string;
|
|
@@ -8,7 +8,7 @@ export type Agent = {
|
|
|
8
8
|
labels: string[];
|
|
9
9
|
clientId: string;
|
|
10
10
|
role: string;
|
|
11
|
-
gender:
|
|
11
|
+
gender: "male" | "female";
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export type AgentDoc = WithId<Agent>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./agents.getters";
|
|
2
|
+
export * from "./agents.types";
|
|
@@ -3,23 +3,28 @@ import {
|
|
|
3
3
|
upsertBackgroundToolResult,
|
|
4
4
|
findBackgroundToolResult,
|
|
5
5
|
findBackgroundToolResultsByCallSid,
|
|
6
|
-
} from
|
|
7
|
-
import { BackgroundToolStatus } from
|
|
6
|
+
} from "../backgroundToolResults.getters";
|
|
7
|
+
import { BackgroundToolStatus } from "../backgroundToolResults.types";
|
|
8
8
|
|
|
9
|
-
describe(
|
|
9
|
+
describe("backgroundToolResults getters", () => {
|
|
10
10
|
it('should return the "backgroundToolResults" collection', () => {
|
|
11
11
|
const collection = getBackgroundToolResultsCollection();
|
|
12
|
-
expect(collection.collectionName).toBe(
|
|
12
|
+
expect(collection.collectionName).toBe("backgroundToolResults");
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
it(
|
|
16
|
-
const callSid =
|
|
17
|
-
const toolName =
|
|
18
|
-
const status: BackgroundToolStatus =
|
|
15
|
+
it("should create a new background tool result with correct fields and default TTL", async () => {
|
|
16
|
+
const callSid = "CA-background-call-1";
|
|
17
|
+
const toolName = "exampleTool";
|
|
18
|
+
const status: BackgroundToolStatus = "pending";
|
|
19
19
|
const result = null;
|
|
20
20
|
|
|
21
21
|
const before = new Date();
|
|
22
|
-
const doc = await upsertBackgroundToolResult({
|
|
22
|
+
const doc = await upsertBackgroundToolResult({
|
|
23
|
+
callSid,
|
|
24
|
+
toolName,
|
|
25
|
+
status,
|
|
26
|
+
result,
|
|
27
|
+
});
|
|
23
28
|
const after = new Date();
|
|
24
29
|
|
|
25
30
|
expect(doc).not.toBeNull();
|
|
@@ -42,14 +47,14 @@ describe('backgroundToolResults getters', () => {
|
|
|
42
47
|
expect(doc!.updatedAt.getTime()).toBeLessThanOrEqual(after.getTime());
|
|
43
48
|
});
|
|
44
49
|
|
|
45
|
-
it(
|
|
46
|
-
const callSid =
|
|
47
|
-
const toolName =
|
|
50
|
+
it("should upsert by callSid + toolName and keep createdAt while updating other fields", async () => {
|
|
51
|
+
const callSid = "CA-background-call-2";
|
|
52
|
+
const toolName = "aggregationTool";
|
|
48
53
|
|
|
49
54
|
const first = await upsertBackgroundToolResult({
|
|
50
55
|
callSid,
|
|
51
56
|
toolName,
|
|
52
|
-
status:
|
|
57
|
+
status: "pending",
|
|
53
58
|
result: null,
|
|
54
59
|
});
|
|
55
60
|
|
|
@@ -65,7 +70,7 @@ describe('backgroundToolResults getters', () => {
|
|
|
65
70
|
const second = await upsertBackgroundToolResult({
|
|
66
71
|
callSid,
|
|
67
72
|
toolName,
|
|
68
|
-
status:
|
|
73
|
+
status: "success",
|
|
69
74
|
result: secondResultPayload,
|
|
70
75
|
ttlMs: customTtlMs,
|
|
71
76
|
});
|
|
@@ -74,12 +79,14 @@ describe('backgroundToolResults getters', () => {
|
|
|
74
79
|
expect(second!._id.toHexString()).toBe(first!._id.toHexString());
|
|
75
80
|
expect(second!.callSid).toBe(callSid);
|
|
76
81
|
expect(second!.toolName).toBe(toolName);
|
|
77
|
-
expect(second!.status).toBe(
|
|
82
|
+
expect(second!.status).toBe("success");
|
|
78
83
|
expect(second!.result).toEqual(secondResultPayload);
|
|
79
84
|
|
|
80
85
|
expect(second!.createdAt.getTime()).toBe(firstCreatedAt.getTime());
|
|
81
86
|
|
|
82
|
-
expect(second!.updatedAt.getTime()).toBeGreaterThanOrEqual(
|
|
87
|
+
expect(second!.updatedAt.getTime()).toBeGreaterThanOrEqual(
|
|
88
|
+
firstUpdatedAt.getTime(),
|
|
89
|
+
);
|
|
83
90
|
expect(second!.expiredAt.getTime()).not.toBe(firstExpiredAt.getTime());
|
|
84
91
|
|
|
85
92
|
const ttlMs = second!.expiredAt.getTime() - second!.updatedAt.getTime();
|
|
@@ -87,15 +94,15 @@ describe('backgroundToolResults getters', () => {
|
|
|
87
94
|
expect(ttlMs).toBeLessThanOrEqual(customTtlMs + 1000);
|
|
88
95
|
});
|
|
89
96
|
|
|
90
|
-
it(
|
|
91
|
-
const callSid =
|
|
92
|
-
const toolName =
|
|
97
|
+
it("should find background tool result by callSid and toolName", async () => {
|
|
98
|
+
const callSid = "CA-background-call-3";
|
|
99
|
+
const toolName = "fetchUserData";
|
|
93
100
|
|
|
94
101
|
await upsertBackgroundToolResult({
|
|
95
102
|
callSid,
|
|
96
103
|
toolName,
|
|
97
|
-
status:
|
|
98
|
-
result: { foo:
|
|
104
|
+
status: "success",
|
|
105
|
+
result: { foo: "bar" },
|
|
99
106
|
});
|
|
100
107
|
|
|
101
108
|
const found = await findBackgroundToolResult(callSid, toolName);
|
|
@@ -104,18 +111,21 @@ describe('backgroundToolResults getters', () => {
|
|
|
104
111
|
expect(found?.toolName).toBe(toolName);
|
|
105
112
|
});
|
|
106
113
|
|
|
107
|
-
it(
|
|
108
|
-
const found = await findBackgroundToolResult(
|
|
114
|
+
it("should return null when background tool result does not exist", async () => {
|
|
115
|
+
const found = await findBackgroundToolResult(
|
|
116
|
+
"non-existing-callSid",
|
|
117
|
+
"nonExistingTool",
|
|
118
|
+
);
|
|
109
119
|
expect(found).toBeNull();
|
|
110
120
|
});
|
|
111
121
|
|
|
112
|
-
it(
|
|
113
|
-
const callSid =
|
|
122
|
+
it("should return all background tool results for a callSid ordered by createdAt", async () => {
|
|
123
|
+
const callSid = "CA-background-call-4";
|
|
114
124
|
|
|
115
125
|
await upsertBackgroundToolResult({
|
|
116
126
|
callSid,
|
|
117
|
-
toolName:
|
|
118
|
-
status:
|
|
127
|
+
toolName: "toolA",
|
|
128
|
+
status: "pending",
|
|
119
129
|
result: null,
|
|
120
130
|
});
|
|
121
131
|
|
|
@@ -123,14 +133,15 @@ describe('backgroundToolResults getters', () => {
|
|
|
123
133
|
|
|
124
134
|
await upsertBackgroundToolResult({
|
|
125
135
|
callSid,
|
|
126
|
-
toolName:
|
|
127
|
-
status:
|
|
136
|
+
toolName: "toolB",
|
|
137
|
+
status: "success",
|
|
128
138
|
result: { ok: true },
|
|
129
139
|
});
|
|
130
140
|
|
|
131
141
|
const results = await findBackgroundToolResultsByCallSid(callSid);
|
|
132
142
|
expect(results).toHaveLength(2);
|
|
133
|
-
expect(results[0].createdAt.getTime()).toBeLessThanOrEqual(
|
|
143
|
+
expect(results[0].createdAt.getTime()).toBeLessThanOrEqual(
|
|
144
|
+
results[1].createdAt.getTime(),
|
|
145
|
+
);
|
|
134
146
|
});
|
|
135
147
|
});
|
|
136
|
-
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { Collection } from
|
|
2
|
-
import { getDb } from
|
|
1
|
+
import { Collection } from "mongodb";
|
|
2
|
+
import { getDb } from "../index";
|
|
3
3
|
import {
|
|
4
4
|
BackgroundToolResult,
|
|
5
5
|
BackgroundToolResultDoc,
|
|
6
6
|
UpsertBackgroundToolResultInput,
|
|
7
|
-
} from
|
|
7
|
+
} from "./backgroundToolResults.types";
|
|
8
8
|
|
|
9
|
-
const getBackgroundToolResultsCollection =
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const getBackgroundToolResultsCollection =
|
|
10
|
+
(): Collection<BackgroundToolResult> => {
|
|
11
|
+
return getDb().collection<BackgroundToolResult>("backgroundToolResults");
|
|
12
|
+
};
|
|
12
13
|
|
|
13
14
|
const upsertBackgroundToolResult = async (
|
|
14
|
-
input: UpsertBackgroundToolResultInput
|
|
15
|
+
input: UpsertBackgroundToolResultInput,
|
|
15
16
|
): Promise<BackgroundToolResultDoc | null> => {
|
|
16
17
|
const collection = getBackgroundToolResultsCollection();
|
|
17
18
|
const now = new Date();
|
|
@@ -35,7 +36,7 @@ const upsertBackgroundToolResult = async (
|
|
|
35
36
|
createdAt: now,
|
|
36
37
|
},
|
|
37
38
|
},
|
|
38
|
-
{ upsert: true }
|
|
39
|
+
{ upsert: true },
|
|
39
40
|
);
|
|
40
41
|
|
|
41
42
|
return collection.findOne(filter);
|
|
@@ -43,14 +44,14 @@ const upsertBackgroundToolResult = async (
|
|
|
43
44
|
|
|
44
45
|
const findBackgroundToolResult = async (
|
|
45
46
|
callSid: string,
|
|
46
|
-
toolName: string
|
|
47
|
+
toolName: string,
|
|
47
48
|
): Promise<BackgroundToolResultDoc | null> => {
|
|
48
49
|
const collection = getBackgroundToolResultsCollection();
|
|
49
50
|
return collection.findOne({ callSid, toolName });
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
const findBackgroundToolResultsByCallSid = async (
|
|
53
|
-
callSid: string
|
|
54
|
+
callSid: string,
|
|
54
55
|
): Promise<BackgroundToolResultDoc[]> => {
|
|
55
56
|
const collection = getBackgroundToolResultsCollection();
|
|
56
57
|
return collection.find({ callSid }).sort({ createdAt: 1 }).toArray();
|
|
@@ -62,4 +63,3 @@ export {
|
|
|
62
63
|
findBackgroundToolResult,
|
|
63
64
|
findBackgroundToolResultsByCallSid,
|
|
64
65
|
};
|
|
65
|
-
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { WithId } from
|
|
1
|
+
import { WithId } from "mongodb";
|
|
2
2
|
|
|
3
|
-
export type BackgroundToolStatus =
|
|
3
|
+
export type BackgroundToolStatus = "success" | "pending" | "error";
|
|
4
4
|
|
|
5
5
|
export interface BackgroundToolResult {
|
|
6
6
|
callSid: string;
|
|
@@ -21,4 +21,3 @@ export interface UpsertBackgroundToolResultInput {
|
|
|
21
21
|
status: BackgroundToolStatus;
|
|
22
22
|
ttlMs?: number;
|
|
23
23
|
}
|
|
24
|
-
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export type * from
|
|
1
|
+
export * from "./backgroundToolResults.getters";
|
|
2
|
+
export type * from "./backgroundToolResults.types";
|
|
@@ -4,14 +4,17 @@ import {
|
|
|
4
4
|
range,
|
|
5
5
|
startOfDay,
|
|
6
6
|
getCallsCollection,
|
|
7
|
-
} from
|
|
8
|
-
import {
|
|
7
|
+
} from "../calls.getters";
|
|
8
|
+
import {
|
|
9
|
+
createIncomingCallDoc,
|
|
10
|
+
createOutGoingCallDoc,
|
|
11
|
+
} from "../../../test-utils/factories";
|
|
9
12
|
|
|
10
|
-
describe(
|
|
11
|
-
describe(
|
|
12
|
-
it(
|
|
13
|
-
const phone =
|
|
14
|
-
const baseDate = new Date(
|
|
13
|
+
describe("callStats.utils", () => {
|
|
14
|
+
describe("countCallsByPhoneInRange", () => {
|
|
15
|
+
it("counts outgoing calls for a phone within a date range", async () => {
|
|
16
|
+
const phone = "+972500000001";
|
|
17
|
+
const baseDate = new Date("2023-01-10T10:00:00Z");
|
|
15
18
|
|
|
16
19
|
const outgoingInside = createOutGoingCallDoc({
|
|
17
20
|
customerPhoneNumber: phone,
|
|
@@ -27,16 +30,16 @@ describe('callStats.utils', () => {
|
|
|
27
30
|
});
|
|
28
31
|
|
|
29
32
|
await getCallsCollection().insertMany([
|
|
30
|
-
{ ...outgoingInside, updatedAt: outgoingInside.createdAt, env:
|
|
33
|
+
{ ...outgoingInside, updatedAt: outgoingInside.createdAt, env: "test" },
|
|
31
34
|
{
|
|
32
35
|
...outgoingOutsideBefore,
|
|
33
36
|
updatedAt: outgoingOutsideBefore.createdAt,
|
|
34
|
-
env:
|
|
37
|
+
env: "test",
|
|
35
38
|
},
|
|
36
39
|
{
|
|
37
40
|
...outgoingOutsideAfter,
|
|
38
41
|
updatedAt: outgoingOutsideAfter.createdAt,
|
|
39
|
-
env:
|
|
42
|
+
env: "test",
|
|
40
43
|
},
|
|
41
44
|
]);
|
|
42
45
|
|
|
@@ -52,9 +55,9 @@ describe('callStats.utils', () => {
|
|
|
52
55
|
expect(count).toBe(1);
|
|
53
56
|
});
|
|
54
57
|
|
|
55
|
-
it(
|
|
56
|
-
const phone =
|
|
57
|
-
const createdAt = new Date(
|
|
58
|
+
it("filters by incoming/outgoing flags", async () => {
|
|
59
|
+
const phone = "+972500000002";
|
|
60
|
+
const createdAt = new Date("2023-02-01T12:00:00Z");
|
|
58
61
|
|
|
59
62
|
const outgoing = createOutGoingCallDoc({
|
|
60
63
|
customerPhoneNumber: phone,
|
|
@@ -66,8 +69,8 @@ describe('callStats.utils', () => {
|
|
|
66
69
|
});
|
|
67
70
|
|
|
68
71
|
await getCallsCollection().insertMany([
|
|
69
|
-
{ ...outgoing, updatedAt: outgoing.createdAt, env:
|
|
70
|
-
{ ...incoming, updatedAt: incoming.createdAt, env:
|
|
72
|
+
{ ...outgoing, updatedAt: outgoing.createdAt, env: "test" },
|
|
73
|
+
{ ...incoming, updatedAt: incoming.createdAt, env: "test" },
|
|
71
74
|
]);
|
|
72
75
|
|
|
73
76
|
const outgoingCount = await countCallsByPhoneInRange(
|
|
@@ -86,9 +89,9 @@ describe('callStats.utils', () => {
|
|
|
86
89
|
});
|
|
87
90
|
});
|
|
88
91
|
|
|
89
|
-
describe(
|
|
90
|
-
it(
|
|
91
|
-
const d = new Date(
|
|
92
|
+
describe("date helpers", () => {
|
|
93
|
+
it("startOfDay normalizes to midnight", () => {
|
|
94
|
+
const d = new Date("2023-03-10T15:30:45.000Z");
|
|
92
95
|
const s = startOfDay(d);
|
|
93
96
|
expect(s.getUTCHours()).toBe(0);
|
|
94
97
|
expect(s.getUTCMinutes()).toBe(0);
|
|
@@ -96,19 +99,16 @@ describe('callStats.utils', () => {
|
|
|
96
99
|
expect(s.getUTCMilliseconds()).toBe(0);
|
|
97
100
|
});
|
|
98
101
|
|
|
99
|
-
it(
|
|
100
|
-
const d = new Date(
|
|
102
|
+
it("addDays shifts the date by given days", () => {
|
|
103
|
+
const d = new Date("2023-03-10T00:00:00.000Z");
|
|
101
104
|
expect(addDays(d, 1).getUTCDate()).toBe(11);
|
|
102
105
|
expect(addDays(d, -1).getUTCDate()).toBe(9);
|
|
103
106
|
});
|
|
104
107
|
|
|
105
|
-
it(
|
|
106
|
-
const base = new Date(
|
|
108
|
+
it("range helpers produce expected bounds", () => {
|
|
109
|
+
const base = new Date("2023-03-15T10:00:00.000Z");
|
|
107
110
|
|
|
108
|
-
const betweenRange = range.between(
|
|
109
|
-
addDays(base, -1),
|
|
110
|
-
addDays(base, 1),
|
|
111
|
-
);
|
|
111
|
+
const betweenRange = range.between(addDays(base, -1), addDays(base, 1));
|
|
112
112
|
expect(betweenRange.since).toEqual(addDays(base, -1));
|
|
113
113
|
expect(betweenRange.until).toEqual(addDays(base, 1));
|
|
114
114
|
|
|
@@ -125,4 +125,4 @@ describe('callStats.utils', () => {
|
|
|
125
125
|
expect(startToNowRange.until).toBeInstanceOf(Date);
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
|
-
})
|
|
128
|
+
});
|
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
countCalls,
|
|
9
9
|
getCallsByClientAndDateRange,
|
|
10
10
|
getCallsCollection,
|
|
11
|
-
} from
|
|
12
|
-
import { ObjectId } from
|
|
13
|
-
import { createOutGoingCallDoc } from
|
|
11
|
+
} from "../calls.getters";
|
|
12
|
+
import { ObjectId } from "mongodb";
|
|
13
|
+
import { createOutGoingCallDoc } from "../../../test-utils/factories";
|
|
14
14
|
|
|
15
|
-
describe(
|
|
16
|
-
it(
|
|
15
|
+
describe("db.calls", () => {
|
|
16
|
+
it("should return calls by flow", async () => {
|
|
17
17
|
const flowId = new ObjectId();
|
|
18
18
|
const call1 = createOutGoingCallDoc({ flowId });
|
|
19
19
|
const call2 = createOutGoingCallDoc({ flowId });
|
|
@@ -26,11 +26,11 @@ describe('db.calls', () => {
|
|
|
26
26
|
expect(result.length).toBe(2);
|
|
27
27
|
expect(result).toMatchObject([
|
|
28
28
|
{ callSid: call1.callSid },
|
|
29
|
-
{ callSid: call2.callSid }
|
|
29
|
+
{ callSid: call2.callSid },
|
|
30
30
|
]);
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
it(
|
|
33
|
+
it("should get call by callSid", async () => {
|
|
34
34
|
const call = createOutGoingCallDoc();
|
|
35
35
|
await createCallDoc(call);
|
|
36
36
|
|
|
@@ -40,39 +40,54 @@ describe('db.calls', () => {
|
|
|
40
40
|
expect(result?.callSid).toBe(call.callSid);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
it(
|
|
43
|
+
it("should get calls by client", async () => {
|
|
44
44
|
const call = createOutGoingCallDoc();
|
|
45
45
|
await createCallDoc(call);
|
|
46
46
|
|
|
47
47
|
const result = await getCallsByClient(call.clientId);
|
|
48
48
|
|
|
49
|
-
expect(result.some(c => c.callSid === call.callSid)).toBe(true);
|
|
49
|
+
expect(result.some((c) => c.callSid === call.callSid)).toBe(true);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
it(
|
|
52
|
+
it("should get calls by phone number", async () => {
|
|
53
53
|
const call = createOutGoingCallDoc();
|
|
54
54
|
await createCallDoc(call);
|
|
55
55
|
|
|
56
56
|
const result = await getCallsByPhoneNumber(call.customerPhoneNumber);
|
|
57
57
|
|
|
58
|
-
expect(result.some(c => c.callSid === call.callSid)).toBe(true);
|
|
58
|
+
expect(result.some((c) => c.callSid === call.callSid)).toBe(true);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
describe(
|
|
62
|
-
it(
|
|
63
|
-
const clientId =
|
|
64
|
-
const call1 = createOutGoingCallDoc({ clientId, status:
|
|
65
|
-
const call2 = createOutGoingCallDoc({ clientId, status:
|
|
66
|
-
const call3 = createOutGoingCallDoc({ clientId, status:
|
|
61
|
+
describe("findCallsByQuery()", () => {
|
|
62
|
+
it("should find calls by status with limit and sort", async () => {
|
|
63
|
+
const clientId = "client123";
|
|
64
|
+
const call1 = createOutGoingCallDoc({ clientId, status: "completed" });
|
|
65
|
+
const call2 = createOutGoingCallDoc({ clientId, status: "completed" });
|
|
66
|
+
const call3 = createOutGoingCallDoc({ clientId, status: "busy" });
|
|
67
67
|
|
|
68
68
|
// We need to control createdAt to test sort. We'll insert directly.
|
|
69
|
-
await getCallsCollection().insertOne({
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
await getCallsCollection().insertOne({
|
|
70
|
+
...call1,
|
|
71
|
+
createdAt: new Date("2023-01-01"),
|
|
72
|
+
updatedAt: new Date(),
|
|
73
|
+
env: "test",
|
|
74
|
+
});
|
|
75
|
+
await getCallsCollection().insertOne({
|
|
76
|
+
...call2,
|
|
77
|
+
createdAt: new Date("2023-01-02"),
|
|
78
|
+
updatedAt: new Date(),
|
|
79
|
+
env: "test",
|
|
80
|
+
});
|
|
81
|
+
await getCallsCollection().insertOne({
|
|
82
|
+
...call3,
|
|
83
|
+
createdAt: new Date(),
|
|
84
|
+
updatedAt: new Date(),
|
|
85
|
+
env: "test",
|
|
86
|
+
});
|
|
72
87
|
|
|
73
88
|
const result = await findCallsByQuery(
|
|
74
|
-
{ clientId, status:
|
|
75
|
-
{ sort: { createdAt: -1 }, limit: 1 }
|
|
89
|
+
{ clientId, status: "completed" },
|
|
90
|
+
{ sort: { createdAt: -1 }, limit: 1 },
|
|
76
91
|
);
|
|
77
92
|
|
|
78
93
|
expect(result.length).toBe(1);
|
|
@@ -80,33 +95,58 @@ describe('db.calls', () => {
|
|
|
80
95
|
});
|
|
81
96
|
});
|
|
82
97
|
|
|
83
|
-
describe(
|
|
84
|
-
it(
|
|
85
|
-
const clientId =
|
|
86
|
-
await createCallDoc(
|
|
87
|
-
|
|
88
|
-
|
|
98
|
+
describe("countCalls()", () => {
|
|
99
|
+
it("should count calls matching query", async () => {
|
|
100
|
+
const clientId = "countClient";
|
|
101
|
+
await createCallDoc(
|
|
102
|
+
createOutGoingCallDoc({ clientId, status: "completed" }),
|
|
103
|
+
);
|
|
104
|
+
await createCallDoc(
|
|
105
|
+
createOutGoingCallDoc({ clientId, status: "completed" }),
|
|
106
|
+
);
|
|
107
|
+
await createCallDoc(
|
|
108
|
+
createOutGoingCallDoc({ clientId, status: "failed" }),
|
|
109
|
+
);
|
|
89
110
|
|
|
90
|
-
const count = await countCalls({ clientId, status:
|
|
111
|
+
const count = await countCalls({ clientId, status: "completed" });
|
|
91
112
|
expect(count).toBe(2);
|
|
92
113
|
});
|
|
93
114
|
});
|
|
94
115
|
|
|
95
|
-
describe(
|
|
96
|
-
it(
|
|
97
|
-
const clientId =
|
|
98
|
-
const startDate = new Date(
|
|
99
|
-
const endDate = new Date(
|
|
116
|
+
describe("getCallsByClientAndDateRange()", () => {
|
|
117
|
+
it("should return calls within date range", async () => {
|
|
118
|
+
const clientId = "dateRangeClient";
|
|
119
|
+
const startDate = new Date("2023-05-01");
|
|
120
|
+
const endDate = new Date("2023-05-31");
|
|
100
121
|
|
|
101
122
|
const callInside = createOutGoingCallDoc({ clientId });
|
|
102
123
|
const callBefore = createOutGoingCallDoc({ clientId });
|
|
103
124
|
const callAfter = createOutGoingCallDoc({ clientId });
|
|
104
125
|
|
|
105
|
-
await getCallsCollection().insertOne({
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
126
|
+
await getCallsCollection().insertOne({
|
|
127
|
+
...callInside,
|
|
128
|
+
createdAt: new Date("2023-05-15"),
|
|
129
|
+
updatedAt: new Date(),
|
|
130
|
+
env: "test",
|
|
131
|
+
});
|
|
132
|
+
await getCallsCollection().insertOne({
|
|
133
|
+
...callBefore,
|
|
134
|
+
createdAt: new Date("2023-04-30"),
|
|
135
|
+
updatedAt: new Date(),
|
|
136
|
+
env: "test",
|
|
137
|
+
});
|
|
138
|
+
await getCallsCollection().insertOne({
|
|
139
|
+
...callAfter,
|
|
140
|
+
createdAt: new Date("2023-06-01"),
|
|
141
|
+
updatedAt: new Date(),
|
|
142
|
+
env: "test",
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const result = await getCallsByClientAndDateRange(
|
|
146
|
+
clientId,
|
|
147
|
+
startDate,
|
|
148
|
+
endDate,
|
|
149
|
+
);
|
|
110
150
|
expect(result.length).toBe(1);
|
|
111
151
|
expect(result[0].callSid).toBe(callInside.callSid);
|
|
112
152
|
});
|