Skip to content
Snippets Groups Projects
onlineMediation.controller.spec.ts 1.84 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { getModelToken } from '@nestjs/mongoose';
    
    import { Test } from '@nestjs/testing';
    
    import { onlineMediationMockData, singleOnlineMediationMock } from '../../test/mock/data/onlineMediation.mock.data';
    import { OnlineMediationController } from './onlineMediation.controller';
    import { OnlineMediation } from './onlineMediation.schema';
    import { OnlineMediationService } from './onlineMediation.service';
    
    describe('UserRegistryController', () => {
    
      let onlineMediationController: OnlineMediationController;
    
    
      const onlineMediationServiceMock = {
        getAll: jest.fn(),
        create: jest.fn(),
      };
    
      beforeEach(async () => {
    
        const module = await Test.createTestingModule({
    
          imports: [],
          providers: [
            {
              provide: OnlineMediationService,
              useValue: onlineMediationServiceMock,
            },
            {
              provide: getModelToken('OnlineMediation'),
              useValue: OnlineMediation,
            },
          ],
          controllers: [OnlineMediationController],
        }).compile();
    
    
        onlineMediationController = module.get<OnlineMediationController>(OnlineMediationController);
    
      });
    
      it('should be defined', () => {
    
        expect(onlineMediationController).toBeDefined();
    
      });
    
      describe('findAll', () => {
        it('should findAll entries', async () => {
          onlineMediationServiceMock.getAll.mockResolvedValue(onlineMediationMockData);
    
          const reply = await onlineMediationController.findAll();
    
          expect(reply).toStrictEqual(onlineMediationMockData);
        });
      });
      describe('createOnlineMediation', () => {
        it('should create a new entry', async () => {
          onlineMediationServiceMock.create.mockResolvedValue(singleOnlineMediationMock);
    
          const reply = await onlineMediationController.createOnlineMediation(singleOnlineMediationMock);
    
          expect(reply).toStrictEqual(singleOnlineMediationMock);
        });
      });
    });