Habits: store one history entry per day (#10442)

* initial refactor

* add scoredUp and scoredDown values for habits history entries, one entry per habit per day

* fix lint and add initial migration

* update old test

* remove scoreNotes

* dry run for migration

* migration fixes

* update migration and remove old test

* fix

* add challenges migration (read only)

* fix challenges migration

* handle custom day start

* update tasks in migration

* scoring: support cds

* add new test
This commit is contained in:
Matteo Pagliazzi
2018-06-21 21:25:19 +02:00
committed by GitHub
parent 8437b916c4
commit c1bd7f5dc5
11 changed files with 421 additions and 67 deletions
@@ -406,7 +406,8 @@ describe('POST /tasks/:id/score/:direction', () => {
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
});
it('adds score notes to task', async () => {
// not supported anymore
it('does not add score notes to task', async () => {
let scoreNotesString = 'test-notes';
await user.post(`/tasks/${habit._id}/score/up`, {
@@ -414,20 +415,24 @@ describe('POST /tasks/:id/score/:direction', () => {
});
let updatedTask = await user.get(`/tasks/${habit._id}`);
expect(updatedTask.history[0].scoreNotes).to.eql(scoreNotesString);
expect(updatedTask.history[0].scoreNotes).to.eql(undefined);
});
it('errors when score notes are too large', async () => {
let scoreNotesString = new Array(258).join('a');
it('records only one history entry per day', async () => {
const initialHistoryLength = habit.history.length;
await expect(user.post(`/tasks/${habit._id}/score/up`, {
scoreNotes: scoreNotesString,
}))
.to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('taskScoreNotesTooLong'),
});
await user.post(`/tasks/${habit._id}/score/up`);
await user.post(`/tasks/${habit._id}/score/up`);
await user.post(`/tasks/${habit._id}/score/down`);
await user.post(`/tasks/${habit._id}/score/up`);
const updatedTask = await user.get(`/tasks/${habit._id}`);
expect(updatedTask.history.length).to.eql(initialHistoryLength + 1);
const lastHistoryEntry = updatedTask.history[updatedTask.history.length - 1];
expect(lastHistoryEntry.scoredUp).to.equal(3);
expect(lastHistoryEntry.scoredDown).to.equal(1);
});
});