-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook-id.test.ts
More file actions
36 lines (30 loc) · 1.34 KB
/
book-id.test.ts
File metadata and controls
36 lines (30 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { describe, it, expect } from 'vitest';
import { BookId } from '@catalog/domain/book/book-id.vo';
import { BookIdCannotBeEmpty } from '@catalog/domain/book/exceptions/book-id-cannot-be-empty.exception';
import { BookIdCannotContainWhitespace } from '@catalog/domain/book/exceptions/book-id-cannot-contain-whitespace.exception';
describe('BookId', () => {
it('creates a BookId from a string', () => {
const id = BookId.create('abc-123');
expect(id.value).toBe('abc-123');
});
it('two BookIds with the same value are equal', () => {
const id1 = BookId.create('abc-123');
const id2 = BookId.create('abc-123');
expect(id1.equals(id2)).toBe(true);
});
it('two BookIds with different values are not equal', () => {
const id1 = BookId.create('abc-123');
const id2 = BookId.create('def-456');
expect(id1.equals(id2)).toBe(false);
});
it('rejects an empty BookId', () => {
expect(() => BookId.create('')).toThrow(BookIdCannotBeEmpty);
expect(() => BookId.create(' ')).toThrow(BookIdCannotBeEmpty);
});
it('rejects a BookId with leading or trailing whitespace', () => {
expect(() => BookId.create(' book-1 ')).toThrow(BookIdCannotContainWhitespace);
});
it('rejects a BookId with internal whitespace', () => {
expect(() => BookId.create('book 1')).toThrow(BookIdCannotContainWhitespace);
});
});