Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class ChecklistItem extends ValueObject {
}

public static create(title: Text): ChecklistItem {
const itemId = new ChecklistItemId(ID.generateId().getId());
const itemId = new ChecklistItemId(ID.generateId().toString());
return new ChecklistItem(itemId, title, false);
}

Expand Down
6 changes: 3 additions & 3 deletions backend/src/modules/project/core/model/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export default class Project extends Entity {

public generateInvitationToken(): string {
this.invitaionToken = ID.generateId();
return (this.invitaionToken as ID).getId();
return (this.invitaionToken as ID).toString();
}

public invalidateInvitationToken(): void {
Expand Down Expand Up @@ -306,7 +306,7 @@ export default class Project extends Entity {

public getToken(): string | None{
this.ensureCanBeModified();
return this.invitaionToken instanceof ID? this.invitaionToken.getId(): new None();
return this.invitaionToken instanceof ID? this.invitaionToken.toString(): new None();
}

private ensureCanBeModified(): void{
Expand All @@ -332,7 +332,7 @@ export default class Project extends Entity {
addMemberSettings: this.addMemberSettings.getSetting(),
createResourcesSettings: this.createResourcesSettings.getSetting(),
showCompletedTasks: this.showCompletedTasks,
invitaionToken: this.invitaionToken instanceof None ? null : (this.invitaionToken as ID).getId(),
invitaionToken: this.invitaionToken instanceof None ? null : (this.invitaionToken as ID).toString(),
};
}
}
2 changes: 1 addition & 1 deletion backend/src/modules/shared/core/objects/ID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class ID extends ValueObject {
return tmpID;
}

public getId(): string {
public toString(): string {
return this.id.getText();
}
}
2 changes: 1 addition & 1 deletion backend/src/modules/shared/core/objects/IdEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default class IdEntity {
}

public getID(): string {
return this.id.getId();
return this.id.toString();
}
}
2 changes: 1 addition & 1 deletion backend/src/modules/user/core/model/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class User extends Entity {

this.primaryAccount = newPrimary;
this.addEvent(
new AccountChanged(ID.generateId().getId(), DateTime.now(), this.getID(), super.getID(), newPrimary, { previousPrimary: previous }),
new AccountChanged(ID.generateId().toString(), DateTime.now(), this.getID(), super.getID(), newPrimary, { previousPrimary: previous }),
);
}

Expand Down
16 changes: 8 additions & 8 deletions backend/tests/modules/account/core/model/Account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { describe, it, expect } from 'vitest';

describe('Account model', () => {
it('create builds account with current signature', () => {
const id = new IdAccount(ID.generateId().getId());
const owner = new IdEntity(ID.generateId().getId());
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');
Expand All @@ -32,12 +32,12 @@ describe('Account model', () => {

it('fromPrimitives and toPrimitives roundtrip with null profile image', () => {
const primitives = {
id: ID.generateId().getId(),
id: ID.generateId().toString(),
email: 'test2@example.com',
name: 'Test 2',
provider: 'local',
profileImage: null,
userId: ID.generateId().getId(),
userId: ID.generateId().toString(),
createdAt: new Date(),
isPrimary: false,
};
Expand All @@ -60,12 +60,12 @@ describe('Account model', () => {

it('fromPrimitives throws when provider is missing', () => {
const primitives = {
id: ID.generateId().getId(),
id: ID.generateId().toString(),
email: 'test3@example.com',
name: 'Test 3',
provider: '',
profileImage: null,
userId: ID.generateId().getId(),
userId: ID.generateId().toString(),
createdAt: new Date(),
isPrimary: false,
};
Expand All @@ -76,12 +76,12 @@ describe('Account model', () => {

it('fromPrimitives throws when createdAt is missing', () => {
const primitives = {
id: ID.generateId().getId(),
id: ID.generateId().toString(),
email: 'test4@example.com',
name: 'Test 4',
provider: 'local',
profileImage: null,
userId: ID.generateId().getId(),
userId: ID.generateId().toString(),
isPrimary: true,
};

Expand Down
14 changes: 7 additions & 7 deletions backend/tests/modules/checklist/core/model/CheckList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { describe, it, expect } from 'vitest';
import type DomainEvent from '../../../../../src/modules/shared/core/events/DomainEvent';

describe('CheckList', () => {
const owner = new IdEntity(ID.generateId().getId());
const actor = new IdEntity(ID.generateId().getId());
const owner = new IdEntity(ID.generateId().toString());
const actor = new IdEntity(ID.generateId().toString());
const key = 'event-key';

it('creates a checklist and emits a CheckListCreated event', () => {
const checklist = CheckList.create(new IdCheckList(ID.generateId().getId()), owner, new CheckListName('My checklist'), actor, key);
const checklist = CheckList.create(new IdCheckList(ID.generateId().toString()), owner, new CheckListName('My checklist'), actor, key);
const events = checklist.pullEvents();

expect(checklist.getName().getName()).toBe('My checklist');
Expand All @@ -24,7 +24,7 @@ describe('CheckList', () => {
});

it('adds an item and updates completed percentage', () => {
const checklist = CheckList.create(new IdCheckList(ID.generateId().getId()), owner, new CheckListName('Tasks'), actor, key);
const checklist = CheckList.create(new IdCheckList(ID.generateId().toString()), owner, new CheckListName('Tasks'), actor, key);
checklist.pullEvents();

checklist.addChecklistItem(new Text('Wash dishes'), actor, key);
Expand All @@ -37,7 +37,7 @@ describe('CheckList', () => {
});

it('completes an item and emits ChecklistItemCompleted', () => {
const checklist = CheckList.create(new IdCheckList(ID.generateId().getId()), owner, new CheckListName('Tasks'), actor, key);
const checklist = CheckList.create(new IdCheckList(ID.generateId().toString()), owner, new CheckListName('Tasks'), actor, key);
checklist.addChecklistItem(new Text('Write tests'), actor, key);
const itemId = checklist.getItems()[0]!.getId().getID();
checklist.pullEvents();
Expand All @@ -51,7 +51,7 @@ describe('CheckList', () => {
});

it('marks an item as pending and recalculates percentage', () => {
const checklist = CheckList.create(new IdCheckList(ID.generateId().getId()), owner, new CheckListName('Tasks'), actor, key);
const checklist = CheckList.create(new IdCheckList(ID.generateId().toString()), owner, new CheckListName('Tasks'), actor, key);
checklist.addChecklistItem(new Text('Build feature'), actor, key);
const itemId = checklist.getItems()[0]!.getId().getID();
checklist.completeChecklistItem(itemId, actor, key);
Expand All @@ -64,7 +64,7 @@ describe('CheckList', () => {
});

it('updates the checklist title and emits CheckListTitleUpdated', () => {
const checklist = CheckList.create(new IdCheckList(ID.generateId().getId()), owner, new CheckListName('Initial'), actor, key);
const checklist = CheckList.create(new IdCheckList(ID.generateId().toString()), owner, new CheckListName('Initial'), actor, key);
checklist.pullEvents();

checklist.updateName(new CheckListName('Updated name'), actor, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import ID from '../../../../../src/modules/shared/core/objects/ID';

describe('Invitation events', () => {
it('InvitationCreated contains expected data', () => {
const id = ID.generateId().getId();
const id = ID.generateId().toString();
const date = DateTime.now();
const actor = new IdEntity(ID.generateId().getId());
const host = new IdEntity(ID.generateId().getId());
const invitationId = new IdEntity(ID.generateId().getId());
const actor = new IdEntity(ID.generateId().toString());
const host = new IdEntity(ID.generateId().toString());
const invitationId = new IdEntity(ID.generateId().toString());

const ev = new InvitationCreated(id, date, actor, host, invitationId, { foo: 'bar' });

Expand All @@ -21,11 +21,11 @@ describe('Invitation events', () => {
});

it('InvitationCanceled contains expected data', () => {
const id = ID.generateId().getId();
const id = ID.generateId().toString();
const date = DateTime.now();
const actor = new IdEntity(ID.generateId().getId());
const host = new IdEntity(ID.generateId().getId());
const invitationId = new IdEntity(ID.generateId().getId());
const actor = new IdEntity(ID.generateId().toString());
const host = new IdEntity(ID.generateId().toString());
const invitationId = new IdEntity(ID.generateId().toString());

const ev = new InvitationCanceled(id, date, actor, host, invitationId);

Expand Down
4 changes: 2 additions & 2 deletions backend/tests/modules/member/core/model/Member.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const createParams = (overrides?: Partial<{
...overrides
});

const DEFAULT_ID = ID.generateId().getId();
const createModifier = () => new IdEntity(ID.generateId().getId());
const DEFAULT_ID = ID.generateId().toString();
const createModifier = () => new IdEntity(ID.generateId().toString());

const createMember = (overrides?: Parameters<typeof createParams>[0]) => {
const params = createParams(overrides);
Expand Down
10 changes: 5 additions & 5 deletions backend/tests/modules/shared/core/model/Entity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ describe('Entity abstract class', () => {
}

function createTestEntity(): TestEntity {
const idEntity = new IdEntity(ID.generateId().getId());
const idEntity = new IdEntity(ID.generateId().toString());
return new TestEntity(idEntity);
}

function createDomainEvent(): DomainEvent {
return new DomainEvent(
ID.generateId().getId(),
ID.generateId().toString(),
DateTime.now(),
new IdEntity(ID.generateId().getId()),
new IdEntity(ID.generateId().getId()),
new IdEntity(ID.generateId().getId()),
new IdEntity(ID.generateId().toString()),
new IdEntity(ID.generateId().toString()),
new IdEntity(ID.generateId().toString()),
"TEST_EVENT"
);
}
Expand Down
8 changes: 4 additions & 4 deletions backend/tests/modules/shared/core/objects/ID.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ describe("ID tests", () => {
it('Should create a valid ID instance', () => {
const id = ID.generateId();
expect(id).toBeInstanceOf(ID);
expect(id.getId()).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
expect(id.toString()).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
});

it("Should create a valid instance of ID from a string", () => {
const id = ID.fromString('0195f3a2-7b4d-7e8f-9a1b-3c2d4e5f6a7b');
expect(id).toBeInstanceOf(ID);
expect(id.getId()).toBe('0195f3a2-7b4d-7e8f-9a1b-3c2d4e5f6a7b');
expect(id.toString()).toBe('0195f3a2-7b4d-7e8f-9a1b-3c2d4e5f6a7b');
});

it("Should create and validate valid uuid v7", () => {
const validUuidV7 = ID.generateId().getId();
const validUuidV7 = ID.generateId().toString();
const id = ID.fromString(validUuidV7);
expect(id).toBeInstanceOf(ID);
expect(id.getId()).toBe(validUuidV7);
expect(id.toString()).toBe(validUuidV7);
});

it('Should throw if the ID string is not a valid UUIDv7', () => {
Expand Down
8 changes: 4 additions & 4 deletions backend/tests/modules/user/core/model/User.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('User entity', () => {

it('changePrimaryAccount emits ACCOUNT_CHANGED event with previous info', () => {
const user = User.fromPrimitives(params as UserParams);
const newPrimary = new IdEntity(ID.generateId().getId());
const newPrimary = new IdEntity(ID.generateId().toString());
user.addAccount(newPrimary);
user.changePrimaryAccount(newPrimary);

Expand All @@ -47,7 +47,7 @@ describe('User entity', () => {

it("Should remove an account", () => {
const user = User.fromPrimitives(params as UserParams);
const acc = new IdEntity(ID.generateId().getId());
const acc = new IdEntity(ID.generateId().toString());
user.addAccount(acc);

expect(user.getAccounts().length === 2);
Expand All @@ -65,12 +65,12 @@ describe('User entity', () => {
it("Should throw if the account tring to remove doesnt exists", () => {
const user = User.fromPrimitives(params as UserParams);

expect(() => user.removeAccount(new IdEntity(ID.generateId().getId()))).toThrow(AccountDoesntExist)
expect(() => user.removeAccount(new IdEntity(ID.generateId().toString()))).toThrow(AccountDoesntExist)
});

it("Should take the first account as the primary in case that remove the primary account", () => {
const user = User.fromPrimitives(params as UserParams);
const newPrimary = new IdEntity(ID.generateId().getId());
const newPrimary = new IdEntity(ID.generateId().toString());
user.addAccount(newPrimary);
user.changePrimaryAccount(newPrimary);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import ID from '../../../../../src/modules/shared/core/objects/ID';
import InvalidParameters from '../../../../../src/modules/shared/core/errors/InvalidParameters';

const buildParams = () => ({
id: ID.generateId().getId(),
userId: ID.generateId().getId(),
id: ID.generateId().toString(),
userId: ID.generateId().toString(),
language: AllowedLanguage.en as AllowedLanguageType,
theme: AllowedTheme.dark as AllowedThemeType,
timezone: 'Europe/Madrid',
Expand Down
Loading