hwillson / meteor-stub-collections

Stub out Meteor collections with in-memory local collections.
MIT License
24 stars 17 forks source link

Work with aldeed:collection2 #12

Open eric-burel opened 7 years ago

eric-burel commented 7 years ago

Hi,

This issue may refer to #8 , however I open a new one here since it seems to be a different issue.

I am using aldeed:simple-schema together with aldeed:collection2. Here is a piece of test I created:

 it("Should create a clean UserState object on signup", function(){
      const userId = Meteor.call('user.signup', dummyUser.email, dummyUser.password)
      const userState = UserState.findOne({userId})

      assert.deepEqual(userState, UserState.schema.clean({userId}))
    })

UserState collection has been stubbed, and the idea of the test is that the userState object in the stub collection should have been created and cleaned. However it is not, and userState equals {userId:"foobar"} where it should equal something similar to {userId:"foobar", someAutoGeneratedValue: {...} }. It seems that collection2 is not applied on the stubbed collection. When I don't stub the collection, my test is passing as simple-schema clean method is applied thanks to collection2.

Is that an expected behaviour ? The problem is that I use collection2 to auto generate some value. I can't apply clean manually to my object inside my test, since I am testing the method that wraps the insert call.

Thanks !

thebarty commented 7 years ago

same question here - any answers?

Check out this topic https://github.com/hwillson/meteor-stub-collections/issues/14

hwillson commented 7 years ago

Hi guys - I've been a bit swamped on other things lately; I'll try to look at this (and the other outstanding issues) shortly, but in the meantime, I love PR's. 🙂 If you have a chance to take a look at this yourself, and can supply a fix (with tests), that would be awesome! Thanks - and sorry for the delay!

Floriferous commented 6 years ago

Wow, it took me a while to identify this package as the one preventing simple schema and collection2 to do their job.

This does not stub (without errors):

    StubCollections.add(Collection);
    StubCollections.stub();

This does stub:

    StubCollections.add([Collection]);
    StubCollections.stub();

And weirdly, this does stub too:

    StubCollections.stub(Collection);

Whereas this is the documented variant (which obviously works):

    StubCollections.stub([Collection]);

Maybe it would be helpful to clarify that stub() can take a single collection, but add() can't ? (Or maybe something else is happening that I don't understand)

hwillson commented 6 years ago

@Floriferous I've merged your PR (https://github.com/hwillson/meteor-stub-collections/pull/18), so that should help with this issue. I'm publishing a new version later today - thanks!

Floriferous commented 6 years ago

This issue should actually be reopened, #18 did not address the fact that this library still does not cooperate with simple schema and collection2.

hwillson commented 5 years ago

Thanks @Floriferous - re-opening.

jankapunkt commented 2 years ago

In case this is still of interest to people, I opened a PR for this: https://github.com/hwillson/meteor-stub-collections/pull/38