@tellescope/sdk 0.0.17 → 0.0.18
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/enduser.d.ts +5 -2
- package/lib/cjs/enduser.d.ts.map +1 -1
- package/lib/cjs/enduser.js +4 -3
- package/lib/cjs/enduser.js.map +1 -1
- package/lib/cjs/sdk.d.ts +7 -5
- package/lib/cjs/sdk.d.ts.map +1 -1
- package/lib/cjs/sdk.js +5 -6
- package/lib/cjs/sdk.js.map +1 -1
- package/lib/cjs/session.d.ts +4 -21
- package/lib/cjs/session.d.ts.map +1 -1
- package/lib/cjs/session.js +1 -0
- package/lib/cjs/session.js.map +1 -1
- package/lib/cjs/tests/public_endpoint_tests.js +1 -1
- package/lib/cjs/tests/public_endpoint_tests.js.map +1 -1
- package/lib/cjs/tests/socket_tests.d.ts +1 -1
- package/lib/cjs/tests/socket_tests.d.ts.map +1 -1
- package/lib/cjs/tests/socket_tests.js +124 -7
- package/lib/cjs/tests/socket_tests.js.map +1 -1
- package/lib/cjs/tests/tests.js +118 -88
- package/lib/cjs/tests/tests.js.map +1 -1
- package/lib/esm/enduser.d.ts +5 -2
- package/lib/esm/enduser.d.ts.map +1 -1
- package/lib/esm/enduser.js +4 -3
- package/lib/esm/enduser.js.map +1 -1
- package/lib/esm/sdk.d.ts +7 -5
- package/lib/esm/sdk.d.ts.map +1 -1
- package/lib/esm/sdk.js +5 -6
- package/lib/esm/sdk.js.map +1 -1
- package/lib/esm/session.d.ts +4 -21
- package/lib/esm/session.d.ts.map +1 -1
- package/lib/esm/session.js +1 -0
- package/lib/esm/session.js.map +1 -1
- package/lib/esm/tests/public_endpoint_tests.js +1 -1
- package/lib/esm/tests/public_endpoint_tests.js.map +1 -1
- package/lib/esm/tests/socket_tests.d.ts +1 -1
- package/lib/esm/tests/socket_tests.d.ts.map +1 -1
- package/lib/esm/tests/socket_tests.js +122 -7
- package/lib/esm/tests/socket_tests.js.map +1 -1
- package/lib/esm/tests/tests.js +118 -88
- package/lib/esm/tests/tests.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/enduser.ts +10 -6
- package/src/sdk.ts +20 -12
- package/src/session.ts +3 -18
- package/src/tests/public_endpoint_tests.ts +1 -1
- package/src/tests/socket_tests.ts +67 -4
- package/src/tests/tests.ts +42 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tellescope/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Code for interacting with the Tellescope API",
|
|
5
5
|
"main": "./lib/cjs/sdk.js",
|
|
6
6
|
"module": "./lib/esm/sdk.js",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/tellescope-os/tellescope#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@tellescope/constants": "^0.0.
|
|
34
|
-
"@tellescope/schema": "^0.0.
|
|
35
|
-
"@tellescope/testing": "^0.0.
|
|
36
|
-
"@tellescope/types-client": "^0.0.
|
|
37
|
-
"@tellescope/types-models": "^0.0.
|
|
38
|
-
"@tellescope/types-utilities": "^0.0.
|
|
39
|
-
"@tellescope/utilities": "^0.0.
|
|
40
|
-
"@tellescope/validation": "^0.0.
|
|
33
|
+
"@tellescope/constants": "^0.0.18",
|
|
34
|
+
"@tellescope/schema": "^0.0.18",
|
|
35
|
+
"@tellescope/testing": "^0.0.18",
|
|
36
|
+
"@tellescope/types-client": "^0.0.18",
|
|
37
|
+
"@tellescope/types-models": "^0.0.18",
|
|
38
|
+
"@tellescope/types-utilities": "^0.0.18",
|
|
39
|
+
"@tellescope/utilities": "^0.0.18",
|
|
40
|
+
"@tellescope/validation": "^0.0.18",
|
|
41
41
|
"axios": "^0.21.1",
|
|
42
42
|
"form-data": "^4.0.0",
|
|
43
43
|
"socket.io-client": "^4.2.0",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "8019bedb3e6f90e2d26ee71ee989bd05fc1b7ee6"
|
|
57
57
|
}
|
package/src/enduser.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { io } from 'socket.io-client'
|
|
2
2
|
|
|
3
|
-
import { Session, SessionOptions
|
|
3
|
+
import { Session, SessionOptions } from "./session"
|
|
4
|
+
import { APIQuery } from "./sdk"
|
|
4
5
|
import { url_safe_path } from "@tellescope/utilities"
|
|
5
6
|
|
|
6
7
|
import { S3PresignedPost, UserIdentity } from "@tellescope/types-utilities"
|
|
@@ -14,7 +15,6 @@ import {
|
|
|
14
15
|
Enduser,
|
|
15
16
|
File,
|
|
16
17
|
} from "@tellescope/types-client"
|
|
17
|
-
import { stringValidator } from "@tellescope/validation";
|
|
18
18
|
|
|
19
19
|
export interface EnduserSessionOptions extends SessionOptions {}
|
|
20
20
|
|
|
@@ -30,8 +30,9 @@ export const defaultQueries = <N extends keyof ClientModelForName>(
|
|
|
30
30
|
return {
|
|
31
31
|
createOne: o => s._POST(`/v1/${singularName}`, o),
|
|
32
32
|
createSome: os => s._POST(`/v1/${safeName}`, { create: os }),
|
|
33
|
-
getOne: (
|
|
34
|
-
|
|
33
|
+
getOne: (argument) => typeof argument === 'string' ? s._GET(`/v1/${singularName}/${argument}`)
|
|
34
|
+
: s._GET(`/v1/${singularName}`, { filter: argument}),
|
|
35
|
+
getSome: o => s._GET(`/v1/${safeName}`, o),
|
|
35
36
|
updateOne: (id, updates, options) => s._PATCH(`/v1/${singularName}/${id}`, { updates, options }),
|
|
36
37
|
deleteOne: id => s._DELETE(`/v1/${singularName}/${id}`),
|
|
37
38
|
}
|
|
@@ -124,8 +125,11 @@ export class EnduserSession extends Session {
|
|
|
124
125
|
return { authToken, enduser }
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
authenticate = async (email: string, password: string) => this.handle_new_session(
|
|
128
|
-
await this.POST<
|
|
128
|
+
authenticate = async (email: string, password: string, o?: { expirationInSeconds?: number }) => this.handle_new_session(
|
|
129
|
+
await this.POST<
|
|
130
|
+
{email: string, password: string, expirationInSeconds?: number },
|
|
131
|
+
{ authToken: string, enduser: Enduser }
|
|
132
|
+
>('/v1/login-enduser', { email, password, ...o })
|
|
129
133
|
)
|
|
130
134
|
|
|
131
135
|
refresh_session = async () => {
|
package/src/sdk.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AttendeeInfo,
|
|
3
3
|
JourneyState,
|
|
4
|
-
MeetingStatus,
|
|
5
4
|
Meeting,
|
|
6
5
|
UserSession,
|
|
7
6
|
MeetingInfo,
|
|
7
|
+
ReadFilter,
|
|
8
8
|
} from "@tellescope/types-models"
|
|
9
9
|
|
|
10
10
|
import {
|
|
@@ -19,12 +19,18 @@ import {
|
|
|
19
19
|
import { CustomUpdateOptions, SortOption, S3PresignedPost, UserIdentity } from "@tellescope/types-utilities"
|
|
20
20
|
import { url_safe_path } from "@tellescope/utilities"
|
|
21
21
|
|
|
22
|
-
import { Session as SessionManager, SessionOptions
|
|
22
|
+
import { Session as SessionManager, SessionOptions } from "./session"
|
|
23
23
|
|
|
24
24
|
export * from "./public"
|
|
25
25
|
export * from "./enduser"
|
|
26
26
|
|
|
27
|
-
export type LoadFunction<T> = (o?: {
|
|
27
|
+
export type LoadFunction<T> = (o?: {
|
|
28
|
+
lastId?: string,
|
|
29
|
+
limit?: number,
|
|
30
|
+
sort?: SortOption,
|
|
31
|
+
threadKey?: string,
|
|
32
|
+
filter?: ReadFilter<T>,
|
|
33
|
+
}) => Promise<T[]>
|
|
28
34
|
|
|
29
35
|
export interface APIQuery<
|
|
30
36
|
N extends keyof ClientModelForName,
|
|
@@ -36,7 +42,7 @@ export interface APIQuery<
|
|
|
36
42
|
{
|
|
37
43
|
createOne: (t: CREATE) => Promise<T>;
|
|
38
44
|
createSome: (ts: CREATE[]) => Promise<{ created: T[], errors: object[] }>;
|
|
39
|
-
getOne: (
|
|
45
|
+
getOne: (argument: string | ReadFilter<T>) => Promise<T>;
|
|
40
46
|
getSome: LoadFunction<T>;
|
|
41
47
|
updateOne: (id: string, updates: UPDATE, options?: CustomUpdateOptions) => Promise<T>;
|
|
42
48
|
deleteOne: (id: string) => Promise<void>;
|
|
@@ -52,7 +58,8 @@ export const defaultQueries = <N extends keyof ClientModelForName>(
|
|
|
52
58
|
return {
|
|
53
59
|
createOne: o => s._POST(`/v1/${singularName}`, o),
|
|
54
60
|
createSome: os => s._POST(`/v1/${safeName}`, { create: os }),
|
|
55
|
-
getOne: (
|
|
61
|
+
getOne: (argument) => typeof argument === 'string' ? s._GET(`/v1/${singularName}/${argument}`)
|
|
62
|
+
: s._GET(`/v1/${singularName}`, { filter: argument }),
|
|
56
63
|
getSome: (o) => s._GET(`/v1/${safeName}`, o),
|
|
57
64
|
updateOne: (id, updates, options) => s._PATCH(`/v1/${singularName}/${id}`, { updates, options }),
|
|
58
65
|
deleteOne: id => s._DELETE(`/v1/${singularName}/${id}`),
|
|
@@ -173,13 +180,14 @@ export class Session extends SessionManager {
|
|
|
173
180
|
if (this.AUTO_REFRESH_MS < elapsedSessionMS) { return await this.refresh_session()}
|
|
174
181
|
}
|
|
175
182
|
|
|
176
|
-
authenticate = async (email: string, password: string,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
authenticate = async (email: string, password: string, o?: { expirationInSeconds?: number }) => (
|
|
184
|
+
this.handle_new_session(
|
|
185
|
+
await this.POST<
|
|
186
|
+
{email: string, password: string, expirationInSeconds?: number },
|
|
187
|
+
UserSession & { authToken: string }
|
|
188
|
+
>('/submit-login', { email, password, ...o })
|
|
189
|
+
)
|
|
190
|
+
)
|
|
183
191
|
logout = async () => {
|
|
184
192
|
this.clearState()
|
|
185
193
|
await this.POST('/logout-api').catch(console.error)
|
package/src/session.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface SessionOptions {
|
|
|
22
22
|
authToken?: string;
|
|
23
23
|
host?: string;
|
|
24
24
|
cacheKey?: string;
|
|
25
|
+
expirationInSeconds?: number,
|
|
25
26
|
handleUnauthenticated?: () => Promise<void>;
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -29,24 +30,6 @@ interface RequestOptions {
|
|
|
29
30
|
refresh_session?: () => Promise<any>,
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
export type Filter<T> = { [K in keyof T]: T[K] }
|
|
33
|
-
|
|
34
|
-
export interface APIQuery<
|
|
35
|
-
N extends keyof ClientModelForName,
|
|
36
|
-
T=ClientModelForName[N],
|
|
37
|
-
Req=ClientModelForName_required[N],
|
|
38
|
-
CREATE=Omit<Req & Partial<T>, keyof ClientModelForName_readonly[N]>,
|
|
39
|
-
UPDATE=Omit<Partial<T>, keyof (ClientModelForName_readonly[N] & ClientModelForName_updatesDisabled[N])>,
|
|
40
|
-
>
|
|
41
|
-
{
|
|
42
|
-
createOne: (t: CREATE) => Promise<T>;
|
|
43
|
-
createSome: (ts: CREATE[]) => Promise<{ created: T[], errors: object[] }>;
|
|
44
|
-
getOne: (id: string, filter?: Filter<Partial<T>>) => Promise<T>;
|
|
45
|
-
getSome: (o?: { lastId?: string, limit?: number, sort?: SortOption, threadKey?: string }, f?: Filter<Partial<T>>) => Promise<T[]>
|
|
46
|
-
updateOne: (id: string, updates: UPDATE, options?: CustomUpdateOptions) => Promise<T>;
|
|
47
|
-
deleteOne: (id: string) => Promise<void>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
33
|
const generateBearer = (authToken: string) => `Bearer ${authToken}`
|
|
51
34
|
|
|
52
35
|
const parseError = (err: any) => {
|
|
@@ -71,6 +54,7 @@ export class Session {
|
|
|
71
54
|
apiKey?: string;
|
|
72
55
|
socket?: Socket;
|
|
73
56
|
handleUnauthenticated?: SessionOptions['handleUnauthenticated']
|
|
57
|
+
expirationInSeconds?: number;
|
|
74
58
|
socketAuthenticated: boolean;
|
|
75
59
|
userInfo: { businessId?: string };
|
|
76
60
|
sessionStart = Date.now();
|
|
@@ -81,6 +65,7 @@ export class Session {
|
|
|
81
65
|
constructor(o={} as SessionOptions & RequestOptions) {
|
|
82
66
|
this.host= o.host ?? DEFAULT_HOST
|
|
83
67
|
this.apiKey = o.apiKey ?? '';
|
|
68
|
+
this.expirationInSeconds = o.expirationInSeconds
|
|
84
69
|
this.socket = undefined as Socket | undefined
|
|
85
70
|
this.socketAuthenticated = false
|
|
86
71
|
this.handleUnauthenticated = o.handleUnauthenticated
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "crypto"
|
|
1
2
|
import {
|
|
2
3
|
assert,
|
|
3
4
|
async_test,
|
|
@@ -17,6 +18,7 @@ import { EnduserSession } from "../enduser"
|
|
|
17
18
|
import { Session, /* APIQuery */ } from "../sdk"
|
|
18
19
|
import { PLACEHOLDER_ID } from "@tellescope/constants"
|
|
19
20
|
|
|
21
|
+
export const get_sha256 = (s='') => createHash('sha256').update(s).digest('hex')
|
|
20
22
|
|
|
21
23
|
const host = process.env.TEST_URL || 'http://localhost:8080'
|
|
22
24
|
const [email, password] = [process.env.TEST_EMAIL, process.env.TEST_PASSWORD]
|
|
@@ -198,28 +200,89 @@ const enduser_tests = async () => {
|
|
|
198
200
|
// await user1.api.chats.deleteOne(messageToUser.id)
|
|
199
201
|
}
|
|
200
202
|
|
|
203
|
+
const TEST_SESSION_DURATION = 2 // seconds
|
|
204
|
+
const SESSION_TIMEOUT_DELAY = 2000 // ms
|
|
205
|
+
const deauthentication_tests = async (byTimeout=false) => {
|
|
206
|
+
log_header(`Unauthenticated Tests ${byTimeout ? '- With Timeout, requires Worker' : '- With Manual Logout' }`)
|
|
207
|
+
|
|
208
|
+
const enduser = await user1.api.endusers.createOne({ email: "socketenduser@tellescope.com" })
|
|
209
|
+
await user1.api.endusers.set_password({ id: enduser.id, password: 'enduserPassword!' })
|
|
210
|
+
await enduserSDK.authenticate(enduser.email as string, 'enduserPassword!', { expirationInSeconds: byTimeout ? TEST_SESSION_DURATION : undefined })
|
|
211
|
+
await wait(undefined, 25)
|
|
212
|
+
|
|
213
|
+
const room = await user1.api.chat_rooms.createOne({
|
|
214
|
+
type: 'external',
|
|
215
|
+
userIds: [user1.userInfo.id],
|
|
216
|
+
enduserIds: [enduser.id],
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
const userEvents = [] as ChatMessage[]
|
|
220
|
+
const enduserEvents = [] as ChatMessage[]
|
|
221
|
+
user1.subscribe({ [room.id]: 'chats' })
|
|
222
|
+
enduserSDK.subscribe({ [room.id]: 'chats' })
|
|
223
|
+
user1.handle_events({ 'created-chats': rs => userEvents.push(...rs) })
|
|
224
|
+
enduserSDK.handle_events({ 'created-chats': rs => enduserEvents.push(...rs) })
|
|
225
|
+
await wait(undefined, 10)
|
|
226
|
+
|
|
227
|
+
if (!byTimeout) {
|
|
228
|
+
await enduserSDK.api.endusers.logout()
|
|
229
|
+
} else {
|
|
230
|
+
await wait(undefined, TEST_SESSION_DURATION * 1000 + SESSION_TIMEOUT_DELAY)
|
|
231
|
+
}
|
|
232
|
+
await user1.api.chats.createOne({ roomId: room.id, message: "Hello!" })
|
|
233
|
+
await wait(undefined, 25)
|
|
234
|
+
assert(objects_equivalent(enduserEvents[0], undefined), 'enduser got message after logout on socket', 'enduser logged out')
|
|
235
|
+
|
|
236
|
+
// re-authenticate enduser to send message to user
|
|
237
|
+
await enduserSDK.authenticate(enduser.email as string, 'enduserPassword!')
|
|
238
|
+
|
|
239
|
+
// ensure user logged out appropriately for not receiving message
|
|
240
|
+
await user1.logout()
|
|
241
|
+
if (byTimeout) {
|
|
242
|
+
await user1.authenticate(email, password, { expirationInSeconds: byTimeout ? TEST_SESSION_DURATION : undefined } )
|
|
243
|
+
await wait(undefined, TEST_SESSION_DURATION * 1000 + SESSION_TIMEOUT_DELAY)
|
|
244
|
+
}
|
|
245
|
+
await enduserSDK.api.chats.createOne({ roomId: room.id, message: "Hello right back!" })
|
|
246
|
+
await wait(undefined, 25)
|
|
247
|
+
assert(objects_equivalent(userEvents[0], undefined), 'user got message after logout', 'user logged out')
|
|
248
|
+
|
|
249
|
+
// must come before cleanup, so cleanup works
|
|
250
|
+
await user1.authenticate(email, password), // reauthenticate for later tests as needed
|
|
251
|
+
|
|
252
|
+
// cleanup
|
|
253
|
+
await Promise.all([
|
|
254
|
+
user1.api.endusers.deleteOne(enduser.id),
|
|
255
|
+
user1.api.chat_rooms.deleteOne(room.id), // deletes chats as side effect
|
|
256
|
+
])
|
|
257
|
+
}
|
|
258
|
+
|
|
201
259
|
(async () => {
|
|
202
260
|
log_header("Sockets")
|
|
203
261
|
|
|
204
262
|
try {
|
|
205
|
-
await user1.authenticate(email, password
|
|
263
|
+
await user1.authenticate(email, password)
|
|
206
264
|
await user1.reset_db()
|
|
207
|
-
await user2.authenticate(email2, password2
|
|
265
|
+
await user2.authenticate(email2, password2) // generate authToken + socket connection for API keyj
|
|
208
266
|
await wait(undefined, 25)
|
|
209
267
|
|
|
210
268
|
let loopCount = 0
|
|
211
269
|
while (!(user1.socketAuthenticated && user2.socketAuthenticated) && ++loopCount < 10) {
|
|
212
|
-
|
|
270
|
+
if (!user1.socketAuthenticated) user1.authenticate_socket()
|
|
271
|
+
if (!user2.socketAuthenticated) user2.authenticate_socket()
|
|
213
272
|
await wait(undefined, 100)
|
|
214
273
|
}
|
|
215
274
|
if (loopCount === 10) {
|
|
216
275
|
console.log("Failed to authenticate")
|
|
217
276
|
process.exit()
|
|
218
277
|
}
|
|
219
|
-
|
|
278
|
+
|
|
220
279
|
await enduser_tests()
|
|
221
280
|
await basic_tests()
|
|
222
281
|
await access_tests()
|
|
282
|
+
|
|
283
|
+
await deauthentication_tests() // should come last!
|
|
284
|
+
await deauthentication_tests(true) // should come last!
|
|
285
|
+
|
|
223
286
|
} catch(err) {
|
|
224
287
|
console.error(err)
|
|
225
288
|
}
|
package/src/tests/tests.ts
CHANGED
|
@@ -71,7 +71,7 @@ const userId = '60398b0231a295e64f084fd9'
|
|
|
71
71
|
// await sdk.api.endusers.deleteOne(enduser.id)
|
|
72
72
|
// }
|
|
73
73
|
|
|
74
|
-
const sdk = new Session()
|
|
74
|
+
const sdk = new Session({ host })
|
|
75
75
|
const sdkOther = new Session({ host, apiKey: "ba745e25162bb95a795c5fa1af70df188d93c4d3aac9c48b34a5c8c9dd7b80f7" })
|
|
76
76
|
const enduserSDK = new EnduserSession({ host })
|
|
77
77
|
// const sdkOtherEmail = "sebass@tellescope.com"
|
|
@@ -90,8 +90,6 @@ const setup_tests = async () => {
|
|
|
90
90
|
await async_test('test_online', sdk.test_online, { expectedResult: 'API V1 Online' })
|
|
91
91
|
await async_test('test_authenticated', sdk.test_authenticated, { expectedResult: 'Authenticated!' })
|
|
92
92
|
|
|
93
|
-
// console.log(await sdk.api.api_keys.createOne({}))
|
|
94
|
-
|
|
95
93
|
await async_test(
|
|
96
94
|
'test_authenticated (with API Key)',
|
|
97
95
|
(new Session({ host, apiKey: '3n5q0SCBT_iUvZz-b9BJtX7o7HQUVJ9v132PgHJNJsg.' /* local test key */ })).test_authenticated,
|
|
@@ -100,7 +98,7 @@ const setup_tests = async () => {
|
|
|
100
98
|
|
|
101
99
|
await sdk.logout()
|
|
102
100
|
await async_test<string, string>('test_authenticated - (logout invalidates jwt)', sdk.test_authenticated, { shouldError: true, onError: e => e === 'Unauthenticated' })
|
|
103
|
-
await sdk.authenticate(email, password
|
|
101
|
+
await sdk.authenticate(email, password)
|
|
104
102
|
await async_test('test_authenticated (re-authenticated)', sdk.test_authenticated, { expectedResult: 'Authenticated!' })
|
|
105
103
|
|
|
106
104
|
await async_test('reset_db', () => sdk.reset_db(), passOnVoid)
|
|
@@ -191,6 +189,20 @@ const threadKeyTests = async () => {
|
|
|
191
189
|
])
|
|
192
190
|
}
|
|
193
191
|
|
|
192
|
+
const badInputTests = async () => {
|
|
193
|
+
log_header("Bad Input Tests")
|
|
194
|
+
await async_test(
|
|
195
|
+
`_-prefixed fields are not allowed`,
|
|
196
|
+
() => sdk.api.endusers.createOne({ email: 'failure@tellescope.com', fields: { "_notallowed": 'hello' } }),
|
|
197
|
+
{ shouldError: true, onError: e => e.message === "Error parsing field fields: Fields that start with '_' are not allowed" },
|
|
198
|
+
)
|
|
199
|
+
await async_test(
|
|
200
|
+
`_-prefixed fields are not allowed`,
|
|
201
|
+
() => sdk.api.notes.createOne({ enduserId: PLACEHOLDER_ID, fields: { "_notallowed": 'hello' } }),
|
|
202
|
+
{ shouldError: true, onError: e => e.message === "Error parsing field fields: Fields that start with '_' are not allowed" },
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
|
|
194
206
|
const filterTests = async () => {
|
|
195
207
|
const enduser = await sdk.api.endusers.createOne({ email: 'filtertests@tellescope.com', fname: 'test', fields: { field1: 'value1', field2: 'value2' } })
|
|
196
208
|
const otherEnduser = await sdk.api.endusers.createOne({ email: 'other@tellescope.com' })
|
|
@@ -199,6 +211,17 @@ const filterTests = async () => {
|
|
|
199
211
|
() => sdk.api.endusers.getSome({ filter: { email: 'filtertests@tellescope.com' }}),
|
|
200
212
|
{ onResult: es => es.length === 1 && es[0].id === enduser.id },
|
|
201
213
|
)
|
|
214
|
+
await async_test(
|
|
215
|
+
`find enduser by _exists filter`,
|
|
216
|
+
() => sdk.api.endusers.getSome({ filter: { fname: { _exists: true } }}),
|
|
217
|
+
{ onResult: es => es.length === 1 && es[0].id === enduser.id },
|
|
218
|
+
)
|
|
219
|
+
await async_test(
|
|
220
|
+
`find enduser by _exists filter (findOne)`,
|
|
221
|
+
// () => sdk.api.endusers.getOne({ fname: { _exists: true } }),
|
|
222
|
+
() => sdk.api.endusers.getOne({ fname: { _exists: true } }),
|
|
223
|
+
{ onResult: e => e.id === enduser.id },
|
|
224
|
+
)
|
|
202
225
|
await async_test(
|
|
203
226
|
`find enduser by compound filter`,
|
|
204
227
|
() => sdk.api.endusers.getSome({ filter: { email: 'filtertests@tellescope.com', fname: 'test' }}),
|
|
@@ -419,7 +442,7 @@ const run_generated_tests = async <N extends ModelName>({ queries, model, name,
|
|
|
419
442
|
}
|
|
420
443
|
await async_test(
|
|
421
444
|
`get-${singularName}`,
|
|
422
|
-
() => queries.getOne(_id
|
|
445
|
+
() => queries.getOne(_id),
|
|
423
446
|
{ onResult: d => {
|
|
424
447
|
if (!d?.id) return false
|
|
425
448
|
|
|
@@ -452,7 +475,7 @@ const run_generated_tests = async <N extends ModelName>({ queries, model, name,
|
|
|
452
475
|
)
|
|
453
476
|
await async_test(
|
|
454
477
|
`get-${singularName} (verify delete)`,
|
|
455
|
-
() => queries.getOne(_id
|
|
478
|
+
() => queries.getOne(_id),
|
|
456
479
|
{ shouldError: true, onError: e => e.message === 'Could not find a record for the given id' }
|
|
457
480
|
)
|
|
458
481
|
}
|
|
@@ -840,32 +863,22 @@ const chat_tests = async() => {
|
|
|
840
863
|
const chat = await sdk.api.chats.createOne({ roomId: room.id, message: "Hello!" })
|
|
841
864
|
const chat2 = await sdk.api.chats.createOne({ roomId: room.id, message: "Hello..." })
|
|
842
865
|
|
|
843
|
-
await async_test(
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
)
|
|
866
|
+
// await async_test(
|
|
867
|
+
// `get-chat (without filter)`,
|
|
868
|
+
// () => sdk.api.chats.getOne(chat.id),
|
|
869
|
+
// { shouldError: true, onError: () => true }
|
|
870
|
+
// )
|
|
848
871
|
await async_test(
|
|
849
872
|
`get-chats (without filter)`,
|
|
850
873
|
() => sdk.api.chats.getSome({}),
|
|
851
874
|
{ shouldError: true, onError: () => true }
|
|
852
875
|
)
|
|
853
|
-
await async_test(
|
|
854
|
-
`get-chat (with filter)`,
|
|
855
|
-
() => sdk.api.chats.getOne(chat.id, { roomId: room.id }),
|
|
856
|
-
{ onResult: c => c?.id === chat.id }
|
|
857
|
-
)
|
|
858
876
|
await async_test(
|
|
859
877
|
`get-chats (with filter)`,
|
|
860
878
|
() => sdk.api.chats.getSome({ filter: { roomId: room.id } }),
|
|
861
879
|
{ onResult: c => c?.length === 2 }
|
|
862
880
|
)
|
|
863
881
|
|
|
864
|
-
await async_test(
|
|
865
|
-
`get-chat not allowed`,
|
|
866
|
-
() => sdk2.api.chats.getOne(chat.id, { roomId: room.id }),
|
|
867
|
-
{ shouldError: true, onError: e => e.message === 'You do not have permission to access this resource' }
|
|
868
|
-
)
|
|
869
882
|
await async_test(
|
|
870
883
|
`get-chats not allowed`,
|
|
871
884
|
() => sdk2.api.chats.getSome({ filter: { roomId: room.id } }),
|
|
@@ -894,12 +907,12 @@ const chat_tests = async() => {
|
|
|
894
907
|
await wait(undefined, 25)
|
|
895
908
|
await async_test(
|
|
896
909
|
`get-chat (deleted as dependency of room 1)`,
|
|
897
|
-
() => sdk.api.chats.getOne(chat.id
|
|
910
|
+
() => sdk.api.chats.getOne(chat.id),
|
|
898
911
|
{ shouldError: true, onError: e => e.message === 'Could not find a record for the given id' }
|
|
899
912
|
)
|
|
900
913
|
await async_test(
|
|
901
914
|
`get-chat (deleted as dependency of room 2)`,
|
|
902
|
-
() => sdk.api.chats.getOne(chat2.id
|
|
915
|
+
() => sdk.api.chats.getOne(chat2.id),
|
|
903
916
|
{ shouldError: true, onError: e => e.message === 'Could not find a record for the given id' }
|
|
904
917
|
)
|
|
905
918
|
|
|
@@ -908,12 +921,12 @@ const chat_tests = async() => {
|
|
|
908
921
|
const sharedChat2 = await sdk2.api.chats.createOne({ roomId: sharedRoom.id, message: "Hello there!", })
|
|
909
922
|
await async_test(
|
|
910
923
|
`get-chat (shared, user1)`,
|
|
911
|
-
() => sdk.api.chats.getOne(sharedChat.id
|
|
924
|
+
() => sdk.api.chats.getOne(sharedChat.id),
|
|
912
925
|
{ onResult: r => r.id === sharedChat.id }
|
|
913
926
|
)
|
|
914
927
|
await async_test(
|
|
915
928
|
`get-chat (shared, user2)`,
|
|
916
|
-
() => sdk2.api.chats.getOne(sharedChat.id
|
|
929
|
+
() => sdk2.api.chats.getOne(sharedChat.id),
|
|
917
930
|
{ onResult: r => r.id === sharedChat.id }
|
|
918
931
|
)
|
|
919
932
|
await async_test(
|
|
@@ -936,7 +949,7 @@ const chat_tests = async() => {
|
|
|
936
949
|
await sdk.api.chats.deleteOne(chatNull.id)
|
|
937
950
|
await async_test(
|
|
938
951
|
`get-chat (setNull working)`,
|
|
939
|
-
() => sdk.api.chats.getOne(chat2Null.id
|
|
952
|
+
() => sdk.api.chats.getOne(chat2Null.id),
|
|
940
953
|
{ onResult: c => c.replyId === null }
|
|
941
954
|
)
|
|
942
955
|
}
|
|
@@ -1058,13 +1071,13 @@ const tests: { [K in keyof ClientModelForName]: () => void } = {
|
|
|
1058
1071
|
};
|
|
1059
1072
|
|
|
1060
1073
|
(async () => {
|
|
1061
|
-
await sdk.authenticate(email, password, host)
|
|
1062
|
-
|
|
1063
1074
|
log_header("API")
|
|
1064
|
-
|
|
1075
|
+
|
|
1065
1076
|
try {
|
|
1077
|
+
await sdk.authenticate(email, password)
|
|
1066
1078
|
await setup_tests()
|
|
1067
1079
|
await multi_tenant_tests() // should come right after setup tests
|
|
1080
|
+
await badInputTests()
|
|
1068
1081
|
await filterTests()
|
|
1069
1082
|
await updatesTests()
|
|
1070
1083
|
await threadKeyTests()
|