mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +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,
|
||||
requester,
|
||||
translate as t,
|
||||
getProperty,
|
||||
} from '../../../../../helpers/api-integration/v3';
|
||||
import passport from 'passport';
|
||||
|
||||
@@ -44,6 +45,15 @@ describe('POST /user/auth/social', () => {
|
||||
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 () => {
|
||||
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
|
||||
}
|
||||
|
||||
// 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
|
||||
if (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 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') {
|
||||
taskTypes = ['habit', 'daily', 'todo', 'reward', 'tag'];
|
||||
|
||||
@@ -158,7 +166,7 @@ schema.pre('save', true, function preSaveUser (next, done) {
|
||||
|
||||
// Populate new users with default content
|
||||
if (this.isNew) {
|
||||
_populateDefaultsForNewUser(this)
|
||||
_setUpNewUser(this)
|
||||
.then(() => done())
|
||||
.catch(done);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user