import { CBFileSystem } from '../../src/node/file-system'; import { ensureFileExists, isNonEmptyString } from '../../src/validator/validator-utils'; const mockFileSystem = { existsSync: jest.fn(), readFileSync: jest.fn(), writeFileSync: jest.fn(), readdirSync: jest.fn(), mkdirSync: jest.fn(), unlinkSync: jest.fn(), rmdirSync: jest.fn(), statSync: jest.fn(), createWriteStream: jest.fn(), copyFileSync: jest.fn(), lstatSync: jest.fn(), renameSync: jest.fn(), cpSync: jest.fn() } as jest.Mocked; describe('validator-utils ensureFileExists', () => { beforeEach(() => { jest.clearAllMocks(); }); it('should throw with basename in message when file does not exist', () => { mockFileSystem.existsSync.mockReturnValue(false); expect(() => ensureFileExists(mockFileSystem, '/app/iparams.json')).toThrow('iparams.json not found'); expect(mockFileSystem.existsSync).toHaveBeenCalledWith('/app/iparams.json'); }); it('should not throw when file exists', () => { mockFileSystem.existsSync.mockReturnValue(true); expect(() => ensureFileExists(mockFileSystem, '/app/iparams.json')).not.toThrow(); }); }); describe('validator-utils isNonEmptyString', () => { it('should return false when value is not a non-empty string', () => { expect(isNonEmptyString(undefined)).toBe(false); expect(isNonEmptyString(null)).toBe(false); expect(isNonEmptyString('')).toBe(false); expect(isNonEmptyString(' ')).toBe(false); }); it('should return true for a string with non-whitespace content', () => { expect(isNonEmptyString('a')).toBe(true); expect(isNonEmptyString(' x ')).toBe(true); }); });