@tellescope/sdk 1.10.0 → 1.11.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.
@@ -4855,7 +4855,13 @@ var run_autoreply_test = function (title, _a) {
4855
4855
  blocks = _b.sent();
4856
4856
  return [4 /*yield*/, Promise.all(__spreadArray([
4857
4857
  sdk.api.endusers.deleteOne(enduser.id),
4858
- sdk.api.chat_rooms.deleteOne(room.id)
4858
+ sdk.api.chat_rooms.deleteOne(room.id),
4859
+ // cleanup availabilities
4860
+ sdk.api.users.updateOne(sdk.userInfo.id, {
4861
+ weeklyAvailabilities: []
4862
+ }, {
4863
+ replaceObjectFields: true
4864
+ })
4859
4865
  ], blocks.map(function (b) { return (sdk.api.availability_blocks.deleteOne(b.id)); }), true))];
4860
4866
  case 15:
4861
4867
  _b.sent();
@@ -4865,13 +4871,21 @@ var run_autoreply_test = function (title, _a) {
4865
4871
  });
4866
4872
  };
4867
4873
  var auto_reply_tests = function () { return __awaiter(void 0, void 0, void 0, function () {
4868
- var today, activeBlockInfo, activeWithRange, inactiveEarly, inactiveLate, inactiveOldBlockInfo, wrongDayBlockInfo, wrongEntityTypeBlockInfo, wrongEntityIdInfo, wrongTimeBlockInfo;
4874
+ var today, activeBlockInfo, activeWithRange, inactiveEarly, inactiveLate, wrongDayBlockInfo, wrongEntityTypeBlockInfo, wrongEntityIdInfo, wrongTimeBlockInfo;
4869
4875
  return __generator(this, function (_a) {
4870
4876
  switch (_a.label) {
4871
- case 0:
4872
- (0, testing_1.log_header)("Autoreply");
4873
- return [4 /*yield*/, run_autoreply_test('No availabilities', { expectingAutoreply: false })];
4877
+ case 0:
4878
+ // cleanup user availabilities / autoReplyEnabled to avoid conflicts
4879
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, {
4880
+ autoReplyEnabled: false,
4881
+ weeklyAvailabilities: [],
4882
+ }, { replaceObjectFields: true })];
4874
4883
  case 1:
4884
+ // cleanup user availabilities / autoReplyEnabled to avoid conflicts
4885
+ _a.sent();
4886
+ (0, testing_1.log_header)("Autoreply (Organization-wide)");
4887
+ return [4 /*yield*/, run_autoreply_test('No availabilities', { expectingAutoreply: false })];
4888
+ case 2:
4875
4889
  _a.sent();
4876
4890
  today = new Date();
4877
4891
  activeBlockInfo = {
@@ -4888,7 +4902,6 @@ var auto_reply_tests = function () { return __awaiter(void 0, void 0, void 0, fu
4888
4902
  } });
4889
4903
  inactiveEarly = __assign(__assign({}, activeBlockInfo), { active: { from: new Date(Date.now() + 1000000) } });
4890
4904
  inactiveLate = __assign(__assign({}, activeBlockInfo), { active: { to: new Date(Date.now() - 1000000) } });
4891
- inactiveOldBlockInfo = __assign(__assign({}, activeBlockInfo), { dayOfWeekStartingSundayIndexedByZero: (today.getDay() + 1) % 7 });
4892
4905
  wrongDayBlockInfo = __assign(__assign({}, activeBlockInfo), { dayOfWeekStartingSundayIndexedByZero: (today.getDay() + 1) % 7 });
4893
4906
  wrongEntityTypeBlockInfo = __assign(__assign({}, activeBlockInfo), { entity: 'user' });
4894
4907
  wrongEntityIdInfo = __assign(__assign({}, activeBlockInfo), { entityId: sdk.userInfo.id });
@@ -4896,56 +4909,110 @@ var auto_reply_tests = function () { return __awaiter(void 0, void 0, void 0, fu
4896
4909
  return [4 /*yield*/, sdk.api.organizations.updateOne(sdk.userInfo.businessId, {
4897
4910
  settings: { endusers: { autoReplyEnabled: false } }
4898
4911
  })];
4899
- case 2:
4912
+ case 3:
4900
4913
  _a.sent();
4901
4914
  return [4 /*yield*/, sdk.api.availability_blocks.createSome([wrongTimeBlockInfo])];
4902
- case 3:
4915
+ case 4:
4903
4916
  _a.sent();
4904
4917
  return [4 /*yield*/, run_autoreply_test('Autoreply disabled', { expectingAutoreply: false })];
4905
- case 4:
4918
+ case 5:
4906
4919
  _a.sent();
4907
4920
  return [4 /*yield*/, sdk.api.organizations.updateOne(sdk.userInfo.businessId, {
4908
4921
  settings: { endusers: { autoReplyEnabled: true } }
4909
4922
  })];
4910
- case 5:
4923
+ case 6:
4911
4924
  _a.sent();
4912
4925
  return [4 /*yield*/, sdk.api.availability_blocks.createSome([wrongTimeBlockInfo])];
4913
- case 6:
4926
+ case 7:
4914
4927
  _a.sent();
4915
4928
  return [4 /*yield*/, run_autoreply_test('One bad', { expectingAutoreply: true })];
4916
- case 7:
4929
+ case 8:
4917
4930
  _a.sent();
4918
4931
  return [4 /*yield*/, sdk.api.availability_blocks.createSome([
4919
4932
  inactiveEarly,
4920
4933
  inactiveLate,
4921
- inactiveOldBlockInfo,
4922
4934
  wrongDayBlockInfo,
4923
4935
  wrongEntityIdInfo,
4924
4936
  wrongEntityTypeBlockInfo,
4925
4937
  wrongTimeBlockInfo,
4926
4938
  ])];
4927
- case 8:
4939
+ case 9:
4928
4940
  _a.sent();
4929
4941
  return [4 /*yield*/, run_autoreply_test('Multiple bad blocks', { expectingAutoreply: true })];
4930
- case 9:
4942
+ case 10:
4931
4943
  _a.sent();
4932
4944
  return [4 /*yield*/, sdk.api.availability_blocks.createSome([activeBlockInfo])];
4933
- case 10:
4945
+ case 11:
4934
4946
  _a.sent();
4935
4947
  return [4 /*yield*/, run_autoreply_test('One active block', { expectingAutoreply: false })];
4936
- case 11:
4948
+ case 12:
4937
4949
  _a.sent();
4938
4950
  return [4 /*yield*/, sdk.api.availability_blocks.createSome([activeWithRange])];
4939
- case 12:
4951
+ case 13:
4940
4952
  _a.sent();
4941
4953
  return [4 /*yield*/, run_autoreply_test('One active with range', { expectingAutoreply: false })];
4942
- case 13:
4954
+ case 14:
4943
4955
  _a.sent();
4944
4956
  return [4 /*yield*/, sdk.api.availability_blocks.createSome([activeBlockInfo, activeWithRange, activeBlockInfo, activeWithRange])];
4945
- case 14:
4957
+ case 15:
4946
4958
  _a.sent();
4947
4959
  return [4 /*yield*/, run_autoreply_test('Multiple active blocks', { expectingAutoreply: false })];
4948
- case 15:
4960
+ case 16:
4961
+ _a.sent();
4962
+ (0, testing_1.log_header)("Autoreply (User)");
4963
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, {
4964
+ autoReplyEnabled: false,
4965
+ })];
4966
+ case 17:
4967
+ _a.sent();
4968
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, {
4969
+ weeklyAvailabilities: [wrongTimeBlockInfo]
4970
+ })];
4971
+ case 18:
4972
+ _a.sent();
4973
+ return [4 /*yield*/, run_autoreply_test('User: Autoreply disabled', { expectingAutoreply: false })];
4974
+ case 19:
4975
+ _a.sent();
4976
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, {
4977
+ autoReplyEnabled: true,
4978
+ })];
4979
+ case 20:
4980
+ _a.sent();
4981
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, { weeklyAvailabilities: [wrongTimeBlockInfo] })];
4982
+ case 21:
4983
+ _a.sent();
4984
+ return [4 /*yield*/, run_autoreply_test('User: One bad', { expectingAutoreply: true })];
4985
+ case 22:
4986
+ _a.sent();
4987
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, {
4988
+ weeklyAvailabilities: [
4989
+ inactiveEarly,
4990
+ inactiveLate,
4991
+ wrongDayBlockInfo,
4992
+ ]
4993
+ })];
4994
+ case 23:
4995
+ _a.sent();
4996
+ return [4 /*yield*/, run_autoreply_test('User: Multiple bad blocks', { expectingAutoreply: true })];
4997
+ case 24:
4998
+ _a.sent();
4999
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, { weeklyAvailabilities: [activeBlockInfo] })];
5000
+ case 25:
5001
+ _a.sent();
5002
+ return [4 /*yield*/, run_autoreply_test('User: One active block', { expectingAutoreply: false })];
5003
+ case 26:
5004
+ _a.sent();
5005
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, { weeklyAvailabilities: [activeWithRange] })];
5006
+ case 27:
5007
+ _a.sent();
5008
+ return [4 /*yield*/, run_autoreply_test('User: One active with range', { expectingAutoreply: false })];
5009
+ case 28:
5010
+ _a.sent();
5011
+ return [4 /*yield*/, sdk.api.users.updateOne(sdk.userInfo.id, { weeklyAvailabilities: [activeBlockInfo, activeWithRange, activeBlockInfo, activeWithRange] })];
5012
+ case 29:
5013
+ _a.sent();
5014
+ return [4 /*yield*/, run_autoreply_test('User: Multiple active blocks', { expectingAutoreply: false })];
5015
+ case 30:
4949
5016
  _a.sent();
4950
5017
  return [2 /*return*/];
4951
5018
  }
@@ -5033,13 +5100,13 @@ var tests = {
5033
5100
  return [4 /*yield*/, multi_tenant_tests()]; // should come right after setup tests
5034
5101
  case 4:
5035
5102
  _k.sent(); // should come right after setup tests
5036
- return [4 /*yield*/, automation_trigger_tests()];
5103
+ return [4 /*yield*/, auto_reply_tests()];
5037
5104
  case 5:
5038
5105
  _k.sent();
5039
- return [4 /*yield*/, sub_organization_enduser_tests()];
5106
+ return [4 /*yield*/, automation_trigger_tests()];
5040
5107
  case 6:
5041
5108
  _k.sent();
5042
- return [4 /*yield*/, auto_reply_tests()];
5109
+ return [4 /*yield*/, sub_organization_enduser_tests()];
5043
5110
  case 7:
5044
5111
  _k.sent();
5045
5112
  return [4 /*yield*/, sub_organization_tests()];