Publication unit testing


#1

Hi All,
I’m reading the testing guide and there is a section there about unit testing a publication.
It’s not very clear to me what are the use cases for testing a publication.
I can’t really image a test, which doesn’t only test the internal implementation of the publication, and not an app logic. In that case this is not a good unit test…
An example for that is the publication unit testing of the default “links” app of meteor.

I would love to be hear/referenced to examples which unit testing a publication is actually testing an app logic.


#2

I tend to agree that many tests I’ve seen as examples basically just repeat the tests that MDG do when releasing updates - does all the wiring continue to work?

Business test cases are few and far between and as far as publications are concerned don’t fall into the “if I publish A, do I get A when I subscribe?” category.


#3

I agree, this why I think I would only write unit test for publication that implement business logic (which is probably be never).
Thanks


#4

I’m unit testing publications to make sure they do things like only send data for the current user or was shared with the current user, that it doesn’t send anything when the user is not logged in.

They end up being simple, because my logic is simple, but that also makes them easy to add, so it’s still worth doing


#5

That’s a good use case, but I think it’s more of an integration test.


#6

“–full-app” will load all your publication

you can import collection which you want to test, then write test like what an user do normally.

like

  1. Meteor.loginWith user
  2. subscribe your publication
  3. test if collection has the data that u have sent with 2

same thing apply to meteor.methods

u don’t have to simulate userId to test from server side


#7

On my publications I sometimes have search parms and limit I wanna make sure behave properly.

Also if you have publications that return more interesting stuff like contents of a folder or read other collections to feed ‘in’ statements to filter your main data source it becomes important to test them.