@tellescope/sdk 1.4.94 → 1.4.96

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.
@@ -2884,7 +2884,7 @@ export var formsUnsubmittedCancelConditionTest = function () { return __awaiter(
2884
2884
  }] })];
2885
2885
  case 17:
2886
2886
  _a.sent();
2887
- return [4 /*yield*/, wait(undefined, 2500)]; // allow background creation with generous pause
2887
+ return [4 /*yield*/, wait(undefined, 4000)]; // allow background creation with generous pause
2888
2888
  case 18:
2889
2889
  _a.sent(); // allow background creation with generous pause
2890
2890
  return [4 /*yield*/, async_test("FormsUnsubmitted cancel conditions work", function () { return sdk.api.automated_actions.getSome(); }, { onResult: function (as) {
@@ -3007,7 +3007,7 @@ export var formsUnsubmittedTest = function () { return __awaiter(void 0, void 0,
3007
3007
  case 9:
3008
3008
  form_responses = _a.sent();
3009
3009
  // allow fast followup to trigger
3010
- return [4 /*yield*/, wait(undefined, 2500)]; // allow background creation with generous pause
3010
+ return [4 /*yield*/, wait(undefined, 5000)]; // allow background creation with generous pause
3011
3011
  case 10:
3012
3012
  // allow fast followup to trigger
3013
3013
  _a.sent(); // allow background creation with generous pause
@@ -3028,7 +3028,7 @@ export var formsUnsubmittedTest = function () { return __awaiter(void 0, void 0,
3028
3028
  case 12:
3029
3029
  // trigger cancel conditions
3030
3030
  _a.sent();
3031
- return [4 /*yield*/, wait(undefined, 2500)]; // allow background creation with generous pause
3031
+ return [4 /*yield*/, wait(undefined, 5000)]; // allow background creation with generous pause
3032
3032
  case 13:
3033
3033
  _a.sent(); // allow background creation with generous pause
3034
3034
  return [4 /*yield*/, async_test("formResponses not triggered yet after 1 form remaining", function () { return sdk.api.endusers.getOne(enduser.id); }, { onResult: function (e) { var _a; return ((_a = e === null || e === void 0 ? void 0 : e.journeys) === null || _a === void 0 ? void 0 : _a[journey.id]) !== 'formsSubmitted'; } })];
@@ -3044,7 +3044,7 @@ export var formsUnsubmittedTest = function () { return __awaiter(void 0, void 0,
3044
3044
  }] })];
3045
3045
  case 15:
3046
3046
  _a.sent();
3047
- return [4 /*yield*/, wait(undefined, 2500)]; // allow background creation with generous pause
3047
+ return [4 /*yield*/, wait(undefined, 5000)]; // allow background creation with generous pause
3048
3048
  case 16:
3049
3049
  _a.sent(); // allow background creation with generous pause
3050
3050
  return [4 /*yield*/, async_test("formResponses triggered after both forms submitted", function () { return sdk.api.endusers.getOne(enduser.id); }, { onResult: function (e) { var _a; return ((_a = e === null || e === void 0 ? void 0 : e.journeys) === null || _a === void 0 ? void 0 : _a[journey.id]) === 'formsSubmitted'; } })];
@@ -4449,8 +4449,168 @@ export var role_based_access_permissions_tests = function () { return __awaiter(
4449
4449
  }
4450
4450
  });
4451
4451
  }); };
4452
+ // runs tests and resets availability afterwards
4453
+ // creates a new enduser (to avoid duplicate autoreply)
4454
+ var run_autoreply_test = function (title, _a) {
4455
+ var expectingAutoreply = _a.expectingAutoreply;
4456
+ return __awaiter(void 0, void 0, void 0, function () {
4457
+ var enduser, room, blocks;
4458
+ return __generator(this, function (_b) {
4459
+ switch (_b.label) {
4460
+ case 0:
4461
+ log_header("Autoreply: ".concat(title));
4462
+ return [4 /*yield*/, sdk.api.endusers.createOne({ fname: 'Autoreply', lname: "Test", email: "autoreply@tellescope.com" })];
4463
+ case 1:
4464
+ enduser = _b.sent();
4465
+ return [4 /*yield*/, sdk.api.endusers.set_password({ id: enduser.id, password: password })];
4466
+ case 2:
4467
+ _b.sent();
4468
+ return [4 /*yield*/, enduserSDK.authenticate(enduser.email, password)];
4469
+ case 3:
4470
+ _b.sent();
4471
+ return [4 /*yield*/, sdk.api.chat_rooms.createOne({
4472
+ userIds: [sdk.userInfo.id],
4473
+ enduserIds: [enduser.id]
4474
+ })];
4475
+ case 4:
4476
+ room = _b.sent();
4477
+ return [4 /*yield*/, sdk.api.chats.createOne({ roomId: room.id, message: 'user' })];
4478
+ case 5:
4479
+ _b.sent();
4480
+ return [4 /*yield*/, wait(undefined, 50)];
4481
+ case 6:
4482
+ _b.sent();
4483
+ return [4 /*yield*/, async_test('User/outbound chat does not trigger autoreply', function () { return sdk.api.chats.getSome({ filter: { roomId: room.id } }); }, { onResult: function (cs) { return cs.length === 1; } })];
4484
+ case 7:
4485
+ _b.sent();
4486
+ return [4 /*yield*/, enduserSDK.api.chats.createOne({ roomId: room.id, message: 'enduser' })];
4487
+ case 8:
4488
+ _b.sent();
4489
+ return [4 /*yield*/, wait(undefined, 50)];
4490
+ case 9:
4491
+ _b.sent();
4492
+ return [4 /*yield*/, async_test('Main test', function () { return sdk.api.chats.getSome({ filter: { roomId: room.id } }); }, { onResult: function (cs) { return (expectingAutoreply
4493
+ ? cs.length === 3
4494
+ : cs.length === 2); } })];
4495
+ case 10:
4496
+ _b.sent();
4497
+ return [4 /*yield*/, enduserSDK.api.chats.createOne({ roomId: room.id, message: 'enduser again' })];
4498
+ case 11:
4499
+ _b.sent();
4500
+ return [4 /*yield*/, wait(undefined, 50)];
4501
+ case 12:
4502
+ _b.sent();
4503
+ return [4 /*yield*/, async_test("Duplicate autoreply avoided", function () { return sdk.api.chats.getSome({ filter: { roomId: room.id } }); }, { onResult: function (cs) { return (expectingAutoreply
4504
+ ? cs.length === 4
4505
+ : cs.length === 3); } })
4506
+ // cleanup, including any availability blocks
4507
+ ];
4508
+ case 13:
4509
+ _b.sent();
4510
+ return [4 /*yield*/, sdk.api.availability_blocks.getSome()];
4511
+ case 14:
4512
+ blocks = _b.sent();
4513
+ return [4 /*yield*/, Promise.all(__spreadArray([
4514
+ sdk.api.endusers.deleteOne(enduser.id),
4515
+ sdk.api.chat_rooms.deleteOne(room.id)
4516
+ ], blocks.map(function (b) { return (sdk.api.availability_blocks.deleteOne(b.id)); }), true))];
4517
+ case 15:
4518
+ _b.sent();
4519
+ return [2 /*return*/];
4520
+ }
4521
+ });
4522
+ });
4523
+ };
4524
+ var auto_reply_tests = function () { return __awaiter(void 0, void 0, void 0, function () {
4525
+ var today, activeBlockInfo, activeWithRange, inactiveEarly, inactiveLate, inactiveOldBlockInfo, wrongDayBlockInfo, wrongEntityTypeBlockInfo, wrongEntityIdInfo, wrongTimeBlockInfo;
4526
+ return __generator(this, function (_a) {
4527
+ switch (_a.label) {
4528
+ case 0:
4529
+ log_header("Autoreply");
4530
+ return [4 /*yield*/, run_autoreply_test('No availabilities', { expectingAutoreply: false })];
4531
+ case 1:
4532
+ _a.sent();
4533
+ today = new Date();
4534
+ activeBlockInfo = {
4535
+ dayOfWeekStartingSundayIndexedByZero: today.getDay(),
4536
+ startTimeInMinutes: 0,
4537
+ endTimeInMinutes: 60 * 24,
4538
+ entity: 'organization',
4539
+ entityId: sdk.userInfo.businessId,
4540
+ index: 0,
4541
+ };
4542
+ activeWithRange = __assign(__assign({}, activeBlockInfo), { active: {
4543
+ from: new Date(Date.now() - 1000000),
4544
+ to: new Date(Date.now() + 1000000),
4545
+ } });
4546
+ inactiveEarly = __assign(__assign({}, activeBlockInfo), { active: { from: new Date(Date.now() + 1000000) } });
4547
+ inactiveLate = __assign(__assign({}, activeBlockInfo), { active: { to: new Date(Date.now() - 1000000) } });
4548
+ inactiveOldBlockInfo = __assign(__assign({}, activeBlockInfo), { dayOfWeekStartingSundayIndexedByZero: (today.getDay() + 1) % 7 });
4549
+ wrongDayBlockInfo = __assign(__assign({}, activeBlockInfo), { dayOfWeekStartingSundayIndexedByZero: (today.getDay() + 1) % 7 });
4550
+ wrongEntityTypeBlockInfo = __assign(__assign({}, activeBlockInfo), { entity: 'user' });
4551
+ wrongEntityIdInfo = __assign(__assign({}, activeBlockInfo), { entityId: sdk.userInfo.id });
4552
+ wrongTimeBlockInfo = __assign(__assign({}, activeBlockInfo), { endTimeInMinutes: 0 });
4553
+ return [4 /*yield*/, sdk.api.organizations.updateOne(sdk.userInfo.businessId, {
4554
+ settings: { endusers: { autoReplyEnabled: false } }
4555
+ })];
4556
+ case 2:
4557
+ _a.sent();
4558
+ return [4 /*yield*/, sdk.api.availability_blocks.createSome([wrongTimeBlockInfo])];
4559
+ case 3:
4560
+ _a.sent();
4561
+ return [4 /*yield*/, run_autoreply_test('Autoreply disabled', { expectingAutoreply: false })];
4562
+ case 4:
4563
+ _a.sent();
4564
+ return [4 /*yield*/, sdk.api.organizations.updateOne(sdk.userInfo.businessId, {
4565
+ settings: { endusers: { autoReplyEnabled: true } }
4566
+ })];
4567
+ case 5:
4568
+ _a.sent();
4569
+ return [4 /*yield*/, sdk.api.availability_blocks.createSome([wrongTimeBlockInfo])];
4570
+ case 6:
4571
+ _a.sent();
4572
+ return [4 /*yield*/, run_autoreply_test('One bad', { expectingAutoreply: true })];
4573
+ case 7:
4574
+ _a.sent();
4575
+ return [4 /*yield*/, sdk.api.availability_blocks.createSome([
4576
+ inactiveEarly,
4577
+ inactiveLate,
4578
+ inactiveOldBlockInfo,
4579
+ wrongDayBlockInfo,
4580
+ wrongEntityIdInfo,
4581
+ wrongEntityTypeBlockInfo,
4582
+ wrongTimeBlockInfo,
4583
+ ])];
4584
+ case 8:
4585
+ _a.sent();
4586
+ return [4 /*yield*/, run_autoreply_test('Multiple bad blocks', { expectingAutoreply: true })];
4587
+ case 9:
4588
+ _a.sent();
4589
+ return [4 /*yield*/, sdk.api.availability_blocks.createSome([activeBlockInfo])];
4590
+ case 10:
4591
+ _a.sent();
4592
+ return [4 /*yield*/, run_autoreply_test('One active block', { expectingAutoreply: false })];
4593
+ case 11:
4594
+ _a.sent();
4595
+ return [4 /*yield*/, sdk.api.availability_blocks.createSome([activeWithRange])];
4596
+ case 12:
4597
+ _a.sent();
4598
+ return [4 /*yield*/, run_autoreply_test('One active with range', { expectingAutoreply: false })];
4599
+ case 13:
4600
+ _a.sent();
4601
+ return [4 /*yield*/, sdk.api.availability_blocks.createSome([activeBlockInfo, activeWithRange, activeBlockInfo, activeWithRange])];
4602
+ case 14:
4603
+ _a.sent();
4604
+ return [4 /*yield*/, run_autoreply_test('Multiple active blocks', { expectingAutoreply: false })];
4605
+ case 15:
4606
+ _a.sent();
4607
+ return [2 /*return*/];
4608
+ }
4609
+ });
4610
+ }); };
4452
4611
  var NO_TEST = function () { };
4453
4612
  var tests = {
4613
+ availability_blocks: NO_TEST,
4454
4614
  analytics_frames: NO_TEST,
4455
4615
  automation_steps: automation_events_tests,
4456
4616
  products: NO_TEST,
@@ -4511,7 +4671,7 @@ var tests = {
4511
4671
  log_header("API");
4512
4672
  _k.label = 1;
4513
4673
  case 1:
4514
- _k.trys.push([1, 21, , 22]);
4674
+ _k.trys.push([1, 22, , 23]);
4515
4675
  return [4 /*yield*/, Promise.all([
4516
4676
  sdk.authenticate(email, password),
4517
4677
  sdkSub.authenticate(subUserEmail, password),
@@ -4527,56 +4687,59 @@ var tests = {
4527
4687
  return [4 /*yield*/, multi_tenant_tests()]; // should come right after setup tests
4528
4688
  case 4:
4529
4689
  _k.sent(); // should come right after setup tests
4530
- return [4 /*yield*/, sub_organization_enduser_tests()];
4690
+ return [4 /*yield*/, auto_reply_tests()];
4531
4691
  case 5:
4532
4692
  _k.sent();
4533
- return [4 /*yield*/, sub_organization_tests()];
4693
+ return [4 /*yield*/, sub_organization_enduser_tests()];
4534
4694
  case 6:
4535
4695
  _k.sent();
4536
- return [4 /*yield*/, self_serve_appointment_booking_tests()];
4696
+ return [4 /*yield*/, sub_organization_tests()];
4537
4697
  case 7:
4538
4698
  _k.sent();
4539
- return [4 /*yield*/, filter_by_date_tests()];
4699
+ return [4 /*yield*/, self_serve_appointment_booking_tests()];
4540
4700
  case 8:
4541
4701
  _k.sent();
4542
- return [4 /*yield*/, generate_user_auth_tests()];
4702
+ return [4 /*yield*/, filter_by_date_tests()];
4543
4703
  case 9:
4544
4704
  _k.sent();
4545
- return [4 /*yield*/, role_based_access_tests()];
4705
+ return [4 /*yield*/, generate_user_auth_tests()];
4546
4706
  case 10:
4547
4707
  _k.sent();
4548
- return [4 /*yield*/, generateEnduserAuthTests()];
4708
+ return [4 /*yield*/, role_based_access_tests()];
4549
4709
  case 11:
4550
4710
  _k.sent();
4551
- return [4 /*yield*/, public_form_tests()];
4711
+ return [4 /*yield*/, generateEnduserAuthTests()];
4552
4712
  case 12:
4553
4713
  _k.sent();
4554
- return [4 /*yield*/, search_tests()];
4714
+ return [4 /*yield*/, public_form_tests()];
4555
4715
  case 13:
4556
4716
  _k.sent();
4557
- return [4 /*yield*/, badInputTests()];
4717
+ return [4 /*yield*/, search_tests()];
4558
4718
  case 14:
4559
4719
  _k.sent();
4560
- return [4 /*yield*/, filterTests()];
4720
+ return [4 /*yield*/, badInputTests()];
4561
4721
  case 15:
4562
4722
  _k.sent();
4563
- return [4 /*yield*/, updatesTests()];
4723
+ return [4 /*yield*/, filterTests()];
4564
4724
  case 16:
4565
4725
  _k.sent();
4566
- return [4 /*yield*/, threadKeyTests()];
4726
+ return [4 /*yield*/, updatesTests()];
4567
4727
  case 17:
4568
4728
  _k.sent();
4569
- return [4 /*yield*/, enduserAccessTests()];
4729
+ return [4 /*yield*/, threadKeyTests()];
4570
4730
  case 18:
4571
4731
  _k.sent();
4572
- return [4 /*yield*/, enduser_session_tests()];
4732
+ return [4 /*yield*/, enduserAccessTests()];
4573
4733
  case 19:
4574
4734
  _k.sent();
4575
- return [4 /*yield*/, enduser_redaction_tests()];
4735
+ return [4 /*yield*/, enduser_session_tests()];
4576
4736
  case 20:
4577
4737
  _k.sent();
4578
- return [3 /*break*/, 22];
4738
+ return [4 /*yield*/, enduser_redaction_tests()];
4579
4739
  case 21:
4740
+ _k.sent();
4741
+ return [3 /*break*/, 23];
4742
+ case 22:
4580
4743
  err_1 = _k.sent();
4581
4744
  console.error("Failed during custom test");
4582
4745
  if (err_1.message && err_1.info) {
@@ -4586,18 +4749,18 @@ var tests = {
4586
4749
  console.error(err_1);
4587
4750
  }
4588
4751
  process.exit(1);
4589
- return [3 /*break*/, 22];
4590
- case 22:
4752
+ return [3 /*break*/, 23];
4753
+ case 23:
4591
4754
  _a = schema;
4592
4755
  _b = [];
4593
4756
  for (_c in _a)
4594
4757
  _b.push(_c);
4595
4758
  _i = 0;
4596
- _k.label = 23;
4597
- case 23:
4598
- if (!(_i < _b.length)) return [3 /*break*/, 26];
4759
+ _k.label = 24;
4760
+ case 24:
4761
+ if (!(_i < _b.length)) return [3 /*break*/, 27];
4599
4762
  _c = _b[_i];
4600
- if (!(_c in _a)) return [3 /*break*/, 25];
4763
+ if (!(_c in _a)) return [3 /*break*/, 26];
4601
4764
  n = _c;
4602
4765
  returnValidation = (_j = (_h = schema[n].customActions) === null || _h === void 0 ? void 0 : _h.create) === null || _j === void 0 ? void 0 : _j.returns;
4603
4766
  return [4 /*yield*/, run_generated_tests({
@@ -4608,41 +4771,41 @@ var tests = {
4608
4771
  create: returnValidation // ModelFields<ClientModel>,
4609
4772
  }
4610
4773
  })];
4611
- case 24:
4612
- _k.sent();
4613
- _k.label = 25;
4614
4774
  case 25:
4615
- _i++;
4616
- return [3 /*break*/, 23];
4775
+ _k.sent();
4776
+ _k.label = 26;
4617
4777
  case 26:
4778
+ _i++;
4779
+ return [3 /*break*/, 24];
4780
+ case 27:
4618
4781
  _d = tests;
4619
4782
  _e = [];
4620
4783
  for (_f in _d)
4621
4784
  _e.push(_f);
4622
4785
  _g = 0;
4623
- _k.label = 27;
4624
- case 27:
4625
- if (!(_g < _e.length)) return [3 /*break*/, 32];
4626
- _f = _e[_g];
4627
- if (!(_f in _d)) return [3 /*break*/, 31];
4628
- t = _f;
4629
4786
  _k.label = 28;
4630
4787
  case 28:
4631
- _k.trys.push([28, 30, , 31]);
4632
- return [4 /*yield*/, tests[t]()];
4788
+ if (!(_g < _e.length)) return [3 /*break*/, 33];
4789
+ _f = _e[_g];
4790
+ if (!(_f in _d)) return [3 /*break*/, 32];
4791
+ t = _f;
4792
+ _k.label = 29;
4633
4793
  case 29:
4634
- _k.sent();
4635
- return [3 /*break*/, 31];
4794
+ _k.trys.push([29, 31, , 32]);
4795
+ return [4 /*yield*/, tests[t]()];
4636
4796
  case 30:
4797
+ _k.sent();
4798
+ return [3 /*break*/, 32];
4799
+ case 31:
4637
4800
  err_2 = _k.sent();
4638
4801
  console.error("Error running test:");
4639
4802
  console.error(err_2);
4640
4803
  process.exit(1);
4641
- return [3 /*break*/, 31];
4642
- case 31:
4643
- _g++;
4644
- return [3 /*break*/, 27];
4804
+ return [3 /*break*/, 32];
4645
4805
  case 32:
4806
+ _g++;
4807
+ return [3 /*break*/, 28];
4808
+ case 33:
4646
4809
  process.exit();
4647
4810
  return [2 /*return*/];
4648
4811
  }