Skip to content

Commit b70fe23

Browse files
committed
make test data more readable, tweak contributing instructions
1 parent 1fb4ba1 commit b70fe23

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ to ensure that exported user records contain the password hashes of the user acc
255255
5. Set your **Cloud SQL instance ID** to `my-instance`
256256
6. Set your **Database name** to `my-database`
257257
7. Set your **Service ID** to `my-service`
258-
8. Click **Submit**. This operation may take up to 10 minutes to complete.
259-
2. Set up your Data Connect schema locally (currently there is no way to
260-
create/edit your schema from the Console):
258+
8. Click **Submit**. This operation may take up to 10 minutes to complete - you may
259+
continue setting up while this completes.
260+
2. Set up your Data Connect schema locally:
261261
1. Run the following commands from the command line to setup your data connect app:
262262
```bash
263263
$ mkdir fdc-integration-test
@@ -284,7 +284,7 @@ to ensure that exported user records contain the password hashes of the user acc
284284
from: User!
285285
}
286286
```
287-
6. Run the following commands from `fdc-integration-test/` to setup your data connect app:
287+
6. Run the following commands from `fdc-integration-test/` to deploy your schema:
288288
```bash
289289
$ firebase deploy --only dataconnect
290290
```

test/integration/data-connect.spec.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ interface ListEmailsResponse {
8383
emails: Email[];
8484
}
8585

86-
interface QueryUserVariables {
86+
interface GetUserVariables {
8787
id: { id: string; };
8888
}
8989

@@ -92,15 +92,15 @@ const connectorConfig: ConnectorConfig = {
9292
serviceId: 'my-service',
9393
};
9494

95-
const fredUser = { id: '00000000000000000000000000000000', address: '32 Elm St.', name: 'Fred' }
95+
const fredUser = { id: 'fred_id', address: '32 Elm St.', name: 'Fred' }
9696
const fredrickUser = { id: fredUser.id, address: '64 Elm St. North', name: 'Fredrick' }
9797

98-
const jeffUser = { id: '11111111111111111111111111111111', address: '99 Oak St.', name: 'Jeff' }
98+
const jeffUser = { id: 'jeff_id', address: '99 Oak St.', name: 'Jeff' }
9999

100100
const expectedUserIds = [fredUser.id, jeffUser.id]
101101

102102
const fredEmail = {
103-
id: '99999999999999999999999999999999',
103+
id: 'email_id',
104104
subject: 'free bitcoin inside',
105105
date: '1999-12-31',
106106
text: 'get pranked! LOL!',
@@ -116,19 +116,23 @@ describe('getDataConnect()', () => {
116116
});
117117
});
118118

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 =
121123
'query ListEmails @auth(level: NO_ACCESS) { emails { id subject text date from { name } } }';
124+
/** no @auth specified - default permissions */
122125
const queryGetUserById = 'query GetUser($id: User_Key!) { user(key: $id) { id name } }';
123126

124-
const queryListUsersImpersonationUserLevel = `
127+
/** @auth(level: USER) */
128+
const queryListUsersImpersonation = `
125129
query ListUsers @auth(level: USER) {
126130
users(where: { id: { eq_expr: "auth.uid" } }) { id, name, address }
127131
}`;
128132

129133
const multipleQueries = `
130-
${queryListUsersPublicLevel}
131-
${queryListEmailsNoAccess}
134+
${queryListUsers}
135+
${queryListEmails}
132136
`;
133137

134138
/** hardcoded upsert fredUser query, with non-impersonateable id */
@@ -168,27 +172,27 @@ describe('getDataConnect()', () => {
168172
const fredResponse = await getDataConnect(connectorConfig).executeGraphql<UserUpsertResponse, unknown>(
169173
upsertFredUser
170174
);
171-
//{ data: { user_insert: { id: '00000000000000000000000000000000' } } }
175+
//{ data: { user_insert: { id: 'fred_id' } } }
172176
expect(fredResponse.data.user_upsert.id).to.be.not.empty;
173177
expect(fredResponse.data.user_upsert.id).equals(fredUser.id);
174178

175179
const jeffResponse = await getDataConnect(connectorConfig).executeGraphql<UserUpsertResponse, unknown>(
176180
upsertJeffUser
177181
);
178-
//{ data: { user_insert: { id: '11111111111111111111111111111111' } } }
182+
//{ data: { user_insert: { id: 'jeff_id' } } }
179183
expect(jeffResponse.data.user_upsert.id).to.be.not.empty;
180184
expect(jeffResponse.data.user_upsert.id).equals(jeffUser.id);
181185

182186
const emailResponse = await getDataConnect(connectorConfig).executeGraphql<EmailUpsertResponse, unknown>(
183187
upsertFredEmail
184188
);
185-
//{ data: { email_upsert: { id: '99999999999999999999999999999999' } } }
189+
//{ data: { email_upsert: { id: 'email_id' } } }
186190
expect(emailResponse.data.email_upsert.id).to.be.not.empty;
187191
});
188192

189193
it('executeGraphql() successfully executes a GraphQL query', async () => {
190194
const resp = await getDataConnect(connectorConfig)
191-
.executeGraphql<ListUsersResponse, QueryUserVariables>(queryListUsersPublicLevel);
195+
.executeGraphql<ListUsersResponse, undefined>(queryListUsers);
192196
expect(resp.data.users).to.be.not.empty;
193197
expect(resp.data.users.length).to.greaterThan(1);
194198
resp.data.users.forEach((user) => {
@@ -213,7 +217,7 @@ describe('getDataConnect()', () => {
213217
});
214218

215219
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>(
217221
queryGetUserById,
218222
{ variables: { id: { id: fredUser.id } } }
219223
);
@@ -226,7 +230,7 @@ describe('getDataConnect()', () => {
226230
describe('executeGraphqlRead()', () => {
227231
it('executeGraphqlRead() successfully executes a read-only GraphQL', async () => {
228232
const resp = await getDataConnect(connectorConfig)
229-
.executeGraphqlRead<ListUsersResponse, QueryUserVariables>(queryListUsersPublicLevel);
233+
.executeGraphqlRead<ListUsersResponse, undefined>(queryListUsers);
230234
expect(resp.data.users).to.be.not.empty;
231235
expect(resp.data.users.length).to.be.greaterThan(1);
232236
resp.data.users.forEach((user) => {
@@ -269,7 +273,7 @@ describe('getDataConnect()', () => {
269273
it('executeGraphqlRead() successfully executes an impersonated query with authenticated claims', async () => {
270274
const resp =
271275
await getDataConnect(connectorConfig).executeGraphqlRead<ListUsersResponse, undefined>(
272-
queryListUsersImpersonationUserLevel,
276+
queryListUsersImpersonation,
273277
optsAuthorizedFredClaims
274278
);
275279
expect(resp.data.users).to.be.not.empty;
@@ -279,31 +283,31 @@ describe('getDataConnect()', () => {
279283

280284
it('executeGraphqlRead() should throw for impersonated query with unauthenticated claims', async () => {
281285
return getDataConnect(connectorConfig).executeGraphqlRead(
282-
queryListUsersImpersonationUserLevel,
286+
queryListUsersImpersonation,
283287
optsUnauthorizedClaims
284288
)
285289
.should.eventually.be.rejected.and.have.property('code', 'data-connect/unauthenticated');
286290
});
287291

288292
it('executeGraphql() successfully executes an impersonated query with authenticated claims', async () => {
289293
const resp = await getDataConnect(connectorConfig).executeGraphqlRead<ListUsersResponse, undefined>(
290-
queryListUsersImpersonationUserLevel, optsAuthorizedFredClaims);
294+
queryListUsersImpersonation, optsAuthorizedFredClaims);
291295
expect(resp.data.users).to.be.not.empty;
292296
expect(resp.data.users.length).equals(1);
293297
expect(resp.data.users[0]).to.deep.equal(fredUser);
294298
});
295299

296300
it('executeGraphql() should throw for impersonated query with unauthenticated claims', async () => {
297301
return getDataConnect(connectorConfig).executeGraphql(
298-
queryListUsersImpersonationUserLevel, optsUnauthorizedClaims)
302+
queryListUsersImpersonation, optsUnauthorizedClaims)
299303
.should.eventually.be.rejected.and.has.property('code', 'data-connect/unauthenticated');
300304
});
301305

302306
it('executeGraphql() should return an empty list for an impersonated query with non-existing authenticated ' +
303307
'claims',
304308
async () => {
305309
const resp = await getDataConnect(connectorConfig).executeGraphql<ListUsersResponse, undefined>(
306-
queryListUsersImpersonationUserLevel, optsNonExistingClaims);
310+
queryListUsersImpersonation, optsNonExistingClaims);
307311
// Should find no data
308312
expect(resp.data.users).to.be.empty;
309313
});
@@ -335,7 +339,7 @@ describe('getDataConnect()', () => {
335339
describe('PUBLIC Auth Policy', () => {
336340
it('executeGraphql() successfully executes an impersonated query with authenticated claims', async () => {
337341
const resp = await getDataConnect(connectorConfig).executeGraphql<ListUsersResponse, undefined>(
338-
queryListUsersPublicLevel, optsAuthorizedFredClaims);
342+
queryListUsers, optsAuthorizedFredClaims);
339343
expect(resp.data.users).to.be.not.empty;
340344
expect(resp.data.users.length).to.be.greaterThan(1);
341345
resp.data.users.forEach((user) => {
@@ -345,7 +349,7 @@ describe('getDataConnect()', () => {
345349

346350
it('executeGraphql() successfully executes an impersonated query with unauthenticated claims', async () => {
347351
const resp = await getDataConnect(connectorConfig).executeGraphql<ListUsersResponse, undefined>(
348-
queryListUsersPublicLevel, optsUnauthorizedClaims);
352+
queryListUsers, optsUnauthorizedClaims);
349353
expect(resp.data.users).to.be.not.empty;
350354
expect(resp.data.users.length).to.be.greaterThan(1);
351355
resp.data.users.forEach((user) => {
@@ -356,7 +360,7 @@ describe('getDataConnect()', () => {
356360
it('executeGraphql() successfully executes an impersonated query with non-existing authenticated claims',
357361
async () => {
358362
const resp = await getDataConnect(connectorConfig).executeGraphql<ListUsersResponse, undefined>(
359-
queryListUsersPublicLevel, optsNonExistingClaims);
363+
queryListUsers, optsNonExistingClaims);
360364
expect(resp.data.users).to.be.not.empty;
361365
expect(resp.data.users.length).to.be.greaterThan(1);
362366
resp.data.users.forEach((user) => {
@@ -367,18 +371,18 @@ describe('getDataConnect()', () => {
367371

368372
describe('NO_ACCESS Auth Policy', () => {
369373
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)
371375
.should.eventually.be.rejected.and.has.property('code', 'data-connect/permission-denied');
372376
});
373377

374378
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)
376380
.should.eventually.be.rejected.and.has.property('code', 'data-connect/permission-denied');
377381
});
378382

379383
it('executeGraphql() should throw for an impersonated query with non-existing authenticated claims',
380384
async () => {
381-
return await getDataConnect(connectorConfig).executeGraphql(queryListEmailsNoAccess, optsNonExistingClaims)
385+
return await getDataConnect(connectorConfig).executeGraphql(queryListEmails, optsNonExistingClaims)
382386
.should.eventually.be.rejected.and.has.property('code', 'data-connect/permission-denied');
383387
});
384388
});

0 commit comments

Comments
 (0)