import { Test, TestingModule } from '@nestjs/testing';
import { MotdResponseDto } from './dto/motd-response.dto';
import { MotdController } from './motd.controller';
import { GetCurrentMotdWorkflow } from './workflows/get-current-motd/get-current-motd.workflow';

describe('MotdController', () => {
  let controller: MotdController;
  const motdTime = Date.now();

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      controllers: [MotdController],
      providers: [
        {
          provide: GetCurrentMotdWorkflow,
          useValue: {
            get: jest
              .fn()
              .mockResolvedValue(
                new MotdResponseDto({ from: motdTime, to: motdTime }, 'body')
              ),
          },
        },
      ],
    }).compile();

    controller = module.get<MotdController>(MotdController);
  });

  it('should be defined', () => {
    expect(controller).toBeDefined();
  });

  it('should return motd value', async () => {
    const result = await controller.getCurrentMotd();

    expect(result).toEqual({
      time: { from: motdTime, to: motdTime },
      body: 'body',
    });
  });
});
