@tellescope/sdk 1.4.95 → 1.4.97
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.d.ts +5 -3
- package/lib/cjs/sdk.d.ts.map +1 -1
- package/lib/cjs/sdk.js +4 -1
- package/lib/cjs/sdk.js.map +1 -1
- package/lib/cjs/session.d.ts +0 -1
- package/lib/cjs/session.d.ts.map +1 -1
- package/lib/cjs/tests/tests.js +209 -47
- package/lib/cjs/tests/tests.js.map +1 -1
- package/lib/esm/sdk.d.ts +3 -1
- package/lib/esm/sdk.d.ts.map +1 -1
- package/lib/esm/sdk.js +4 -1
- package/lib/esm/sdk.js.map +1 -1
- package/lib/esm/tests/tests.js +209 -47
- package/lib/esm/tests/tests.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/sdk.ts +15 -5
- package/src/tests/tests.ts +147 -4
package/src/tests/tests.ts
CHANGED
|
@@ -2316,7 +2316,7 @@ export const formsUnsubmittedCancelConditionTest = async () => {
|
|
|
2316
2316
|
fieldTitle: field.title,
|
|
2317
2317
|
}] })
|
|
2318
2318
|
|
|
2319
|
-
await wait(undefined,
|
|
2319
|
+
await wait(undefined, 4000) // allow background creation with generous pause
|
|
2320
2320
|
|
|
2321
2321
|
await async_test(
|
|
2322
2322
|
`FormsUnsubmitted cancel conditions work`,
|
|
@@ -2416,7 +2416,7 @@ export const formsUnsubmittedTest = async () => {
|
|
|
2416
2416
|
const form_responses = await sdk.api.form_responses.getSome()
|
|
2417
2417
|
|
|
2418
2418
|
// allow fast followup to trigger
|
|
2419
|
-
await wait(undefined,
|
|
2419
|
+
await wait(undefined, 5000) // allow background creation with generous pause
|
|
2420
2420
|
|
|
2421
2421
|
await async_test(
|
|
2422
2422
|
`formsUnsubmitted handler worked`,
|
|
@@ -2433,7 +2433,7 @@ export const formsUnsubmittedTest = async () => {
|
|
|
2433
2433
|
fieldId: field.id,
|
|
2434
2434
|
fieldTitle: field.title,
|
|
2435
2435
|
}] })
|
|
2436
|
-
await wait(undefined,
|
|
2436
|
+
await wait(undefined, 5000) // allow background creation with generous pause
|
|
2437
2437
|
|
|
2438
2438
|
await async_test(
|
|
2439
2439
|
`formResponses not triggered yet after 1 form remaining`,
|
|
@@ -2450,7 +2450,7 @@ export const formsUnsubmittedTest = async () => {
|
|
|
2450
2450
|
fieldTitle: field.title,
|
|
2451
2451
|
}] })
|
|
2452
2452
|
|
|
2453
|
-
await wait(undefined,
|
|
2453
|
+
await wait(undefined, 5000) // allow background creation with generous pause
|
|
2454
2454
|
|
|
2455
2455
|
await async_test(
|
|
2456
2456
|
`formResponses triggered after both forms submitted`,
|
|
@@ -3647,6 +3647,148 @@ export const role_based_access_permissions_tests = async () => {
|
|
|
3647
3647
|
await sdkNonAdmin.authenticate(nonAdminEmail, nonAdminPassword) // to use new role, handle logout on role change
|
|
3648
3648
|
}
|
|
3649
3649
|
|
|
3650
|
+
// runs tests and resets availability afterwards
|
|
3651
|
+
// creates a new enduser (to avoid duplicate autoreply)
|
|
3652
|
+
const run_autoreply_test = async (title: string, { expectingAutoreply } : { expectingAutoreply: boolean }) => {
|
|
3653
|
+
log_header(`Autoreply: ${title}`)
|
|
3654
|
+
|
|
3655
|
+
const enduser = await sdk.api.endusers.createOne({ fname: 'Autoreply', lname: "Test", email: "autoreply@tellescope.com" })
|
|
3656
|
+
await sdk.api.endusers.set_password({ id: enduser.id, password })
|
|
3657
|
+
await enduserSDK.authenticate(enduser.email!, password)
|
|
3658
|
+
|
|
3659
|
+
const room = await sdk.api.chat_rooms.createOne({
|
|
3660
|
+
userIds: [sdk.userInfo.id],
|
|
3661
|
+
enduserIds: [enduser.id]
|
|
3662
|
+
})
|
|
3663
|
+
|
|
3664
|
+
await sdk.api.chats.createOne({ roomId: room.id, message: 'user' })
|
|
3665
|
+
await wait (undefined, 50)
|
|
3666
|
+
await async_test(
|
|
3667
|
+
'User/outbound chat does not trigger autoreply',
|
|
3668
|
+
() => sdk.api.chats.getSome({ filter: { roomId: room.id }}),
|
|
3669
|
+
{ onResult: cs => cs.length === 1 }
|
|
3670
|
+
)
|
|
3671
|
+
|
|
3672
|
+
await enduserSDK.api.chats.createOne({ roomId: room.id, message: 'enduser' })
|
|
3673
|
+
await wait (undefined, 50)
|
|
3674
|
+
await async_test(
|
|
3675
|
+
'Main test',
|
|
3676
|
+
() => sdk.api.chats.getSome({ filter: { roomId: room.id }}),
|
|
3677
|
+
{ onResult: cs => (
|
|
3678
|
+
expectingAutoreply
|
|
3679
|
+
? cs.length === 3
|
|
3680
|
+
: cs.length === 2
|
|
3681
|
+
) }
|
|
3682
|
+
)
|
|
3683
|
+
|
|
3684
|
+
await enduserSDK.api.chats.createOne({ roomId: room.id, message: 'enduser again' })
|
|
3685
|
+
await wait (undefined, 50)
|
|
3686
|
+
await async_test(
|
|
3687
|
+
"Duplicate autoreply avoided",
|
|
3688
|
+
() => sdk.api.chats.getSome({ filter: { roomId: room.id }}),
|
|
3689
|
+
{ onResult: cs => (
|
|
3690
|
+
expectingAutoreply
|
|
3691
|
+
? cs.length === 4
|
|
3692
|
+
: cs.length === 3
|
|
3693
|
+
) }
|
|
3694
|
+
)
|
|
3695
|
+
|
|
3696
|
+
// cleanup, including any availability blocks
|
|
3697
|
+
const blocks = await sdk.api.availability_blocks.getSome()
|
|
3698
|
+
await Promise.all([
|
|
3699
|
+
sdk.api.endusers.deleteOne(enduser.id),
|
|
3700
|
+
sdk.api.chat_rooms.deleteOne(room.id),
|
|
3701
|
+
...blocks.map(b => (
|
|
3702
|
+
sdk.api.availability_blocks.deleteOne(b.id)
|
|
3703
|
+
))
|
|
3704
|
+
])
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3707
|
+
const auto_reply_tests = async () => {
|
|
3708
|
+
log_header("Autoreply")
|
|
3709
|
+
await run_autoreply_test('No availabilities', { expectingAutoreply: false })
|
|
3710
|
+
|
|
3711
|
+
const today = new Date()
|
|
3712
|
+
|
|
3713
|
+
const activeBlockInfo = {
|
|
3714
|
+
dayOfWeekStartingSundayIndexedByZero: today.getDay(),
|
|
3715
|
+
startTimeInMinutes: 0,
|
|
3716
|
+
endTimeInMinutes: 60 * 24,
|
|
3717
|
+
entity: 'organization' as const,
|
|
3718
|
+
entityId: sdk.userInfo.businessId,
|
|
3719
|
+
index: 0,
|
|
3720
|
+
}
|
|
3721
|
+
const activeWithRange = {
|
|
3722
|
+
...activeBlockInfo,
|
|
3723
|
+
active: {
|
|
3724
|
+
from: new Date(Date.now() - 1000000),
|
|
3725
|
+
to: new Date(Date.now() + 1000000),
|
|
3726
|
+
}
|
|
3727
|
+
}
|
|
3728
|
+
const inactiveEarly = {
|
|
3729
|
+
...activeBlockInfo,
|
|
3730
|
+
active: { from: new Date(Date.now() + 1000000) }
|
|
3731
|
+
}
|
|
3732
|
+
const inactiveLate = {
|
|
3733
|
+
...activeBlockInfo,
|
|
3734
|
+
active: { to: new Date(Date.now() - 1000000) }
|
|
3735
|
+
}
|
|
3736
|
+
const inactiveOldBlockInfo = {
|
|
3737
|
+
...activeBlockInfo,
|
|
3738
|
+
dayOfWeekStartingSundayIndexedByZero: (today.getDay() + 1) % 7,
|
|
3739
|
+
}
|
|
3740
|
+
const wrongDayBlockInfo = {
|
|
3741
|
+
...activeBlockInfo,
|
|
3742
|
+
dayOfWeekStartingSundayIndexedByZero: (today.getDay() + 1) % 7,
|
|
3743
|
+
}
|
|
3744
|
+
const wrongEntityTypeBlockInfo = {
|
|
3745
|
+
...activeBlockInfo,
|
|
3746
|
+
entity: 'user' as const,
|
|
3747
|
+
}
|
|
3748
|
+
const wrongEntityIdInfo = {
|
|
3749
|
+
...activeBlockInfo,
|
|
3750
|
+
entityId: sdk.userInfo.id,
|
|
3751
|
+
}
|
|
3752
|
+
const wrongTimeBlockInfo = {
|
|
3753
|
+
...activeBlockInfo,
|
|
3754
|
+
endTimeInMinutes: 0, // start and end at 0
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
await sdk.api.organizations.updateOne(sdk.userInfo.businessId, {
|
|
3758
|
+
settings: { endusers: { autoReplyEnabled: false } }
|
|
3759
|
+
})
|
|
3760
|
+
|
|
3761
|
+
await sdk.api.availability_blocks.createSome([wrongTimeBlockInfo])
|
|
3762
|
+
await run_autoreply_test('Autoreply disabled', { expectingAutoreply: false })
|
|
3763
|
+
|
|
3764
|
+
await sdk.api.organizations.updateOne(sdk.userInfo.businessId, {
|
|
3765
|
+
settings: { endusers: { autoReplyEnabled: true } }
|
|
3766
|
+
})
|
|
3767
|
+
|
|
3768
|
+
await sdk.api.availability_blocks.createSome([wrongTimeBlockInfo])
|
|
3769
|
+
await run_autoreply_test('One bad', { expectingAutoreply: true })
|
|
3770
|
+
|
|
3771
|
+
await sdk.api.availability_blocks.createSome([
|
|
3772
|
+
inactiveEarly,
|
|
3773
|
+
inactiveLate,
|
|
3774
|
+
inactiveOldBlockInfo,
|
|
3775
|
+
wrongDayBlockInfo,
|
|
3776
|
+
wrongEntityIdInfo,
|
|
3777
|
+
wrongEntityTypeBlockInfo,
|
|
3778
|
+
wrongTimeBlockInfo,
|
|
3779
|
+
])
|
|
3780
|
+
await run_autoreply_test('Multiple bad blocks', { expectingAutoreply: true })
|
|
3781
|
+
|
|
3782
|
+
await sdk.api.availability_blocks.createSome([activeBlockInfo])
|
|
3783
|
+
await run_autoreply_test('One active block', { expectingAutoreply: false })
|
|
3784
|
+
|
|
3785
|
+
await sdk.api.availability_blocks.createSome([activeWithRange])
|
|
3786
|
+
await run_autoreply_test('One active with range', { expectingAutoreply: false })
|
|
3787
|
+
|
|
3788
|
+
await sdk.api.availability_blocks.createSome([activeBlockInfo, activeWithRange, activeBlockInfo, activeWithRange])
|
|
3789
|
+
await run_autoreply_test('Multiple active blocks', { expectingAutoreply: false })
|
|
3790
|
+
}
|
|
3791
|
+
|
|
3650
3792
|
const NO_TEST = () => {}
|
|
3651
3793
|
const tests: { [K in keyof ClientModelForName]: () => void } = {
|
|
3652
3794
|
availability_blocks: NO_TEST,
|
|
@@ -3715,6 +3857,7 @@ const tests: { [K in keyof ClientModelForName]: () => void } = {
|
|
|
3715
3857
|
])
|
|
3716
3858
|
await setup_tests()
|
|
3717
3859
|
await multi_tenant_tests() // should come right after setup tests
|
|
3860
|
+
await auto_reply_tests()
|
|
3718
3861
|
await sub_organization_enduser_tests()
|
|
3719
3862
|
await sub_organization_tests()
|
|
3720
3863
|
await self_serve_appointment_booking_tests()
|