|
- import {
- beforeEach,
- describe,
- expect,
- it,
- vi,
- } from 'vitest';
- import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
- import { CardServiceImpl } from '../service';
- import { CardController, CardControllerImpl } from '../controller';
-
- describe('CardController', () => {
- let cardController: CardController;
-
- beforeEach(() => {
- cardController = new CardControllerImpl();
- });
-
- describe('generate', () => {
- it('generates cards', async () => {
- vi
- .spyOn(CardServiceImpl.prototype, 'generate')
- .mockReturnValueOnce('random card');
-
- const request = {
- query: {},
- } as FastifyRequest;
- const reply = {
- send: vi.fn(),
- } as unknown as FastifyReply;
- const fastifyInstance = {} as unknown as FastifyInstance;
- const generate = cardController.generate.bind(fastifyInstance);
- await generate(request, reply);
- expect(reply.send).toBeCalledWith('random card');
- });
- });
- });
|