@tellescope/sdk 0.0.9 → 0.0.13

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.
@@ -2,7 +2,6 @@ require('source-map-support').install();
2
2
 
3
3
  import {
4
4
  Enduser,
5
- ChatRoom,
6
5
  ClientModelForName,
7
6
  ClientModelForName_required,
8
7
  } from "@tellescope/types-client"
@@ -25,7 +24,7 @@ import {
25
24
 
26
25
  import { Session, APIQuery, EnduserSession } from "../sdk"
27
26
  import { } from "@tellescope/utilities"
28
- import { DEFAULT_OPERATIONS } from "@tellescope/constants"
27
+ import { DEFAULT_OPERATIONS, PLACEHOLDER_ID } from "@tellescope/constants"
29
28
  import {
30
29
  schema,
31
30
  Model,
@@ -218,6 +217,30 @@ const filterTests = async () => {
218
217
  await sdk.api.endusers.deleteOne(otherEnduser.id)
219
218
  }
220
219
 
220
+ const updatesTests = async () => {
221
+ const enduser = await sdk.api.endusers.createOne({ email: 'test@tellescope.com', phone: '+15555555555' })
222
+ await sdk.api.endusers.updateOne(enduser.id, { phone: '+15555555552' }) // update to new phone number
223
+ await sdk.api.endusers.updateOne(enduser.id, { phone: '+15555555552' }) // update to same phone number
224
+ assert(!!enduser, '', 'Updated phone number')
225
+
226
+ const task = await sdk.api.tasks.createOne({ text: "do the thing", completed: false })
227
+ await sdk.api.tasks.updateOne(task.id, { completed: false }) // test setting false (falsey value) on update
228
+ assert(!!task, '', 'Set completed false')
229
+
230
+ await sdk.api.tasks.deleteOne(task.id)
231
+ await sdk.api.endusers.deleteOne(enduser.id)
232
+ }
233
+
234
+ const generateEnduserAuthTests = async () => {
235
+ log_header("Generated Enduser authToken Tests")
236
+ const enduser = await sdk.api.endusers.createOne({ email: 'generated@tellescope.com'})
237
+ const { authToken } = await sdk.api.endusers.generateAuthToken({ id: enduser.id })
238
+ const { isAuthenticated } = await sdk.api.endusers.isAuthenticated({ id: enduser.id, authToken })
239
+ assert(isAuthenticated, 'invalid authToken generated for enduser', 'Generate authToken for enduser is valid')
240
+
241
+ await sdk.api.endusers.deleteOne(enduser.id)
242
+ }
243
+
221
244
  const instanceForModel = <N extends ModelName, T=ClientModelForName[N], REQ=ClientModelForName_required[N]>(model: Model<T, N>, i=0) => {
222
245
  const instance = {} as Indexable
223
246
  const updates = {} as Indexable
@@ -730,8 +753,31 @@ const chat_room_tests = async () => {
730
753
  () => sdk2.api.chat_rooms.getOne(room.id),
731
754
  { shouldError: true, onError: e => e.message === "Could not find a record for the given id" }
732
755
  )
756
+ await sdk.api.chat_rooms.deleteOne(room.id)
733
757
 
734
- sdk.api.chat_rooms.deleteOne(room.id)
758
+
759
+ const emptyRoom = await sdk.api.chat_rooms.createOne({ })
760
+ await async_test(
761
+ `get-chat-room (creator can access, even when not in userIds)`,
762
+ () => sdk.api.chat_rooms.getOne(emptyRoom.id),
763
+ { onResult: r => r.id === emptyRoom.id }
764
+ )
765
+ await async_test(
766
+ `get-chat-room (not in empty room)`,
767
+ () => sdk2.api.chat_rooms.getOne(emptyRoom.id),
768
+ { shouldError: true, onError: e => e.message === "Could not find a record for the given id" }
769
+ )
770
+ await async_test(
771
+ `join-room`,
772
+ () => sdk2.api.chat_rooms.join_room({ id: emptyRoom.id }),
773
+ { onResult: ({ room }) => room.id === emptyRoom.id }
774
+ )
775
+ await async_test(
776
+ `get-chat-room (join successful)`,
777
+ () => sdk2.api.chat_rooms.getOne(emptyRoom.id),
778
+ { onResult: r => r.id === emptyRoom.id }
779
+ )
780
+ await sdk.api.chat_rooms.deleteOne(emptyRoom.id)
735
781
  }
736
782
 
737
783
  const chat_tests = async() => {
@@ -899,6 +945,31 @@ const enduserAccessTests = async () => {
899
945
  }
900
946
  }
901
947
 
948
+ const ticketAccessible = await sdk.api.tickets.createOne({ enduserId: enduser.id, title: "Accessible ticket" })
949
+ const ticketInaccessible = await sdk.api.tickets.createOne({ enduserId: PLACEHOLDER_ID, title: "Inaccessible ticket" })
950
+ await async_test(
951
+ `enduser cannot create ticket for another enduser`,
952
+ () => enduserSDK.api.tickets.createOne({ enduserId: sdk.userInfo.id, title: "Error on Creation" }),
953
+ { shouldError: true, onError: e => e.message === "enduserId does not match creator id for enduser session" }
954
+ )
955
+ await async_test(
956
+ `enduser-access default, no access constraints, matching enduserId`,
957
+ () => enduserSDK.api.tickets.getOne(ticketAccessible.id),
958
+ { onResult: t => t.id === ticketAccessible.id }
959
+ )
960
+ await async_test(
961
+ `no-enduser-access default, no access constraints, non-matching enduserId`,
962
+ () => enduserSDK.api.tickets.getOne(ticketInaccessible.id),
963
+ { shouldError: true, onError: e => e.message.startsWith("Could not find")}
964
+ )
965
+ await async_test(
966
+ `no-enduser-access default, no access constraints, get many`,
967
+ () => enduserSDK.api.tickets.getSome(),
968
+ { onResult: ts => ts.length === 1 }
969
+ )
970
+
971
+ await sdk.api.tickets.deleteOne(ticketAccessible.id)
972
+ await sdk.api.tickets.deleteOne(ticketInaccessible.id)
902
973
  await sdk.api.endusers.deleteOne(enduser.id)
903
974
  }
904
975
 
@@ -915,17 +986,29 @@ const tests: { [K in keyof ClientModelForName]: () => void } = {
915
986
  users: () => {},
916
987
  templates: () => {},
917
988
  files: () => {},
989
+ tickets: () => {},
990
+ meetings: () => {},
918
991
  };
919
992
 
920
993
  (async () => {
921
994
  await sdk.authenticate(email, password, host)
922
995
 
923
996
  log_header("API")
924
- await setup_tests()
925
- await multi_tenant_tests() // should come right after setup tests
926
- await filterTests()
927
- await threadKeyTests()
928
- await enduserAccessTests()
997
+
998
+ try {
999
+ await setup_tests()
1000
+ await multi_tenant_tests() // should come right after setup tests
1001
+ await filterTests()
1002
+ await updatesTests()
1003
+ await threadKeyTests()
1004
+ await enduserAccessTests()
1005
+ await generateEnduserAuthTests()
1006
+ } catch(err) {
1007
+ console.error("Failed during custom test")
1008
+ console.error(err)
1009
+ process.exit()
1010
+ }
1011
+
929
1012
 
930
1013
  let n: keyof typeof schema;
931
1014
  for (n in schema) {