【发布时间】:2017-09-20 03:41:43
【问题描述】:
我打算编写一个 Firebase 数据库触发器。我的用例非常简单。每当 Facebook messenger webhook 调用 database 更新用户短信并使用 Firebase 数据库触发器从 AI 获取消息并返回给 messenger。
现在我的 Firebase 数据库触发器无法正常工作。即使我的测试用例都通过了。
myapp
|_ messages
|__ 432423423423
|__ 32432432432423
|__ owrijrw8hy2487hf34
|_ recipient: "45354353"
|_ sender: "422342342"
|_ text: "this is text"
现在我想使用 firebase 数据库触发器向用户发送消息。
// Realtime Database triggers
exports.facebookMessage = functions.database.ref('/messages/{pageID}/{userID}')
.onCreate(event => {
console.log(event)
return;
})
/test.js
describe('Database /messages/{pageID}/{userID}', () => {
it('Should trigger when the message write it t', () => {
pushParam = {
text: 'Hello',
sender: 'USER_ID',
recipient: 'PAGE_ID',
timestamp: 1458692752478
}
// Firebase database fake event
const fakeEvent = {
// DeltaSnapshot(app: firebase.app.App, adminApp: firebase.app.App, data: any, delta: any, path?: string);
data: new functions.database.DeltaSnapshot(null, null, null, pushParam),
params: {
pageID: 'PAGE_ID',
userID: 'USER_ID'
}
}
// Stub data reference
refParam = '/messages/'
childPageParam = 'PAGE_ID'
childUserParam = 'USER_ID'
// Stubs are objects that fake and/or record function calls.
// These are excellent for verifying that functions have been called and to validate the
// parameters passed to those functions.
const refStub = sinon.stub()
const childPageStub = sinon.stub()
const childUserStub = sinon.stub()
const pushStub = sinon.stub()
Object.defineProperty(fakeEvent.data, 'ref', {get: refStub})
refStub.returns({parent: {child: childPageStub}})
childPageStub.returns({parent: {child: childUserStub}})
childUserStub.returns({push: pushStub})
pushStub.withArgs(pushParam).returns(true)
return assert.eventually.equal(fiobotFunctions.facebookMessage(fakeEvent), undefined);
在控制台中我没有看到来自 facebookMessage 的任何日志我现在该怎么办?
【问题讨论】:
-
对我来说看起来像是相当复杂的 JavaScript。尊敬的,您可能想从基础开始。
-
我正在学习 Ron,尽管这是我完全使用 firebase 并且完全不使用 python 的第一个项目。 :)
-
坚持下去,罗!你可以做到。
标签: javascript firebase firebase-realtime-database