mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Drop Cap A/B Tests: v2 (#12759)
* drop cap ab test: enroll all web users, 50/50 * update tests * fix lint
This commit is contained in:
@@ -311,25 +311,8 @@ describe('cron middleware', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not enroll 50% of users', async () => {
|
it('enables the new notification for 50% of users', async () => {
|
||||||
sandbox.stub(Math, 'random').returns(0.6);
|
sandbox.stub(Math, 'random').returns(0.5);
|
||||||
user.lastCron = moment(new Date()).subtract({ days: 2 });
|
|
||||||
await user.save();
|
|
||||||
req.headers['x-client'] = 'habitica-web';
|
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
cronMiddleware(req, res, async err => {
|
|
||||||
if (err) return reject(err);
|
|
||||||
user = await User.findById(user._id).exec();
|
|
||||||
expect(user._ABtests.dropCapNotif).to.be.equal('drop-cap-notif-not-enrolled');
|
|
||||||
|
|
||||||
return resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('enables the new notification for 25% of users', async () => {
|
|
||||||
sandbox.stub(Math, 'random').returns(0.25);
|
|
||||||
user.lastCron = moment(new Date()).subtract({ days: 2 });
|
user.lastCron = moment(new Date()).subtract({ days: 2 });
|
||||||
await user.save();
|
await user.save();
|
||||||
req.headers['x-client'] = 'habitica-web';
|
req.headers['x-client'] = 'habitica-web';
|
||||||
@@ -345,8 +328,8 @@ describe('cron middleware', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('disables the new notification for 25% of users', async () => {
|
it('disables the new notification for 50% of users', async () => {
|
||||||
sandbox.stub(Math, 'random').returns(0.5);
|
sandbox.stub(Math, 'random').returns(0.51);
|
||||||
user.lastCron = moment(new Date()).subtract({ days: 2 });
|
user.lastCron = moment(new Date()).subtract({ days: 2 });
|
||||||
await user.save();
|
await user.save();
|
||||||
req.headers['x-client'] = 'habitica-web';
|
req.headers['x-client'] = 'habitica-web';
|
||||||
|
|||||||
@@ -464,12 +464,8 @@ async function scoreTask (user, task, direction, req, res) {
|
|||||||
user,
|
user,
|
||||||
});
|
});
|
||||||
|
|
||||||
const isEnrolledInDropCapTest = user._ABtests.dropCapNotif
|
|
||||||
&& user._ABtests.dropCapNotif !== 'drop-cap-notif-not-enrolled';
|
|
||||||
|
|
||||||
// Track when new users (first 7 days) score tasks
|
// Track when new users (first 7 days) score tasks
|
||||||
// or if they're enrolled in the Drop Cap A/B Test
|
if (moment().diff(user.auth.timestamps.created, 'days') < 7) {
|
||||||
if (moment().diff(user.auth.timestamps.created, 'days') < 7 || isEnrolledInDropCapTest) {
|
|
||||||
res.analytics.track('task score', {
|
res.analytics.track('task score', {
|
||||||
uuid: user._id,
|
uuid: user._id,
|
||||||
hitType: 'event',
|
hitType: 'event',
|
||||||
|
|||||||
@@ -534,13 +534,11 @@ schema.methods.enrollInDropCapABTest = function enrollInDropCapABTest (xClientHe
|
|||||||
|
|
||||||
if (isWeb && !this._ABtests.dropCapNotif && !this.isSubscribed()) {
|
if (isWeb && !this._ABtests.dropCapNotif && !this.isSubscribed()) {
|
||||||
const testGroup = Math.random();
|
const testGroup = Math.random();
|
||||||
// Enroll 20% of users, splitting them 50/50
|
// Enroll 100% of users, splitting them 50/50
|
||||||
if (testGroup <= 0.25) {
|
if (testGroup <= 0.50) {
|
||||||
this._ABtests.dropCapNotif = 'drop-cap-notif-enabled';
|
this._ABtests.dropCapNotif = 'drop-cap-notif-enabled';
|
||||||
} else if (testGroup <= 0.5) {
|
|
||||||
this._ABtests.dropCapNotif = 'drop-cap-notif-disabled';
|
|
||||||
} else {
|
} else {
|
||||||
this._ABtests.dropCapNotif = 'drop-cap-notif-not-enrolled';
|
this._ABtests.dropCapNotif = 'drop-cap-notif-disabled';
|
||||||
}
|
}
|
||||||
this.markModified('_ABtests');
|
this.markModified('_ABtests');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user