soumak77 / firebase-mock

Firebase mock library for writing unit tests
https://soumak77.github.io/firebase-mock
349 stars 97 forks source link

Add support for messaging in Admin SDK #164

Open raman-nbg opened 4 years ago

raman-nbg commented 4 years ago

Currently Firebase messaging in the admin SDK is not supported. Are there any plans to add support for this?

In my case I need to test/mock multicast message (sendMulticast()).

dmurvihill commented 4 years ago

Hi @raman-nbg, any good PR to add support for mocking Firebase messaging in the admin SDK would be gladly accepted! Cheers.

raman-nbg commented 4 years ago

Ok, going to try this.

But one question about the implementation:

Messaging.send(message) (https://firebase.google.com/docs/reference/admin/node/admin.messaging.Messaging.html#send) takes a message as an argument. Should I validate this message according to https://firebase.google.com/docs/reference/admin/node/TokenMessage.html?

raman-nbg commented 4 years ago

Or should I implement it like described in erros.md?

dmurvihill commented 4 years ago

Anyone else interested in mocking admin FCM? @op? If so, I'd love to get your opinion.

Unless it makes a big difference in your workflow, @raman-nbg, I'd suggest preserving the pattern from errors.md and not bother with validating the message.

Note that the message will be a Message instance and not necessarily a TokenMessage!

dmurvihill commented 4 years ago

One more thing: we are migrating away from this repo in the near future; for now, if you could open your PR against https://github.com/dmurvihill/firebase-mock/, I will be publishing from there.

raman-nbg commented 4 years ago

Created PR: https://github.com/dmurvihill/firebase-mock/pull/43

raman-nbg commented 4 years ago

In the implementation you can see, that this is one is very simple. Messaging is stateless (send message, get result and forget about it) but the other components like firestore are stateful.

Messaging could also be mocked easily using sinon. But I think we should still add this feature. It's more convenient to have the same test behaviour for all firebase components.

raman-nbg commented 4 years ago

The change is arleady merged into master, but not release yet. Is there any plan to release a new version soon?

mull commented 3 years ago

Ping!