Last active
August 29, 2015 14:01
-
-
Save kgarfinkel/14b48d1c144491a4a1a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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