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);
    }
  });
});
