@tellescope/sdk 1.3.41 → 1.3.43

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.
@@ -1,3 +1,4 @@
1
+ export declare const cancelConditionsTests: () => Promise<void>;
1
2
  export declare const meetings_tests: () => Promise<void>;
2
3
  export declare const managed_content_records_tests: () => Promise<void>;
3
4
  export declare const calendar_event_RSVPs_tests: () => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"tests.d.ts","sourceRoot":"","sources":["../../../src/tests/tests.ts"],"names":[],"mappings":"AAk2DA,eAAO,MAAM,cAAc,qBAqC1B,CAAA;AA0eD,eAAO,MAAM,6BAA6B,qBAgCzC,CAAA;AAED,eAAO,MAAM,0BAA0B,qBAmFtC,CAAA;AAoED,eAAO,MAAM,eAAe,qBA8C3B,CAAA"}
1
+ {"version":3,"file":"tests.d.ts","sourceRoot":"","sources":["../../../src/tests/tests.ts"],"names":[],"mappings":"AAy0DA,eAAO,MAAM,qBAAqB,qBAoHjC,CAAA;AA4FD,eAAO,MAAM,cAAc,qBAqC1B,CAAA;AA0eD,eAAO,MAAM,6BAA6B,qBAgCzC,CAAA;AAED,eAAO,MAAM,0BAA0B,qBAmFtC,CAAA;AAoED,eAAO,MAAM,eAAe,qBA8C3B,CAAA"}
@@ -82,7 +82,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
82
82
  return (mod && mod.__esModule) ? mod : { "default": mod };
83
83
  };
84
84
  Object.defineProperty(exports, "__esModule", { value: true });
85
- exports.databases_tests = exports.calendar_event_RSVPs_tests = exports.managed_content_records_tests = exports.meetings_tests = void 0;
85
+ exports.databases_tests = exports.calendar_event_RSVPs_tests = exports.managed_content_records_tests = exports.meetings_tests = exports.cancelConditionsTests = void 0;
86
86
  require('source-map-support').install();
87
87
  var crypto_1 = __importDefault(require("crypto"));
88
88
  var buffer = __importStar(require("buffer")); // only node >=15.7.0
@@ -1856,7 +1856,7 @@ var formEventTests = function () { return __awaiter(void 0, void 0, void 0, func
1856
1856
  field = _a.sent();
1857
1857
  return [4 /*yield*/, sdk.api.automation_steps.createOne({
1858
1858
  journeyId: journey.id,
1859
- event: { type: 'onJourneyStart', info: {} },
1859
+ events: [{ type: 'onJourneyStart', info: {} }],
1860
1860
  // in practice, this would send a form, so that the next step(s) could handle the response
1861
1861
  // but we don't want to send emails in testing, and can still attach this Id to a form response to test a trigger
1862
1862
  action: {
@@ -1868,10 +1868,10 @@ var formEventTests = function () { return __awaiter(void 0, void 0, void 0, func
1868
1868
  triggerStep = _a.sent();
1869
1869
  return [4 /*yield*/, sdk.api.automation_steps.createOne({
1870
1870
  journeyId: journey.id,
1871
- event: {
1872
- type: 'formResponse',
1873
- info: { automationStepId: triggerStep.id }
1874
- },
1871
+ events: [{
1872
+ type: 'formResponse',
1873
+ info: { automationStepId: triggerStep.id }
1874
+ }],
1875
1875
  action: {
1876
1876
  type: 'setEnduserStatus',
1877
1877
  info: { status: 'placeholder' },
@@ -1939,7 +1939,7 @@ var ticketEventTests = function () { return __awaiter(void 0, void 0, void 0, fu
1939
1939
  nullJourney = _c.sent();
1940
1940
  return [4 /*yield*/, sdk.api.automation_steps.createOne({
1941
1941
  journeyId: journey.id,
1942
- event: { type: 'onJourneyStart', info: {} },
1942
+ events: [{ type: 'onJourneyStart', info: {} }],
1943
1943
  action: {
1944
1944
  type: 'createTicket',
1945
1945
  info: {
@@ -1957,7 +1957,7 @@ var ticketEventTests = function () { return __awaiter(void 0, void 0, void 0, fu
1957
1957
  root = _c.sent();
1958
1958
  return [4 /*yield*/, sdk.api.automation_steps.createOne({
1959
1959
  journeyId: nullJourney.id,
1960
- event: { type: 'onJourneyStart', info: {} },
1960
+ events: [{ type: 'onJourneyStart', info: {} }],
1961
1961
  action: {
1962
1962
  type: 'createTicket',
1963
1963
  info: {
@@ -1975,7 +1975,7 @@ var ticketEventTests = function () { return __awaiter(void 0, void 0, void 0, fu
1975
1975
  nullRoot = _c.sent();
1976
1976
  createStep = function (journeyId, automationStepId, closedForReason) { return (sdk.api.automation_steps.createOne({
1977
1977
  journeyId: journeyId,
1978
- event: { type: 'ticketCompleted', info: { automationStepId: automationStepId, closedForReason: closedForReason, } },
1978
+ events: [{ type: 'ticketCompleted', info: { automationStepId: automationStepId, closedForReason: closedForReason, } }],
1979
1979
  action: { type: 'setEnduserStatus', info: { status: closedForReason !== null && closedForReason !== void 0 ? closedForReason : 'Null' }, },
1980
1980
  })); };
1981
1981
  return [4 /*yield*/, createStep(nullJourney.id, nullRoot.id)];
@@ -2008,7 +2008,7 @@ var ticketEventTests = function () { return __awaiter(void 0, void 0, void 0, fu
2008
2008
  return [4 /*yield*/, sdk.api.endusers.updateOne(enduserWithTeam.id, { journeys: (_b = {}, _b[nullJourney.id] = 'Added (Null)', _b) })];
2009
2009
  case 16:
2010
2010
  _c.sent();
2011
- return [4 /*yield*/, (0, testing_1.wait)(undefined, 2000)]; // wait for tickets to be automatically created
2011
+ return [4 /*yield*/, (0, testing_1.wait)(undefined, 2200)]; // wait for tickets to be automatically created
2012
2012
  case 17:
2013
2013
  _c.sent(); // wait for tickets to be automatically created
2014
2014
  return [4 /*yield*/, (0, testing_1.async_test)("Tickets automatically created", function () { return sdk.api.tickets.getSome(); }, { onResult: function (tickets) { return (tickets === null || tickets === void 0 ? void 0 : tickets.length) === 2; } })];
@@ -2078,13 +2078,92 @@ var ticketEventTests = function () { return __awaiter(void 0, void 0, void 0, fu
2078
2078
  });
2079
2079
  }); };
2080
2080
  var removeFromJourneyTests = function () { return __awaiter(void 0, void 0, void 0, function () {
2081
- var journey, journey2, enduser, enduser2, step, step2, createAction, numberOfActions, i;
2081
+ var journey, enduser, TEST_DELAY, step;
2082
2082
  var _a;
2083
2083
  return __generator(this, function (_b) {
2084
2084
  switch (_b.label) {
2085
2085
  case 0:
2086
2086
  (0, testing_1.log_header)("Remove from Journey");
2087
2087
  return [4 /*yield*/, sdk.api.journeys.createOne({ title: 'test journey' })];
2088
+ case 1:
2089
+ journey = _b.sent();
2090
+ return [4 /*yield*/, sdk.api.endusers.createOne({ email: 'test@tellescope.com' })];
2091
+ case 2:
2092
+ enduser = _b.sent();
2093
+ TEST_DELAY = 1000;
2094
+ return [4 /*yield*/, (sdk.api.automation_steps.createOne({
2095
+ journeyId: journey.id,
2096
+ events: [{ type: 'onJourneyStart', info: {} }],
2097
+ action: { type: 'setEnduserStatus', info: { status: 'Root' }, },
2098
+ }))];
2099
+ case 3:
2100
+ step = _b.sent();
2101
+ return [4 /*yield*/, (sdk.api.automation_steps.createOne({
2102
+ journeyId: journey.id,
2103
+ events: [{ type: 'afterAction', info: {
2104
+ automationStepId: step.id,
2105
+ delay: TEST_DELAY / 1000,
2106
+ delayInMS: TEST_DELAY,
2107
+ unit: 'Seconds',
2108
+ } }],
2109
+ action: { type: 'setEnduserStatus', info: { status: 'Delayed Step' }, },
2110
+ }))
2111
+ // test empty events step doesn't get triggered or cause errors
2112
+ ];
2113
+ case 4:
2114
+ _b.sent();
2115
+ // test empty events step doesn't get triggered or cause errors
2116
+ return [4 /*yield*/, (sdk.api.automation_steps.createOne({
2117
+ journeyId: journey.id,
2118
+ events: [],
2119
+ action: { type: 'setEnduserStatus', info: { status: 'INVARIANT_VIOLATION' }, },
2120
+ }))
2121
+ // add to journey to trigger initial action
2122
+ ];
2123
+ case 5:
2124
+ // test empty events step doesn't get triggered or cause errors
2125
+ _b.sent();
2126
+ // add to journey to trigger initial action
2127
+ return [4 /*yield*/, sdk.api.endusers.updateOne(enduser.id, { journeys: (_a = {}, _a[journey.id] = 'New', _a) }, { replaceObjectFields: true })];
2128
+ case 6:
2129
+ // add to journey to trigger initial action
2130
+ _b.sent();
2131
+ return [4 /*yield*/, (0, testing_1.wait)(undefined, 250)];
2132
+ case 7:
2133
+ _b.sent();
2134
+ return [4 /*yield*/, (0, testing_1.async_test)("Root action triggered (only root)", function () { return sdk.api.automated_actions.getSome({ filter: { enduserId: enduser.id } }); }, { onResult: function (es) { return es.length === 1; } })];
2135
+ case 8:
2136
+ _b.sent();
2137
+ return [4 /*yield*/, (0, testing_1.wait)(undefined, 500)];
2138
+ case 9:
2139
+ _b.sent();
2140
+ return [4 /*yield*/, (0, testing_1.async_test)("Next step not trigged early", function () { return sdk.api.endusers.getOne(enduser.id); }, { onResult: function (e) { var _a; return ((_a = e.journeys) === null || _a === void 0 ? void 0 : _a[journey.id]) !== 'Delayed Step'; } })];
2141
+ case 10:
2142
+ _b.sent();
2143
+ return [4 /*yield*/, (0, testing_1.wait)(undefined, 2 * TEST_DELAY)]; // wait long enough for automation to process and delay to pass
2144
+ case 11:
2145
+ _b.sent(); // wait long enough for automation to process and delay to pass
2146
+ return [4 /*yield*/, (0, testing_1.async_test)("Sequenced action triggered", function () { return sdk.api.endusers.getOne(enduser.id); }, { onResult: function (e) { var _a; return ((_a = e.journeys) === null || _a === void 0 ? void 0 : _a[journey.id]) === 'Delayed Step'; } })];
2147
+ case 12:
2148
+ _b.sent();
2149
+ return [4 /*yield*/, Promise.all([
2150
+ sdk.api.journeys.deleteOne(journey.id),
2151
+ sdk.api.endusers.deleteOne(enduser.id),
2152
+ ])];
2153
+ case 13:
2154
+ _b.sent();
2155
+ return [2 /*return*/];
2156
+ }
2157
+ });
2158
+ }); };
2159
+ var sequenceTests = function () { return __awaiter(void 0, void 0, void 0, function () {
2160
+ var journey, journey2, enduser, enduser2, step, step2, createAction, numberOfActions, i;
2161
+ var _a;
2162
+ return __generator(this, function (_b) {
2163
+ switch (_b.label) {
2164
+ case 0:
2165
+ (0, testing_1.log_header)("Automation Sequencing");
2166
+ return [4 /*yield*/, sdk.api.journeys.createOne({ title: 'test journey' })];
2088
2167
  case 1:
2089
2168
  journey = _b.sent();
2090
2169
  return [4 /*yield*/, sdk.api.journeys.createOne({ title: 'other journey' })];
@@ -2101,14 +2180,14 @@ var removeFromJourneyTests = function () { return __awaiter(void 0, void 0, void
2101
2180
  _b.sent();
2102
2181
  return [4 /*yield*/, (sdk.api.automation_steps.createOne({
2103
2182
  journeyId: journey.id,
2104
- event: { type: 'onJourneyStart', info: {} },
2183
+ events: [{ type: 'onJourneyStart', info: {} }],
2105
2184
  action: { type: 'setEnduserStatus', info: { status: 'Root' }, },
2106
2185
  }))];
2107
2186
  case 6:
2108
2187
  step = _b.sent();
2109
2188
  return [4 /*yield*/, (sdk.api.automation_steps.createOne({
2110
2189
  journeyId: journey2.id,
2111
- event: { type: 'onJourneyStart', info: {} },
2190
+ events: [{ type: 'onJourneyStart', info: {} }],
2112
2191
  action: { type: 'setEnduserStatus', info: { status: 'Root' }, },
2113
2192
  }))];
2114
2193
  case 7:
@@ -2116,7 +2195,6 @@ var removeFromJourneyTests = function () { return __awaiter(void 0, void 0, void
2116
2195
  createAction = function (journeyId, step, enduserId) { return (sdk.api.automated_actions.createOne({
2117
2196
  journeyId: journeyId,
2118
2197
  automationStepId: step.id,
2119
- cancelConditions: [],
2120
2198
  enduserId: enduserId !== null && enduserId !== void 0 ? enduserId : enduser.id,
2121
2199
  processAfter: Date.now() + 1000000,
2122
2200
  status: 'active',
@@ -2169,19 +2247,173 @@ var removeFromJourneyTests = function () { return __awaiter(void 0, void 0, void
2169
2247
  }
2170
2248
  });
2171
2249
  }); };
2250
+ var cancelConditionsTests = function () { return __awaiter(void 0, void 0, void 0, function () {
2251
+ var enduser, journey, form, field, triggerStep, unsub, accessCode;
2252
+ return __generator(this, function (_a) {
2253
+ switch (_a.label) {
2254
+ case 0:
2255
+ (0, testing_1.log_header)("Cancel Condition Tests");
2256
+ return [4 /*yield*/, sdk.api.endusers.createOne({ email: 'deletemeee@tellescope.com' })];
2257
+ case 1:
2258
+ enduser = _a.sent();
2259
+ return [4 /*yield*/, sdk.api.journeys.createOne({ title: 'test journey ' })];
2260
+ case 2:
2261
+ journey = _a.sent();
2262
+ return [4 /*yield*/, sdk.api.forms.createOne({ title: 'test form' })];
2263
+ case 3:
2264
+ form = _a.sent();
2265
+ return [4 /*yield*/, sdk.api.form_fields.createOne({
2266
+ formId: form.id, title: 'question', type: 'string',
2267
+ previousFields: [{ type: 'root', info: {} }]
2268
+ })
2269
+ // this action won't be fired, because patient isn't added to journey as part of tests
2270
+ ];
2271
+ case 4:
2272
+ field = _a.sent();
2273
+ return [4 /*yield*/, sdk.api.automation_steps.createOne({
2274
+ journeyId: journey.id,
2275
+ events: [{ type: 'onJourneyStart', info: {} }],
2276
+ // in practice, this would send a form, so that the next step(s) could handle the response
2277
+ // but we don't want to send emails in testing, and can still attach this Id to a form response to test a trigger
2278
+ action: {
2279
+ type: 'setEnduserStatus',
2280
+ info: { status: 'start' },
2281
+ },
2282
+ })];
2283
+ case 5:
2284
+ triggerStep = _a.sent();
2285
+ return [4 /*yield*/, sdk.api.automation_steps.createOne({
2286
+ journeyId: journey.id,
2287
+ events: [{
2288
+ type: 'formUnsubmitted',
2289
+ info: {
2290
+ automationStepId: triggerStep.id,
2291
+ delayInMS: 25,
2292
+ delay: 0, unit: 'Seconds',
2293
+ cancelConditions: [{ type: 'formResponse', info: { automationStepId: triggerStep.id } }]
2294
+ }
2295
+ }],
2296
+ action: {
2297
+ type: 'setEnduserStatus',
2298
+ info: { status: 'triggered' },
2299
+ },
2300
+ })];
2301
+ case 6:
2302
+ unsub = _a.sent();
2303
+ return [4 /*yield*/, sdk.api.automation_steps.createOne({
2304
+ journeyId: journey.id,
2305
+ events: [{
2306
+ type: 'afterAction',
2307
+ info: {
2308
+ automationStepId: unsub.id,
2309
+ delayInMS: 1000000,
2310
+ delay: 0, unit: 'Seconds',
2311
+ cancelConditions: [{ type: 'formResponse', info: { automationStepId: triggerStep.id } }]
2312
+ }
2313
+ }],
2314
+ action: {
2315
+ type: 'setEnduserStatus',
2316
+ info: { status: 'violation 1' },
2317
+ },
2318
+ })
2319
+ // a second followup to the unsub event (to create example of two actions with same cancel condition)
2320
+ ];
2321
+ case 7:
2322
+ _a.sent();
2323
+ // a second followup to the unsub event (to create example of two actions with same cancel condition)
2324
+ return [4 /*yield*/, sdk.api.automation_steps.createOne({
2325
+ journeyId: journey.id,
2326
+ events: [{
2327
+ type: 'afterAction',
2328
+ info: {
2329
+ automationStepId: unsub.id,
2330
+ delayInMS: 1000000,
2331
+ delay: 0, unit: 'Seconds',
2332
+ cancelConditions: [{ type: 'formResponse', info: { automationStepId: triggerStep.id } }]
2333
+ }
2334
+ }],
2335
+ action: {
2336
+ type: 'setEnduserStatus',
2337
+ info: { status: 'violation 2' },
2338
+ },
2339
+ })];
2340
+ case 8:
2341
+ // a second followup to the unsub event (to create example of two actions with same cancel condition)
2342
+ _a.sent();
2343
+ return [4 /*yield*/, sdk.api.form_responses.prepare_form_response({
2344
+ formId: form.id,
2345
+ automationStepId: triggerStep.id,
2346
+ enduserId: enduser.id
2347
+ })
2348
+ // allow formUnsubmitted to trigger
2349
+ ];
2350
+ case 9:
2351
+ accessCode = (_a.sent()).accessCode;
2352
+ // allow formUnsubmitted to trigger
2353
+ return [4 /*yield*/, (0, testing_1.wait)(undefined, 2000)]; // allow background creation with generous pause
2354
+ case 10:
2355
+ // allow formUnsubmitted to trigger
2356
+ _a.sent(); // allow background creation with generous pause
2357
+ return [4 /*yield*/, (0, testing_1.async_test)("formUnsubmitted event with short delay is triggered", 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]) === 'triggered'; } })
2358
+ // trigger cancel conditions
2359
+ ];
2360
+ case 11:
2361
+ _a.sent();
2362
+ // trigger cancel conditions
2363
+ return [4 /*yield*/, sdk.api.form_responses.submit_form_response({ accessCode: accessCode, automationStepId: triggerStep.id, responses: [{
2364
+ answer: {
2365
+ type: 'string',
2366
+ value: 'answer'
2367
+ },
2368
+ fieldId: field.id,
2369
+ fieldTitle: field.title,
2370
+ }] })];
2371
+ case 12:
2372
+ // trigger cancel conditions
2373
+ _a.sent();
2374
+ return [4 /*yield*/, (0, testing_1.wait)(undefined, 2000)]; // allow background creation with generous pause
2375
+ case 13:
2376
+ _a.sent(); // allow background creation with generous pause
2377
+ return [4 /*yield*/, (0, testing_1.async_test)("Cancel conditions work for followup", function () { return sdk.api.automated_actions.getSome(); }, { onResult: function (as) {
2378
+ var _a;
2379
+ return as.length === 3
2380
+ && ((_a = as.find(function (a) { return a.automationStepId === unsub.id; })) === null || _a === void 0 ? void 0 : _a.status) === 'finished'
2381
+ && as.filter(function (a) { return a.status === 'cancelled'; }).length === 2;
2382
+ }
2383
+ })];
2384
+ case 14:
2385
+ _a.sent();
2386
+ return [4 /*yield*/, Promise.all([
2387
+ sdk.api.forms.deleteOne(form.id),
2388
+ sdk.api.journeys.deleteOne(journey.id),
2389
+ sdk.api.endusers.deleteOne(enduser.id)
2390
+ ])];
2391
+ case 15:
2392
+ _a.sent();
2393
+ return [2 /*return*/];
2394
+ }
2395
+ });
2396
+ }); };
2397
+ exports.cancelConditionsTests = cancelConditionsTests;
2172
2398
  var automation_events_tests = function () { return __awaiter(void 0, void 0, void 0, function () {
2173
2399
  return __generator(this, function (_a) {
2174
2400
  switch (_a.label) {
2175
2401
  case 0:
2176
2402
  (0, testing_1.log_header)("Automation Events");
2177
- return [4 /*yield*/, formEventTests()];
2403
+ return [4 /*yield*/, (0, exports.cancelConditionsTests)()];
2178
2404
  case 1:
2179
2405
  _a.sent();
2180
- return [4 /*yield*/, ticketEventTests()];
2406
+ return [4 /*yield*/, sequenceTests()];
2181
2407
  case 2:
2182
2408
  _a.sent();
2183
- return [4 /*yield*/, removeFromJourneyTests()];
2409
+ return [4 /*yield*/, formEventTests()];
2184
2410
  case 3:
2411
+ _a.sent();
2412
+ return [4 /*yield*/, ticketEventTests()];
2413
+ case 4:
2414
+ _a.sent();
2415
+ return [4 /*yield*/, removeFromJourneyTests()];
2416
+ case 5:
2185
2417
  _a.sent();
2186
2418
  return [2 /*return*/];
2187
2419
  }
@@ -3172,6 +3404,7 @@ var databases_tests = function () { return __awaiter(void 0, void 0, void 0, fun
3172
3404
  exports.databases_tests = databases_tests;
3173
3405
  var NO_TEST = function () { };
3174
3406
  var tests = {
3407
+ automation_steps: automation_events_tests,
3175
3408
  calendar_event_templates: NO_TEST,
3176
3409
  databases: exports.databases_tests,
3177
3410
  database_records: NO_TEST,
@@ -3197,7 +3430,6 @@ var tests = {
3197
3430
  form_responses: form_response_tests,
3198
3431
  calendar_events: calendar_events_tests,
3199
3432
  webhooks: NO_TEST,
3200
- automation_steps: automation_events_tests,
3201
3433
  sequence_automations: NO_TEST,
3202
3434
  automated_actions: NO_TEST,
3203
3435
  enduser_status_updates: status_update_tests,