@tellescope/sdk 1.204.2 → 1.205.0

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.
@@ -37,7 +37,7 @@ import {
37
37
  } from "@tellescope/validation"
38
38
 
39
39
  import { Session, APIQuery, EnduserSession } from "../sdk"
40
- import { evaluate_conditional_logic_for_enduser_fields, FORM_LOGIC_CALCULATED_FIELDS, get_care_team_primary, get_flattened_fields, replace_enduser_template_values, responses_satisfy_conditions, weighted_round_robin, YYYY_MM_DD_to_MM_DD_YYYY } from "@tellescope/utilities"
40
+ import { evaluate_conditional_logic_for_enduser_fields, FORM_LOGIC_CALCULATED_FIELDS, get_care_team_primary, get_flattened_fields, get_next_reminder_timestamp, replace_enduser_template_values, responses_satisfy_conditions, weighted_round_robin, YYYY_MM_DD_to_MM_DD_YYYY } from "@tellescope/utilities"
41
41
  import { DEFAULT_OPERATIONS, PLACEHOLDER_ID, ZOOM_TITLE } from "@tellescope/constants"
42
42
  import {
43
43
  schema,
@@ -11449,6 +11449,148 @@ const inbox_loading_tests = async () => {
11449
11449
  ])
11450
11450
  }
11451
11451
 
11452
+ const get_next_reminder_timestamp_tests = () => {
11453
+ log_header("Get Next Reminder Timestamp Tests")
11454
+
11455
+ const startTimeInMS = Date.now()
11456
+ assert(
11457
+ get_next_reminder_timestamp({ attendees: [], startTimeInMS }) === -1,
11458
+ 'invalid get_next_reminder_timestamp',
11459
+ 'get_next_reminder_timestamp with no attendees, no reminders'
11460
+ )
11461
+
11462
+ assert(
11463
+ get_next_reminder_timestamp({ attendees: [], startTimeInMS, reminders: [] }) === -1,
11464
+ 'invalid get_next_reminder_timestamp',
11465
+ 'get_next_reminder_timestamp with no attendees, empty reminders'
11466
+ )
11467
+
11468
+ assert(
11469
+ get_next_reminder_timestamp({ attendees: [], startTimeInMS,
11470
+ reminders: [{ type: 'Remove From Journey', info: { journeyId: PLACEHOLDER_ID }, msBeforeStartTime: 0, didRemind: true } ]
11471
+ }) === -1,
11472
+ 'invalid get_next_reminder_timestamp',
11473
+ 'get_next_reminder_timestamp with no attendees, didRemind true'
11474
+ )
11475
+
11476
+ assert(
11477
+ get_next_reminder_timestamp({ attendees: [], startTimeInMS,
11478
+ reminders: [{ type: 'add-to-journey', info: { journeyId: PLACEHOLDER_ID }, msBeforeStartTime: 0 } ]
11479
+ }) === -1,
11480
+ 'invalid get_next_reminder_timestamp',
11481
+ 'get_next_reminder_timestamp with no attendees, add-to-journey no attendees'
11482
+ )
11483
+
11484
+ assert(
11485
+ get_next_reminder_timestamp({ attendees: [], startTimeInMS,
11486
+ reminders: [{ type: 'Remove From Journey', info: { journeyId: PLACEHOLDER_ID }, msBeforeStartTime: 0 } ]
11487
+ }) === startTimeInMS,
11488
+ 'invalid get_next_reminder_timestamp',
11489
+ 'get_next_reminder_timestamp with no attendees, Remove From Journey'
11490
+ )
11491
+
11492
+ assert(
11493
+ get_next_reminder_timestamp({ attendees: [{ id: '', type: 'enduser' }], startTimeInMS,
11494
+ reminders: [{ type: 'add-to-journey', info: { journeyId: PLACEHOLDER_ID }, msBeforeStartTime: 0 } ]
11495
+ }) === startTimeInMS,
11496
+ 'invalid get_next_reminder_timestamp',
11497
+ 'get_next_reminder_timestamp with no attendees, add-to-journey with attendees',
11498
+ )
11499
+
11500
+ assert(
11501
+ get_next_reminder_timestamp({ attendees: [{ id: '', type: 'enduser' }], startTimeInMS,
11502
+ reminders: [{ type: 'add-to-journey', info: { journeyId: PLACEHOLDER_ID }, msBeforeStartTime: 0 } ]
11503
+ }) === startTimeInMS,
11504
+ 'invalid get_next_reminder_timestamp',
11505
+ 'get_next_reminder_timestamp with no attendees, Remove from Journey with attendees',
11506
+ )
11507
+
11508
+ assert(
11509
+ get_next_reminder_timestamp({ attendees: [{ id: '', type: 'enduser' }], startTimeInMS,
11510
+ reminders: [{ type: 'add-to-journey', info: { journeyId: PLACEHOLDER_ID }, msBeforeStartTime: -1000 } ]
11511
+ }) === startTimeInMS + 1000,
11512
+ 'invalid get_next_reminder_timestamp',
11513
+ 'get_next_reminder_timestamp with no attendees, start time in future',
11514
+ )
11515
+
11516
+ assert(
11517
+ get_next_reminder_timestamp({ attendees: [{ id: '', type: 'enduser' }], startTimeInMS,
11518
+ reminders: [{ type: 'add-to-journey', info: { journeyId: PLACEHOLDER_ID }, msBeforeStartTime: 1000 } ]
11519
+ }) === startTimeInMS - 1000,
11520
+ 'invalid get_next_reminder_timestamp',
11521
+ 'get_next_reminder_timestamp with no attendees, start time in past',
11522
+ )
11523
+
11524
+ assert(
11525
+ get_next_reminder_timestamp({ attendees: [{ id: '', type: 'enduser' }], startTimeInMS,
11526
+ reminders: [
11527
+ { type: 'add-to-journey', info: { journeyId: PLACEHOLDER_ID }, msBeforeStartTime: 1000 },
11528
+ { type: 'add-to-journey', info: { journeyId: PLACEHOLDER_ID }, msBeforeStartTime: -3000 },
11529
+ { type: 'add-to-journey', info: { journeyId: PLACEHOLDER_ID }, msBeforeStartTime: -5000 },
11530
+ ]
11531
+ }) === startTimeInMS - 1000,
11532
+ 'invalid get_next_reminder_timestamp',
11533
+ 'get_next_reminder_timestamp with no attendees multiple reminders',
11534
+ )
11535
+ }
11536
+
11537
+ const ip_address_form_tests = async () => {
11538
+ log_header("IP Address Form Tests")
11539
+
11540
+ const form = await sdk.api.forms.createOne({
11541
+ title: 'IP Address Form Test',
11542
+ allowPublicURL: true,
11543
+ ipAddressCustomField: 'IP'
11544
+ })
11545
+ // form (may) need at least 1 question for future endpoints to work
11546
+ await sdk.api.form_fields.createOne({
11547
+ formId: form.id,
11548
+ title: 'IP Address Field',
11549
+ type: 'description',
11550
+ previousFields: [{ type: 'root', info: { }}]
11551
+ })
11552
+
11553
+ const enduserSDKPublic = new EnduserSession({ host, businessId: form.businessId })
11554
+ const { enduserId} = await enduserSDKPublic.api.form_responses.session_for_public_form({
11555
+ formId: form.id,
11556
+ businessId: form.businessId,
11557
+ email: 'test@tellescope.com',
11558
+ phone: '+15555555555',
11559
+ fname: 'session',
11560
+ lname: 'test',
11561
+ })
11562
+
11563
+ async_test(
11564
+ 'IP Set on Enduser creation',
11565
+ () => sdk.api.endusers.getOne(enduserId),
11566
+ { onResult: result => !!result.fields?.IP }
11567
+ )
11568
+
11569
+ // clear ip and set other field to make sure IP doesn't overwrite other custom fields
11570
+ await sdk.api.endusers.updateOne(enduserId, { fields: { otherField: "Set" } }, { replaceObjectFields: true })
11571
+
11572
+ // should match and update in place
11573
+ await enduserSDKPublic.api.form_responses.session_for_public_form({
11574
+ formId: form.id,
11575
+ businessId: form.businessId,
11576
+ email: 'test@tellescope.com',
11577
+ phone: '+15555555555',
11578
+ fname: 'session',
11579
+ lname: 'test',
11580
+ })
11581
+
11582
+ async_test(
11583
+ 'IP Set on update',
11584
+ () => sdk.api.endusers.getOne(enduserId),
11585
+ { onResult: result => !!result.fields?.IP && result.fields?.otherField === 'Set' && result.id === enduserId }
11586
+ )
11587
+
11588
+ await Promise.all([
11589
+ sdk.api.forms.deleteOne(form.id),
11590
+ sdk.api.endusers.deleteOne(enduserId),
11591
+ ])
11592
+ }
11593
+
11452
11594
  (async () => {
11453
11595
  log_header("API")
11454
11596
 
@@ -11459,6 +11601,7 @@ const inbox_loading_tests = async () => {
11459
11601
  )
11460
11602
 
11461
11603
  try {
11604
+ get_next_reminder_timestamp_tests()
11462
11605
  form_conditional_logic_tests()
11463
11606
 
11464
11607
  await test_weighted_round_robin()
@@ -11563,6 +11706,7 @@ const inbox_loading_tests = async () => {
11563
11706
  await replace_enduser_template_values_tests()
11564
11707
  await mfa_tests()
11565
11708
  await setup_tests()
11709
+ await ip_address_form_tests()
11566
11710
  await bulk_update_tests()
11567
11711
  await formsort_tests()
11568
11712
  await inbox_loading_tests()
Binary file