@tellescope/sdk 1.32.9 → 1.33.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.
@@ -4062,11 +4062,110 @@ const auto_reply_tests = async () => {
4062
4062
 
4063
4063
  await sdk.api.users.updateOne(sdk.userInfo.id, { weeklyAvailabilities: [activeBlockInfo, activeWithRange, activeBlockInfo, activeWithRange] })
4064
4064
  await run_autoreply_test('User: Multiple active blocks', { expectingAutoreply: false })
4065
+ }
4066
+
4067
+ const merge_enduser_tests = async () => {
4068
+ log_header("Merge Endusers")
4069
+
4070
+ const [source, destination, otherEnduser] = (await sdk.api.endusers.createSome([
4071
+ { email: 'source@tellescope.com', fname: 'source', lname: 'enduser' },
4072
+ { email: 'destination@tellescope.com'},
4073
+ { email: 'other@tellescope.com'},
4074
+ ])).created
4075
+
4076
+ // represents any model with enduserId field
4077
+ const [emailToMove, email] = (await sdk.api.emails.createSome([
4078
+ { enduserId: source.id, subject: 'subject', logOnly: true, textContent: 'email' },
4079
+ { enduserId: otherEnduser.id, subject: 'subject', logOnly: true, textContent: 'email' },
4080
+ ])).created
4081
+
4082
+ const [eventToMove, event] = (await sdk.api.calendar_events.createSome([
4083
+ { attendees: [{ type: 'enduser', id: source.id }], durationInMinutes: 5, startTimeInMS: Date.now(), title: 'title' },
4084
+ { attendees: [{ type: 'enduser', id: otherEnduser.id }], durationInMinutes: 5, startTimeInMS: Date.now(), title: 'title' },
4085
+ ])).created
4086
+
4087
+ const [roomToMove, room] = (await sdk.api.chat_rooms.createSome([
4088
+ { enduserIds: [source.id], title: 'title' },
4089
+ { enduserIds: [otherEnduser.id], title: 'title' },
4090
+ ])).created
4091
+
4092
+ const chatToMove = await sdk.api.chats.createOne(
4093
+ { roomId: roomToMove.id, senderId: source.id, message: 'test' },
4094
+ )
4095
+ const chat = await sdk.api.chats.createOne({
4096
+ roomId: room.id, senderId: otherEnduser.id, message: 'test'
4097
+ })
4098
+
4099
+ await sdk.api.endusers.merge({ sourceEnduserId: source.id, destinationEnduserId: destination.id })
4100
+
4101
+ await async_test(
4102
+ "Source is deleted",
4103
+ () => sdk.api.endusers.getOne(source.id),
4104
+ handleAnyError
4105
+ )
4106
+ await async_test(
4107
+ "Destination merged",
4108
+ () => sdk.api.endusers.getOne(destination.id),
4109
+ { onResult: e => (
4110
+ e.email === destination.email
4111
+ && e.fname === source.fname
4112
+ && e.lname === source.lname
4113
+ )}
4114
+ )
4115
+
4116
+ await async_test(
4117
+ "Other email is unchanged",
4118
+ () => sdk.api.emails.getOne(email.id),
4119
+ { onResult: e => e.enduserId === otherEnduser.id}
4120
+ )
4121
+ await async_test(
4122
+ "Other event is unchanged",
4123
+ () => sdk.api.calendar_events.getOne(event.id),
4124
+ { onResult: e => e.attendees?.length === 1 && !!e.attendees.find(e => e.id === otherEnduser.id)}
4125
+ )
4126
+ await async_test(
4127
+ "Other room is unchanged",
4128
+ () => sdk.api.chat_rooms.getOne(room.id),
4129
+ { onResult: e => room.enduserIds?.length === 1 && !!e.enduserIds?.find(id => id === otherEnduser.id)}
4130
+ )
4131
+ await async_test(
4132
+ "Other chat is unchanged",
4133
+ () => sdk.api.chats.getOne(chat.id),
4134
+ { onResult: e => e.senderId === otherEnduser.id}
4135
+ )
4065
4136
 
4137
+ await async_test(
4138
+ "Email moved",
4139
+ () => sdk.api.emails.getOne(emailToMove.id),
4140
+ { onResult: e => e.enduserId === destination.id }
4141
+ )
4142
+ await async_test(
4143
+ "Chat moved",
4144
+ () => sdk.api.chats.getOne(chatToMove.id),
4145
+ { onResult: e => e.senderId === destination.id }
4146
+ )
4147
+ await async_test(
4148
+ "Room moved",
4149
+ () => sdk.api.chat_rooms.getOne(roomToMove.id),
4150
+ { onResult: e => e.enduserIds?.length === 1 && !!e.enduserIds?.includes(destination.id) }
4151
+ )
4152
+ await async_test(
4153
+ "Event moved",
4154
+ () => sdk.api.calendar_events.getOne(eventToMove.id),
4155
+ { onResult: e => e.attendees.length === 1 && !!e.attendees?.find(a => a.id === destination.id) }
4156
+ )
4157
+
4158
+ await Promise.all([
4159
+ sdk.api.endusers.deleteOne(destination.id),
4160
+ sdk.api.endusers.deleteOne(otherEnduser.id),
4161
+ sdk.api.calendar_events.deleteOne(event.id),
4162
+ sdk.api.calendar_events.deleteOne(eventToMove.id),
4163
+ ])
4066
4164
  }
4067
4165
 
4068
4166
  const NO_TEST = () => {}
4069
4167
  const tests: { [K in keyof ClientModelForName]: () => void } = {
4168
+ phone_trees: NO_TEST,
4070
4169
  enduser_medications: NO_TEST,
4071
4170
  automation_triggers: NO_TEST,
4072
4171
  automation_steps: automation_events_tests,
@@ -4140,6 +4239,7 @@ const tests: { [K in keyof ClientModelForName]: () => void } = {
4140
4239
  ])
4141
4240
  await setup_tests()
4142
4241
  await multi_tenant_tests() // should come right after setup tests
4242
+ await merge_enduser_tests()
4143
4243
  await self_serve_appointment_booking_tests()
4144
4244
  await auto_reply_tests()
4145
4245
  await automation_trigger_tests()