From 12c01b2d873448cd5539370903cfd2259ca3b89f Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sat, 8 Apr 2023 12:21:00 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(task)=20title=20is=20now?= =?UTF-8?q?=20mandatory=20in=20constructor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/use-cases/task/models/task.test.ts | 11 ++++------- src/use-cases/task/models/task.ts | 6 ++---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/use-cases/task/models/task.test.ts b/src/use-cases/task/models/task.test.ts index c887941..38d232d 100644 --- a/src/use-cases/task/models/task.test.ts +++ b/src/use-cases/task/models/task.test.ts @@ -8,7 +8,7 @@ describe('Task', () => { it('has a simple id', () => { const uuid = faker.datatype.uuid() - const task = new Task(uuid) + const task = new Task(uuid, faker.animal.bear()) expect(task.id).equals(uuid) }) @@ -26,7 +26,7 @@ describe('Task', () => { }) it('adds steps and removes them', () => { - const task = new Task(faker.datatype.uuid()) + const task = new Task(faker.datatype.uuid(), faker.color.human()) const [firstStep, secondStep] = [createStepFixture(), createStepFixture()] @@ -42,10 +42,7 @@ describe('Task', () => { }) it('must have an id, a title and steps to be valid', () => { - const task = new Task(faker.datatype.uuid()) - expect(Task.validate(task)).toEqual(false) - - task.title = faker.animal.bird() + const task = new Task(faker.datatype.uuid(), faker.color.human()) expect(Task.validate(task)).toEqual(false) task.addSteps(createStepFixture()) @@ -53,7 +50,7 @@ describe('Task', () => { }) it('calculates the total estimation of steps', () => { - const task = new Task(faker.datatype.uuid()) + const task = new Task(faker.datatype.uuid(), faker.color.human()) task.addSteps( createStepFixture({ estimation: 1 }), diff --git a/src/use-cases/task/models/task.ts b/src/use-cases/task/models/task.ts index 13fe993..b3b485e 100644 --- a/src/use-cases/task/models/task.ts +++ b/src/use-cases/task/models/task.ts @@ -4,10 +4,9 @@ import { Step } from '@/use-cases/task/models/step' export class Task implements Taskable { public steps: Step[] = [] - public title = '' public link: string | null = null - constructor(public readonly id: string) {} + constructor(public readonly id: string, public readonly title: string) {} public addSteps(...steps: Stepable[]) { this.steps.push(...Step.fromStepable(...steps)) @@ -32,8 +31,7 @@ export class Task implements Taskable { } public static fromTaskable(taskable: Taskable) { - const task = new Task(taskable.id) - task.title = taskable.title + const task = new Task(taskable.id, taskable.title) task.link = taskable.link task.addSteps(...taskable.steps)