Upgrade to mongoose 7 (#14971)

* remove some unused dependencies

* update mongoose version

* make common tests pass

* Make unit tests pass

* make api v3 integration tests pass

* fix lint issues

* fix issue with package-lock

* fix(lint): we don't need no .js

* fix(lint): update to latest config-habitrpg

* chore(npm): update package locks

* fix(test): replace deprecated fn

* chore(package): update eslint-habitrpg again

* fix(lint): server linting

* fix(lint): client linting

* fix(client): correct mangled common imports

* chore(npm): update package-locks

* fix(lint): punctuation, module

---------

Co-authored-by: SabreCat <sabrecat@gmail.com>
Co-authored-by: SabreCat <sabe@habitica.com>
This commit is contained in:
Phillip Thelen
2024-01-16 22:18:47 +01:00
committed by GitHub
parent d0e4b533e3
commit f8d315ff6e
189 changed files with 2645 additions and 1423 deletions

View File

@@ -45,7 +45,7 @@ describe('POST /news', () => {
context('calls updateLastNewsPost', () => {
beforeEach(async () => {
await NewsPost.remove({ });
await NewsPost.deleteMany({ });
});
afterEach(async () => {

View File

@@ -53,7 +53,7 @@ describe('PUT /news/:newsID', () => {
context('calls updateLastNewsPost', () => {
beforeEach(async () => {
await NewsPost.remove({ });
await NewsPost.deleteMany({ });
});
it('updates post data', async () => {

View File

@@ -103,7 +103,7 @@ describe('POST /tasks/bulk-score', () => {
const initialLvl = user.stats.lvl;
await user.update({
await user.updateOne({
'stats.exp': 3000,
});
const task = await user.post('/tasks/user', {
@@ -160,7 +160,7 @@ describe('POST /tasks/bulk-score', () => {
type: 'habit',
});
await user.update({
await user.updateOne({
'party.quest.key': 'gryphon',
});

View File

@@ -18,7 +18,7 @@ describe('POST /user/class/cast/:spellId', () => {
});
it('returns an error if spell does not exist', async () => {
await user.update({ 'stats.class': 'rogue' });
await user.updateOne({ 'stats.class': 'rogue' });
const spellId = 'invalidSpell';
await expect(user.post(`/user/class/cast/${spellId}`))
.to.eventually.be.rejected.and.eql({
@@ -39,7 +39,7 @@ describe('POST /user/class/cast/:spellId', () => {
});
it('returns an error if spell.mana > user.mana', async () => {
await user.update({ 'stats.class': 'rogue' });
await user.updateOne({ 'stats.class': 'rogue' });
await expect(user.post('/user/class/cast/backStab'))
.to.eventually.be.rejected.and.eql({
code: 401,
@@ -58,7 +58,7 @@ describe('POST /user/class/cast/:spellId', () => {
});
it('returns an error if spell.lvl > user.level', async () => {
await user.update({ 'stats.mp': 200, 'stats.class': 'wizard' });
await user.updateOne({ 'stats.mp': 200, 'stats.class': 'wizard' });
await expect(user.post('/user/class/cast/earth'))
.to.eventually.be.rejected.and.eql({
code: 401,
@@ -86,7 +86,7 @@ describe('POST /user/class/cast/:spellId', () => {
});
it('returns an error if targetId is required but missing', async () => {
await user.update({ 'stats.class': 'rogue', 'stats.lvl': 11 });
await user.updateOne({ 'stats.class': 'rogue', 'stats.lvl': 11 });
await expect(user.post('/user/class/cast/pickPocket'))
.to.eventually.be.rejected.and.eql({
code: 400,
@@ -96,7 +96,7 @@ describe('POST /user/class/cast/:spellId', () => {
});
it('returns an error if targeted task doesn\'t exist', async () => {
await user.update({ 'stats.class': 'rogue', 'stats.lvl': 11 });
await user.updateOne({ 'stats.class': 'rogue', 'stats.lvl': 11 });
await expect(user.post(`/user/class/cast/pickPocket?targetId=${generateUUID()}`))
.to.eventually.be.rejected.and.eql({
code: 404,
@@ -112,7 +112,7 @@ describe('POST /user/class/cast/:spellId', () => {
await groupLeader.post(`/tasks/challenge/${challenge._id}`, [
{ type: 'habit', text: 'task text' },
]);
await groupLeader.update({ 'stats.class': 'rogue', 'stats.lvl': 11 });
await groupLeader.updateOne({ 'stats.class': 'rogue', 'stats.lvl': 11 });
await sleep(0.5);
await groupLeader.sync();
await expect(groupLeader.post(`/user/class/cast/pickPocket?targetId=${groupLeader.tasksOrder.habits[0]}`))
@@ -131,7 +131,7 @@ describe('POST /user/class/cast/:spellId', () => {
type: 'todo',
});
await groupLeader.post(`/tasks/${groupTask._id}/assign`, [groupLeader._id]);
await groupLeader.update({ 'stats.class': 'rogue', 'stats.lvl': 11 });
await groupLeader.updateOne({ 'stats.class': 'rogue', 'stats.lvl': 11 });
await sleep(0.5);
await groupLeader.sync();
@@ -148,7 +148,7 @@ describe('POST /user/class/cast/:spellId', () => {
groupDetails: { type: 'party', privacy: 'private' },
members: 1,
});
await groupLeader.update({ 'items.special.snowball': 3 });
await groupLeader.updateOne({ 'items.special.snowball': 3 });
const target = generateUUID();
await expect(groupLeader.post(`/user/class/cast/snowball?targetId=${target}`))
@@ -160,7 +160,7 @@ describe('POST /user/class/cast/:spellId', () => {
});
it('returns an error if party does not exists', async () => {
await user.update({ 'items.special.snowball': 3 });
await user.updateOne({ 'items.special.snowball': 3 });
await expect(user.post(`/user/class/cast/snowball?targetId=${generateUUID()}`))
.to.eventually.be.rejected.and.eql({
@@ -175,7 +175,7 @@ describe('POST /user/class/cast/:spellId', () => {
groupDetails: { type: 'party', privacy: 'private' },
members: 1,
});
await groupLeader.update({ 'stats.mp': 200, 'stats.class': 'wizard', 'stats.lvl': 13 });
await groupLeader.updateOne({ 'stats.mp': 200, 'stats.class': 'wizard', 'stats.lvl': 13 });
await groupLeader.post('/user/class/cast/earth');
await sleep(1);
@@ -192,11 +192,11 @@ describe('POST /user/class/cast/:spellId', () => {
});
let promises = [];
promises.push(group.groupLeader.update({ 'stats.mp': 200, 'stats.class': 'wizard', 'stats.lvl': 20 }));
promises.push(group.members[0].update({ 'stats.mp': 0, 'stats.class': 'warrior', 'stats.lvl': 20 }));
promises.push(group.members[1].update({ 'stats.mp': 0, 'stats.class': 'wizard', 'stats.lvl': 20 }));
promises.push(group.members[2].update({ 'stats.mp': 0, 'stats.class': 'rogue', 'stats.lvl': 20 }));
promises.push(group.members[3].update({ 'stats.mp': 0, 'stats.class': 'healer', 'stats.lvl': 20 }));
promises.push(group.groupLeader.updateOne({ 'stats.mp': 200, 'stats.class': 'wizard', 'stats.lvl': 20 }));
promises.push(group.members[0].updateOne({ 'stats.mp': 0, 'stats.class': 'warrior', 'stats.lvl': 20 }));
promises.push(group.members[1].updateOne({ 'stats.mp': 0, 'stats.class': 'wizard', 'stats.lvl': 20 }));
promises.push(group.members[2].updateOne({ 'stats.mp': 0, 'stats.class': 'rogue', 'stats.lvl': 20 }));
promises.push(group.members[3].updateOne({ 'stats.mp': 0, 'stats.class': 'healer', 'stats.lvl': 20 }));
await Promise.all(promises);
await group.groupLeader.post('/user/class/cast/mpheal');
@@ -244,7 +244,7 @@ describe('POST /user/class/cast/:spellId', () => {
groupDetails: { type: 'party', privacy: 'private' },
members: 3,
});
await groupLeader.update({
await groupLeader.updateOne({
'stats.mp': 200, 'stats.class': habitClass.className, 'stats.lvl': 20, 'stats.hp': 40,
});
// need this for task spells and for stealth
@@ -261,7 +261,7 @@ describe('POST /user/class/cast/:spellId', () => {
expect(groupLeader.stats.mp).to.be.lessThan(200);
});
it('works without a party', async () => {
await user.update({
await user.updateOne({
'stats.mp': 200, 'stats.class': habitClass.className, 'stats.lvl': 20, 'stats.hp': 40,
});
// need this for task spells and for stealth
@@ -288,7 +288,7 @@ describe('POST /user/class/cast/:spellId', () => {
members: 1,
});
await groupLeader.update({ 'stats.mp': 200, 'stats.class': 'wizard', 'stats.lvl': 13 });
await groupLeader.updateOne({ 'stats.mp': 200, 'stats.class': 'wizard', 'stats.lvl': 13 });
await groupLeader.post('/user/class/cast/earth', { quantity: 2 });
await sleep(1);
@@ -311,7 +311,7 @@ describe('POST /user/class/cast/:spellId', () => {
text: 'todo group',
type: 'todo',
});
await user.update({ 'stats.class': 'healer', 'stats.mp': 200, 'stats.lvl': 15 });
await user.updateOne({ 'stats.class': 'healer', 'stats.mp': 200, 'stats.lvl': 15 });
await user.post(`/tasks/${groupTask._id}/assign`, [user._id]);
await user.put('/user', {
'preferences.tasks.mirrorGroupTasks': [guild._id],
@@ -341,7 +341,7 @@ describe('POST /user/class/cast/:spellId', () => {
});
const leader = party.groupLeader;
const recipient = party.members[0];
await leader.update({ 'stats.gp': 10 });
await leader.updateOne({ 'stats.gp': 10 });
await leader.post(`/user/class/cast/birthday?targetId=${recipient._id}`);
await leader.sync();
await recipient.sync();
@@ -350,14 +350,14 @@ describe('POST /user/class/cast/:spellId', () => {
});
it('only increases user\'s achievement one if target == caster', async () => {
await user.update({ 'stats.gp': 10 });
await user.updateOne({ 'stats.gp': 10 });
await user.post(`/user/class/cast/birthday?targetId=${user._id}`);
await user.sync();
expect(user.achievements.birthday).to.equal(1);
});
it('passes correct target to spell when targetType === \'task\'', async () => {
await user.update({ 'stats.class': 'wizard', 'stats.lvl': 11 });
await user.updateOne({ 'stats.class': 'wizard', 'stats.lvl': 11 });
const task = await user.post('/tasks/user', {
text: 'test habit',
@@ -370,7 +370,7 @@ describe('POST /user/class/cast/:spellId', () => {
});
it('passes correct target to spell when targetType === \'self\'', async () => {
await user.update({ 'stats.class': 'wizard', 'stats.lvl': 14, 'stats.mp': 50 });
await user.updateOne({ 'stats.class': 'wizard', 'stats.lvl': 14, 'stats.mp': 50 });
const result = await user.post('/user/class/cast/frost');

View File

@@ -24,7 +24,7 @@ describe('POST /user/rebirth', () => {
// More tests in common code unit tests
it('resets user\'s tasks', async () => {
await user.update({
await user.updateOne({
balance: 1.5,
});

View File

@@ -24,7 +24,7 @@ describe('POST /user/reroll', () => {
// More tests in common code unit tests
it('resets user\'s tasks', async () => {
await user.update({
await user.updateOne({
balance: 2,
});

View File

@@ -147,7 +147,7 @@ describe('PUT /user', () => {
it(`updates user with ${type} that is a default`, async () => {
const dbUpdate = {};
dbUpdate[`purchased.${type}.${item}`] = true;
await user.update(dbUpdate);
await user.updateOne(dbUpdate);
// Sanity checks to make sure user is not already equipped with item
expect(get(user.preferences, type)).to.not.eql(item);
@@ -169,7 +169,7 @@ describe('PUT /user', () => {
});
it('can set beard to default', async () => {
await user.update({
await user.updateOne({
'purchased.hair.beard': 3,
'preferences.hair.beard': 3,
});
@@ -182,7 +182,7 @@ describe('PUT /user', () => {
});
it('can set mustache to default', async () => {
await user.update({
await user.updateOne({
'purchased.hair.mustache': 2,
'preferences.hair.mustache': 2,
});
@@ -221,7 +221,7 @@ describe('PUT /user', () => {
it(`updates user with ${type} user does own`, async () => {
const dbUpdate = {};
dbUpdate[`purchased.${type}.${item}`] = true;
await user.update(dbUpdate);
await user.updateOne(dbUpdate);
// Sanity check to make sure user is not already equipped with item
expect(get(user.preferences, type)).to.not.eql(item);

View File

@@ -444,7 +444,7 @@ describe('POST /user/auth/local/register', () => {
});
});
it('succeeds', async () => {
await user.update({ 'auth.facebook.id': 'some-fb-id', 'auth.local': { ok: true } });
await user.updateOne({ 'auth.facebook.id': 'some-fb-id', 'auth.local': { ok: true } });
await user.post('/user/auth/local/register', {
username,
email,
@@ -478,7 +478,7 @@ describe('POST /user/auth/local/register', () => {
});
});
it('succeeds', async () => {
await user.update({ 'auth.google.id': 'some-google-id', 'auth.local': { ok: true } });
await user.updateOne({ 'auth.google.id': 'some-google-id', 'auth.local': { ok: true } });
await user.post('/user/auth/local/register', {
username,
email,
@@ -512,7 +512,7 @@ describe('POST /user/auth/local/register', () => {
});
});
it('succeeds', async () => {
await user.update({ 'auth.apple.id': 'some-apple-id', 'auth.local': { ok: true } });
await user.updateOne({ 'auth.apple.id': 'some-apple-id', 'auth.local': { ok: true } });
await user.post('/user/auth/local/register', {
username,
email,