-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthor.test.ts
More file actions
36 lines (30 loc) · 1.42 KB
/
author.test.ts
File metadata and controls
36 lines (30 loc) · 1.42 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 { Author } from '@catalog/domain/book/author.vo';
import { AuthorNameCannotBeEmpty } from '@catalog/domain/book/exceptions/author-name-cannot-be-empty.exception';
import { AuthorNameCannotExceed255Characters } from '@catalog/domain/book/exceptions/author-name-cannot-exceed-255-characters.exception';
describe('Author', () => {
it('creates a valid author', () => {
const author = Author.create('Robert C. Martin');
expect(author.value).toBe('Robert C. Martin');
});
it('rejects an empty author name', () => {
expect(() => Author.create('')).toThrow(AuthorNameCannotBeEmpty);
expect(() => Author.create(' ')).toThrow(AuthorNameCannotBeEmpty);
});
it('rejects an author name exceeding 255 characters', () => {
expect(() => Author.create('A'.repeat(256))).toThrow(AuthorNameCannotExceed255Characters);
});
it('accepts an author name of exactly 255 characters', () => {
const author = Author.create('A'.repeat(255));
expect(author.value).toHaveLength(255);
});
it('trims whitespace from the author name', () => {
const author = Author.create(' Robert C. Martin ');
expect(author.value).toBe('Robert C. Martin');
});
it('two authors with the same name are equal', () => {
const author1 = Author.create('Robert C. Martin');
const author2 = Author.create('Robert C. Martin');
expect(author1.equals(author2)).toBe(true);
});
});