@tellescope/sdk 1.10.0 → 1.12.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.
@@ -4814,7 +4814,13 @@ var run_autoreply_test = function (title, _a) {
4814
4814
  blocks = _b.sent();
4815
4815
  return [4 /*yield*/, Promise.all(__spreadArray([
4816
4816
  sdk.api.endusers.deleteOne(enduser.id),
4817
- sdk.api.chat_rooms.deleteOne(room.id)
4817
+ sdk.api.chat_rooms.deleteOne(room.id),
4818
+ // cleanup availabilities
4819
+ sdk.api.users.updateOne(sdk.userInfo.id, {
4820
+ weeklyAvailabilities: []
4821
+ }, {
4822
+ replaceObjectFields: true
4823
+ })
4818
4824
  ], blocks.map(function (b) { return (sdk.api.availability_blocks.deleteOne(b.id)); }), true))];
4819
4825
  case 15:
4820
4826
  _b.sent();
@@ -4824,13 +4830,21 @@ var run_autoreply_test = function (title, _a) {
4824
4830
  });
4825
4831
  };
4826
4832
  var auto_reply_tests = function () { return __awaiter(void 0, void 0, void 0, function () {
4827
- var today, activeBlockInfo, activeWithRange, inactiveEarly, inactiveLate, inactiveOldBlockInfo, wrongDayBlockInfo, wrongEntityTypeBlockInfo, wrongEntityIdInfo, wrongTimeBlockInfo;
4833
+ var today, activeBlockInfo, activeWithRange, inactiveEarly, inactiveLate, wrongDayBlockInfo, wrongEntityTypeBlockInfo, wrongEntityIdInfo, wrongTimeBlockInfo;
4828
4834
  return __generator(this, function (_a) {
4829
4835
  switch (_a.label) {
4830
- case 0:
4831
- log_header("Autoreply");
4832
- return [4 /*yield*/, run_autoreply_test('No availabilities', { expectingAutoreply: false })];
4836
+ case 0:
4837
+ // cleanup user availabilities / autoReplyEnabled to avoid conflicts
4838
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, {
4839
+ autoReplyEnabled: false,
4840
+ weeklyAvailabilities: [],
4841
+ }, { replaceObjectFields: true })];
4833
4842
  case 1:
4843
+ // cleanup user availabilities / autoReplyEnabled to avoid conflicts
4844
+ _a.sent();
4845
+ log_header("Autoreply (Organization-wide)");
4846
+ return [4 /*yield*/, run_autoreply_test('No availabilities', { expectingAutoreply: false })];
4847
+ case 2:
4834
4848
  _a.sent();
4835
4849
  today = new Date();
4836
4850
  activeBlockInfo = {
@@ -4847,7 +4861,6 @@ var auto_reply_tests = function () { return __awaiter(void 0, void 0, void 0, fu
4847
4861
  } });
4848
4862
  inactiveEarly = __assign(__assign({}, activeBlockInfo), { active: { from: new Date(Date.now() + 1000000) } });
4849
4863
  inactiveLate = __assign(__assign({}, activeBlockInfo), { active: { to: new Date(Date.now() - 1000000) } });
4850
- inactiveOldBlockInfo = __assign(__assign({}, activeBlockInfo), { dayOfWeekStartingSundayIndexedByZero: (today.getDay() + 1) % 7 });
4851
4864
  wrongDayBlockInfo = __assign(__assign({}, activeBlockInfo), { dayOfWeekStartingSundayIndexedByZero: (today.getDay() + 1) % 7 });
4852
4865
  wrongEntityTypeBlockInfo = __assign(__assign({}, activeBlockInfo), { entity: 'user' });
4853
4866
  wrongEntityIdInfo = __assign(__assign({}, activeBlockInfo), { entityId: sdk.userInfo.id });
@@ -4855,56 +4868,110 @@ var auto_reply_tests = function () { return __awaiter(void 0, void 0, void 0, fu
4855
4868
  return [4 /*yield*/, sdk.api.organizations.updateOne(sdk.userInfo.businessId, {
4856
4869
  settings: { endusers: { autoReplyEnabled: false } }
4857
4870
  })];
4858
- case 2:
4871
+ case 3:
4859
4872
  _a.sent();
4860
4873
  return [4 /*yield*/, sdk.api.availability_blocks.createSome([wrongTimeBlockInfo])];
4861
- case 3:
4874
+ case 4:
4862
4875
  _a.sent();
4863
4876
  return [4 /*yield*/, run_autoreply_test('Autoreply disabled', { expectingAutoreply: false })];
4864
- case 4:
4877
+ case 5:
4865
4878
  _a.sent();
4866
4879
  return [4 /*yield*/, sdk.api.organizations.updateOne(sdk.userInfo.businessId, {
4867
4880
  settings: { endusers: { autoReplyEnabled: true } }
4868
4881
  })];
4869
- case 5:
4882
+ case 6:
4870
4883
  _a.sent();
4871
4884
  return [4 /*yield*/, sdk.api.availability_blocks.createSome([wrongTimeBlockInfo])];
4872
- case 6:
4885
+ case 7:
4873
4886
  _a.sent();
4874
4887
  return [4 /*yield*/, run_autoreply_test('One bad', { expectingAutoreply: true })];
4875
- case 7:
4888
+ case 8:
4876
4889
  _a.sent();
4877
4890
  return [4 /*yield*/, sdk.api.availability_blocks.createSome([
4878
4891
  inactiveEarly,
4879
4892
  inactiveLate,
4880
- inactiveOldBlockInfo,
4881
4893
  wrongDayBlockInfo,
4882
4894
  wrongEntityIdInfo,
4883
4895
  wrongEntityTypeBlockInfo,
4884
4896
  wrongTimeBlockInfo,
4885
4897
  ])];
4886
- case 8:
4898
+ case 9:
4887
4899
  _a.sent();
4888
4900
  return [4 /*yield*/, run_autoreply_test('Multiple bad blocks', { expectingAutoreply: true })];
4889
- case 9:
4901
+ case 10:
4890
4902
  _a.sent();
4891
4903
  return [4 /*yield*/, sdk.api.availability_blocks.createSome([activeBlockInfo])];
4892
- case 10:
4904
+ case 11:
4893
4905
  _a.sent();
4894
4906
  return [4 /*yield*/, run_autoreply_test('One active block', { expectingAutoreply: false })];
4895
- case 11:
4907
+ case 12:
4896
4908
  _a.sent();
4897
4909
  return [4 /*yield*/, sdk.api.availability_blocks.createSome([activeWithRange])];
4898
- case 12:
4910
+ case 13:
4899
4911
  _a.sent();
4900
4912
  return [4 /*yield*/, run_autoreply_test('One active with range', { expectingAutoreply: false })];
4901
- case 13:
4913
+ case 14:
4902
4914
  _a.sent();
4903
4915
  return [4 /*yield*/, sdk.api.availability_blocks.createSome([activeBlockInfo, activeWithRange, activeBlockInfo, activeWithRange])];
4904
- case 14:
4916
+ case 15:
4905
4917
  _a.sent();
4906
4918
  return [4 /*yield*/, run_autoreply_test('Multiple active blocks', { expectingAutoreply: false })];
4907
- case 15:
4919
+ case 16:
4920
+ _a.sent();
4921
+ log_header("Autoreply (User)");
4922
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, {
4923
+ autoReplyEnabled: false,
4924
+ })];
4925
+ case 17:
4926
+ _a.sent();
4927
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, {
4928
+ weeklyAvailabilities: [wrongTimeBlockInfo]
4929
+ })];
4930
+ case 18:
4931
+ _a.sent();
4932
+ return [4 /*yield*/, run_autoreply_test('User: Autoreply disabled', { expectingAutoreply: false })];
4933
+ case 19:
4934
+ _a.sent();
4935
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, {
4936
+ autoReplyEnabled: true,
4937
+ })];
4938
+ case 20:
4939
+ _a.sent();
4940
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, { weeklyAvailabilities: [wrongTimeBlockInfo] })];
4941
+ case 21:
4942
+ _a.sent();
4943
+ return [4 /*yield*/, run_autoreply_test('User: One bad', { expectingAutoreply: true })];
4944
+ case 22:
4945
+ _a.sent();
4946
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, {
4947
+ weeklyAvailabilities: [
4948
+ inactiveEarly,
4949
+ inactiveLate,
4950
+ wrongDayBlockInfo,
4951
+ ]
4952
+ })];
4953
+ case 23:
4954
+ _a.sent();
4955
+ return [4 /*yield*/, run_autoreply_test('User: Multiple bad blocks', { expectingAutoreply: true })];
4956
+ case 24:
4957
+ _a.sent();
4958
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, { weeklyAvailabilities: [activeBlockInfo] })];
4959
+ case 25:
4960
+ _a.sent();
4961
+ return [4 /*yield*/, run_autoreply_test('User: One active block', { expectingAutoreply: false })];
4962
+ case 26:
4963
+ _a.sent();
4964
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, { weeklyAvailabilities: [activeWithRange] })];
4965
+ case 27:
4966
+ _a.sent();
4967
+ return [4 /*yield*/, run_autoreply_test('User: One active with range', { expectingAutoreply: false })];
4968
+ case 28:
4969
+ _a.sent();
4970
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, { weeklyAvailabilities: [activeBlockInfo, activeWithRange, activeBlockInfo, activeWithRange] })];
4971
+ case 29:
4972
+ _a.sent();
4973
+ return [4 /*yield*/, run_autoreply_test('User: Multiple active blocks', { expectingAutoreply: false })];
4974
+ case 30:
4908
4975
  _a.sent();
4909
4976
  return [2 /*return*/];
4910
4977
  }
@@ -4992,13 +5059,13 @@ var tests = {
4992
5059
  return [4 /*yield*/, multi_tenant_tests()]; // should come right after setup tests
4993
5060
  case 4:
4994
5061
  _k.sent(); // should come right after setup tests
4995
- return [4 /*yield*/, automation_trigger_tests()];
5062
+ return [4 /*yield*/, auto_reply_tests()];
4996
5063
  case 5:
4997
5064
  _k.sent();
4998
- return [4 /*yield*/, sub_organization_enduser_tests()];
5065
+ return [4 /*yield*/, automation_trigger_tests()];
4999
5066
  case 6:
5000
5067
  _k.sent();
5001
- return [4 /*yield*/, auto_reply_tests()];
5068
+ return [4 /*yield*/, sub_organization_enduser_tests()];
5002
5069
  case 7:
5003
5070
  _k.sent();
5004
5071
  return [4 /*yield*/, sub_organization_tests()];