From a3af182c6dd4a3b83a7b192eca8d44d681f02132 Mon Sep 17 00:00:00 2001 From: Alexandre Rousseau Date: Mon, 29 Apr 2024 22:38:21 +0200 Subject: [PATCH] fix: complete a task without creation date --- src/Item.completed.test.ts | 11 +++++++++++ src/Item.ts | 8 ++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Item.completed.test.ts b/src/Item.completed.test.ts index c7cfcf1..dbc94e2 100644 --- a/src/Item.completed.test.ts +++ b/src/Item.completed.test.ts @@ -7,9 +7,20 @@ test('setCompleted › Adding with Date', (t) => { item.setCompleted(due); t.deepEqual(item.completed(), due); t.true(item.complete()); + t.is(item.createdToString(), '2022-06-29'); t.is(item.toString(), 'x 2022-07-01 2022-06-29 I have to do this.'); }); +test('setCompleted › Set a task completed without a creating date ', (t) => { + const item = new Item('I have to do this.'); + const due = new Date(2022, 6, 1); + item.setCompleted(due); + t.deepEqual(item.completed(), due); + t.true(item.complete()); + t.is(item.created(), null); + t.is(item.toString(), 'x 2022-07-01 I have to do this.'); +}); + test('setCompleted › Adding with string', (t) => { const item = new Item('2022-06-29 I have to do this.'); const due = new Date(2022, 6, 1); diff --git a/src/Item.ts b/src/Item.ts index 9ea9915..b050120 100644 --- a/src/Item.ts +++ b/src/Item.ts @@ -329,19 +329,15 @@ export class Item { * * @param date * @throws An Error when the date is provided as a string and is invalid. - * @throws An Error when the created date is not set. */ setCompleted(date: Date | string | null = null) { if (date === null) { this.clearCompleted(); } else { - if (this.#created === null) { - throw new Error('Can not set completed date without a created date set.'); - } if (date instanceof Date) { - this.#completed = date; + this.#completed = date; } else { - this.#completed = dateFromString(date); + this.#completed = dateFromString(date); } this.#complete = true; }