-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functions: Update firebase-functions dependency
- Loading branch information
Showing
11 changed files
with
83 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import { DocumentSnapshot } from '@google-cloud/firestore'; | ||
import * as functions from 'firebase-functions'; | ||
import { Change, EventContext } from 'firebase-functions'; | ||
import { logger } from 'firebase-functions'; | ||
import { onDocumentWritten } from 'firebase-functions/v2/firestore'; | ||
import { DateTime } from 'luxon'; | ||
import { DEFAULT_REGION } from '../../../../shared/src/firebase'; | ||
import { FirestoreAuditor } from './FirestoreAuditor'; | ||
|
||
/** | ||
* Triggers changes to documents of root collections | ||
*/ | ||
export default functions | ||
// Using v1 functions because tests are not supported with v2 yet: https://github.com/firebase/firebase-functions-test/issues/163 | ||
.region(DEFAULT_REGION) | ||
.firestore.document('{collectionId}/{document=**}') | ||
.onWrite(async (change: Change<DocumentSnapshot>, context: EventContext) => { | ||
const firestoreAuditor = new FirestoreAuditor(); | ||
return firestoreAuditor.auditFirestore(change, DateTime.fromISO(context.timestamp)); | ||
}); | ||
const auditFirestore = onDocumentWritten({ document: '{collectionId}/{document=**}' }, async (event) => { | ||
const firestoreAuditor = new FirestoreAuditor(); | ||
if (!event.data) { | ||
logger.warn('No data in event'); | ||
return; | ||
} | ||
await firestoreAuditor.auditFirestore(event.data, DateTime.fromISO(event.time)); | ||
}); | ||
|
||
export default auditFirestore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import auditCollectionTriggerFunction from './firestore-auditor'; | ||
import auditFirestore from './firestore-auditor'; | ||
|
||
export const auditCollectionTrigger = auditCollectionTriggerFunction; | ||
export const auditCollectionTrigger = auditFirestore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,11 @@ afterEach(async () => { | |
}); | ||
|
||
test('GetPaymentCSV', async () => { | ||
const result = await triggerFunction( | ||
{ type: PaymentProcessTaskType.GetPaymentCSV, timestamp: paymentDate.toSeconds() }, | ||
{ auth: { token: { email: '[email protected]' } } }, | ||
); | ||
const result = await triggerFunction({ | ||
data: { type: PaymentProcessTaskType.GetPaymentCSV, timestamp: paymentDate.toSeconds() }, | ||
// @ts-ignore | ||
auth: { token: { email: '[email protected]' } }, | ||
}); | ||
|
||
const rows = result.split('\n').map((row: string) => row.split(',')); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,11 @@ afterEach(async () => { | |
}); | ||
|
||
test('GetRegistrationCSV', async () => { | ||
const result = await triggerFunction( | ||
{ type: PaymentProcessTaskType.GetRegistrationCSV, timestamp: paymentDate.toSeconds() }, | ||
{ auth: { token: { email: '[email protected]' } } }, | ||
); | ||
const result = await triggerFunction({ | ||
data: { type: PaymentProcessTaskType.GetRegistrationCSV, timestamp: paymentDate.toSeconds() }, | ||
// @ts-ignore | ||
auth: { token: { email: '[email protected]' } }, | ||
}); | ||
|
||
const rows = result.split('\n').map((row: string) => row.split(',')); | ||
expect(rows).toHaveLength(4); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,12 +34,11 @@ afterEach(async () => { | |
}); | ||
|
||
test('CreatePayments', async () => { | ||
const result = await triggerFunction( | ||
{ type: PaymentProcessTaskType.CreatePayments, timestamp: paymentDate.toSeconds() }, | ||
{ | ||
auth: { token: { email: '[email protected]' } }, | ||
}, | ||
); | ||
const result = await triggerFunction({ | ||
data: { type: PaymentProcessTaskType.CreatePayments, timestamp: paymentDate.toSeconds() }, | ||
// @ts-ignore | ||
auth: { token: { email: '[email protected]' } }, | ||
}); | ||
expect(result).toEqual( | ||
'Set status of 3 payments to paid and created 3 payments for next month. Set status to "former" for 0 recipients and status to active for 1 recipients.', | ||
); | ||
|
@@ -81,10 +80,11 @@ test('CreatePayments', async () => { | |
expect(nextPayment.currency).toEqual('SLE'); | ||
} | ||
|
||
const secondExecutionResult = await triggerFunction( | ||
{ type: PaymentProcessTaskType.CreatePayments, timestamp: paymentDate.toSeconds() }, | ||
{ auth: { token: { email: '[email protected]' } } }, | ||
); | ||
const secondExecutionResult = await triggerFunction({ | ||
data: { type: PaymentProcessTaskType.CreatePayments, timestamp: paymentDate.toSeconds() }, | ||
// @ts-ignore | ||
auth: { token: { email: '[email protected]' } }, | ||
}); | ||
expect(secondExecutionResult).toEqual( | ||
'Set status of 0 payments to paid and created 0 payments for next month. Set status to "former" for 0 recipients and status to active for 0 recipients.', | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.