Does anyone have any example test code of how to either create a test user record and login as them in a meteor client test, or to mock a logged in user that corresponds with a mock record in the test database? I see examples for “login with password” but my project does not use accounts-password. I’m using Mocha as my testing framework but I’ll take any framework example I can get.
How do you login? GitHub? Twitter?
Logging in using the accounts-google
package.
You may want to take a look at Avital’s e2e package, which uses mocha to run the core OAuth tests. It’s the closest thing that I know of to what you’re looking for, since it does the actual core testing for the accounts-google
package.
I started work on a community-use branch in a separate fork that makes it a bit easier to use for more general OAuth testing. The community-use branch can now be run as a stand alone utility, has some extra environment variables you can set, can run against urls other than rainforest.meteor.com, etc.
I’ve written a Github stub and a Twitter stub, both of which are packages you install to get OAuth testing stubs. You can see them here
One of them uses OAuth1 flow and the other uses OAuth2
I would be happy to help you in creating a meteor-google-stub, it will likely be similar to the github. Could you tell me a little more about your use case? specifically, what your test looks like
@mark It’s worth noting that the E2E work that the MDG will not help you. They did the following:
- Created a test-driving app called rainforrest that is deployed on meteor.com
- Put all the accounts on it (twitter/github etc)
- Used a custom mocha + selenium combination to exercise the test app by looping over each account type and testing it
None of the above is suited for the integration testing you asked for. If you want to “create a test user record and login as them in a meteor client test” or “mock a logged in user that corresponds with a mock record in the test database” you’ll need to use a stub solution. Let me see if I can knock a google authenticator for you in the next few days. I’m going to need it anyway for my book
@sam I’ve got a working google-fake based on github-fake.
edit, here it is: https://github.com/emmerge/meteor-google-fake
Question: I’m writing a test for meteor-google-fake
but the test that clicks the login button fails with ReferenceError: Can't find variable: URL
. It appears that PhantomJS does not have the URL function. Suggestions to workaround?
Edit: Note that tests work 100% when running in Velocity Html Reporter but fail when running meteor --test
Workable solution: Made some plain js to manipulate the url string if URL is not defined. See here: https://github.com/emmerge/meteor-google-fake/commit/ed56c88f75df2434c442944e7ee6413bdc9729fb
Feel free to steal that for other fakes @sam
Did you ever find a good way to do this?
Try here