Added tests for Facebook auth

This commit is contained in:
Keith Holliday
2016-07-27 14:27:21 -05:00
parent 9d4fa6fd4e
commit e6dd8cc03a
3 changed files with 66 additions and 3 deletions

View File

@@ -0,0 +1,59 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import passport from 'passport';
describe('POST /user/auth/social', () => {
let api;
let user;
let endpoint = '/user/auth/social';
let randomAccessToken = '123456';
let facebookId = 'facebookId';
let network = 'facebook';
before(async () => {
api = requester();
user = await generateUser();
let expectedResult = {id: facebookId};
let passportFacebookProfile = sinon.stub(passport._strategies.facebook, 'userProfile');
passportFacebookProfile.yields(null, expectedResult);
});
it('fails if network is not facebook', async () => {
await expect(api.post(endpoint, {
authResponse: {access_token: randomAccessToken},
network: 'NotFacebook',
})).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('onlyFbSupported'),
});
});
it('registers a new user', async () => {
let response = await api.post(endpoint, {
authResponse: {access_token: randomAccessToken},
network,
});
expect(response.apiToken).to.exist;
expect(response.id).to.exist;
expect(response.newUser).to.be.true;
});
it('logs an existing user in', async () => {
await user.update({ 'auth.facebook.id': facebookId });
let response = await api.post(endpoint, {
authResponse: {access_token: randomAccessToken},
network,
});
expect(response.apiToken).to.eql(user.apiToken);
expect(response.id).to.eql(user._id);
expect(response.newUser).to.be.false;
});
});