mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 05:37:22 +01:00
Upgrade tests tools and lint migrations and scripts (part 2) (#9998)
* upgrade gulp-babel * upgrade babel-eslint * upgrade eslint-friendly-formatter * start upgrading chai * start to upgrade eslint * restore skipped tests * start to upgrqde monk * fix linting and remove unused file * fix mocha notifications, and common tests * fix unit tests * start to fix initrgration tests * more integration tests fixes * upgrade monk to latest version * lint /scripts * migrations: start moving to /archive unused migrations and run eslint with --fix * lint migrations * fix more integration tests * fix test
This commit is contained in:
10
migrations/command-line/.eslintrc
Normal file
10
migrations/command-line/.eslintrc
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"root": false,
|
||||
"globals": {
|
||||
"db": true,
|
||||
"moment": true,
|
||||
"print": true,
|
||||
"printjson": true,
|
||||
"_": true,
|
||||
},
|
||||
}
|
||||
1
migrations/command-line/apology_gems.js
Normal file
1
migrations/command-line/apology_gems.js
Normal file
@@ -0,0 +1 @@
|
||||
db.users.update({_id: {$in: ['']}}, {$inc: {balance: 0.5}}, {multi: true});
|
||||
11
migrations/command-line/cancelSubscription.js
Normal file
11
migrations/command-line/cancelSubscription.js
Normal file
@@ -0,0 +1,11 @@
|
||||
// mongo habitrpg ./node_modules/moment/moment.js ./migrations/cancelSubscription.js
|
||||
|
||||
// For some reason people often to contact me to cancel their sub, rather than do it online. Even when I point them to
|
||||
// the FAQ (http://goo.gl/1uoPGQ) they insist...
|
||||
|
||||
db.users.update(
|
||||
{_id: ''},
|
||||
{$set: {
|
||||
'purchased.plan.dateTerminated': moment().add('month', 1).toDate(),
|
||||
}}
|
||||
);
|
||||
23
migrations/command-line/contribs_plan.js
Normal file
23
migrations/command-line/contribs_plan.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// Give contrib.level 7+ free subscription for life
|
||||
db.users.update(
|
||||
|
||||
{
|
||||
'contributor.level': {$gte: 7},
|
||||
'purchased.plan.customerId': null,
|
||||
},
|
||||
|
||||
{
|
||||
$set: {
|
||||
'purchased.plan': {
|
||||
planId: 'basic',
|
||||
customerId: 'habitrpg',
|
||||
dateCreated: new Date(),
|
||||
dateUpdated: new Date(),
|
||||
gemsBought: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{multi: true}
|
||||
|
||||
);
|
||||
5
migrations/command-line/current_period_end.js
Normal file
5
migrations/command-line/current_period_end.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// mongo habitrpg ./node_modules/moment/moment.js ./migrations/current_period_end.js
|
||||
db.users.update(
|
||||
{_id: ''},
|
||||
{$set: {'purchased.plan.dateTerminated': moment().add({days: 7}).toDate()}}
|
||||
);
|
||||
88
migrations/command-line/duplicatedTasksFindAndRemove.js
Normal file
88
migrations/command-line/duplicatedTasksFindAndRemove.js
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* IMPORTANT:
|
||||
*
|
||||
* DO NOT TRUST THIS SCRIPT YET
|
||||
*
|
||||
*
|
||||
* This has been written by Alys to identify and remove duplicated tasks
|
||||
* i.e., tasks that have the same `id` value as another task.
|
||||
* However it could almost certainly be improved (the aggregation step HAS
|
||||
* to be easier that this!) and Alys is still working on it. Improvements
|
||||
* welcome.
|
||||
*
|
||||
* If you use it, do ALL of the following things:
|
||||
*
|
||||
* - configuration, as described below
|
||||
* - make a full backup of the user's data
|
||||
* - be aware of how to restore the user's data from that backup
|
||||
* - test the script first on a local copy of the database
|
||||
* - dump the user's data to a text file before running the script so that
|
||||
* it can later be compared to a dump made afterwards
|
||||
* - run the script once first with both of the db.users.update() commands
|
||||
* commented-out and check that the printed task IDs are correct
|
||||
* - run the script with all code enabled
|
||||
* - dump the user's data to a text file after running the script
|
||||
* - diff the two dumps to ensure that only the correct tasks were removed
|
||||
*
|
||||
*
|
||||
* When two tasks exist with the same ID, only one of those tasks will be
|
||||
* removed (whichever copy the script finds first).
|
||||
* If three tasks exist with the same ID, you'll probably need to run this
|
||||
* script twice.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// CONFIGURATION:
|
||||
// - Change the uuid below to be the user's uuid.
|
||||
// - Change ALL instances of "todos" to "habits"/"dailys"/"rewards" as
|
||||
// needed. Do not miss any of them!
|
||||
|
||||
|
||||
let uuid = '30fb2640-7121-4968-ace5-f385e60ea6c5';
|
||||
|
||||
db.users.aggregate([
|
||||
{$match: {
|
||||
_id: uuid,
|
||||
}},
|
||||
{$project: {
|
||||
_id: 0, todos: 1,
|
||||
}},
|
||||
{$unwind: '$todos'},
|
||||
{$group: {
|
||||
_id: { taskid: '$todos.id' },
|
||||
count: { $sum: 1 },
|
||||
}},
|
||||
{$match: {
|
||||
count: { $gt: 1 },
|
||||
}},
|
||||
{$project: {
|
||||
'_id.taskid': 1,
|
||||
}},
|
||||
{$group: {
|
||||
_id: { taskid: '$todos.id' },
|
||||
troublesomeIds: { $addToSet: '$_id.taskid' },
|
||||
}},
|
||||
{$project: {
|
||||
_id: 0,
|
||||
troublesomeIds: 1,
|
||||
}},
|
||||
]).forEach((data) => {
|
||||
// print( "\n" ); printjson(data);
|
||||
data.troublesomeIds.forEach((taskid) => {
|
||||
print(`non-unique task: ${ taskid}`);
|
||||
db.users.update({
|
||||
_id: uuid,
|
||||
todos: { $elemMatch: { id: taskid } },
|
||||
}, {
|
||||
$set: { 'todos.$.id': 'de666' },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
db.users.update(
|
||||
{_id: uuid},
|
||||
{$pull: { todos: { id: 'de666' } } },
|
||||
{multi: false }
|
||||
);
|
||||
|
||||
10
migrations/command-line/facebook_to_local.js
Normal file
10
migrations/command-line/facebook_to_local.js
Normal file
@@ -0,0 +1,10 @@
|
||||
let oldId = '';
|
||||
let newId = '';
|
||||
let newUser = db.users.findOne({_id: newId});
|
||||
|
||||
db.users.update({_id: oldId}, {$set: {auth: newUser.auth}});
|
||||
|
||||
// remove the auth on the new user (which is a template account). The account will be preened automatically later,
|
||||
// this allows us to keep the account around a few days in case there was a mistake
|
||||
db.users.update({_id: newId}, {$unset: {auth: 1}});
|
||||
|
||||
12
migrations/command-line/find_unique_user.js
Normal file
12
migrations/command-line/find_unique_user.js
Normal file
@@ -0,0 +1,12 @@
|
||||
// mongo habitrpg ./node_modules/lodash/index.js ./migrations/find_unique_user.js
|
||||
|
||||
/**
|
||||
* There are some rare instances of lost user accounts, due to a corrupt user auth variable (see https://github.com/lefnire/habitrpg/wiki/User-ID)
|
||||
* Past in the text of a unique habit here to find the user, then you can restore their UUID
|
||||
*/
|
||||
|
||||
db.users.find().forEach((user) => {
|
||||
user.tasks = user.habits.concat(user.dailys).concat(user.todos).concat(user.rewards);
|
||||
let found = _.some(user.tasks, {text: ''});
|
||||
if (found) printjson({id: user._id, auth: user.auth});
|
||||
});
|
||||
32
migrations/command-line/freeMonth.js
Normal file
32
migrations/command-line/freeMonth.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// mongo habitrpg ./node_modules/moment/moment.js ./migrations/freeMonth.js
|
||||
|
||||
db.users.update(
|
||||
{_id: ''},
|
||||
{$set: {
|
||||
'purchased.plan.customerId': 'temporary',
|
||||
'purchased.plan.paymentMethod': 'Stripe',
|
||||
'purchased.plan.planId': 'basic_earned',
|
||||
'purchased.plan.dateTerminated': moment().add('month', 1).toDate(),
|
||||
}}
|
||||
);
|
||||
// var m = 12;
|
||||
// db.users.update(
|
||||
// {_id:''},
|
||||
// {$set:{'purchased.plan':{
|
||||
// planId: 'basic_'+m+'mo',
|
||||
// paymentMethod: 'Paypal',
|
||||
// customerId: 'Gift',
|
||||
// dateCreated: new Date(),
|
||||
// dateTerminated: moment().add('month',m).toDate(),
|
||||
// dateUpdated: new Date(),
|
||||
// extraMonths: 0,
|
||||
// gemsBought: 0,
|
||||
// mysteryItems: [],
|
||||
// consecutive: {
|
||||
// count: 0,
|
||||
// offset: m,
|
||||
// gemCapExtra: m/3*5,
|
||||
// trinkets: m/3
|
||||
// }
|
||||
// }}}
|
||||
// )
|
||||
5
migrations/command-line/habitica_day.js
Normal file
5
migrations/command-line/habitica_day.js
Normal file
@@ -0,0 +1,5 @@
|
||||
db.users.update(
|
||||
{},
|
||||
{$inc: {'achievements.habiticaDays': 1}},
|
||||
{multi: 1}
|
||||
);
|
||||
1
migrations/command-line/missing_gems.js
Normal file
1
migrations/command-line/missing_gems.js
Normal file
@@ -0,0 +1 @@
|
||||
db.users.update({_id: ''}, {$inc: {balance: 5}});
|
||||
51
migrations/command-line/mystery_items.js
Normal file
51
migrations/command-line/mystery_items.js
Normal file
@@ -0,0 +1,51 @@
|
||||
let UserNotification = require('../../website/server/models/userNotification').model;
|
||||
|
||||
let _id = '';
|
||||
|
||||
let items = ['back_mystery_201801', 'headAccessory_mystery_201801'];
|
||||
|
||||
let update = {
|
||||
$addToSet: {
|
||||
'purchased.plan.mysteryItems': {
|
||||
$each: items,
|
||||
},
|
||||
},
|
||||
$push: {
|
||||
notifications: (new UserNotification({
|
||||
type: 'NEW_MYSTERY_ITEMS',
|
||||
data: {
|
||||
items,
|
||||
},
|
||||
})).toJSON(),
|
||||
},
|
||||
};
|
||||
|
||||
/* var update = {
|
||||
$set:{
|
||||
'purchased.plan':{
|
||||
customerId: "",
|
||||
dateCreated: new Date(),
|
||||
dateTerminated: null,
|
||||
dateUpdated:new Date(),
|
||||
gemsBought: 0,
|
||||
mysteryItems: [],
|
||||
paymentMethod: "Paypal",
|
||||
planId : "basic_earned"
|
||||
}
|
||||
}
|
||||
};*/
|
||||
|
||||
if (_id) {
|
||||
// singular (missing items)
|
||||
db.users.update({_id}, update);
|
||||
} else {
|
||||
// multiple (once @ start of event)
|
||||
db.users.update({
|
||||
'purchased.plan.customerId': { $ne: null },
|
||||
$or: [
|
||||
{ 'purchased.plan.dateTerminated': { $gte: new Date() } },
|
||||
{ 'purchased.plan.dateTerminated': { $exists: false } },
|
||||
{ 'purchased.plan.dateTerminated': { $eq: null } },
|
||||
],
|
||||
}, update, { multi: true });
|
||||
}
|
||||
Reference in New Issue
Block a user