52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { HelloController } from './HelloController';
|
|
|
|
describe('HelloController', () => {
|
|
let controller: HelloController;
|
|
let mockService: { getHello: ReturnType<typeof vi.fn> };
|
|
|
|
beforeEach(() => {
|
|
mockService = {
|
|
getHello: vi.fn(),
|
|
};
|
|
|
|
controller = new HelloController(mockService as never);
|
|
});
|
|
|
|
describe('health', () => {
|
|
it('should return health status', async () => {
|
|
const result = await controller.health();
|
|
|
|
expect(result).toEqual({ status: 'ok' });
|
|
});
|
|
});
|
|
|
|
describe('getHello', () => {
|
|
it('should return hello message from service', async () => {
|
|
const helloMessage = 'Hello World';
|
|
mockService.getHello.mockReturnValue(helloMessage);
|
|
|
|
const result = await controller.getHello();
|
|
|
|
expect(mockService.getHello).toHaveBeenCalledTimes(1);
|
|
expect(result).toBe(helloMessage);
|
|
});
|
|
|
|
it('should return custom hello message', async () => {
|
|
const customMessage = 'Hello from Test';
|
|
mockService.getHello.mockReturnValue(customMessage);
|
|
|
|
const result = await controller.getHello();
|
|
|
|
expect(result).toBe(customMessage);
|
|
});
|
|
|
|
it('should handle empty string from service', async () => {
|
|
mockService.getHello.mockReturnValue('');
|
|
|
|
const result = await controller.getHello();
|
|
|
|
expect(result).toBe('');
|
|
});
|
|
});
|
|
}); |