@tellescope/sdk 1.67.1 → 1.67.4

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.
@@ -5029,11 +5029,11 @@ const nextReminderInMS_tests = async () => {
5029
5029
  ])
5030
5030
  }
5031
5031
 
5032
- const pollForResults = async <T>(f: () => Promise<T[]>, intervalInMS=500, iterations=20) => {
5032
+ const pollForResults = async <T>(f: () => Promise<T>, evaluate: (r: T) => boolean, intervalInMS=500, iterations=20) => {
5033
5033
  for (let i = 0; i < iterations; i++) {
5034
5034
  await wait(undefined, intervalInMS)
5035
5035
  const result = await f()
5036
- if (result.length) return result
5036
+ if (evaluate(result)) return result
5037
5037
  }
5038
5038
 
5039
5039
  throw new Error("failed pollForResults")
@@ -5127,7 +5127,7 @@ const test_ticket_automation_assignment_and_optimization = async () => {
5127
5127
  if (testDelayedChild) {
5128
5128
  await async_test(
5129
5129
  `Delayed child ticket`,
5130
- () => pollForResults(() => sdk.api.automated_actions.getSome({ filter: { automationStepId: child.id } })),
5130
+ () => pollForResults(() => sdk.api.automated_actions.getSome({ filter: { automationStepId: child.id } }), t => !!t.length),
5131
5131
  { onResult: steps => steps.length === 1 && !steps[0].isNOP }
5132
5132
  )
5133
5133
  }
@@ -5242,7 +5242,7 @@ const test_ticket_automation_assignment_and_optimization = async () => {
5242
5242
 
5243
5243
  await async_test(
5244
5244
  `Background ticket assignment ${++backgroundTestCounter}`,
5245
- () => pollForResults(() => sdk.api.tickets.getSome({ filter: { enduserId: e.id, title: 'background ticket' } })),
5245
+ () => pollForResults(() => sdk.api.tickets.getSome({ filter: { enduserId: e.id, title: 'background ticket' } }), t => !!t.length),
5246
5246
  { onResult: ts => ts.length === 1 && !!ts[0].owner && validOwners.includes(ts[0].owner) }
5247
5247
  )
5248
5248
 
@@ -5328,6 +5328,117 @@ const test_ticket_automation_assignment_and_optimization = async () => {
5328
5328
  ])
5329
5329
  }
5330
5330
 
5331
+ const field_equals_trigger_tests = async () => {
5332
+ log_header("Field Equals / Trigger Tests")
5333
+
5334
+ const journey = await sdk.api.journeys.createOne({ title: 'test' })
5335
+ const step = await sdk.api.automation_steps.createOne({
5336
+ journeyId: journey.id,
5337
+ events: [{
5338
+ type: 'onJourneyStart',
5339
+ info: {}
5340
+ }],
5341
+ action: {
5342
+ type: 'addEnduserTags',
5343
+ info: { tags: ['Journey Tag']}
5344
+ },
5345
+ })
5346
+
5347
+ const existsTriggerTags = await sdk.api.automation_triggers.createOne({
5348
+ event: { type: 'Field Equals', info: { field: 'fname', value: "$exists" } },
5349
+ action: { type: 'Add Tags', info: { tags: ["Tag"] } },
5350
+ status: "Active",
5351
+ title: 'existsTriggerTags',
5352
+ })
5353
+ const existsTriggerAddToJourney = await sdk.api.automation_triggers.createOne({
5354
+ event: { type: 'Field Equals', info: { field: 'fname', value: "$exists" } },
5355
+ action: { type: 'Add To Journey', info: { journeyId: journey.id } },
5356
+ status: "Active",
5357
+ title: 'existsTriggerAddToJourney',
5358
+ })
5359
+ const equalsTriggerTags = await sdk.api.automation_triggers.createOne({
5360
+ event: { type: 'Field Equals', info: { field: 'lname', value: "Explicit" } },
5361
+ action: { type: 'Add Tags', info: { tags: ["Tag"] } },
5362
+ status: "Active",
5363
+ title: 'equalsTriggerTags',
5364
+ })
5365
+ const equalsTriggerAddToJourney = await sdk.api.automation_triggers.createOne({
5366
+ event: { type: 'Field Equals', info: { field: 'lname', value: "Explicit" } },
5367
+ action: { type: 'Add To Journey', info: { journeyId: journey.id } },
5368
+ enduserCondition: { $and: [ { condition: { lname: 'Explicit' } } ] },
5369
+ status: "Active",
5370
+ title: 'equalsTriggerAddToJourney',
5371
+ })
5372
+ const conditionalTriggerTags = await sdk.api.automation_triggers.createOne({
5373
+ event: { type: 'Field Equals', info: { field: 'mname', value: "$exists" } },
5374
+ action: { type: 'Add Tags', info: { tags: ["Tag"] } },
5375
+ status: "Active",
5376
+ enduserCondition: { $and: [ { condition: { lname: 'Conditional' } } ] },
5377
+ title: 'conditionalTriggerTags',
5378
+ })
5379
+ const conditionalTriggerAddToJourney = await sdk.api.automation_triggers.createOne({
5380
+ event: { type: 'Field Equals', info: { field: 'mname', value: "$exists" } },
5381
+ action: { type: 'Add To Journey', info: { journeyId: journey.id } },
5382
+ enduserCondition: { $and: [ { condition: { lname: 'Conditional' } } ] },
5383
+ status: "Active",
5384
+ title: 'conditionalTriggerAddToJourney',
5385
+ })
5386
+
5387
+ // names are capitalized automatically, so make sure that is reflected in conditions
5388
+ const endusers = (await sdk.api.endusers.createSome([
5389
+ { fname: 'Test' },
5390
+ { fname: 'Test' },
5391
+ { lname: 'Test' }, // should not be added to any journey
5392
+ { lname: 'Explicit' },
5393
+ { mname: 'Test' }, // should not be added to any journey for failing conditional logic
5394
+ { mname: 'Test' }, // should not be added to any journey for failing conditional logic
5395
+ { mname: 'Test', lname: 'Nonconditional' }, // should not be added to any journey for failing conditional logic
5396
+ { mname: 'Test', lname: 'Conditional' },
5397
+ ])).created
5398
+
5399
+ await async_test(
5400
+ `Journey and tags set`,
5401
+ () => pollForResults(
5402
+ sdk.api.endusers.getSome,
5403
+ es => (
5404
+ es.filter(e => e.tags?.includes('Tag') && e.journeys?.[journey.id] !== undefined).length === 4
5405
+ ),
5406
+ 200,
5407
+ 25,
5408
+ ),
5409
+ passOnAnyResult,
5410
+ )
5411
+ await async_test(
5412
+ `Background action queued for journey`,
5413
+ () => pollForResults(
5414
+ sdk.api.automated_actions.getSome,
5415
+ as => (
5416
+ as.filter(a => a.automationStepId === step.id && endusers.find(e => e.id === a.enduserId)).length === 4
5417
+ ),
5418
+ 200,
5419
+ 25,
5420
+ ),
5421
+ passOnAnyResult,
5422
+ )
5423
+ await async_test(
5424
+ `Endusers have trigger ids`,
5425
+ sdk.api.endusers.getSome,
5426
+ { onResult: es => es.filter(e => e.triggerIds?.length === 2).length === 4 },
5427
+ )
5428
+
5429
+
5430
+ return await Promise.all([
5431
+ sdk.api.journeys.deleteOne(journey.id),
5432
+ sdk.api.automation_triggers.deleteOne(existsTriggerTags.id),
5433
+ sdk.api.automation_triggers.deleteOne(existsTriggerAddToJourney.id),
5434
+ sdk.api.automation_triggers.deleteOne(equalsTriggerAddToJourney.id),
5435
+ sdk.api.automation_triggers.deleteOne(equalsTriggerTags.id),
5436
+ sdk.api.automation_triggers.deleteOne(conditionalTriggerTags.id),
5437
+ sdk.api.automation_triggers.deleteOne(conditionalTriggerAddToJourney.id),
5438
+ ...endusers.map(e => sdk.api.endusers.deleteOne(e.id)),
5439
+ ])
5440
+ }
5441
+
5331
5442
  const NO_TEST = () => {}
5332
5443
  const tests: { [K in keyof ClientModelForName]: () => void } = {
5333
5444
  phone_trees: NO_TEST,
@@ -5467,6 +5578,7 @@ const validate_schema = () => {
5467
5578
  await mfa_tests()
5468
5579
  await setup_tests()
5469
5580
  await multi_tenant_tests() // should come right after setup tests
5581
+ await field_equals_trigger_tests()
5470
5582
  await test_ticket_automation_assignment_and_optimization()
5471
5583
  await role_based_access_tests()
5472
5584
  await automation_trigger_tests()
Binary file