mirror of
https://github.com/HabitRPG/habitica.git
synced 2026-05-03 11:31:13 -05:00
update social tests
This commit is contained in:
+1
-1
Submodule habitica-images updated: 1c6f7d65d7...aa72332019
@@ -7,7 +7,7 @@ import {
|
||||
getProperty,
|
||||
} from '../../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('POST /user/auth/social', () => {
|
||||
describe.only('POST /user/auth/social', () => {
|
||||
let api;
|
||||
let user;
|
||||
const endpoint = '/user/auth/social';
|
||||
@@ -64,6 +64,18 @@ describe('POST /user/auth/social', () => {
|
||||
await expect(getProperty('users', response.id, 'profile.name')).to.eventually.equal('a google user');
|
||||
});
|
||||
|
||||
it('fails if allowRegister is false and user does not exist', async () => {
|
||||
await expect(api.post(endpoint, {
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
allowRegister: false,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('userNotFound'),
|
||||
});
|
||||
});
|
||||
|
||||
it('logs an existing user in', async () => {
|
||||
const registerResponse = await api.post(endpoint, {
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
@@ -131,6 +143,36 @@ describe('POST /user/auth/social', () => {
|
||||
expect(response.newUser).to.be.false;
|
||||
});
|
||||
|
||||
it('logs an existing user into their social account if allowRegister is false', async () => {
|
||||
const registerResponse = await api.post(endpoint, {
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
});
|
||||
expect(registerResponse.newUser).to.be.true;
|
||||
// This is important for existing accounts before the new social handling
|
||||
passport._strategies.google.userProfile.restore();
|
||||
const expectedResult = {
|
||||
id: randomGoogleId,
|
||||
displayName: 'a google user',
|
||||
emails: [
|
||||
{ value: user.auth.local.email },
|
||||
],
|
||||
};
|
||||
sandbox.stub(passport._strategies.google, 'userProfile').yields(null, expectedResult);
|
||||
|
||||
const response = await api.post(endpoint, {
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
allowRegister: false,
|
||||
});
|
||||
|
||||
expect(response.apiToken).to.eql(registerResponse.apiToken);
|
||||
expect(response.id).to.eql(registerResponse.id);
|
||||
expect(response.apiToken).not.to.eql(user.apiToken);
|
||||
expect(response.id).not.to.eql(user._id);
|
||||
expect(response.newUser).to.be.false;
|
||||
});
|
||||
|
||||
it('add social auth to an existing user', async () => {
|
||||
const response = await user.post(endpoint, {
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import passport from 'passport';
|
||||
import common from '../../../common';
|
||||
import { BadRequest, NotAuthorized } from '../errors';
|
||||
import { BadRequest, NotAuthorized, NotFound } from '../errors';
|
||||
import logger from '../logger';
|
||||
import {
|
||||
generateUsername,
|
||||
@@ -75,7 +75,7 @@ export async function loginSocial (req, res) { // eslint-disable-line import/pre
|
||||
}
|
||||
|
||||
if (!allowRegister) {
|
||||
return res.respond(404, {});
|
||||
throw new NotFound(res.t('userNotFound'));
|
||||
}
|
||||
|
||||
let email;
|
||||
|
||||
Reference in New Issue
Block a user