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