test(api): add unit tests for admin, leads, and reviews modules

Add missing test coverage:
- reject-listing handler spec
- user-deactivated listener spec
- lead-score value object spec
- rating value object spec

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-11 01:38:45 +07:00
parent 8265130477
commit 97c7d58f5e
4 changed files with 290 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import { Rating } from '../value-objects/rating.vo';
describe('Rating Value Object', () => {
it('should create a valid rating of 1', () => {
const result = Rating.create(1);
expect(result.isOk).toBe(true);
expect(result.unwrap().value).toBe(1);
});
it('should create a valid rating of 5', () => {
const result = Rating.create(5);
expect(result.isOk).toBe(true);
expect(result.unwrap().value).toBe(5);
});
it('should create a valid rating of 3', () => {
const result = Rating.create(3);
expect(result.isOk).toBe(true);
expect(result.unwrap().value).toBe(3);
});
it('should reject rating of 0', () => {
const result = Rating.create(0);
expect(result.isErr).toBe(true);
expect(result.unwrapErr()).toBe('Đánh giá phải từ 1 đến 5 sao');
});
it('should reject rating above 5', () => {
const result = Rating.create(6);
expect(result.isErr).toBe(true);
expect(result.unwrapErr()).toBe('Đánh giá phải từ 1 đến 5 sao');
});
it('should reject negative rating', () => {
const result = Rating.create(-1);
expect(result.isErr).toBe(true);
expect(result.unwrapErr()).toBe('Đánh giá phải từ 1 đến 5 sao');
});
it('should reject non-integer rating', () => {
const result = Rating.create(3.5);
expect(result.isErr).toBe(true);
expect(result.unwrapErr()).toBe('Đánh giá phải từ 1 đến 5 sao');
});
it('should create all valid integer ratings (1-5)', () => {
for (let i = 1; i <= 5; i++) {
const result = Rating.create(i);
expect(result.isOk).toBe(true);
expect(result.unwrap().value).toBe(i);
}
});
});