|
1 | 1 | import * as functions from 'firebase-functions'; |
2 | 2 | import { TestSuite, expectEq } from './testing'; |
| 3 | +import * as admin from 'firebase-admin'; |
| 4 | +import UserMetadata = admin.auth.UserRecord; |
3 | 5 |
|
4 | | -export const createUserTests: any = functions.auth.user().onCreate(receivedEvent => { |
5 | | - let user = receivedEvent.data; |
6 | | - let testId: string = user.displayName; |
| 6 | +export const createUserTests: any = functions.auth.user().onCreate((u, c) => { |
| 7 | + let testId: string = u.displayName; |
7 | 8 | console.log(`testId is ${testId}`); |
8 | 9 |
|
9 | | - return new TestSuite('auth user onCreate') |
10 | | - .it('should have a project as resource', event => expectEq( |
11 | | - event.resource, `projects/${process.env.GCLOUD_PROJECT}`)) |
| 10 | + return new TestSuite<UserMetadata>('auth user onCreate') |
| 11 | + .it('should have a project as resource', (user, context) => expectEq( |
| 12 | + context.resource, `projects/${process.env.GCLOUD_PROJECT}`)) |
12 | 13 |
|
13 | | - .it('should not have a path', event => expectEq(event.path, undefined)) |
| 14 | + .it('should not have a path', (user, context) => expectEq((context as any).path, undefined)) |
14 | 15 |
|
15 | | - .it('should have the correct eventType', event => expectEq( |
16 | | - event.eventType, 'providers/firebase.auth/eventTypes/user.create')) |
| 16 | + .it('should have the correct eventType', (user, context) => expectEq( |
| 17 | + context.eventType, 'providers/firebase.auth/eventTypes/user.create')) |
17 | 18 |
|
18 | | - .it('should have an eventId', event => event.eventId) |
| 19 | + .it('should have an eventId', (user, context)=> context.eventId) |
19 | 20 |
|
20 | | - .it('should have a timestamp', event => event.timestamp) |
| 21 | + .it('should have a timestamp', (user, context) => context.timestamp) |
21 | 22 |
|
22 | | - .it('should not have auth', event => expectEq(event.auth, undefined)) |
| 23 | + .it('should not have auth', (user, context) => expectEq((context as any).auth, undefined)) |
23 | 24 |
|
24 | | - .it('should not have action', event => expectEq(event.action, undefined)) |
| 25 | + .it('should not have action', (user, context) => expectEq((context as any).action, undefined)) |
25 | 26 |
|
26 | | - .run(testId, receivedEvent); |
| 27 | + .run(testId, u, c); |
27 | 28 | }); |
28 | 29 |
|
29 | | -export const deleteUserTests: any = functions.auth.user().onDelete(receivedEvent => { |
30 | | - let user = receivedEvent.data; |
31 | | - let testId: string = user.displayName; |
| 30 | +export const deleteUserTests: any = functions.auth.user().onDelete((u, c) => { |
| 31 | + let testId: string = u.displayName; |
32 | 32 | console.log(`testId is ${testId}`); |
33 | 33 |
|
34 | | - return new TestSuite('auth user onDelete') |
35 | | - .it('should have a project as resource', event => expectEq( |
36 | | - event.resource, `projects/${process.env.GCLOUD_PROJECT}`)) |
| 34 | + return new TestSuite<UserMetadata>('auth user onDelete') |
| 35 | + .it('should have a project as resource', (user, context) => expectEq( |
| 36 | + context.resource, `projects/${process.env.GCLOUD_PROJECT}`)) |
37 | 37 |
|
38 | | - .it('should not have a path', event => expectEq(event.path, undefined)) |
| 38 | + .it('should not have a path', (user, context) => expectEq((context as any).path, undefined)) |
39 | 39 |
|
40 | | - .it('should have the correct eventType', event => expectEq( |
41 | | - event.eventType, 'providers/firebase.auth/eventTypes/user.delete')) |
| 40 | + .it('should have the correct eventType', (user, context) => expectEq( |
| 41 | + context.eventType, 'providers/firebase.auth/eventTypes/user.delete')) |
42 | 42 |
|
43 | | - .it('should have an eventId', event => event.eventId) |
| 43 | + .it('should have an eventId', (user, context) => context.eventId) |
44 | 44 |
|
45 | | - .it('should have a timestamp', event => event.timestamp) |
| 45 | + .it('should have a timestamp', (user, context) => context.timestamp) |
46 | 46 |
|
47 | | - .it('should not have auth', event => expectEq(event.auth, undefined)) |
| 47 | + .it('should not have auth', (user, context) => expectEq((context as any).auth, undefined)) |
48 | 48 |
|
49 | | - .it('should not have action', event => expectEq(event.action, undefined)) |
| 49 | + .it('should not have action', (user, context) => expectEq((context as any).action, undefined)) |
50 | 50 |
|
51 | | - .run(testId, receivedEvent); |
| 51 | + .run(testId, u, c); |
52 | 52 | }); |
0 commit comments