Newer
Older
import { Test, TestingModule } from '@nestjs/testing';
import { ContactController } from './contact.controller';
import { ContactService } from './contact.service';
import { MailerModule } from '../mailer/mailer.module';
import { ContactMessage } from './schemas/contact-message.schema';
describe('ContactController', () => {
let controller: ContactController;
const contactServiceMock = {
sendMessage: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [MailerModule],
providers: [
{
provide: ContactService,
useValue: contactServiceMock,
},
],
controllers: [ContactController],
}).compile();
controller = module.get<ContactController>(ContactController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
it('should call sendMessage', async () => {
const spyer = jest.spyOn(contactServiceMock, 'sendMessage');
await controller.sendContactMessage({ contactMessage: new ContactMessage() });
expect(spyer).toBeCalledTimes(1);
expect(spyer).toBeCalledWith(new ContactMessage());
});