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:
MathWhiz
2017-03-03 07:57:57 -06:00
committed by Matteo Pagliazzi
parent 4fb1ff2baa
commit 207dbf35d6
3 changed files with 56 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import {
createAndPopulateGroup,
getProperty,
} from '../../../../../helpers/api-integration/v3';
import { ApiUser } from '../../../../../helpers/api-integration/api-classes';
import { v4 as generateRandomUserName } from 'uuid';
import { each } from 'lodash';
import { encrypt } from '../../../../../../website/server/libs/encryption';
@@ -416,5 +417,37 @@ describe('POST /user/auth/local/register', () => {
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);
});
});
});

View File

@@ -2999,6 +2999,11 @@ api.userDefaults = {
up: true,
down: false,
attribute: 'per',
tags: [
t('defaultTag1'), // Work
t('defaultTag4'), // School
t('defaultTag6'), // Chores
],
}, {
type: 'habit',
text: t('defaultHabit2Text'),
@@ -3006,6 +3011,9 @@ api.userDefaults = {
up: false,
down: true,
attribute: 'str',
tags: [
t('defaultTag3'), // Health + Wellness
],
}, {
type: 'habit',
text: t('defaultHabit3Text'),
@@ -3013,6 +3021,10 @@ api.userDefaults = {
up: true,
down: true,
attribute: 'str',
tags: [
t('defaultTag2'), // Exercise
t('defaultTag3'), // Health + Wellness
],
},
],
dailys: [],

View File

@@ -23,6 +23,13 @@ schema.post('init', function postInitUser (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) {
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();
});