Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work with aldeed:collection2 #12

Open
eric-burel opened this issue Nov 10, 2016 · 7 comments
Open

Work with aldeed:collection2 #12

eric-burel opened this issue Nov 10, 2016 · 7 comments

Comments

@eric-burel
Copy link

eric-burel commented Nov 10, 2016

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
Copy link

thebarty commented Feb 15, 2017

same question here - any answers?

Check out this topic #14

@hwillson
Copy link
Owner

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
Copy link
Contributor

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
Copy link
Owner

@Floriferous I've merged your PR (#18), so that should help with this issue. I'm publishing a new version later today - thanks!

@Floriferous
Copy link
Contributor

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
Copy link
Owner

Thanks @Floriferous - re-opening.

@jankapunkt
Copy link

In case this is still of interest to people, I opened a PR for this: #38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants