-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add node8 firebase snippets * Address sam's comments * Add (unit) tests for Firebase snippets * Move deps to devDeps * Fix quotes
- Loading branch information
Ace Nassri
authored
Aug 27, 2018
1 parent
ce721d6
commit 7c53c42
Showing
3 changed files
with
146 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Copyright 2018, Google LLC. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const uuid = require('uuid'); | ||
const test = require('ava'); | ||
const utils = require('@google-cloud/nodejs-repo-tools'); | ||
|
||
const program = require('../'); | ||
|
||
test.beforeEach(utils.stubConsole); | ||
test.afterEach.always(utils.restoreConsole); | ||
|
||
test.serial('should monitor Firebase RTDB', t => { | ||
const dataId = uuid.v4(); | ||
const resourceId = uuid.v4(); | ||
|
||
const data = { | ||
admin: true, | ||
delta: { | ||
id: dataId | ||
} | ||
}; | ||
const context = { | ||
resource: resourceId | ||
}; | ||
|
||
program.helloRTDB(data, context); | ||
|
||
t.true(console.log.firstCall.args[0].includes(resourceId)); | ||
t.deepEqual(console.log.secondCall.args, ['Admin?: true']); | ||
t.true(console.log.getCall(3).args[0].includes(dataId)); | ||
}); | ||
|
||
test.serial('should monitor Firestore', t => { | ||
const resourceId = uuid.v4(); | ||
|
||
const context = { | ||
resource: resourceId | ||
}; | ||
const data = { | ||
oldValue: { uuid: uuid.v4() }, | ||
value: { uuid: uuid.v4() } | ||
}; | ||
|
||
program.helloFirestore(data, context); | ||
|
||
t.true(console.log.firstCall.args[0].includes(resourceId)); | ||
t.true(console.log.calledWith(JSON.stringify(data.oldValue, null, 2))); | ||
t.true(console.log.calledWith(JSON.stringify(data.value, null, 2))); | ||
}); | ||
|
||
test.serial('should monitor Auth', t => { | ||
const userId = uuid.v4(); | ||
const dateString = (new Date()).toISOString(); | ||
const emailString = `${uuid.v4()}@${uuid.v4()}.com`; | ||
|
||
const data = { | ||
uid: userId, | ||
metadata: { | ||
createdAt: dateString | ||
}, | ||
email: emailString | ||
}; | ||
|
||
program.helloAuth(data, null); | ||
|
||
t.true(console.log.firstCall.args[0].includes(userId)); | ||
t.true(console.log.secondCall.args[0].includes(dateString)); | ||
t.true(console.log.thirdCall.args[0].includes(emailString)); | ||
}); |