mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
Add tags to default tasks (#8419)
* Add ability to add tags to default tasks * fix missing semicolon * fix nesting callbacks error * Add tags to default tasks * fix default tags * Start test * Finish test * Fix tests * Move test * Fix padded-bock * Fix test * Fix request * fix requests * fix test * fix lint * Refine test * Fix test * Fix Test * Fix tests * Please work :( * Fix stupid mistake * Fix lint * Fixes * fix function * fix lint * fix lint
This commit is contained in:
committed by
Matteo Pagliazzi
parent
4fb1ff2baa
commit
207dbf35d6
@@ -5,6 +5,7 @@ import {
|
|||||||
createAndPopulateGroup,
|
createAndPopulateGroup,
|
||||||
getProperty,
|
getProperty,
|
||||||
} from '../../../../../helpers/api-integration/v3';
|
} from '../../../../../helpers/api-integration/v3';
|
||||||
|
import { ApiUser } from '../../../../../helpers/api-integration/api-classes';
|
||||||
import { v4 as generateRandomUserName } from 'uuid';
|
import { v4 as generateRandomUserName } from 'uuid';
|
||||||
import { each } from 'lodash';
|
import { each } from 'lodash';
|
||||||
import { encrypt } from '../../../../../../website/server/libs/encryption';
|
import { encrypt } from '../../../../../../website/server/libs/encryption';
|
||||||
@@ -416,5 +417,37 @@ describe('POST /user/auth/local/register', () => {
|
|||||||
|
|
||||||
expect(user.tags).to.not.be.empty;
|
expect(user.tags).to.not.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('adds the correct tags to the correct tasks', async () => {
|
||||||
|
let user = await api.post('/user/auth/local/register', {
|
||||||
|
username,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
confirmPassword: password,
|
||||||
|
});
|
||||||
|
|
||||||
|
let requests = new ApiUser(user);
|
||||||
|
|
||||||
|
let habits = await requests.get('/tasks/user?type=habits');
|
||||||
|
let todos = await requests.get('/tasks/user?type=todos');
|
||||||
|
|
||||||
|
function findTag (tagName) {
|
||||||
|
let tag = user.tags.find((userTag) => {
|
||||||
|
return userTag.name === t(tagName);
|
||||||
|
});
|
||||||
|
return tag.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(habits[0].tags).to.have.a.lengthOf(3);
|
||||||
|
expect(habits[0].tags).to.include.members(['defaultTag1', 'defaultTag4', 'defaultTag6'].map(findTag));
|
||||||
|
|
||||||
|
expect(habits[1].tags).to.have.a.lengthOf(1);
|
||||||
|
expect(habits[1].tags).to.include.members(['defaultTag3'].map(findTag));
|
||||||
|
|
||||||
|
expect(habits[2].tags).to.have.a.lengthOf(2);
|
||||||
|
expect(habits[2].tags).to.include.members(['defaultTag2', 'defaultTag3'].map(findTag));
|
||||||
|
|
||||||
|
expect(todos[0].tags).to.have.a.lengthOf(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2999,6 +2999,11 @@ api.userDefaults = {
|
|||||||
up: true,
|
up: true,
|
||||||
down: false,
|
down: false,
|
||||||
attribute: 'per',
|
attribute: 'per',
|
||||||
|
tags: [
|
||||||
|
t('defaultTag1'), // Work
|
||||||
|
t('defaultTag4'), // School
|
||||||
|
t('defaultTag6'), // Chores
|
||||||
|
],
|
||||||
}, {
|
}, {
|
||||||
type: 'habit',
|
type: 'habit',
|
||||||
text: t('defaultHabit2Text'),
|
text: t('defaultHabit2Text'),
|
||||||
@@ -3006,6 +3011,9 @@ api.userDefaults = {
|
|||||||
up: false,
|
up: false,
|
||||||
down: true,
|
down: true,
|
||||||
attribute: 'str',
|
attribute: 'str',
|
||||||
|
tags: [
|
||||||
|
t('defaultTag3'), // Health + Wellness
|
||||||
|
],
|
||||||
}, {
|
}, {
|
||||||
type: 'habit',
|
type: 'habit',
|
||||||
text: t('defaultHabit3Text'),
|
text: t('defaultHabit3Text'),
|
||||||
@@ -3013,6 +3021,10 @@ api.userDefaults = {
|
|||||||
up: true,
|
up: true,
|
||||||
down: true,
|
down: true,
|
||||||
attribute: 'str',
|
attribute: 'str',
|
||||||
|
tags: [
|
||||||
|
t('defaultTag2'), // Exercise
|
||||||
|
t('defaultTag3'), // Health + Wellness
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
dailys: [],
|
dailys: [],
|
||||||
|
|||||||
@@ -23,6 +23,13 @@ schema.post('init', function postInitUser (doc) {
|
|||||||
shared.wrap(doc);
|
shared.wrap(doc);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function findTag (user, tagName) {
|
||||||
|
let tagID = _.find(user.tags, (userTag) => {
|
||||||
|
return userTag.name === tagName(user.preferences.language);
|
||||||
|
});
|
||||||
|
return tagID.id;
|
||||||
|
}
|
||||||
|
|
||||||
function _populateDefaultTasks (user, taskTypes) {
|
function _populateDefaultTasks (user, taskTypes) {
|
||||||
let tagsI = taskTypes.indexOf('tag');
|
let tagsI = taskTypes.indexOf('tag');
|
||||||
|
|
||||||
@@ -59,6 +66,10 @@ function _populateDefaultTasks (user, taskTypes) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (taskDefaults.tags) {
|
||||||
|
newTask.tags = _.compact(_.map(taskDefaults.tags, _.partial(findTag, user)));
|
||||||
|
}
|
||||||
|
|
||||||
return newTask.save();
|
return newTask.save();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user