Web API for Oblique Strategies.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
988 B

  1. import {
  2. beforeEach,
  3. describe,
  4. expect,
  5. it,
  6. vi,
  7. } from 'vitest';
  8. import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
  9. import { CardServiceImpl } from '../service';
  10. import { CardController, CardControllerImpl } from '../controller';
  11. describe('CardController', () => {
  12. let cardController: CardController;
  13. beforeEach(() => {
  14. cardController = new CardControllerImpl();
  15. });
  16. describe('generate', () => {
  17. it('generates cards', async () => {
  18. vi
  19. .spyOn(CardServiceImpl.prototype, 'generate')
  20. .mockReturnValueOnce('random card');
  21. const request = {
  22. query: {},
  23. } as FastifyRequest;
  24. const reply = {
  25. send: vi.fn(),
  26. } as unknown as FastifyReply;
  27. const fastifyInstance = {} as unknown as FastifyInstance;
  28. const generate = cardController.generate.bind(fastifyInstance);
  29. await generate(request, reply);
  30. expect(reply.send).toBeCalledWith('random card');
  31. });
  32. });
  33. });