const {
  isNonEmptyString,
  isValidMonth,
  isValidDateTime,
  validateRecordPayload,
} = require('../utils/validators');

describe('Validators', () => {
  describe('isNonEmptyString', () => {
    test('returns true for non-empty string', () => {
      expect(isNonEmptyString('hello')).toBe(true);
    });

    test('returns false for empty string', () => {
      expect(isNonEmptyString('')).toBe(false);
    });

    test('returns false for non-string', () => {
      expect(isNonEmptyString(123)).toBe(false);
      expect(isNonEmptyString(null)).toBe(false);
    });
  });

  describe('isValidMonth', () => {
    test('returns true for valid month format', () => {
      expect(isValidMonth('2024-01')).toBe(true);
    });

    test('returns false for invalid month format', () => {
      expect(isValidMonth('2024-1')).toBe(false);
    });
  });

  describe('validateRecordPayload', () => {
    test('returns null for valid payload', () => {
      const payload = {
        type: 'expense',
        amount: 100,
        category: '餐饮',
        date: '2024-01-15',
      };
      expect(validateRecordPayload(payload)).toBeNull();
    });

    test('returns error for invalid type', () => {
      const payload = {
        type: 'invalid',
        amount: 100,
        category: '餐饮',
        date: '2024-01-15',
      };
      expect(validateRecordPayload(payload)).toBe('账目类型错误');
    });
  });
});
