tests
This commit is contained in:
52
apps/api/src/domain/hello/HelloController.test.ts
Normal file
52
apps/api/src/domain/hello/HelloController.test.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
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('');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user