* feat: Add alias property to task model
This commit is contained in:
Blade Barringer
2016-06-16 12:28:45 -05:00
committed by GitHub
parent c34c21192b
commit b7b61e6251
21 changed files with 536 additions and 97 deletions

View File

@@ -9,7 +9,7 @@ import { v4 as generateUUID } from 'uuid';
describe('PUT /tasks/:id', () => {
let user;
before(async () => {
beforeEach(async () => {
user = await generateUser();
});
@@ -59,7 +59,7 @@ describe('PUT /tasks/:id', () => {
expect(savedTask.notValid).to.be.undefined;
});
it(`only allows setting streak, reminders, checklist, notes, attribute, tags
it(`only allows setting streak, alias, reminders, checklist, notes, attribute, tags
fields for challenge tasks owned by a user`, async () => {
let guild = await generateGroup(user);
let challenge = await generateChallenge(user, guild);
@@ -87,6 +87,7 @@ describe('PUT /tasks/:id', () => {
_id: 123,
type: 'daily',
userId: 123,
alias: 'a-short-task-name',
history: [123],
createdAt: 'yesterday',
updatedAt: 'tomorrow',
@@ -176,6 +177,44 @@ describe('PUT /tasks/:id', () => {
expect(savedDaily.reminders[0].id).to.equal(id1);
expect(savedDaily.reminders[1].id).to.equal(id2);
});
it('can set a alias if no other task has that alias', async () => {
let savedDaily = await user.put(`/tasks/${daily._id}`, {
alias: 'alias',
});
expect(savedDaily.alias).to.eql('alias');
});
it('does not set alias to a alias that is already in use', async () => {
await user.post('/tasks/user', {
type: 'todo',
text: 'a todo',
alias: 'some-alias',
});
await expect(user.put(`/tasks/${daily._id}`, {
alias: 'some-alias',
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: 'daily validation failed',
});
});
it('can use alias to update a task', async () => {
daily = await user.put(`/tasks/${daily._id}`, {
alias: 'alias',
});
await user.put(`/tasks/${daily.alias}`, {
text: 'saved',
});
let fetchedDaily = await user.get(`/tasks/${daily._id}`);
expect(fetchedDaily.text).to.eql('saved');
});
});
context('habits', () => {