mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Handle social auth in A/B testing (#8024)
* fix(AB-testing): handle social auth * refactor(AB-testing): move to pre save hooks
This commit is contained in:
committed by
Matteo Pagliazzi
parent
81b7eeeb71
commit
86c9bddc09
@@ -2,6 +2,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
|
getProperty,
|
||||||
} from '../../../../../helpers/api-integration/v3';
|
} from '../../../../../helpers/api-integration/v3';
|
||||||
import passport from 'passport';
|
import passport from 'passport';
|
||||||
|
|
||||||
@@ -44,6 +45,15 @@ describe('POST /user/auth/social', () => {
|
|||||||
expect(response.newUser).to.be.true;
|
expect(response.newUser).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('enrolls a new user in an A/B test', async () => {
|
||||||
|
await api.post(endpoint, {
|
||||||
|
authResponse: {access_token: randomAccessToken}, // eslint-disable-line camelcase
|
||||||
|
network,
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(getProperty('users', user._id, '_ABtest')).to.eventually.be.a('string');
|
||||||
|
});
|
||||||
|
|
||||||
it('logs an existing user in', async () => {
|
it('logs an existing user in', async () => {
|
||||||
await user.update({ 'auth.facebook.id': facebookId });
|
await user.update({ 'auth.facebook.id': facebookId });
|
||||||
|
|
||||||
|
|||||||
@@ -130,14 +130,6 @@ api.registerLocal = {
|
|||||||
newUser.registeredThrough = req.headers['x-client']; // Not saved, used to create the correct tasks based on the device used
|
newUser.registeredThrough = req.headers['x-client']; // Not saved, used to create the correct tasks based on the device used
|
||||||
}
|
}
|
||||||
|
|
||||||
// A/B Test 2016-09-12: Start with Sound Enabled?
|
|
||||||
if (Math.random() < 0.5) {
|
|
||||||
newUser.preferences.sound = 'rosstavoTheme';
|
|
||||||
newUser._ABtest = '20160912-soundEnabled';
|
|
||||||
} else {
|
|
||||||
newUser._ABtest = '20160912-soundDisabled';
|
|
||||||
}
|
|
||||||
|
|
||||||
// we check for partyInvite for backward compatibility
|
// we check for partyInvite for backward compatibility
|
||||||
if (req.query.groupInvite || req.query.partyInvite) {
|
if (req.query.groupInvite || req.query.partyInvite) {
|
||||||
await _handleGroupInvitation(newUser, req.query.groupInvite || req.query.partyInvite);
|
await _handleGroupInvitation(newUser, req.query.groupInvite || req.query.partyInvite);
|
||||||
|
|||||||
@@ -73,10 +73,18 @@ function _populateDefaultTasks (user, taskTypes) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function _populateDefaultsForNewUser (user) {
|
function _setUpNewUser (user) {
|
||||||
let taskTypes;
|
let taskTypes;
|
||||||
let iterableFlags = user.flags.toObject();
|
let iterableFlags = user.flags.toObject();
|
||||||
|
|
||||||
|
// A/B Test 2016-09-12: Start with Sound Enabled?
|
||||||
|
if (Math.random() < 0.5) {
|
||||||
|
user.preferences.sound = 'rosstavoTheme';
|
||||||
|
user._ABtest = '20160912-soundEnabled';
|
||||||
|
} else {
|
||||||
|
user._ABtest = '20160912-soundDisabled';
|
||||||
|
}
|
||||||
|
|
||||||
if (user.registeredThrough === 'habitica-web' || user.registeredThrough === 'habitica-android') {
|
if (user.registeredThrough === 'habitica-web' || user.registeredThrough === 'habitica-android') {
|
||||||
taskTypes = ['habit', 'daily', 'todo', 'reward', 'tag'];
|
taskTypes = ['habit', 'daily', 'todo', 'reward', 'tag'];
|
||||||
|
|
||||||
@@ -158,7 +166,7 @@ schema.pre('save', true, function preSaveUser (next, done) {
|
|||||||
|
|
||||||
// Populate new users with default content
|
// Populate new users with default content
|
||||||
if (this.isNew) {
|
if (this.isNew) {
|
||||||
_populateDefaultsForNewUser(this)
|
_setUpNewUser(this)
|
||||||
.then(() => done())
|
.then(() => done())
|
||||||
.catch(done);
|
.catch(done);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user