mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user