@tellescope/sdk 1.4.61 → 1.4.63
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.
- package/lib/cjs/sdk.js +1 -1
- package/lib/cjs/sdk.js.map +1 -1
- package/lib/cjs/session.js +1 -1
- package/lib/cjs/session.js.map +1 -1
- package/lib/cjs/tests/tests.d.ts +2 -1
- package/lib/cjs/tests/tests.d.ts.map +1 -1
- package/lib/cjs/tests/tests.js +272 -85
- package/lib/cjs/tests/tests.js.map +1 -1
- package/lib/esm/enduser.d.ts +1 -0
- package/lib/esm/enduser.d.ts.map +1 -1
- package/lib/esm/sdk.d.ts +1 -0
- package/lib/esm/sdk.d.ts.map +1 -1
- package/lib/esm/sdk.js +1 -1
- package/lib/esm/sdk.js.map +1 -1
- package/lib/esm/session.js +1 -1
- package/lib/esm/session.js.map +1 -1
- package/lib/esm/tests/tests.d.ts +2 -1
- package/lib/esm/tests/tests.d.ts.map +1 -1
- package/lib/esm/tests/tests.js +269 -83
- package/lib/esm/tests/tests.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/sdk.ts +1 -1
- package/src/session.ts +1 -1
- package/src/tests/tests.ts +188 -17
package/src/tests/tests.ts
CHANGED
|
@@ -2021,8 +2021,8 @@ const sequenceTests = async () => {
|
|
|
2021
2021
|
])
|
|
2022
2022
|
}
|
|
2023
2023
|
|
|
2024
|
-
export const
|
|
2025
|
-
log_header("Cancel Condition Tests")
|
|
2024
|
+
export const formUnsubmittedCancelConditionTest = async () => {
|
|
2025
|
+
log_header("formUnsubmitted Cancel Condition Tests")
|
|
2026
2026
|
|
|
2027
2027
|
const enduser = await sdk.api.endusers.createOne({ email: 'deletemeee@tellescope.com' })
|
|
2028
2028
|
const journey = await sdk.api.journeys.createOne({ title: 'test journey '})
|
|
@@ -2052,7 +2052,8 @@ export const cancelConditionsTests = async () => {
|
|
|
2052
2052
|
automationStepId: triggerStep.id,
|
|
2053
2053
|
delayInMS: 0, // should trigger
|
|
2054
2054
|
delay: 0, unit: 'Seconds', // don't matter
|
|
2055
|
-
|
|
2055
|
+
// this cancelCondition is now added automatically, does not need to be part of step
|
|
2056
|
+
// cancelConditions: [{ type: 'formResponse', info: { automationStepId: triggerStep.id }}]
|
|
2056
2057
|
}
|
|
2057
2058
|
}],
|
|
2058
2059
|
action: {
|
|
@@ -2061,6 +2062,7 @@ export const cancelConditionsTests = async () => {
|
|
|
2061
2062
|
},
|
|
2062
2063
|
})
|
|
2063
2064
|
|
|
2065
|
+
// should occur right after unsub
|
|
2064
2066
|
const fastFollowup = await sdk.api.automation_steps.createOne({
|
|
2065
2067
|
journeyId: journey.id,
|
|
2066
2068
|
events: [{
|
|
@@ -2069,7 +2071,8 @@ export const cancelConditionsTests = async () => {
|
|
|
2069
2071
|
automationStepId: unsub.id,
|
|
2070
2072
|
delayInMS: 0, // ensure it triggers right after unsub
|
|
2071
2073
|
delay: 0, unit: 'Seconds', // don't matter
|
|
2072
|
-
|
|
2074
|
+
// this cancelCondition is now added automatically, does not need to be part of step
|
|
2075
|
+
// cancelConditions: [{ type: 'formResponse', info: { automationStepId: triggerStep.id }}]
|
|
2073
2076
|
}
|
|
2074
2077
|
}],
|
|
2075
2078
|
action: {
|
|
@@ -2078,6 +2081,7 @@ export const cancelConditionsTests = async () => {
|
|
|
2078
2081
|
},
|
|
2079
2082
|
})
|
|
2080
2083
|
|
|
2084
|
+
// should be cancelled after unsub
|
|
2081
2085
|
await sdk.api.automation_steps.createOne({
|
|
2082
2086
|
journeyId: journey.id,
|
|
2083
2087
|
events: [{
|
|
@@ -2086,7 +2090,8 @@ export const cancelConditionsTests = async () => {
|
|
|
2086
2090
|
automationStepId: unsub.id,
|
|
2087
2091
|
delayInMS: 1000000, // ensure it doesn't trigger
|
|
2088
2092
|
delay: 0, unit: 'Seconds', // don't matter
|
|
2089
|
-
|
|
2093
|
+
// this cancelCondition is now added automatically, passed down from unsub
|
|
2094
|
+
// cancelConditions: [{ type: 'formResponse', info: { automationStepId: triggerStep.id }}]
|
|
2090
2095
|
}
|
|
2091
2096
|
}],
|
|
2092
2097
|
action: {
|
|
@@ -2095,6 +2100,7 @@ export const cancelConditionsTests = async () => {
|
|
|
2095
2100
|
},
|
|
2096
2101
|
})
|
|
2097
2102
|
|
|
2103
|
+
// should be cancelled after unsub
|
|
2098
2104
|
// a second followup to the unsub event (to create example of two actions with same cancel condition)
|
|
2099
2105
|
await sdk.api.automation_steps.createOne({
|
|
2100
2106
|
journeyId: journey.id,
|
|
@@ -2104,7 +2110,8 @@ export const cancelConditionsTests = async () => {
|
|
|
2104
2110
|
automationStepId: unsub.id,
|
|
2105
2111
|
delayInMS: 1000000, // ensure it doesn't trigger
|
|
2106
2112
|
delay: 0, unit: 'Seconds', // don't matter
|
|
2107
|
-
|
|
2113
|
+
// this cancelCondition is now added automatically, does not need to be part of step
|
|
2114
|
+
// cancelConditions: [{ type: 'formResponse', info: { automationStepId: triggerStep.id }}]
|
|
2108
2115
|
}
|
|
2109
2116
|
}],
|
|
2110
2117
|
action: {
|
|
@@ -2119,15 +2126,6 @@ export const cancelConditionsTests = async () => {
|
|
|
2119
2126
|
enduserId: enduser.id
|
|
2120
2127
|
})
|
|
2121
2128
|
|
|
2122
|
-
// allow formUnsubmitted to trigger
|
|
2123
|
-
// await wait(undefined, 1500) // allow background creation with generous pause
|
|
2124
|
-
|
|
2125
|
-
// await async_test(
|
|
2126
|
-
// `formUnsubmitted event with short delay is triggered`,
|
|
2127
|
-
// () => sdk.api.endusers.getOne(enduser.id),
|
|
2128
|
-
// { onResult: e => e?.journeys?.[journey.id] === 'triggered' }
|
|
2129
|
-
// )
|
|
2130
|
-
|
|
2131
2129
|
// allow fast followup to trigger
|
|
2132
2130
|
await wait(undefined, 4000) // allow background creation with generous pause
|
|
2133
2131
|
await async_test(
|
|
@@ -2165,6 +2163,174 @@ export const cancelConditionsTests = async () => {
|
|
|
2165
2163
|
])
|
|
2166
2164
|
}
|
|
2167
2165
|
|
|
2166
|
+
export const formsUnsubmittedCancelConditionTest = async () => {
|
|
2167
|
+
log_header("formsUnsubmitted Cancel Condition Tests")
|
|
2168
|
+
|
|
2169
|
+
const enduser = await sdk.api.endusers.createOne({ email: 'deletemeee@tellescope.com' })
|
|
2170
|
+
const journey = await sdk.api.journeys.createOne({ title: 'test journey '})
|
|
2171
|
+
const form = await sdk.api.forms.createOne({ title: 'test form' })
|
|
2172
|
+
const field = await sdk.api.form_fields.createOne({
|
|
2173
|
+
formId: form.id, title: 'question', type: 'string',
|
|
2174
|
+
previousFields: [{ type: 'root', info: {} }]
|
|
2175
|
+
})
|
|
2176
|
+
|
|
2177
|
+
// this action won't be fired, because patient isn't added to journey as part of tests
|
|
2178
|
+
const triggerStep = await sdk.api.automation_steps.createOne({
|
|
2179
|
+
journeyId: journey.id,
|
|
2180
|
+
events: [{ type: 'onJourneyStart', info: { } }],
|
|
2181
|
+
// in practice, this would send a form, so that the next step(s) could handle the response
|
|
2182
|
+
// but we don't want to send emails in testing, and can still attach this Id to a form response to test a trigger
|
|
2183
|
+
action: {
|
|
2184
|
+
type: 'setEnduserStatus',
|
|
2185
|
+
info: { status: 'start' },
|
|
2186
|
+
},
|
|
2187
|
+
})
|
|
2188
|
+
|
|
2189
|
+
const unsub = await sdk.api.automation_steps.createOne({
|
|
2190
|
+
journeyId: journey.id,
|
|
2191
|
+
events: [{
|
|
2192
|
+
type: 'formsUnsubmitted',
|
|
2193
|
+
info: {
|
|
2194
|
+
automationStepId: triggerStep.id,
|
|
2195
|
+
delayInMS: 10000, // should't trigger
|
|
2196
|
+
delay: 0, unit: 'Seconds', // don't matter
|
|
2197
|
+
cancelConditions: [
|
|
2198
|
+
// { type: 'formResponse', info: { automationStepId: triggerStep.id }}
|
|
2199
|
+
]
|
|
2200
|
+
}
|
|
2201
|
+
}],
|
|
2202
|
+
action: {
|
|
2203
|
+
type: 'setEnduserStatus',
|
|
2204
|
+
info: { status: 'triggered' },
|
|
2205
|
+
},
|
|
2206
|
+
})
|
|
2207
|
+
|
|
2208
|
+
// test for all forms submitted triggering update
|
|
2209
|
+
await sdk.api.automation_steps.createOne({
|
|
2210
|
+
journeyId: journey.id,
|
|
2211
|
+
events: [{
|
|
2212
|
+
type: 'formResponses',
|
|
2213
|
+
info: { automationStepId: triggerStep.id }
|
|
2214
|
+
}],
|
|
2215
|
+
action: {
|
|
2216
|
+
type: 'setEnduserStatus',
|
|
2217
|
+
info: { status: 'formsSubmitted' },
|
|
2218
|
+
},
|
|
2219
|
+
})
|
|
2220
|
+
|
|
2221
|
+
// triggers formsUnsubmitted automated actions to be created when forms generated in templated message
|
|
2222
|
+
await sdk.api.templates.get_templated_message({
|
|
2223
|
+
channel: 'Email',
|
|
2224
|
+
enduserId: enduser.id,
|
|
2225
|
+
message: `{{forms.${form.id}.link:title}} {{forms.${form.id}.link:title}}`,
|
|
2226
|
+
userId: sdk.userInfo.id,
|
|
2227
|
+
automationStepId: triggerStep.id,
|
|
2228
|
+
})
|
|
2229
|
+
|
|
2230
|
+
const form_responses = await sdk.api.form_responses.getSome()
|
|
2231
|
+
|
|
2232
|
+
// allow fast followup to trigger
|
|
2233
|
+
await wait(undefined, 2500) // allow background creation with generous pause
|
|
2234
|
+
|
|
2235
|
+
|
|
2236
|
+
await async_test(
|
|
2237
|
+
`FormsUnsubmitted action created with cancel conditions`,
|
|
2238
|
+
() => sdk.api.automated_actions.getSome(),
|
|
2239
|
+
{ onResult: as => {
|
|
2240
|
+
const match = as.find(a => a.automationStepId === unsub.id)
|
|
2241
|
+
return !!(
|
|
2242
|
+
as.length === 1
|
|
2243
|
+
&& match?.status === 'active'
|
|
2244
|
+
&& match?.event.type === 'formsUnsubmitted'
|
|
2245
|
+
&& match.event.info.cancelConditions?.find(c =>
|
|
2246
|
+
c.type === 'formResponses'
|
|
2247
|
+
&& c.info.automationStepId === triggerStep.id
|
|
2248
|
+
&& c.info.unsubmittedFormCount === 2
|
|
2249
|
+
)
|
|
2250
|
+
)
|
|
2251
|
+
}}
|
|
2252
|
+
)
|
|
2253
|
+
await async_test(
|
|
2254
|
+
`formResponses not triggered with all forms unsubmitted`,
|
|
2255
|
+
() => sdk.api.endusers.getOne(enduser.id),
|
|
2256
|
+
{ onResult: e => e?.journeys?.[journey.id] !== 'formsSubmitted' }
|
|
2257
|
+
)
|
|
2258
|
+
|
|
2259
|
+
// trigger cancel conditions
|
|
2260
|
+
await sdk.api.form_responses.submit_form_response({ accessCode: form_responses[0].accessCode!, automationStepId: triggerStep.id, responses: [{
|
|
2261
|
+
answer: {
|
|
2262
|
+
type: 'string',
|
|
2263
|
+
value: 'answer'
|
|
2264
|
+
},
|
|
2265
|
+
fieldId: field.id,
|
|
2266
|
+
fieldTitle: field.title,
|
|
2267
|
+
}] })
|
|
2268
|
+
await wait(undefined, 2500) // allow background creation with generous pause
|
|
2269
|
+
|
|
2270
|
+
await async_test(
|
|
2271
|
+
`FormsUnsubmitted cancel conditions working`,
|
|
2272
|
+
() => sdk.api.automated_actions.getSome(),
|
|
2273
|
+
{ onResult: as => {
|
|
2274
|
+
const match = as.find(a => a.automationStepId === unsub.id)
|
|
2275
|
+
return !!(
|
|
2276
|
+
as.length === 1
|
|
2277
|
+
&& match?.status === 'active'
|
|
2278
|
+
&& match?.event.type === 'formsUnsubmitted'
|
|
2279
|
+
&& match.event.info.cancelConditions?.find(c =>
|
|
2280
|
+
c.type === 'formResponses'
|
|
2281
|
+
&& c.info.automationStepId === triggerStep.id
|
|
2282
|
+
&& c.info.unsubmittedFormCount === 1
|
|
2283
|
+
)
|
|
2284
|
+
)
|
|
2285
|
+
}}
|
|
2286
|
+
)
|
|
2287
|
+
await async_test(
|
|
2288
|
+
`formResponses not triggered yet after 1 form remaining`,
|
|
2289
|
+
() => sdk.api.endusers.getOne(enduser.id),
|
|
2290
|
+
{ onResult: e => e?.journeys?.[journey.id] !== 'formsSubmitted' }
|
|
2291
|
+
)
|
|
2292
|
+
|
|
2293
|
+
await sdk.api.form_responses.submit_form_response({ accessCode: form_responses[1].accessCode!, automationStepId: triggerStep.id, responses: [{
|
|
2294
|
+
answer: {
|
|
2295
|
+
type: 'string',
|
|
2296
|
+
value: 'answer'
|
|
2297
|
+
},
|
|
2298
|
+
fieldId: field.id,
|
|
2299
|
+
fieldTitle: field.title,
|
|
2300
|
+
}] })
|
|
2301
|
+
|
|
2302
|
+
await wait(undefined, 2500) // allow background creation with generous pause
|
|
2303
|
+
|
|
2304
|
+
await async_test(
|
|
2305
|
+
`FormsUnsubmitted cancel conditions work`,
|
|
2306
|
+
() => sdk.api.automated_actions.getSome(),
|
|
2307
|
+
{ onResult: as => {
|
|
2308
|
+
const match = as.find(a => a.automationStepId === unsub.id)
|
|
2309
|
+
return !!(
|
|
2310
|
+
as.length === 2 // this now includes formResponses event as well, which we test has worked in the next test
|
|
2311
|
+
&& match?.status === 'cancelled'
|
|
2312
|
+
&& match?.event.type === 'formsUnsubmitted'
|
|
2313
|
+
&& match.event.info.cancelConditions?.find(c =>
|
|
2314
|
+
c.type === 'formResponses'
|
|
2315
|
+
&& c.info.automationStepId === triggerStep.id
|
|
2316
|
+
&& c.info.unsubmittedFormCount === 0
|
|
2317
|
+
)
|
|
2318
|
+
)
|
|
2319
|
+
}}
|
|
2320
|
+
)
|
|
2321
|
+
await async_test(
|
|
2322
|
+
`formResponses triggered after both forms submitted`,
|
|
2323
|
+
() => sdk.api.endusers.getOne(enduser.id),
|
|
2324
|
+
{ onResult: e => e?.journeys?.[journey.id] === 'formsSubmitted' }
|
|
2325
|
+
)
|
|
2326
|
+
|
|
2327
|
+
await Promise.all([
|
|
2328
|
+
sdk.api.forms.deleteOne(form.id),
|
|
2329
|
+
sdk.api.journeys.deleteOne(journey.id),
|
|
2330
|
+
sdk.api.endusers.deleteOne(enduser.id)
|
|
2331
|
+
])
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2168
2334
|
const addToJourneyTests = async () => {
|
|
2169
2335
|
log_header("Add / Re-add to Journey")
|
|
2170
2336
|
|
|
@@ -2215,8 +2381,9 @@ const addToJourneyTests = async () => {
|
|
|
2215
2381
|
|
|
2216
2382
|
const automation_events_tests = async () => {
|
|
2217
2383
|
log_header("Automation Events")
|
|
2384
|
+
await formsUnsubmittedCancelConditionTest()
|
|
2385
|
+
await formUnsubmittedCancelConditionTest()
|
|
2218
2386
|
await addToJourneyTests()
|
|
2219
|
-
await cancelConditionsTests()
|
|
2220
2387
|
await sequenceTests()
|
|
2221
2388
|
await formEventTests()
|
|
2222
2389
|
await ticketEventTests()
|
|
@@ -3306,6 +3473,7 @@ export const role_based_access_permissions_tests = async () => {
|
|
|
3306
3473
|
|
|
3307
3474
|
const NO_TEST = () => {}
|
|
3308
3475
|
const tests: { [K in keyof ClientModelForName]: () => void } = {
|
|
3476
|
+
automation_steps: automation_events_tests,
|
|
3309
3477
|
products: NO_TEST,
|
|
3310
3478
|
purchase_credits: NO_TEST,
|
|
3311
3479
|
purchases: NO_TEST,
|
|
@@ -3313,7 +3481,6 @@ const tests: { [K in keyof ClientModelForName]: () => void } = {
|
|
|
3313
3481
|
appointment_booking_pages: NO_TEST,
|
|
3314
3482
|
role_based_access_permissions: role_based_access_permissions_tests,
|
|
3315
3483
|
chat_rooms: chat_room_tests,
|
|
3316
|
-
automation_steps: automation_events_tests,
|
|
3317
3484
|
files: files_tests,
|
|
3318
3485
|
enduser_tasks: NO_TEST,
|
|
3319
3486
|
care_plans: NO_TEST,
|
|
@@ -3369,6 +3536,10 @@ const tests: { [K in keyof ClientModelForName]: () => void } = {
|
|
|
3369
3536
|
])
|
|
3370
3537
|
await setup_tests()
|
|
3371
3538
|
await multi_tenant_tests() // should come right after setup tests
|
|
3539
|
+
|
|
3540
|
+
console.log('delete me')
|
|
3541
|
+
await automation_events_tests()
|
|
3542
|
+
|
|
3372
3543
|
await sub_organization_enduser_tests()
|
|
3373
3544
|
await sub_organization_tests()
|
|
3374
3545
|
await self_serve_appointment_booking_tests()
|