♻️ (task) title is now mandatory in constructor

This commit is contained in:
Julien Calixte
2023-04-08 12:21:00 +02:00
parent d2242184dd
commit 12c01b2d87
2 changed files with 6 additions and 11 deletions

View File

@@ -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 }),

View File

@@ -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)