From 3f166658bb8088b98f287d1442e1583528b02fb0 Mon Sep 17 00:00:00 2001 From: Rafael-er-byte Date: Mon, 29 Jun 2026 22:58:34 -0600 Subject: [PATCH] refactor: make aggregate create methods accept primitive params --- .../src/modules/account/core/model/Account.ts | 20 +++--- .../modules/category/core/model/Category.ts | 14 ++-- .../modules/checklist/core/model/CheckList.ts | 18 +++-- .../src/modules/comment/core/model/Comment.ts | 19 +++--- .../invitation/core/model/Invitation.ts | 8 ++- backend/src/modules/link/core/model/Link.ts | 14 ++-- backend/src/modules/list/core/model/List.ts | 11 +-- .../src/modules/member/core/model/Member.ts | 17 +++-- .../notification/core/model/Notification.ts | 15 ++--- .../src/modules/project/core/model/Project.ts | 40 +++++------ backend/src/modules/task/core/model/Task.ts | 30 ++++----- .../core/model/TaskAttachment.ts | 17 +++-- .../account/core/model/Account.test.ts | 28 ++++---- .../core/model/TaskAttachment.test.ts | 63 ++++++++++++++--- .../category/core/model/Category.test.ts | 15 +++-- .../checklist/core/model/CheckList.test.ts | 18 +++-- .../comment/core/model/Comment.test.ts | 14 ++-- .../invitation/core/model/Invitation.test.ts | 14 ++-- .../modules/link/core/model/Link.test.ts | 46 +++++++------ .../modules/list/core/model/List.test.ts | 36 +++++----- .../list/core/model/ListWithTasks.test.ts | 28 ++++---- .../modules/member/core/model/Member.test.ts | 30 ++++----- .../core/model/Notification.test.ts | 15 +++-- .../project/core/model/Project.test.ts | 59 +++++++++------- .../modules/task/core/model/Task.test.ts | 67 +++++++++---------- 25 files changed, 372 insertions(+), 284 deletions(-) diff --git a/backend/src/modules/account/core/model/Account.ts b/backend/src/modules/account/core/model/Account.ts index e4ae05a4..6756456e 100644 --- a/backend/src/modules/account/core/model/Account.ts +++ b/backend/src/modules/account/core/model/Account.ts @@ -39,16 +39,20 @@ export default class Account extends Entity { } public static create( - id: IdAccount, - email: Email, - name: AccountName, - provider: string, - profileImage: Url | None, - owner: IdEntity, - isPrimary: boolean + params: Omit, ): Account { + const profileImage = params.profileImage ? new Url(params.profileImage) : new None(); const createdAt = DateTime.now(); - const account = new Account(id, email, isPrimary, name, provider, profileImage, owner, createdAt); + const account = new Account( + new IdAccount(params.id), + new Email(params.email), + params.isPrimary, + new AccountName(params.name), + params.provider, + profileImage, + new IdEntity(params.userId), + createdAt, + ); return account; } diff --git a/backend/src/modules/category/core/model/Category.ts b/backend/src/modules/category/core/model/Category.ts index f5739324..a43dfe62 100644 --- a/backend/src/modules/category/core/model/Category.ts +++ b/backend/src/modules/category/core/model/Category.ts @@ -29,13 +29,13 @@ export default class Category extends Entity { } public static create( - key: string, - id: IdCategory, - name: CategoryName, - color: CategoryColor, - actorId: IdEntity, - projectID: IdEntity, + params: CategoryParams & { key: string; actorId: string }, ) { + const id = new IdCategory(params.id); + const name = new CategoryName(params.name); + const color = new CategoryColor(params.color as AllowedColors); + const projectID = new IdEntity(params.idProject); + const actorId = new IdEntity(params.actorId); const category = new Category( name, color, @@ -43,7 +43,7 @@ export default class Category extends Entity { id ); - category.addEvent(new CategoryCreated(key, DateTime.now(), actorId, projectID, id)); + category.addEvent(new CategoryCreated(params.key, DateTime.now(), actorId, projectID, id)); return category; } diff --git a/backend/src/modules/checklist/core/model/CheckList.ts b/backend/src/modules/checklist/core/model/CheckList.ts index 7d2b03df..94621e84 100644 --- a/backend/src/modules/checklist/core/model/CheckList.ts +++ b/backend/src/modules/checklist/core/model/CheckList.ts @@ -32,16 +32,20 @@ export default class CheckList extends Entity { } public static create( - id: IdCheckList, - owner: IdEntity, - name: CheckListName, - actor: IdEntity, - key: string, - items: ChecklistItem[] = [], + params: Pick & { + actor: string; + key: string; + items?: CheckListParams['items']; + }, ): CheckList { + const id = new IdCheckList(params.id); + const owner = new IdEntity(params.idOwner); + const name = new CheckListName(params.name); + const actor = new IdEntity(params.actor); + const items = (params.items ?? []).map((item) => ChecklistItem.fromPrimitives(item)); const checklist = new CheckList(id, owner, name, items, new PercentageCompleted(0)); checklist.recalculateCompletedPercentage(); - checklist.addEvent(new CheckListCreated(key, DateTime.now(), actor, checklist.getTaskId(), id, checklist.toPrimitives())); + checklist.addEvent(new CheckListCreated(params.key, DateTime.now(), actor, checklist.getTaskId(), id, checklist.toPrimitives())); return checklist; } diff --git a/backend/src/modules/comment/core/model/Comment.ts b/backend/src/modules/comment/core/model/Comment.ts index 07200efd..25a9eb23 100644 --- a/backend/src/modules/comment/core/model/Comment.ts +++ b/backend/src/modules/comment/core/model/Comment.ts @@ -32,16 +32,19 @@ export default class Comment extends Entity { } public static create( - idComment: IdComment, - creator: IdEntity, - task: IdEntity, - content: Text, - key: string, - mentions?: Collection + params: CommentParams & { key: string } ): Comment { - const mentionsCollection = mentions || new Collection([], [], []); + const idComment = new IdComment(params.id); + const creator = new IdEntity(params.creator); + const task = new IdEntity(params.idTask); + const content = new Text(params.content); + const mentionsCollection = new Collection( + params.mentions.map((mention) => new IdEntity(mention)), + [], + [] + ); const comment = new Comment(idComment, creator, task ,content, mentionsCollection); - comment.addEvent(new CommentCreated(key, DateTime.now(), creator, task, idComment, comment.toPrimitives())); + comment.addEvent(new CommentCreated(params.key, DateTime.now(), creator, task, idComment, comment.toPrimitives())); return comment; } diff --git a/backend/src/modules/invitation/core/model/Invitation.ts b/backend/src/modules/invitation/core/model/Invitation.ts index 36862549..192cd929 100644 --- a/backend/src/modules/invitation/core/model/Invitation.ts +++ b/backend/src/modules/invitation/core/model/Invitation.ts @@ -22,9 +22,13 @@ export default class Invitation extends Entity { this.guest = guest; } - public static create(key: string, id: IdInvitation, host: IdEntity, projectId: IdEntity, guest: Email): Invitation { + public static create(params: Omit & { key: string }): Invitation { + const id = new IdInvitation(params.id); + const host = new IdEntity(params.host); + const projectId = new IdEntity(params.projectId); + const guest = new Email(params.guest); const invitation = new Invitation(id, host, projectId, InvitationStatus.pending(), guest); - invitation.addEvent(new InvitationCreated(key, DateTime.now(), host, host, id, invitation.toPrimitives())); + invitation.addEvent(new InvitationCreated(params.key, DateTime.now(), host, host, id, invitation.toPrimitives())); return invitation; } diff --git a/backend/src/modules/link/core/model/Link.ts b/backend/src/modules/link/core/model/Link.ts index 34706259..08e3f047 100644 --- a/backend/src/modules/link/core/model/Link.ts +++ b/backend/src/modules/link/core/model/Link.ts @@ -23,15 +23,15 @@ export default class Link extends Entity { } public static create( - id: LinkId, - task: IdEntity, - url: Url, - key: string, - actor: IdEntity, - visibleText?: Text, + params: LinkParams & { key: string; actor: string }, ): Link { + const id = new LinkId(params.id); + const task = new IdEntity(params.idTask); + const url = new Url(params.url); + const actor = new IdEntity(params.actor); + const visibleText = params.visibleText ? new Text(params.visibleText) : undefined; const link = new Link(id, task, url, visibleText ?? new None()); - link.addEvent(new LinkCreated(key, DateTime.now(), actor, task, id, link.toPrimitives())); + link.addEvent(new LinkCreated(params.key, DateTime.now(), actor, task, id, link.toPrimitives())); return link; } diff --git a/backend/src/modules/list/core/model/List.ts b/backend/src/modules/list/core/model/List.ts index f4415fa2..a8a456f1 100644 --- a/backend/src/modules/list/core/model/List.ts +++ b/backend/src/modules/list/core/model/List.ts @@ -42,12 +42,13 @@ export default class List extends Entity{ } public static create( - id: ListId, - title: ListTitle, - position: PositiveInteger, - tasks: TaskList[], - projectId: IdEntity + params: Pick ){ + const id = new ListId(params.id); + const title = new ListTitle(new Text(params.title)); + const position = new PositiveInteger(params.position); + const projectId = new IdEntity(params.projectId); + const tasks = params.tasks; const list = new List(id, title, position, tasks, projectId); return list; } diff --git a/backend/src/modules/member/core/model/Member.ts b/backend/src/modules/member/core/model/Member.ts index ef97630e..1819294a 100644 --- a/backend/src/modules/member/core/model/Member.ts +++ b/backend/src/modules/member/core/model/Member.ts @@ -36,15 +36,14 @@ export default class Member extends Entity { } public static create( - idMember:IdMember, - idProject: IdEntity, - idAccount: IdEntity, - role: MemberRole, - status: MemberStatus, - modifier: IdEntity, - key: string - + params: Omit & { actor: string; key: string } ): Member { + const idMember = new IdMember(params.id); + const idProject = new IdEntity(params.idProject); + const idAccount = new IdEntity(params.idAccount); + const role = new MemberRole(params.role); + const status = MemberStatus.create(params.status); + const actor = new IdEntity(params.actor); const member = new Member( idMember, @@ -56,7 +55,7 @@ export default class Member extends Entity { ); member.addEvent( - new MemberAddedToProject(key, DateTime.now(), modifier, idProject, idMember, member.toPrimitives()), + new MemberAddedToProject(params.key, DateTime.now(), actor, idProject, idMember, member.toPrimitives()), ); return member; } diff --git a/backend/src/modules/notification/core/model/Notification.ts b/backend/src/modules/notification/core/model/Notification.ts index 4eb6df7d..86b84dd2 100644 --- a/backend/src/modules/notification/core/model/Notification.ts +++ b/backend/src/modules/notification/core/model/Notification.ts @@ -30,16 +30,15 @@ export default class Notification extends Entity { } public static create( - key: string, - idNotification: IdNotification, - eventKey: string, - idUser: IdEntity, - actor: IdEntity, - type: NotificationTypes, + params: Omit & { key: string; actor: string }, ): Notification { - const notification = new Notification(idNotification, eventKey, NotificationStatus.unread(), type, idUser); + const idNotification = new IdNotification(params.id); + const idUser = new IdEntity(params.idUser); + const actor = new IdEntity(params.actor); + const type = params.type as NotificationTypes; + const notification = new Notification(idNotification, params.eventKey, NotificationStatus.unread(), type, idUser); notification.addEvent( - new NotificationCreated(key, DateTime.now(), actor, idUser, idNotification, notification.toPrimitives()), + new NotificationCreated(params.key, DateTime.now(), actor, idUser, idNotification, notification.toPrimitives()), ); return notification; } diff --git a/backend/src/modules/project/core/model/Project.ts b/backend/src/modules/project/core/model/Project.ts index 30dd713c..2b0016b3 100644 --- a/backend/src/modules/project/core/model/Project.ts +++ b/backend/src/modules/project/core/model/Project.ts @@ -83,34 +83,36 @@ export default class Project extends Entity { } public static create( - id: ProjectId, - projectName: ProjectName, - projectDescription: ProjectDescription | None, - background: ProjectBackGroundImage | ProjectBackGroundColor, - lists: ProjectList[], - commentAuthorization: ProjectSetting, - inmutableComment: boolean, - addMemberSettings: ProjectSetting, - createResourcesSettings: ProjectSetting, - showCompletedTasks: boolean, - actor: IdEntity, - key: string, + params: Omit & { actor: string; key: string }, ): Project { + const id = new ProjectId(params.id); + const projectName = new ProjectName(params.projectName); + const projectDescription = params.projectDescription ? new ProjectDescription(params.projectDescription) : new None(); + const imageParams = params.background as ProjectBackgroundImageParams; + const background = params.backgroundType === AllowedBackgroundType.image + ? new ProjectBackGroundImage(new Attachment( + new Url(imageParams.url), + imageParams.type as AllowedAttachments, + new Text(imageParams.name), + new IntNumber(imageParams.size), + )) + : new ProjectBackGroundColor(params.background as AllowedColors); + const actor = new IdEntity(params.actor); const project = new Project( id, ProjectStatus.open(), projectName, projectDescription, background, - lists, - commentAuthorization, - inmutableComment, - addMemberSettings, - createResourcesSettings, - showCompletedTasks, + params.lists, + new ProjectSetting(params.commentAuthorization), + params.inmutableComment, + new ProjectSetting(params.addMemberSettings), + new ProjectSetting(params.createResourcesSettings), + params.showCompletedTasks, ); - project.addEvent(new ProjectCreated(key, DateTime.now(), actor, id, project.toPrimitives())); + project.addEvent(new ProjectCreated(params.key, DateTime.now(), actor, id, project.toPrimitives())); return project; } diff --git a/backend/src/modules/task/core/model/Task.ts b/backend/src/modules/task/core/model/Task.ts index 2d805e54..9f43b69f 100644 --- a/backend/src/modules/task/core/model/Task.ts +++ b/backend/src/modules/task/core/model/Task.ts @@ -120,21 +120,21 @@ export default class Task extends Entity { //mutable methods public static create( - title: TaskTitle, - listContainer: IdEntity, - positionInList: PositiveInteger, - state: TaskState, - archived: boolean, - id: TaskId, - idProject: IdEntity, - description: Text | None, - startDate: DateTime | None, - dueDate: DateTime | None, - categories: Collection, - assigned: Collection, - actor: IdEntity, - key: string + params: Omit & { actor: string; key: string } ): Task { + const title = new TaskTitle(params.title); + const listContainer = new IdEntity(params.listContainer); + const positionInList = new PositiveInteger(params.positionInList); + const state = TaskState.create(params.state as AllowedTaskState); + const archived = params.archived; + const id = new TaskId(params.id); + const idProject = new IdEntity(params.idProject); + const description = params.description ? new Text(params.description) : new None(); + const startDate = params.startDate instanceof Date ? DateTime.create(params.startDate) : new None(); + const dueDate = params.dueDate instanceof Date ? DateTime.create(params.dueDate) : new None(); + const categories = new Collection(params.categories.map((category) => new IdEntity(category)), [], []); + const assigned = new Collection(params.assigned.map((assign) => new IdEntity(assign)), [], []); + const actor = new IdEntity(params.actor); const task = new Task( title, @@ -154,7 +154,7 @@ export default class Task extends Entity { ); task.addEvent( - new TaskCreated(key, DateTime.now(), actor, task.getIdProject(), task.getID(), task.toPrimitives()), + new TaskCreated(params.key, DateTime.now(), actor, task.getIdProject(), task.getID(), task.toPrimitives()), ); return task; } diff --git a/backend/src/modules/taskAttachment/core/model/TaskAttachment.ts b/backend/src/modules/taskAttachment/core/model/TaskAttachment.ts index 909ac27b..386da1b2 100644 --- a/backend/src/modules/taskAttachment/core/model/TaskAttachment.ts +++ b/backend/src/modules/taskAttachment/core/model/TaskAttachment.ts @@ -23,16 +23,21 @@ export default class TaskAttachment extends Entity { } public static create( - attachment: Attachment, - id: TaskAttachmentId, - task: IdEntity, - actor: IdEntity, - key: string, + params: TaskAttachmentParams & { actor: string; key: string }, ): TaskAttachment { + const attachment = new Attachment( + new Url(params.attachment.url), + params.attachment.type as AllowedAttachments, + new Text(params.attachment.name), + new IntNumber(params.attachment.size), + ); + const id = new TaskAttachmentId(params.id); + const task = new IdEntity(params.idTask); + const actor = new IdEntity(params.actor); const taskAttachment = new TaskAttachment(attachment, id, task); taskAttachment.addEvent( new TaskAttachmentCreated( - key, + params.key, DateTime.now(), actor, task, diff --git a/backend/tests/modules/account/core/model/Account.test.ts b/backend/tests/modules/account/core/model/Account.test.ts index 09bfe0cd..5a01c045 100644 --- a/backend/tests/modules/account/core/model/Account.test.ts +++ b/backend/tests/modules/account/core/model/Account.test.ts @@ -1,27 +1,27 @@ import Account from '../../../../../src/modules/account/core/model/Account'; -import IdAccount from '../../../../../src/modules/account/core/objects/IdAccount'; -import IdEntity from '../../../../../src/modules/shared/core/objects/IdEntity'; import ID from '../../../../../src/modules/shared/core/objects/ID'; -import Email from '../../../../../src/modules/shared/core/objects/Email'; -import AccountName from '../../../../../src/modules/account/core/objects/AccountName'; -import Url from '../../../../../src/modules/shared/core/objects/URL'; import None from '../../../../../src/modules/shared/core/objects/None'; import InvalidParameters from '../../../../../src/modules/shared/core/errors/InvalidParameters'; import { describe, it, expect } from 'vitest'; describe('Account model', () => { - it('create builds account with current signature', () => { - const id = new IdAccount(ID.generateId().toString()); - const owner = new IdEntity(ID.generateId().toString()); - const email = new Email('test@example.com'); - const name = new AccountName('Test'); - const profileImage = new Url('https://example.com/photo.png'); + it('create builds account with primitive params', () => { + const id = ID.generateId().toString(); + const userId = ID.generateId().toString(); - const account = Account.create(id, email, name, 'google', profileImage, owner, true); + const account = Account.create({ + id, + userId, + email: 'test@example.com', + name: 'Test', + provider: 'google', + profileImage: 'https://example.com/photo.png', + isPrimary: true, + }); const primitives = account.toPrimitives(); - expect(primitives.id).toBe(id.getID()); - expect(primitives.userId).toBe(owner.getID()); + expect(primitives.id).toBe(id); + expect(primitives.userId).toBe(userId); expect(primitives.email).toBe('test@example.com'); expect(primitives.name).toBe('Test'); expect(primitives.provider).toBe('google'); diff --git a/backend/tests/modules/attachment/core/model/TaskAttachment.test.ts b/backend/tests/modules/attachment/core/model/TaskAttachment.test.ts index 4f378c61..82f3ce61 100644 --- a/backend/tests/modules/attachment/core/model/TaskAttachment.test.ts +++ b/backend/tests/modules/attachment/core/model/TaskAttachment.test.ts @@ -1,6 +1,5 @@ import { describe, it, expect } from 'vitest'; import TaskAttachment from '../../../../../src/modules/taskAttachment/core/model/TaskAttachment'; -import TaskAttachmentId from '../../../../../src/modules/taskAttachment/core/objects/TaskAttachmentId'; import Attachment from '../../../../../src/modules/shared/core/objects/Attachment'; import Url from '../../../../../src/modules/shared/core/objects/URL'; import Text from '../../../../../src/modules/shared/core/objects/Text'; @@ -11,12 +10,23 @@ import IdEntity from '../../../../../src/modules/shared/core/objects/IdEntity'; describe('TaskAttachment entity tests', () => { const validUrl = new Url('http://localhost.com/file.png'); const validAttachment = new Attachment(validUrl, AllowedAttachments.png, new Text('file.png'), new IntNumber(128)); - const taskId = new IdEntity('4043c815-7220-7d64-8c42-6f2af4f9fd37'); - const actorId = new IdEntity('5043c815-7220-7d64-8c42-6f2af4f9fd37'); - const attachmentId = new TaskAttachmentId('6043c815-7220-7d64-8c42-6f2af4f9fd37'); + const taskId = '4043c815-7220-7d64-8c42-6f2af4f9fd37'; + const actorId = '5043c815-7220-7d64-8c42-6f2af4f9fd37'; + const attachmentId = '6043c815-7220-7d64-8c42-6f2af4f9fd37'; it('should create a TaskAttachment and expose attachment information', () => { - const taskAttachment = TaskAttachment.create(validAttachment, attachmentId, taskId, actorId, 'create-key'); + const taskAttachment = TaskAttachment.create({ + id: attachmentId, + idTask: taskId, + actor: actorId, + key: 'create-key', + attachment: { + url: validAttachment.getUrl().getUrl(), + type: validAttachment.getType(), + name: validAttachment.getName().getText(), + size: validAttachment.getSize().getValue(), + }, + }); expect(taskAttachment).toBeInstanceOf(TaskAttachment); expect(taskAttachment.getUrl().getUrl()).toBe('http://localhost.com/file.png'); @@ -31,7 +41,18 @@ describe('TaskAttachment entity tests', () => { }); it('should serialize to primitives and restore from primitives', () => { - const taskAttachment = TaskAttachment.create(validAttachment, attachmentId, taskId, actorId, 'create-key'); + const taskAttachment = TaskAttachment.create({ + id: attachmentId, + idTask: taskId, + actor: actorId, + key: 'create-key', + attachment: { + url: validAttachment.getUrl().getUrl(), + type: validAttachment.getType(), + name: validAttachment.getName().getText(), + size: validAttachment.getSize().getValue(), + }, + }); const primitives = taskAttachment.toPrimitives(); expect(primitives).toEqual({ @@ -52,10 +73,21 @@ describe('TaskAttachment entity tests', () => { }); it('should change the attachment name and emit a name changed event', () => { - const taskAttachment = TaskAttachment.create(validAttachment, attachmentId, taskId, actorId, 'create-key'); + const taskAttachment = TaskAttachment.create({ + id: attachmentId, + idTask: taskId, + actor: actorId, + key: 'create-key', + attachment: { + url: validAttachment.getUrl().getUrl(), + type: validAttachment.getType(), + name: validAttachment.getName().getText(), + size: validAttachment.getSize().getValue(), + }, + }); taskAttachment.pullEvents(); - taskAttachment.changeName(new Text('updated-file.png'), actorId, 'name-change-key'); + taskAttachment.changeName(new Text('updated-file.png'), new IdEntity(actorId), 'name-change-key'); expect(taskAttachment.getName().getText()).toBe('updated-file.png'); const events = taskAttachment.pullEvents(); @@ -64,10 +96,21 @@ describe('TaskAttachment entity tests', () => { }); it('should delete the task attachment and emit a deleted event', () => { - const taskAttachment = TaskAttachment.create(validAttachment, attachmentId, taskId, actorId, 'create-key'); + const taskAttachment = TaskAttachment.create({ + id: attachmentId, + idTask: taskId, + actor: actorId, + key: 'create-key', + attachment: { + url: validAttachment.getUrl().getUrl(), + type: validAttachment.getType(), + name: validAttachment.getName().getText(), + size: validAttachment.getSize().getValue(), + }, + }); taskAttachment.pullEvents(); - taskAttachment.delete(actorId, 'delete-key'); + taskAttachment.delete(new IdEntity(actorId), 'delete-key'); const events = taskAttachment.pullEvents(); expect(events).toHaveLength(1); diff --git a/backend/tests/modules/category/core/model/Category.test.ts b/backend/tests/modules/category/core/model/Category.test.ts index efd7a73d..8f56afb3 100644 --- a/backend/tests/modules/category/core/model/Category.test.ts +++ b/backend/tests/modules/category/core/model/Category.test.ts @@ -2,7 +2,6 @@ import { describe, it, expect, vi } from 'vitest'; import Category from "../../../../../src/modules/category/core/model/Category"; import CategoryColor from "../../../../../src/modules/category/core/objects/CategoryColor"; import CategoryName from "../../../../../src/modules/category/core/objects/CategoryName"; -import IdCategory from "../../../../../src/modules/category/core/objects/IdCategory"; import { AllowedColors } from "../../../../../src/modules/category/core/types/AllowedColors"; import ResourceNotFound from "../../../../../src/modules/shared/core/errors/ResourceNotFound"; import DomainEvent from "../../../../../src/modules/shared/core/events/DomainEvent"; @@ -32,12 +31,14 @@ const buildCategory = (overrides?: Parameters[0]) = const params = createCategoryParams(overrides); return Category.create( - params.key, - new IdCategory(params.id), - new CategoryName(params.name), - new CategoryColor(params.color), - new IdEntity(DEFAULT_ID), - new IdEntity(params.idProject) + { + id: params.id, + idProject: params.idProject, + name: params.name, + color: params.color, + key: params.key, + actorId: DEFAULT_ID, + } ); }; diff --git a/backend/tests/modules/checklist/core/model/CheckList.test.ts b/backend/tests/modules/checklist/core/model/CheckList.test.ts index cca8b413..f5bf1b7a 100644 --- a/backend/tests/modules/checklist/core/model/CheckList.test.ts +++ b/backend/tests/modules/checklist/core/model/CheckList.test.ts @@ -1,30 +1,28 @@ import CheckList from '../../../../../src/modules/checklist/core/model/CheckList'; -import IdCheckList from '../../../../../src/modules/checklist/core/objects/IdCheckList'; import CheckListName from '../../../../../src/modules/checklist/core/objects/CheckListName'; import Text from '../../../../../src/modules/shared/core/objects/Text'; -import IdEntity from '../../../../../src/modules/shared/core/objects/IdEntity'; import ID from '../../../../../src/modules/shared/core/objects/ID'; import { describe, it, expect } from 'vitest'; import type DomainEvent from '../../../../../src/modules/shared/core/events/DomainEvent'; describe('CheckList', () => { - const owner = new IdEntity(ID.generateId().toString()); - const actor = new IdEntity(ID.generateId().toString()); + const owner = ID.generateId().toString(); + const actor = ID.generateId().toString(); const key = 'event-key'; it('creates a checklist and emits a CheckListCreated event', () => { - const checklist = CheckList.create(new IdCheckList(ID.generateId().toString()), owner, new CheckListName('My checklist'), actor, key); + const checklist = CheckList.create({ id: ID.generateId().toString(), idOwner: owner, name: 'My checklist', actor, key }); const events = checklist.pullEvents(); expect(checklist.getName().getName()).toBe('My checklist'); expect(checklist.getCompletedPercentage().getValue()).toBe(0); - expect(checklist.toPrimitives().idOwner).toBe(owner.getID()); + expect(checklist.toPrimitives().idOwner).toBe(owner); expect(events).toHaveLength(1); expect((events[0] as DomainEvent).getEvent()).toBe('CHECKLIST_CREATED'); }); it('adds an item and updates completed percentage', () => { - const checklist = CheckList.create(new IdCheckList(ID.generateId().toString()), owner, new CheckListName('Tasks'), actor, key); + const checklist = CheckList.create({ id: ID.generateId().toString(), idOwner: owner, name: 'Tasks', actor, key }); checklist.pullEvents(); checklist.addChecklistItem(new Text('Wash dishes'), actor, key); @@ -37,7 +35,7 @@ describe('CheckList', () => { }); it('completes an item and emits ChecklistItemCompleted', () => { - const checklist = CheckList.create(new IdCheckList(ID.generateId().toString()), owner, new CheckListName('Tasks'), actor, key); + const checklist = CheckList.create({ id: ID.generateId().toString(), idOwner: owner, name: 'Tasks', actor, key }); checklist.addChecklistItem(new Text('Write tests'), actor, key); const itemId = checklist.getItems()[0]!.getId().getID(); checklist.pullEvents(); @@ -51,7 +49,7 @@ describe('CheckList', () => { }); it('marks an item as pending and recalculates percentage', () => { - const checklist = CheckList.create(new IdCheckList(ID.generateId().toString()), owner, new CheckListName('Tasks'), actor, key); + const checklist = CheckList.create({ id: ID.generateId().toString(), idOwner: owner, name: 'Tasks', actor, key }); checklist.addChecklistItem(new Text('Build feature'), actor, key); const itemId = checklist.getItems()[0]!.getId().getID(); checklist.completeChecklistItem(itemId, actor, key); @@ -64,7 +62,7 @@ describe('CheckList', () => { }); it('updates the checklist title and emits CheckListTitleUpdated', () => { - const checklist = CheckList.create(new IdCheckList(ID.generateId().toString()), owner, new CheckListName('Initial'), actor, key); + const checklist = CheckList.create({ id: ID.generateId().toString(), idOwner: owner, name: 'Initial', actor, key }); checklist.pullEvents(); checklist.updateName(new CheckListName('Updated name'), actor, key); diff --git a/backend/tests/modules/comment/core/model/Comment.test.ts b/backend/tests/modules/comment/core/model/Comment.test.ts index c74ed3ae..90ac1ac1 100644 --- a/backend/tests/modules/comment/core/model/Comment.test.ts +++ b/backend/tests/modules/comment/core/model/Comment.test.ts @@ -1,6 +1,5 @@ import { describe, it, expect, vi } from 'vitest'; import Comment from "../../../../../src/modules/comment/core/model/Comment"; -import IdComment from "../../../../../src/modules/comment/core/objects/IdComment"; import Text from "../../../../../src/modules/shared/core/objects/Text"; import IdEntity from "../../../../../src/modules/shared/core/objects/IdEntity"; import DomainEvent from "../../../../../src/modules/shared/core/events/DomainEvent"; @@ -36,11 +35,14 @@ const buildComment = (overrides?: Parameters[0]) => const params = createCommentParams(overrides); return Comment.create( - new IdComment(params.id), - new IdEntity(params.creator), - new IdEntity(params.idTask), - new Text(params.content), - params.key + { + id: params.id, + creator: params.creator, + idTask: params.idTask, + content: params.content, + mentions: params.mentions, + key: params.key, + } ); }; diff --git a/backend/tests/modules/invitation/core/model/Invitation.test.ts b/backend/tests/modules/invitation/core/model/Invitation.test.ts index 19e8ad02..2ddfdd48 100644 --- a/backend/tests/modules/invitation/core/model/Invitation.test.ts +++ b/backend/tests/modules/invitation/core/model/Invitation.test.ts @@ -1,7 +1,5 @@ import { describe, it, expect } from 'vitest'; import Invitation from "../../../../../src/modules/invitation/core/model/Invitation"; -import IdInvitation from "../../../../../src/modules/invitation/core/objects/IdInvitation"; -import IdEntity from "../../../../../src/modules/shared/core/objects/IdEntity"; import Email from "../../../../../src/modules/shared/core/objects/Email"; import InvitationStatus, { AllowedInvitationStatus } from "../../../../../src/modules/invitation/core/objects/InvitationStatus"; import InvitationCreated from "../../../../../src/modules/invitation/core/events/InvitationCreated"; @@ -15,11 +13,13 @@ const ACTOR_ID = '019df05a-8588-758c-b5e7-92af14bf85c2'; const buildInvitation = () => { return Invitation.create( - 'create-key', - new IdInvitation(DEFAULT_ID), - new IdEntity(HOST_ID), - new IdEntity(PROJECT_ID), - new Email(GUEST_EMAIL), + { + key: 'create-key', + id: DEFAULT_ID, + host: HOST_ID, + projectId: PROJECT_ID, + guest: GUEST_EMAIL, + } ); }; diff --git a/backend/tests/modules/link/core/model/Link.test.ts b/backend/tests/modules/link/core/model/Link.test.ts index 1d815612..21c263f2 100644 --- a/backend/tests/modules/link/core/model/Link.test.ts +++ b/backend/tests/modules/link/core/model/Link.test.ts @@ -1,11 +1,9 @@ import { describe, it, expect } from 'vitest'; import Link from '../../../../../src/modules/link/core/model/Link'; -import LinkId from '../../../../../src/modules/link/core/objects/LinkId'; import type LinkParams from '../../../../../src/modules/link/core/interfaces/LinkParams'; -import Url from '../../../../../src/modules/shared/core/objects/URL'; import Text from '../../../../../src/modules/shared/core/objects/Text'; -import IdEntity from '../../../../../src/modules/shared/core/objects/IdEntity'; import None from '../../../../../src/modules/shared/core/objects/None'; +import IdEntity from '../../../../../src/modules/shared/core/objects/IdEntity'; const LINK_ID = '019df05a-8588-758c-b5e7-92af14bf85d0'; const TASK_ID = '019df05a-8588-758c-b5e7-92af14bf85d1'; @@ -27,12 +25,14 @@ const createLinkParams = ( describe('Link', () => { it('creates a link and emits a LinkCreated event', () => { const link = Link.create( - new LinkId(LINK_ID), - new IdEntity(TASK_ID), - new Url(URL_VALUE), - 'create-key', - new IdEntity(CREATOR_ID), - new Text(INITIAL_TEXT), + { + id: LINK_ID, + idTask: TASK_ID, + url: URL_VALUE, + visibleText: INITIAL_TEXT, + key: 'create-key', + actor: CREATOR_ID, + }, ); const events = link.pullEvents(); @@ -48,12 +48,14 @@ describe('Link', () => { it('updates visible text and emits LinkVisibleTextUpdated event', () => { const link = Link.create( - new LinkId(LINK_ID), - new IdEntity(TASK_ID), - new Url(URL_VALUE), - 'create-key', - new IdEntity(CREATOR_ID), - new Text(INITIAL_TEXT), + { + id: LINK_ID, + idTask: TASK_ID, + url: URL_VALUE, + visibleText: INITIAL_TEXT, + key: 'create-key', + actor: CREATOR_ID, + }, ); link.pullEvents(); @@ -71,12 +73,14 @@ describe('Link', () => { it('deletes the link and emits LinkDeleted event', () => { const link = Link.create( - new LinkId(LINK_ID), - new IdEntity(TASK_ID), - new Url(URL_VALUE), - 'create-key', - new IdEntity(CREATOR_ID), - new Text(INITIAL_TEXT), + { + id: LINK_ID, + idTask: TASK_ID, + url: URL_VALUE, + visibleText: INITIAL_TEXT, + key: 'create-key', + actor: CREATOR_ID, + }, ); link.pullEvents(); diff --git a/backend/tests/modules/list/core/model/List.test.ts b/backend/tests/modules/list/core/model/List.test.ts index b121391f..b4a49810 100644 --- a/backend/tests/modules/list/core/model/List.test.ts +++ b/backend/tests/modules/list/core/model/List.test.ts @@ -9,11 +9,13 @@ import PositiveInteger from '../../../../../src/modules/shared/core/objects/Posi import Text from '../../../../../src/modules/shared/core/objects/Text'; const buildList = () => List.create( - new ListId('0143c815-7220-7d64-8c42-6f2af4f9fd37'), - new ListTitle(new Text('Backlog')), - new PositiveInteger(1), - [], - new IdEntity('0343c815-7220-7d64-8c42-6f2af4f9fd37'), + { + id: '0143c815-7220-7d64-8c42-6f2af4f9fd37', + title: 'Backlog', + position: 1, + tasks: [], + projectId: '0343c815-7220-7d64-8c42-6f2af4f9fd37', + }, ); const buildTask = (position: number, id: string, projectId: string = '0343c815-7220-7d64-8c42-6f2af4f9fd37') => @@ -77,21 +79,25 @@ describe('List', () => { it('does not allow negative list positions', () => { expect(() => List.create( - new ListId('0143c815-7220-7d64-8c42-6f2af4f9fd37'), - new ListTitle(new Text('Backlog')), - new PositiveInteger(-1), - [], - new IdEntity('0343c815-7220-7d64-8c42-6f2af4f9fd37'), + { + id: '0143c815-7220-7d64-8c42-6f2af4f9fd37', + title: 'Backlog', + position: -1, + tasks: [], + projectId: '0343c815-7220-7d64-8c42-6f2af4f9fd37', + }, )).toThrow(InvalidParameters); }); it('does not allow zero list positions', () => { expect(() => List.create( - new ListId('0143c815-7220-7d64-8c42-6f2af4f9fd37'), - new ListTitle(new Text('Backlog')), - new PositiveInteger(0), - [], - new IdEntity('0343c815-7220-7d64-8c42-6f2af4f9fd37'), + { + id: '0143c815-7220-7d64-8c42-6f2af4f9fd37', + title: 'Backlog', + position: 0, + tasks: [], + projectId: '0343c815-7220-7d64-8c42-6f2af4f9fd37', + }, )).toThrow(InvalidParameters); }); diff --git a/backend/tests/modules/list/core/model/ListWithTasks.test.ts b/backend/tests/modules/list/core/model/ListWithTasks.test.ts index fbea1063..ee3ff76b 100644 --- a/backend/tests/modules/list/core/model/ListWithTasks.test.ts +++ b/backend/tests/modules/list/core/model/ListWithTasks.test.ts @@ -11,11 +11,13 @@ import TaskList from '../../../../../src/modules/list/core/object/TaskList'; const buildList = () => List.create( - new ListId('0143c815-7220-7d64-8c42-6f2af4f9fd37'), - new ListTitle(new Text('Backlog')), - new PositiveInteger(1), - [], - new IdEntity('0343c815-7220-7d64-8c42-6f2af4f9fd37'), + { + id: '0143c815-7220-7d64-8c42-6f2af4f9fd37', + title: 'Backlog', + position: 1, + tasks: [], + projectId: '0343c815-7220-7d64-8c42-6f2af4f9fd37', + }, ); const buildTask = (id = '0143c815-7220-7d64-8c42-6f2af4f9fd37', position = 1, project = '0343c815-7220-7d64-8c42-6f2af4f9fd37') => { @@ -73,13 +75,15 @@ describe('List with tasks', () => { const originalProject = '0343c815-7220-7d64-8c42-6f2af4f9fd37'; const newProject = new IdEntity('0543c815-7220-7d64-8c42-6f2af4f9fd37'); const list = List.create( - new ListId('0143c815-7220-7d64-8c42-6f2af4f9fd37'), - new ListTitle(new Text('Backlog')), - new PositiveInteger(1), - [ - buildTask('0143c815-7220-7d64-8c42-6f2af4f9fd44', 1, originalProject), - ], - new IdEntity(originalProject), + { + id: '0143c815-7220-7d64-8c42-6f2af4f9fd37', + title: 'Backlog', + position: 1, + tasks: [ + buildTask('0143c815-7220-7d64-8c42-6f2af4f9fd44', 1, originalProject), + ], + projectId: originalProject, + }, ); const task = list.getTasks()[0]; diff --git a/backend/tests/modules/member/core/model/Member.test.ts b/backend/tests/modules/member/core/model/Member.test.ts index 6404b477..340a081c 100644 --- a/backend/tests/modules/member/core/model/Member.test.ts +++ b/backend/tests/modules/member/core/model/Member.test.ts @@ -1,8 +1,6 @@ import { describe, it, expect } from 'vitest'; import Member from "../../../../../src/modules/member/core/model/Member"; import MemberRole from "../../../../../src/modules/member/core/objects/MemberRole"; -import MemberStatus from "../../../../../src/modules/member/core/objects/MemberStatus"; -import IdMember from "../../../../../src/modules/member/core/objects/IdMember"; import IdEntity from "../../../../../src/modules/shared/core/objects/IdEntity"; import ID from "../../../../../src/modules/shared/core/objects/ID"; import { AllowedMemberRoles } from "../../../../../src/modules/member/core/types/AllowedMemberRoles"; @@ -29,19 +27,21 @@ const createParams = (overrides?: Partial<{ }); const DEFAULT_ID = ID.generateId().toString(); -const createModifier = () => new IdEntity(ID.generateId().toString()); +const createActor = () => new IdEntity(ID.generateId().toString()); const createMember = (overrides?: Parameters[0]) => { const params = createParams(overrides); return Member.create( - new IdMember(params.id), - new IdEntity(params.idProject), - new IdEntity(params.idAccount), - new MemberRole(params.role), - MemberStatus.create(params.status), - createModifier(), - "member-create-key" + { + id: params.id, + idProject: params.idProject, + idAccount: params.idAccount, + role: params.role, + status: params.status, + actor: createActor().getID(), + key: "member-create-key", + } ); }; @@ -65,7 +65,7 @@ describe("Member Entity", () => { it("should block a member", () => { const member = createMember(); - member.block("block-key", createModifier()); + member.block("block-key", createActor()); expect(member.isBlocked()).toBe(true); expect(member.pullEvents()[1]).toBeInstanceOf(MemberBlocked); @@ -74,8 +74,8 @@ describe("Member Entity", () => { it("should unblock a member", () => { const member = createMember(); - member.block("block-key", createModifier()); - member.unBlock("unblock-key", createModifier()); + member.block("block-key", createActor()); + member.unBlock("unblock-key", createActor()); expect(member.isBlocked()).toBe(false); const events = member.pullEvents(); @@ -91,7 +91,7 @@ describe("Member Entity", () => { const member = createMember(); const newRole = new MemberRole(AllowedMemberRoles.member); - member.changeRole("role-key", createModifier(), newRole); + member.changeRole("role-key", createActor(), newRole); const events = member.pullEvents(); expect(member.toPrimitives().role).toBe(AllowedMemberRoles.member); @@ -106,7 +106,7 @@ describe("Member Entity", () => { it("should delete member", () => { const member = createMember(); - member.delete("delete-key", createModifier()); + member.delete("delete-key", createActor()); const events = member.pullEvents(); expect(events[0]).toBeInstanceOf(MemberAddedToProject); diff --git a/backend/tests/modules/notification/core/model/Notification.test.ts b/backend/tests/modules/notification/core/model/Notification.test.ts index 85f99fcc..58cdfa6d 100644 --- a/backend/tests/modules/notification/core/model/Notification.test.ts +++ b/backend/tests/modules/notification/core/model/Notification.test.ts @@ -1,7 +1,6 @@ import { describe, expect, it } from 'vitest'; import NotificationAlreadyRead from '../../../../../src/modules/notification/core/error/NotificationAlreadyRead'; import Notification from '../../../../../src/modules/notification/core/model/Notification'; -import IdNotification from '../../../../../src/modules/notification/core/objects/IdNotification'; import { AllowedNotificationStatus } from '../../../../../src/modules/notification/core/types/AllowedNotificationStatus'; import { NotificationTypes } from '../../../../../src/modules/notification/core/types/NotificationTypes'; import type DomainEvent from '../../../../../src/modules/shared/core/events/DomainEvent'; @@ -35,12 +34,14 @@ const buildNotification = (overrides?: Parameters { it("Should create a project valid instance", () => { project = Project.create( - new ProjectId(DEFAULT_ID), - new ProjectName('Project 1'), - new ProjectDescription("A project example"), - new ProjectBackGroundColor(AllowedColors.BLUE), - [], - new ProjectSetting(AllowedProjectSetting.admins), - false, - new ProjectSetting(AllowedProjectSetting.admins), - new ProjectSetting(AllowedProjectSetting.admins), - true, - new IdEntity(DEFAULT_ID), - 'key-example' + { + id: DEFAULT_ID, + projectName: 'Project 1', + projectDescription: "A project example", + background: AllowedColors.BLUE, + backgroundType: AllowedBackgroundType.color, + lists: [], + commentAuthorization: AllowedProjectSetting.admins, + inmutableComment: false, + addMemberSettings: AllowedProjectSetting.admins, + createResourcesSettings: AllowedProjectSetting.admins, + showCompletedTasks: true, + actor: DEFAULT_ID, + key: 'key-example' + } ); expect(project).toBeInstanceOf(Project); project = null; project = Project.create( - new ProjectId(DEFAULT_ID), - new ProjectName('Project 1'), - new None(), - new ProjectBackGroundImage(DEFAULT_IMAGE), - [], - new ProjectSetting(AllowedProjectSetting.member), - false, - new ProjectSetting(AllowedProjectSetting.member), - new ProjectSetting(AllowedProjectSetting.member), - true, - new IdEntity(DEFAULT_ID), - 'key-example' + { + id: DEFAULT_ID, + projectName: 'Project 1', + projectDescription: null, + background: { + url: DEFAULT_IMAGE.getUrl().getUrl(), + type: DEFAULT_IMAGE.getType(), + name: DEFAULT_IMAGE.getName().getText(), + size: DEFAULT_IMAGE.getSize().getValue(), + }, + backgroundType: AllowedBackgroundType.image, + lists: [], + commentAuthorization: AllowedProjectSetting.member, + inmutableComment: false, + addMemberSettings: AllowedProjectSetting.member, + createResourcesSettings: AllowedProjectSetting.member, + showCompletedTasks: true, + actor: DEFAULT_ID, + key: 'key-example' + } ); expect(project).toBeInstanceOf(Project); diff --git a/backend/tests/modules/task/core/model/Task.test.ts b/backend/tests/modules/task/core/model/Task.test.ts index d3bf4523..d3ab467b 100644 --- a/backend/tests/modules/task/core/model/Task.test.ts +++ b/backend/tests/modules/task/core/model/Task.test.ts @@ -18,30 +18,27 @@ import InvalidParameters from '../../../../../src/modules/shared/core/errors/Inv import InvalidOperation from '../../../../../src/modules/shared/core/errors/InvalidOperation'; const buildTask = () => { - const title = new TaskTitle('Initial task title'); const listContainer = new IdEntity('0143c815-7220-7d64-8c42-6f2af4f9fd37'); - const state = TaskState.pending(); - const taskId = new TaskId('0243c815-7220-7d64-8c42-6f2af4f9fd37'); const projectId = new IdEntity('0343c815-7220-7d64-8c42-6f2af4f9fd37'); const actor = new IdEntity('0443c815-7220-7d64-8c42-6f2af4f9fd37'); - const categories = new Collection([], [], []); - const assigned = new Collection([], [], []); const task = Task.create( - title, - listContainer, - new PositiveInteger(1), - state, - false, - taskId, - projectId, - new None(), - new None(), - new None(), - categories, - assigned, - actor, - 'task-created-key', + { + title: 'Initial task title', + listContainer: listContainer.getID(), + positionInList: 1, + state: TaskState.pending().getState(), + archived: false, + id: '0243c815-7220-7d64-8c42-6f2af4f9fd37', + idProject: projectId.getID(), + description: null, + startDate: null, + dueDate: null, + categories: [], + assigned: [], + actor: actor.getID(), + key: 'task-created-key', + }, ); return { task, actor }; @@ -70,27 +67,27 @@ describe('Task', () => { }); it('does not allow creating a task with negative position', () => { - const title = new TaskTitle('Initial task title'); const listContainer = new IdEntity('0143c815-7220-7d64-8c42-6f2af4f9fd37'); - const taskId = new TaskId('0243c815-7220-7d64-8c42-6f2af4f9fd37'); const projectId = new IdEntity('0343c815-7220-7d64-8c42-6f2af4f9fd37'); const actor = new IdEntity('0443c815-7220-7d64-8c42-6f2af4f9fd37'); expect(() => Task.create( - title, - listContainer, - new PositiveInteger(-1), - TaskState.pending(), - false, - taskId, - projectId, - new None(), - new None(), - new None(), - new Collection([], [], []), - new Collection([], [], []), - actor, - 'task-created-key', + { + title: 'Initial task title', + listContainer: listContainer.getID(), + positionInList: -1, + state: TaskState.pending().getState(), + archived: false, + id: '0243c815-7220-7d64-8c42-6f2af4f9fd37', + idProject: projectId.getID(), + description: null, + startDate: null, + dueDate: null, + categories: [], + assigned: [], + actor: actor.getID(), + key: 'task-created-key', + }, )).toThrow(InvalidParameters); });