Skip to content

Instantly share code, notes, and snippets.

@kgarfinkel
Last active August 29, 2015 14:01
Show Gist options
  • Save kgarfinkel/14b48d1c144491a4a1a8 to your computer and use it in GitHub Desktop.
Save kgarfinkel/14b48d1c144491a4a1a8 to your computer and use it in GitHub Desktop.
// Sign a user in
signin: function (user, callback) {
var self = this,
attributes = { 'sessionId': 'foobar' };
if (typeof(user) == 'function') {
callback = user;
}
else if (typeof(user) == 'object') {
this.user = user;
}
if (typeof callback != 'function') {
throw new Error('Signing in needs a callback!');
}
if (!this.user.api_id) {
throw new Error('Need an API ID to signin a user');
}
attributes.user = apiUsers[this.user.api_id];
attributes.user.orgs = [{
orgName: 'testOrg',
title: 'testOrgs',
id: '123'
}];
sinon.stub(api.User.prototype, 'signin')
.yieldsTo('success', attributes);
sinon.stub(api.User.prototype, 'fetch')
.yieldsTo('success', new api.User(attributes), attributes);
this.request('post', '/signin')
.send(this.user)
.expect(200)
.end(function (err, res) {
(err === null).should.be.true;
api.User.prototype.signin.restore();
api.User.prototype.fetch.restore();
callback(err, res);
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment