Skip to content

Commit

Permalink
Add test for primitive value arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
CeEv committed Aug 5, 2024
1 parent 9916fa5 commit 6ed8437
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion apps/server/src/shared/domain/value-object.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,43 @@ describe('ValueObject', () => {
});
});

describe('By usage of primitive array as value object', () => {
const setup = () => {
class Names extends ValueObject<string[]> {}

const nameThors1 = new Names(['Thor1', 'Thor2', 'Thor3']);
const nameThors2 = new Names(['Thor1', 'Thor2', 'Thor3']);
const nameThorsDifferent = new Names(['Thor1', 'Thor2', 'Thor4']);
const nameThorsDifferentCount = new Names(['Thor1', 'Thor2']);

return { nameThors1, nameThors2, nameThorsDifferent, nameThorsDifferentCount };
};

it('should be return true by same reference', () => {
const { nameThors1 } = setup();

expect(nameThors1.equals(nameThors1)).toBe(true);
});

it('should be return true by different references', () => {
const { nameThors1, nameThors2 } = setup();

expect(nameThors1.equals(nameThors2)).toBe(true);
});

it('should be return false by different values inside the array', () => {
const { nameThors1, nameThorsDifferentCount } = setup();

expect(nameThors1.equals(nameThorsDifferentCount)).toBe(false);
});

it('should be return false by different values inside the array', () => {
const { nameThors1, nameThorsDifferent } = setup();

expect(nameThors1.equals(nameThorsDifferent)).toBe(false);
});
});

describe('When value object with validation is created.', () => {
const setup = () => {
class Name extends ValueObject<string> {
Expand Down Expand Up @@ -64,7 +101,7 @@ describe('ValueObject', () => {

expect(new Name('Thor')).toBeDefined();
});

/*
it('should execute but not throw if is valid value is passsed', () => {
const { Name } = setup();
Expand All @@ -74,6 +111,7 @@ describe('ValueObject', () => {
expect(myName.isValidValue('')).toBe(false);
expect(myName.isValidValue('ABC')).toBe(true);
});
*/
});

describe('When value object with modification is created.', () => {
Expand Down

0 comments on commit 6ed8437

Please sign in to comment.