@tellescope/sdk 1.237.3 → 1.237.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.
@@ -580,6 +580,87 @@ export const inbox_thread_assignment_updates_tests = async ({ sdk, sdkNonAdmin }
580
580
  sdk.api.inbox_threads.deleteOne(sortThread3.id),
581
581
  ])
582
582
 
583
+ // ========== InboxStatus Preservation Tests ==========
584
+ // These tests verify that outbound messages do NOT reset inboxStatus
585
+
586
+ // Test 27: Outbound SMS should NOT reset inboxStatus
587
+ console.log("Testing outbound SMS should NOT reset inboxStatus...")
588
+
589
+ const statusTestSMS1 = await sdk.api.sms_messages.createOne({
590
+ message: "Inbound test message for status test",
591
+ enduserId: testEnduser.id,
592
+ inbound: true,
593
+ phoneNumber: "+15555559999",
594
+ enduserPhoneNumber: "+15555559876",
595
+ logOnly: true,
596
+ })
597
+
598
+ // Build threads using reset_threads + build_threads pattern
599
+ const statusTestFrom = new Date(Date.now() - 60000)
600
+ await sdk.api.inbox_threads.reset_threads()
601
+ await sdk.api.inbox_threads.build_threads({ from: statusTestFrom, to: new Date() })
602
+
603
+ const statusTestThreads = await sdk.api.inbox_threads.load_threads({})
604
+ const statusTestThread = statusTestThreads.threads.find(t =>
605
+ t.type === 'SMS' && t.enduserIds.includes(testEnduser.id) && t.phoneNumber === "+15555559999"
606
+ )
607
+ assert(!!statusTestThread, "Status test SMS thread should be created")
608
+ assert(statusTestThread!.inboxStatus === 'New', `Initial status should be 'New', got '${statusTestThread!.inboxStatus}'`)
609
+
610
+ // Update thread status to "Resolved"
611
+ await sdk.api.inbox_threads.updateOne(statusTestThread!.id, { inboxStatus: "Resolved" })
612
+
613
+ // Create outbound SMS (should NOT reset status)
614
+ const statusTestSMS2 = await sdk.api.sms_messages.createOne({
615
+ message: "Outbound reply - should not reset status",
616
+ enduserId: testEnduser.id,
617
+ inbound: false,
618
+ phoneNumber: "+15555559999",
619
+ enduserPhoneNumber: "+15555559876",
620
+ logOnly: true,
621
+ })
622
+
623
+ // Rebuild threads - status should remain "Resolved"
624
+ await sdk.api.inbox_threads.build_threads({ from: statusTestFrom, to: new Date() })
625
+
626
+ const threadAfterOutbound = (await sdk.api.inbox_threads.load_threads({ ids: [statusTestThread!.id] })).threads[0]
627
+ assert(threadAfterOutbound.inboxStatus === 'Resolved', `Status should remain 'Resolved' after outbound message, got '${threadAfterOutbound.inboxStatus}'`)
628
+ assert(!!threadAfterOutbound.outboundTimestamp, "outboundTimestamp should be set after outbound message")
629
+
630
+ console.log("✅ Outbound SMS does NOT reset inboxStatus test passed")
631
+
632
+ // Test 28: New inbound SMS SHOULD update inboxStatus
633
+ console.log("Testing new inbound SMS SHOULD update inboxStatus...")
634
+
635
+ // Wait to ensure ObjectId timestamps are in different seconds (MongoDB ObjectIds have second-level precision)
636
+ await new Promise(resolve => setTimeout(resolve, 1100))
637
+
638
+ const statusTestSMS3 = await sdk.api.sms_messages.createOne({
639
+ message: "New inbound - should update status",
640
+ enduserId: testEnduser.id,
641
+ inbound: true,
642
+ phoneNumber: "+15555559999",
643
+ enduserPhoneNumber: "+15555559876",
644
+ inboxStatus: "New",
645
+ logOnly: true,
646
+ })
647
+
648
+ // Rebuild threads - status SHOULD be updated from new inbound
649
+ await sdk.api.inbox_threads.build_threads({ from: statusTestFrom, to: new Date() })
650
+
651
+ const threadAfterNewInbound = (await sdk.api.inbox_threads.load_threads({ ids: [statusTestThread!.id] })).threads[0]
652
+ assert(threadAfterNewInbound.inboxStatus === 'New', `Status SHOULD be 'New' after new inbound message, got '${threadAfterNewInbound.inboxStatus}'`)
653
+
654
+ console.log("✅ New inbound SMS DOES update inboxStatus test passed")
655
+
656
+ // Cleanup status preservation test resources
657
+ await Promise.all([
658
+ sdk.api.sms_messages.deleteOne(statusTestSMS1.id),
659
+ sdk.api.sms_messages.deleteOne(statusTestSMS2.id),
660
+ sdk.api.sms_messages.deleteOne(statusTestSMS3.id),
661
+ sdk.api.inbox_threads.deleteOne(statusTestThread!.id),
662
+ ])
663
+
583
664
  console.log("🎉 All InboxThread assignment update tests passed!")
584
665
 
585
666
  } finally {
@@ -12368,6 +12368,25 @@ const replace_enduser_template_values_tests = async () => {
12368
12368
  const d = Date.now()
12369
12369
  assert(replace_enduser_template_values(d as any, enduser) === d as any, 'fail non-string', 'non-string')
12370
12370
 
12371
+ // Test height/weight subfields with values present
12372
+ const enduserWithVitals = await sdk.api.endusers.createOne({
12373
+ fname: "Vitals",
12374
+ height: { value: 72, unit: 'inches' },
12375
+ weight: { value: 180, unit: 'lbs' }
12376
+ })
12377
+
12378
+ assert(replace_enduser_template_values('{{enduser.height.value}}', enduserWithVitals) === '72', 'fail height.value', 'height.value')
12379
+ assert(replace_enduser_template_values('{{enduser.height.unit}}', enduserWithVitals) === 'inches', 'fail height.unit', 'height.unit')
12380
+ assert(replace_enduser_template_values('{{enduser.weight.value}}', enduserWithVitals) === '180', 'fail weight.value', 'weight.value')
12381
+ assert(replace_enduser_template_values('{{enduser.weight.unit}}', enduserWithVitals) === 'lbs', 'fail weight.unit', 'weight.unit')
12382
+
12383
+ // Test undefined safeguards - enduser without height/weight should return empty string
12384
+ assert(replace_enduser_template_values('{{enduser.height.value}}', enduser) === '', 'fail undefined height.value', 'undefined height.value')
12385
+ assert(replace_enduser_template_values('{{enduser.height.unit}}', enduser) === '', 'fail undefined height.unit', 'undefined height.unit')
12386
+ assert(replace_enduser_template_values('{{enduser.weight.value}}', enduser) === '', 'fail undefined weight.value', 'undefined weight.value')
12387
+ assert(replace_enduser_template_values('{{enduser.weight.unit}}', enduser) === '', 'fail undefined weight.unit', 'undefined weight.unit')
12388
+
12389
+ await sdk.api.endusers.deleteOne(enduserWithVitals.id)
12371
12390
  await sdk.api.endusers.deleteOne(enduser.id)
12372
12391
  }
12373
12392
 
Binary file