@talkpilot/core-db 1.1.7 → 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.
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +24 -21
- 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 +4 -8
- 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 +22 -30
- 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 +7 -7
- 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 +9 -19
- 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 +4 -10
- 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 +8 -13
- 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 +29 -50
- 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 +15 -19
- 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 +2 -5
- 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 +3 -3
- 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 +3 -0
- package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
- package/dist/talkpilot/flows/flows.schema.js +80 -87
- package/dist/talkpilot/flows/flows.schema.js.map +1 -1
- package/dist/talkpilot/flows/flows.types.d.ts +17 -16
- package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
- 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.js +9 -8
- 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 +13 -28
- 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 +10 -13
- 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/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 +1 -7
- 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 +1 -6
- 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 +1 -7
- 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 +1 -3
- package/src/__tests__/setup.ts +3 -3
- package/src/connection.ts +25 -27
- package/src/index.ts +9 -9
- package/src/municipal/__tests__/validation.spec.ts +23 -35
- package/src/municipal/cities/cities.getters.ts +10 -16
- package/src/municipal/cities/cities.types.ts +1 -1
- package/src/municipal/cities/index.ts +2 -2
- package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +44 -53
- package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +5 -5
- package/src/municipal/departmentsSubjects/index.ts +3 -2
- package/src/municipal/index.ts +10 -10
- package/src/municipal/mongodb-client.ts +10 -13
- package/src/municipal/streets/index.ts +2 -2
- package/src/municipal/streets/streets.getters.ts +23 -43
- package/src/municipal/streets/streets.types.ts +1 -1
- package/src/municipal/systemInstructions/__tests__/getters.spec.ts +52 -67
- package/src/municipal/systemInstructions/__tests__/setters.spec.ts +238 -271
- package/src/municipal/systemInstructions/index.ts +3 -7
- package/src/municipal/systemInstructions/instructions.getters.ts +18 -30
- package/src/municipal/systemInstructions/instructions.setters.ts +19 -43
- 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 +42 -69
- package/src/municipal/tickets/tickets.types.ts +2 -2
- package/src/municipal/utils/types.ts +3 -8
- package/src/talkpilot/__tests__/db.spec.ts +12 -12
- package/src/talkpilot/__tests__/mongodb-client.spec.ts +8 -7
- package/src/talkpilot/__tests__/validation.spec.ts +24 -30
- 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 +31 -42
- package/src/talkpilot/backgroundToolResults/backgroundToolResults.getters.ts +11 -11
- package/src/talkpilot/backgroundToolResults/backgroundToolResults.types.ts +3 -2
- 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 +39 -79
- package/src/talkpilot/calls/calls.getters.ts +28 -48
- 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 +39 -73
- package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +11 -18
- package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +2 -2
- package/src/talkpilot/clientAudioBuffers/index.ts +2 -2
- package/src/talkpilot/clients/clients.getters.ts +5 -10
- 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 +18 -21
- package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +4 -6
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +8 -10
- package/src/talkpilot/clientsConfig/index.ts +2 -2
- package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +37 -38
- package/src/talkpilot/flows/flows.getter.ts +5 -8
- package/src/talkpilot/flows/flows.schema.ts +80 -87
- package/src/talkpilot/flows/flows.types.ts +24 -23
- package/src/talkpilot/flows/index.ts +2 -2
- package/src/talkpilot/groups/__tests__/groups.spec.ts +27 -34
- package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +20 -20
- package/src/talkpilot/groups/groups.getters.ts +5 -8
- package/src/talkpilot/groups/groups.types.ts +1 -1
- package/src/talkpilot/groups/index.ts +3 -3
- package/src/talkpilot/groups/phone.utils.ts +6 -12
- package/src/talkpilot/index.ts +17 -17
- package/src/talkpilot/leads/index.ts +2 -2
- package/src/talkpilot/leads/leads.getter.ts +4 -5
- package/src/talkpilot/leads/leads.schema.ts +16 -16
- package/src/talkpilot/leads/leads.types.ts +1 -1
- package/src/talkpilot/mongodb-client.ts +12 -12
- package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +44 -84
- package/src/talkpilot/phone_numbers/index.ts +2 -2
- package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +22 -44
- 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 +26 -30
- package/src/talkpilot/plans/index.ts +2 -2
- package/src/talkpilot/plans/plans.getters.ts +18 -25
- package/src/talkpilot/plans/plans.types.ts +23 -27
- package/src/talkpilot/results/index.ts +2 -5
- package/src/talkpilot/results/results.getter.ts +8 -9
- 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 +41 -65
- package/src/talkpilot/sessions/index.ts +2 -2
- package/src/talkpilot/sessions/sessions.getter.ts +16 -21
- 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 +15 -18
- package/src/talkpilot/subscriptions/index.ts +3 -3
- package/src/talkpilot/subscriptions/subscriptions.getters.ts +33 -36
- package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +3 -10
- 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 +25 -32
- package/src/test-utils/factories/municipal/streets.ts +5 -10
- package/src/test-utils/factories/municipal/tickets.ts +6 -12
- 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 +12 -14
- package/src/test-utils/factories/talkpilot/clientsConfig.ts +8 -7
- package/src/test-utils/factories/talkpilot/flows.ts +5 -7
- package/src/test-utils/factories/talkpilot/groups.ts +13 -13
- package/src/test-utils/factories/talkpilot/phone_numbers.ts +6 -8
- package/src/test-utils/factories/talkpilot/sessions.ts +5 -5
- package/src/utils/validation.ts +4 -4
- package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts +0 -4
- package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts.map +0 -1
- package/dist/talkpilot/subscriptions/subscriptions.utils.js +0 -20
- package/dist/talkpilot/subscriptions/subscriptions.utils.js.map +0 -1
|
@@ -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,28 +3,23 @@ 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({
|
|
23
|
-
callSid,
|
|
24
|
-
toolName,
|
|
25
|
-
status,
|
|
26
|
-
result,
|
|
27
|
-
});
|
|
22
|
+
const doc = await upsertBackgroundToolResult({ callSid, toolName, status, result });
|
|
28
23
|
const after = new Date();
|
|
29
24
|
|
|
30
25
|
expect(doc).not.toBeNull();
|
|
@@ -47,14 +42,14 @@ describe("backgroundToolResults getters", () => {
|
|
|
47
42
|
expect(doc!.updatedAt.getTime()).toBeLessThanOrEqual(after.getTime());
|
|
48
43
|
});
|
|
49
44
|
|
|
50
|
-
it(
|
|
51
|
-
const callSid =
|
|
52
|
-
const toolName =
|
|
45
|
+
it('should upsert by callSid + toolName and keep createdAt while updating other fields', async () => {
|
|
46
|
+
const callSid = 'CA-background-call-2';
|
|
47
|
+
const toolName = 'aggregationTool';
|
|
53
48
|
|
|
54
49
|
const first = await upsertBackgroundToolResult({
|
|
55
50
|
callSid,
|
|
56
51
|
toolName,
|
|
57
|
-
status:
|
|
52
|
+
status: 'pending',
|
|
58
53
|
result: null,
|
|
59
54
|
});
|
|
60
55
|
|
|
@@ -70,7 +65,7 @@ describe("backgroundToolResults getters", () => {
|
|
|
70
65
|
const second = await upsertBackgroundToolResult({
|
|
71
66
|
callSid,
|
|
72
67
|
toolName,
|
|
73
|
-
status:
|
|
68
|
+
status: 'success',
|
|
74
69
|
result: secondResultPayload,
|
|
75
70
|
ttlMs: customTtlMs,
|
|
76
71
|
});
|
|
@@ -79,14 +74,12 @@ describe("backgroundToolResults getters", () => {
|
|
|
79
74
|
expect(second!._id.toHexString()).toBe(first!._id.toHexString());
|
|
80
75
|
expect(second!.callSid).toBe(callSid);
|
|
81
76
|
expect(second!.toolName).toBe(toolName);
|
|
82
|
-
expect(second!.status).toBe(
|
|
77
|
+
expect(second!.status).toBe('success');
|
|
83
78
|
expect(second!.result).toEqual(secondResultPayload);
|
|
84
79
|
|
|
85
80
|
expect(second!.createdAt.getTime()).toBe(firstCreatedAt.getTime());
|
|
86
81
|
|
|
87
|
-
expect(second!.updatedAt.getTime()).toBeGreaterThanOrEqual(
|
|
88
|
-
firstUpdatedAt.getTime(),
|
|
89
|
-
);
|
|
82
|
+
expect(second!.updatedAt.getTime()).toBeGreaterThanOrEqual(firstUpdatedAt.getTime());
|
|
90
83
|
expect(second!.expiredAt.getTime()).not.toBe(firstExpiredAt.getTime());
|
|
91
84
|
|
|
92
85
|
const ttlMs = second!.expiredAt.getTime() - second!.updatedAt.getTime();
|
|
@@ -94,15 +87,15 @@ describe("backgroundToolResults getters", () => {
|
|
|
94
87
|
expect(ttlMs).toBeLessThanOrEqual(customTtlMs + 1000);
|
|
95
88
|
});
|
|
96
89
|
|
|
97
|
-
it(
|
|
98
|
-
const callSid =
|
|
99
|
-
const toolName =
|
|
90
|
+
it('should find background tool result by callSid and toolName', async () => {
|
|
91
|
+
const callSid = 'CA-background-call-3';
|
|
92
|
+
const toolName = 'fetchUserData';
|
|
100
93
|
|
|
101
94
|
await upsertBackgroundToolResult({
|
|
102
95
|
callSid,
|
|
103
96
|
toolName,
|
|
104
|
-
status:
|
|
105
|
-
result: { foo:
|
|
97
|
+
status: 'success',
|
|
98
|
+
result: { foo: 'bar' },
|
|
106
99
|
});
|
|
107
100
|
|
|
108
101
|
const found = await findBackgroundToolResult(callSid, toolName);
|
|
@@ -111,21 +104,18 @@ describe("backgroundToolResults getters", () => {
|
|
|
111
104
|
expect(found?.toolName).toBe(toolName);
|
|
112
105
|
});
|
|
113
106
|
|
|
114
|
-
it(
|
|
115
|
-
const found = await findBackgroundToolResult(
|
|
116
|
-
"non-existing-callSid",
|
|
117
|
-
"nonExistingTool",
|
|
118
|
-
);
|
|
107
|
+
it('should return null when background tool result does not exist', async () => {
|
|
108
|
+
const found = await findBackgroundToolResult('non-existing-callSid', 'nonExistingTool');
|
|
119
109
|
expect(found).toBeNull();
|
|
120
110
|
});
|
|
121
111
|
|
|
122
|
-
it(
|
|
123
|
-
const callSid =
|
|
112
|
+
it('should return all background tool results for a callSid ordered by createdAt', async () => {
|
|
113
|
+
const callSid = 'CA-background-call-4';
|
|
124
114
|
|
|
125
115
|
await upsertBackgroundToolResult({
|
|
126
116
|
callSid,
|
|
127
|
-
toolName:
|
|
128
|
-
status:
|
|
117
|
+
toolName: 'toolA',
|
|
118
|
+
status: 'pending',
|
|
129
119
|
result: null,
|
|
130
120
|
});
|
|
131
121
|
|
|
@@ -133,15 +123,14 @@ describe("backgroundToolResults getters", () => {
|
|
|
133
123
|
|
|
134
124
|
await upsertBackgroundToolResult({
|
|
135
125
|
callSid,
|
|
136
|
-
toolName:
|
|
137
|
-
status:
|
|
126
|
+
toolName: 'toolB',
|
|
127
|
+
status: 'success',
|
|
138
128
|
result: { ok: true },
|
|
139
129
|
});
|
|
140
130
|
|
|
141
131
|
const results = await findBackgroundToolResultsByCallSid(callSid);
|
|
142
132
|
expect(results).toHaveLength(2);
|
|
143
|
-
expect(results[0].createdAt.getTime()).toBeLessThanOrEqual(
|
|
144
|
-
results[1].createdAt.getTime(),
|
|
145
|
-
);
|
|
133
|
+
expect(results[0].createdAt.getTime()).toBeLessThanOrEqual(results[1].createdAt.getTime());
|
|
146
134
|
});
|
|
147
135
|
});
|
|
136
|
+
|
|
@@ -1,18 +1,17 @@
|
|
|
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
|
-
|
|
12
|
-
};
|
|
9
|
+
const getBackgroundToolResultsCollection = (): Collection<BackgroundToolResult> => {
|
|
10
|
+
return getDb().collection<BackgroundToolResult>('backgroundToolResults');
|
|
11
|
+
};
|
|
13
12
|
|
|
14
13
|
const upsertBackgroundToolResult = async (
|
|
15
|
-
input: UpsertBackgroundToolResultInput
|
|
14
|
+
input: UpsertBackgroundToolResultInput
|
|
16
15
|
): Promise<BackgroundToolResultDoc | null> => {
|
|
17
16
|
const collection = getBackgroundToolResultsCollection();
|
|
18
17
|
const now = new Date();
|
|
@@ -36,7 +35,7 @@ const upsertBackgroundToolResult = async (
|
|
|
36
35
|
createdAt: now,
|
|
37
36
|
},
|
|
38
37
|
},
|
|
39
|
-
{ upsert: true }
|
|
38
|
+
{ upsert: true }
|
|
40
39
|
);
|
|
41
40
|
|
|
42
41
|
return collection.findOne(filter);
|
|
@@ -44,14 +43,14 @@ const upsertBackgroundToolResult = async (
|
|
|
44
43
|
|
|
45
44
|
const findBackgroundToolResult = async (
|
|
46
45
|
callSid: string,
|
|
47
|
-
toolName: string
|
|
46
|
+
toolName: string
|
|
48
47
|
): Promise<BackgroundToolResultDoc | null> => {
|
|
49
48
|
const collection = getBackgroundToolResultsCollection();
|
|
50
49
|
return collection.findOne({ callSid, toolName });
|
|
51
50
|
};
|
|
52
51
|
|
|
53
52
|
const findBackgroundToolResultsByCallSid = async (
|
|
54
|
-
callSid: string
|
|
53
|
+
callSid: string
|
|
55
54
|
): Promise<BackgroundToolResultDoc[]> => {
|
|
56
55
|
const collection = getBackgroundToolResultsCollection();
|
|
57
56
|
return collection.find({ callSid }).sort({ createdAt: 1 }).toArray();
|
|
@@ -63,3 +62,4 @@ export {
|
|
|
63
62
|
findBackgroundToolResult,
|
|
64
63
|
findBackgroundToolResultsByCallSid,
|
|
65
64
|
};
|
|
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,3 +21,4 @@ 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,17 +4,14 @@ import {
|
|
|
4
4
|
range,
|
|
5
5
|
startOfDay,
|
|
6
6
|
getCallsCollection,
|
|
7
|
-
} from
|
|
8
|
-
import {
|
|
9
|
-
createIncomingCallDoc,
|
|
10
|
-
createOutGoingCallDoc,
|
|
11
|
-
} from "../../../test-utils/factories";
|
|
7
|
+
} from '../calls.getters';
|
|
8
|
+
import { createIncomingCallDoc, createOutGoingCallDoc } from '../../../test-utils/factories';
|
|
12
9
|
|
|
13
|
-
describe(
|
|
14
|
-
describe(
|
|
15
|
-
it(
|
|
16
|
-
const phone =
|
|
17
|
-
const baseDate = new Date(
|
|
10
|
+
describe('callStats.utils', () => {
|
|
11
|
+
describe('countCallsByPhoneInRange', () => {
|
|
12
|
+
it('counts outgoing calls for a phone within a date range', async () => {
|
|
13
|
+
const phone = '+972500000001';
|
|
14
|
+
const baseDate = new Date('2023-01-10T10:00:00Z');
|
|
18
15
|
|
|
19
16
|
const outgoingInside = createOutGoingCallDoc({
|
|
20
17
|
customerPhoneNumber: phone,
|
|
@@ -30,16 +27,16 @@ describe("callStats.utils", () => {
|
|
|
30
27
|
});
|
|
31
28
|
|
|
32
29
|
await getCallsCollection().insertMany([
|
|
33
|
-
{ ...outgoingInside, updatedAt: outgoingInside.createdAt, env:
|
|
30
|
+
{ ...outgoingInside, updatedAt: outgoingInside.createdAt, env: 'test' },
|
|
34
31
|
{
|
|
35
32
|
...outgoingOutsideBefore,
|
|
36
33
|
updatedAt: outgoingOutsideBefore.createdAt,
|
|
37
|
-
env:
|
|
34
|
+
env: 'test',
|
|
38
35
|
},
|
|
39
36
|
{
|
|
40
37
|
...outgoingOutsideAfter,
|
|
41
38
|
updatedAt: outgoingOutsideAfter.createdAt,
|
|
42
|
-
env:
|
|
39
|
+
env: 'test',
|
|
43
40
|
},
|
|
44
41
|
]);
|
|
45
42
|
|
|
@@ -55,9 +52,9 @@ describe("callStats.utils", () => {
|
|
|
55
52
|
expect(count).toBe(1);
|
|
56
53
|
});
|
|
57
54
|
|
|
58
|
-
it(
|
|
59
|
-
const phone =
|
|
60
|
-
const createdAt = new Date(
|
|
55
|
+
it('filters by incoming/outgoing flags', async () => {
|
|
56
|
+
const phone = '+972500000002';
|
|
57
|
+
const createdAt = new Date('2023-02-01T12:00:00Z');
|
|
61
58
|
|
|
62
59
|
const outgoing = createOutGoingCallDoc({
|
|
63
60
|
customerPhoneNumber: phone,
|
|
@@ -69,8 +66,8 @@ describe("callStats.utils", () => {
|
|
|
69
66
|
});
|
|
70
67
|
|
|
71
68
|
await getCallsCollection().insertMany([
|
|
72
|
-
{ ...outgoing, updatedAt: outgoing.createdAt, env:
|
|
73
|
-
{ ...incoming, updatedAt: incoming.createdAt, env:
|
|
69
|
+
{ ...outgoing, updatedAt: outgoing.createdAt, env: 'test' },
|
|
70
|
+
{ ...incoming, updatedAt: incoming.createdAt, env: 'test' },
|
|
74
71
|
]);
|
|
75
72
|
|
|
76
73
|
const outgoingCount = await countCallsByPhoneInRange(
|
|
@@ -89,9 +86,9 @@ describe("callStats.utils", () => {
|
|
|
89
86
|
});
|
|
90
87
|
});
|
|
91
88
|
|
|
92
|
-
describe(
|
|
93
|
-
it(
|
|
94
|
-
const d = new Date(
|
|
89
|
+
describe('date helpers', () => {
|
|
90
|
+
it('startOfDay normalizes to midnight', () => {
|
|
91
|
+
const d = new Date('2023-03-10T15:30:45.000Z');
|
|
95
92
|
const s = startOfDay(d);
|
|
96
93
|
expect(s.getUTCHours()).toBe(0);
|
|
97
94
|
expect(s.getUTCMinutes()).toBe(0);
|
|
@@ -99,16 +96,19 @@ describe("callStats.utils", () => {
|
|
|
99
96
|
expect(s.getUTCMilliseconds()).toBe(0);
|
|
100
97
|
});
|
|
101
98
|
|
|
102
|
-
it(
|
|
103
|
-
const d = new Date(
|
|
99
|
+
it('addDays shifts the date by given days', () => {
|
|
100
|
+
const d = new Date('2023-03-10T00:00:00.000Z');
|
|
104
101
|
expect(addDays(d, 1).getUTCDate()).toBe(11);
|
|
105
102
|
expect(addDays(d, -1).getUTCDate()).toBe(9);
|
|
106
103
|
});
|
|
107
104
|
|
|
108
|
-
it(
|
|
109
|
-
const base = new Date(
|
|
105
|
+
it('range helpers produce expected bounds', () => {
|
|
106
|
+
const base = new Date('2023-03-15T10:00:00.000Z');
|
|
110
107
|
|
|
111
|
-
const betweenRange = range.between(
|
|
108
|
+
const betweenRange = range.between(
|
|
109
|
+
addDays(base, -1),
|
|
110
|
+
addDays(base, 1),
|
|
111
|
+
);
|
|
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,54 +40,39 @@ 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(
|
|
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(
|
|
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
|
-
|
|
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
|
-
});
|
|
69
|
+
await getCallsCollection().insertOne({ ...call1, createdAt: new Date('2023-01-01'), updatedAt: new Date(), env: 'test' });
|
|
70
|
+
await getCallsCollection().insertOne({ ...call2, createdAt: new Date('2023-01-02'), updatedAt: new Date(), env: 'test' });
|
|
71
|
+
await getCallsCollection().insertOne({ ...call3, createdAt: new Date(), updatedAt: new Date(), env: 'test' });
|
|
87
72
|
|
|
88
73
|
const result = await findCallsByQuery(
|
|
89
|
-
{ clientId, status:
|
|
90
|
-
{ sort: { createdAt: -1 }, limit: 1 }
|
|
74
|
+
{ clientId, status: 'completed' },
|
|
75
|
+
{ sort: { createdAt: -1 }, limit: 1 }
|
|
91
76
|
);
|
|
92
77
|
|
|
93
78
|
expect(result.length).toBe(1);
|
|
@@ -95,58 +80,33 @@ describe("db.calls", () => {
|
|
|
95
80
|
});
|
|
96
81
|
});
|
|
97
82
|
|
|
98
|
-
describe(
|
|
99
|
-
it(
|
|
100
|
-
const clientId =
|
|
101
|
-
await createCallDoc(
|
|
102
|
-
|
|
103
|
-
);
|
|
104
|
-
await createCallDoc(
|
|
105
|
-
createOutGoingCallDoc({ clientId, status: "completed" }),
|
|
106
|
-
);
|
|
107
|
-
await createCallDoc(
|
|
108
|
-
createOutGoingCallDoc({ clientId, status: "failed" }),
|
|
109
|
-
);
|
|
83
|
+
describe('countCalls()', () => {
|
|
84
|
+
it('should count calls matching query', async () => {
|
|
85
|
+
const clientId = 'countClient';
|
|
86
|
+
await createCallDoc(createOutGoingCallDoc({ clientId, status: 'completed' }));
|
|
87
|
+
await createCallDoc(createOutGoingCallDoc({ clientId, status: 'completed' }));
|
|
88
|
+
await createCallDoc(createOutGoingCallDoc({ clientId, status: 'failed' }));
|
|
110
89
|
|
|
111
|
-
const count = await countCalls({ clientId, status:
|
|
90
|
+
const count = await countCalls({ clientId, status: 'completed' });
|
|
112
91
|
expect(count).toBe(2);
|
|
113
92
|
});
|
|
114
93
|
});
|
|
115
94
|
|
|
116
|
-
describe(
|
|
117
|
-
it(
|
|
118
|
-
const clientId =
|
|
119
|
-
const startDate = new Date(
|
|
120
|
-
const endDate = new Date(
|
|
95
|
+
describe('getCallsByClientAndDateRange()', () => {
|
|
96
|
+
it('should return calls within date range', async () => {
|
|
97
|
+
const clientId = 'dateRangeClient';
|
|
98
|
+
const startDate = new Date('2023-05-01');
|
|
99
|
+
const endDate = new Date('2023-05-31');
|
|
121
100
|
|
|
122
101
|
const callInside = createOutGoingCallDoc({ clientId });
|
|
123
102
|
const callBefore = createOutGoingCallDoc({ clientId });
|
|
124
103
|
const callAfter = createOutGoingCallDoc({ clientId });
|
|
125
104
|
|
|
126
|
-
await getCallsCollection().insertOne({
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
);
|
|
105
|
+
await getCallsCollection().insertOne({ ...callInside, createdAt: new Date('2023-05-15'), updatedAt: new Date(), env: 'test' });
|
|
106
|
+
await getCallsCollection().insertOne({ ...callBefore, createdAt: new Date('2023-04-30'), updatedAt: new Date(), env: 'test' });
|
|
107
|
+
await getCallsCollection().insertOne({ ...callAfter, createdAt: new Date('2023-06-01'), updatedAt: new Date(), env: 'test' });
|
|
108
|
+
|
|
109
|
+
const result = await getCallsByClientAndDateRange(clientId, startDate, endDate);
|
|
150
110
|
expect(result.length).toBe(1);
|
|
151
111
|
expect(result[0].callSid).toBe(callInside.callSid);
|
|
152
112
|
});
|