@@ -83,7 +83,7 @@ interface ListEmailsResponse {
83
83
emails : Email [ ] ;
84
84
}
85
85
86
- interface QueryUserVariables {
86
+ interface GetUserVariables {
87
87
id : { id : string ; } ;
88
88
}
89
89
@@ -92,15 +92,15 @@ const connectorConfig: ConnectorConfig = {
92
92
serviceId : 'my-service' ,
93
93
} ;
94
94
95
- const fredUser = { id : '00000000000000000000000000000000 ' , address : '32 Elm St.' , name : 'Fred' }
95
+ const fredUser = { id : 'fred_id ' , address : '32 Elm St.' , name : 'Fred' }
96
96
const fredrickUser = { id : fredUser . id , address : '64 Elm St. North' , name : 'Fredrick' }
97
97
98
- const jeffUser = { id : '11111111111111111111111111111111 ' , address : '99 Oak St.' , name : 'Jeff' }
98
+ const jeffUser = { id : 'jeff_id ' , address : '99 Oak St.' , name : 'Jeff' }
99
99
100
100
const expectedUserIds = [ fredUser . id , jeffUser . id ]
101
101
102
102
const fredEmail = {
103
- id : '99999999999999999999999999999999 ' ,
103
+ id : 'email_id ' ,
104
104
subject : 'free bitcoin inside' ,
105
105
date : '1999-12-31' ,
106
106
text : 'get pranked! LOL!' ,
@@ -116,19 +116,23 @@ describe('getDataConnect()', () => {
116
116
} ) ;
117
117
} ) ;
118
118
119
- const queryListUsersPublicLevel = 'query ListUsers @auth(level: PUBLIC) { users { id, name, address } }' ;
120
- const queryListEmailsNoAccess =
119
+ /** @auth (level: PUBLIC) */
120
+ const queryListUsers = 'query ListUsers @auth(level: PUBLIC) { users { id, name, address } }' ;
121
+ /** @auth (level: NO_ACCESS) */
122
+ const queryListEmails =
121
123
'query ListEmails @auth(level: NO_ACCESS) { emails { id subject text date from { name } } }' ;
124
+ /** no @auth specified - default permissions */
122
125
const queryGetUserById = 'query GetUser($id: User_Key!) { user(key: $id) { id name } }' ;
123
126
124
- const queryListUsersImpersonationUserLevel = `
127
+ /** @auth (level: USER) */
128
+ const queryListUsersImpersonation = `
125
129
query ListUsers @auth(level: USER) {
126
130
users(where: { id: { eq_expr: "auth.uid" } }) { id, name, address }
127
131
}` ;
128
132
129
133
const multipleQueries = `
130
- ${ queryListUsersPublicLevel }
131
- ${ queryListEmailsNoAccess }
134
+ ${ queryListUsers }
135
+ ${ queryListEmails }
132
136
` ;
133
137
134
138
/** hardcoded upsert fredUser query, with non-impersonateable id */
@@ -168,27 +172,27 @@ describe('getDataConnect()', () => {
168
172
const fredResponse = await getDataConnect ( connectorConfig ) . executeGraphql < UserUpsertResponse , unknown > (
169
173
upsertFredUser
170
174
) ;
171
- //{ data: { user_insert: { id: '00000000000000000000000000000000 ' } } }
175
+ //{ data: { user_insert: { id: 'fred_id ' } } }
172
176
expect ( fredResponse . data . user_upsert . id ) . to . be . not . empty ;
173
177
expect ( fredResponse . data . user_upsert . id ) . equals ( fredUser . id ) ;
174
178
175
179
const jeffResponse = await getDataConnect ( connectorConfig ) . executeGraphql < UserUpsertResponse , unknown > (
176
180
upsertJeffUser
177
181
) ;
178
- //{ data: { user_insert: { id: '11111111111111111111111111111111 ' } } }
182
+ //{ data: { user_insert: { id: 'jeff_id ' } } }
179
183
expect ( jeffResponse . data . user_upsert . id ) . to . be . not . empty ;
180
184
expect ( jeffResponse . data . user_upsert . id ) . equals ( jeffUser . id ) ;
181
185
182
186
const emailResponse = await getDataConnect ( connectorConfig ) . executeGraphql < EmailUpsertResponse , unknown > (
183
187
upsertFredEmail
184
188
) ;
185
- //{ data: { email_upsert: { id: '99999999999999999999999999999999 ' } } }
189
+ //{ data: { email_upsert: { id: 'email_id ' } } }
186
190
expect ( emailResponse . data . email_upsert . id ) . to . be . not . empty ;
187
191
} ) ;
188
192
189
193
it ( 'executeGraphql() successfully executes a GraphQL query' , async ( ) => {
190
194
const resp = await getDataConnect ( connectorConfig )
191
- . executeGraphql < ListUsersResponse , QueryUserVariables > ( queryListUsersPublicLevel ) ;
195
+ . executeGraphql < ListUsersResponse , undefined > ( queryListUsers ) ;
192
196
expect ( resp . data . users ) . to . be . not . empty ;
193
197
expect ( resp . data . users . length ) . to . greaterThan ( 1 ) ;
194
198
resp . data . users . forEach ( ( user ) => {
@@ -213,7 +217,7 @@ describe('getDataConnect()', () => {
213
217
} ) ;
214
218
215
219
it ( 'executeGraphql() successfully executes a GraphQL query with variables' , async ( ) => {
216
- const resp = await getDataConnect ( connectorConfig ) . executeGraphql < GetUserResponse , QueryUserVariables > (
220
+ const resp = await getDataConnect ( connectorConfig ) . executeGraphql < GetUserResponse , GetUserVariables > (
217
221
queryGetUserById ,
218
222
{ variables : { id : { id : fredUser . id } } }
219
223
) ;
@@ -226,7 +230,7 @@ describe('getDataConnect()', () => {
226
230
describe ( 'executeGraphqlRead()' , ( ) => {
227
231
it ( 'executeGraphqlRead() successfully executes a read-only GraphQL' , async ( ) => {
228
232
const resp = await getDataConnect ( connectorConfig )
229
- . executeGraphqlRead < ListUsersResponse , QueryUserVariables > ( queryListUsersPublicLevel ) ;
233
+ . executeGraphqlRead < ListUsersResponse , undefined > ( queryListUsers ) ;
230
234
expect ( resp . data . users ) . to . be . not . empty ;
231
235
expect ( resp . data . users . length ) . to . be . greaterThan ( 1 ) ;
232
236
resp . data . users . forEach ( ( user ) => {
@@ -269,7 +273,7 @@ describe('getDataConnect()', () => {
269
273
it ( 'executeGraphqlRead() successfully executes an impersonated query with authenticated claims' , async ( ) => {
270
274
const resp =
271
275
await getDataConnect ( connectorConfig ) . executeGraphqlRead < ListUsersResponse , undefined > (
272
- queryListUsersImpersonationUserLevel ,
276
+ queryListUsersImpersonation ,
273
277
optsAuthorizedFredClaims
274
278
) ;
275
279
expect ( resp . data . users ) . to . be . not . empty ;
@@ -279,31 +283,31 @@ describe('getDataConnect()', () => {
279
283
280
284
it ( 'executeGraphqlRead() should throw for impersonated query with unauthenticated claims' , async ( ) => {
281
285
return getDataConnect ( connectorConfig ) . executeGraphqlRead (
282
- queryListUsersImpersonationUserLevel ,
286
+ queryListUsersImpersonation ,
283
287
optsUnauthorizedClaims
284
288
)
285
289
. should . eventually . be . rejected . and . have . property ( 'code' , 'data-connect/unauthenticated' ) ;
286
290
} ) ;
287
291
288
292
it ( 'executeGraphql() successfully executes an impersonated query with authenticated claims' , async ( ) => {
289
293
const resp = await getDataConnect ( connectorConfig ) . executeGraphqlRead < ListUsersResponse , undefined > (
290
- queryListUsersImpersonationUserLevel , optsAuthorizedFredClaims ) ;
294
+ queryListUsersImpersonation , optsAuthorizedFredClaims ) ;
291
295
expect ( resp . data . users ) . to . be . not . empty ;
292
296
expect ( resp . data . users . length ) . equals ( 1 ) ;
293
297
expect ( resp . data . users [ 0 ] ) . to . deep . equal ( fredUser ) ;
294
298
} ) ;
295
299
296
300
it ( 'executeGraphql() should throw for impersonated query with unauthenticated claims' , async ( ) => {
297
301
return getDataConnect ( connectorConfig ) . executeGraphql (
298
- queryListUsersImpersonationUserLevel , optsUnauthorizedClaims )
302
+ queryListUsersImpersonation , optsUnauthorizedClaims )
299
303
. should . eventually . be . rejected . and . has . property ( 'code' , 'data-connect/unauthenticated' ) ;
300
304
} ) ;
301
305
302
306
it ( 'executeGraphql() should return an empty list for an impersonated query with non-existing authenticated ' +
303
307
'claims' ,
304
308
async ( ) => {
305
309
const resp = await getDataConnect ( connectorConfig ) . executeGraphql < ListUsersResponse , undefined > (
306
- queryListUsersImpersonationUserLevel , optsNonExistingClaims ) ;
310
+ queryListUsersImpersonation , optsNonExistingClaims ) ;
307
311
// Should find no data
308
312
expect ( resp . data . users ) . to . be . empty ;
309
313
} ) ;
@@ -335,7 +339,7 @@ describe('getDataConnect()', () => {
335
339
describe ( 'PUBLIC Auth Policy' , ( ) => {
336
340
it ( 'executeGraphql() successfully executes an impersonated query with authenticated claims' , async ( ) => {
337
341
const resp = await getDataConnect ( connectorConfig ) . executeGraphql < ListUsersResponse , undefined > (
338
- queryListUsersPublicLevel , optsAuthorizedFredClaims ) ;
342
+ queryListUsers , optsAuthorizedFredClaims ) ;
339
343
expect ( resp . data . users ) . to . be . not . empty ;
340
344
expect ( resp . data . users . length ) . to . be . greaterThan ( 1 ) ;
341
345
resp . data . users . forEach ( ( user ) => {
@@ -345,7 +349,7 @@ describe('getDataConnect()', () => {
345
349
346
350
it ( 'executeGraphql() successfully executes an impersonated query with unauthenticated claims' , async ( ) => {
347
351
const resp = await getDataConnect ( connectorConfig ) . executeGraphql < ListUsersResponse , undefined > (
348
- queryListUsersPublicLevel , optsUnauthorizedClaims ) ;
352
+ queryListUsers , optsUnauthorizedClaims ) ;
349
353
expect ( resp . data . users ) . to . be . not . empty ;
350
354
expect ( resp . data . users . length ) . to . be . greaterThan ( 1 ) ;
351
355
resp . data . users . forEach ( ( user ) => {
@@ -356,7 +360,7 @@ describe('getDataConnect()', () => {
356
360
it ( 'executeGraphql() successfully executes an impersonated query with non-existing authenticated claims' ,
357
361
async ( ) => {
358
362
const resp = await getDataConnect ( connectorConfig ) . executeGraphql < ListUsersResponse , undefined > (
359
- queryListUsersPublicLevel , optsNonExistingClaims ) ;
363
+ queryListUsers , optsNonExistingClaims ) ;
360
364
expect ( resp . data . users ) . to . be . not . empty ;
361
365
expect ( resp . data . users . length ) . to . be . greaterThan ( 1 ) ;
362
366
resp . data . users . forEach ( ( user ) => {
@@ -367,18 +371,18 @@ describe('getDataConnect()', () => {
367
371
368
372
describe ( 'NO_ACCESS Auth Policy' , ( ) => {
369
373
it ( 'executeGraphql() should throw for an impersonated query with authenticated claims' , async ( ) => {
370
- return await getDataConnect ( connectorConfig ) . executeGraphql ( queryListEmailsNoAccess , optsAuthorizedFredClaims )
374
+ return await getDataConnect ( connectorConfig ) . executeGraphql ( queryListEmails , optsAuthorizedFredClaims )
371
375
. should . eventually . be . rejected . and . has . property ( 'code' , 'data-connect/permission-denied' ) ;
372
376
} ) ;
373
377
374
378
it ( 'executeGraphql() should throw for an impersonated query with unauthenticated claims' , async ( ) => {
375
- return await getDataConnect ( connectorConfig ) . executeGraphql ( queryListEmailsNoAccess , optsUnauthorizedClaims )
379
+ return await getDataConnect ( connectorConfig ) . executeGraphql ( queryListEmails , optsUnauthorizedClaims )
376
380
. should . eventually . be . rejected . and . has . property ( 'code' , 'data-connect/permission-denied' ) ;
377
381
} ) ;
378
382
379
383
it ( 'executeGraphql() should throw for an impersonated query with non-existing authenticated claims' ,
380
384
async ( ) => {
381
- return await getDataConnect ( connectorConfig ) . executeGraphql ( queryListEmailsNoAccess , optsNonExistingClaims )
385
+ return await getDataConnect ( connectorConfig ) . executeGraphql ( queryListEmails , optsNonExistingClaims )
382
386
. should . eventually . be . rejected . and . has . property ( 'code' , 'data-connect/permission-denied' ) ;
383
387
} ) ;
384
388
} ) ;
0 commit comments