practicalmeteor/accounts-phony

Name: accounts-phony

Owner: practicalmeteor

Description: A fake login method for use in testing Meteor apps

Created: 2015-06-09 22:53:15.0

Updated: 2015-06-09 22:53:16.0

Pushed: 2015-06-09 23:03:00.0

Homepage: null

Size: 89

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

accounts-phony Build Status

This package can be used to aid in the testing of Meteor apps. It is most useful when you require a user to be logged in, but don't care about details of logging in itself. Note that it does not run on the production server.

How to use

First install the package meteor add csauer:accounts-phony.

You can now use the package like so:

st be accessed this way because it is a debug only package
Phony = Package['csauer:accounts-phony'].Phony;
or.loginWithPhony(Phony.user);

Please note that you can pass any user object in as an argument. The Phony object is exported with a sample user that you can access with Phony.user. This user is created in the database if it does not already exist automatically.

Here's a quick example of how to use this package while testing with the xolvio:cucumber package:

ure: Phony login

enario: User is logged in
Given: I am logged in
Then: I should see my username
avascript
n a step definition file
.Given(/^I am logged in$/, function (callback) {

r login = function(done) {
Meteor.loginWithPhony(Package['csauer:accounts-phony'].Phony.user, function(err,res) {
  done(res);
});


is.browser.
timeoutsAsyncScript(5000).
executeAsync(login, function(err, res) {
  callback();
});

You can also create your own user to log in. For example:

n a step definition file
.Given(/^I am logged in$/, function (callback) {

r login = function(done) {
var fakeUser = {
  _id: "phony-user-id",
  username: "phony-user",
  emails: [ { address: "phony@example.com", verified: true } ],
  createdAt: Date.now(),
  profile: {
    name: "Phony User"
  },
  "services" : {
    "facebook" : {
      "accessToken" : "__fake_token__",
      "expiresAt" : 1438797800881,
      "id" : "__fake_id__",
      "email" : "phony@example.com",
      "name" : "Phony McPhony",
      "first_name" : "Phony",
      "last_name" : "McPhony",
      "link" : "https://www.facebook.com/app_scoped_user_id/__fake_id__/",
      "gender" : "male",
      "locale" : "en_US"
    },
  },
  roles: {
    __global_roles__: ['user']
  }
};
Meteor.loginWithPhony(fakeUser, function(err,res) {
  done(res);
});


is.browser.
timeoutsAsyncScript(5000).
executeAsync(login, function(err, res) {
  callback();
});

Of course you might want to pull that user out into a fixture for cleaner code. You can see that with this method you can integreate accounts-phony with other packages to test all aspects of your code.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.