Skip to content
Snippets Groups Projects
Select Git revision
  • 1b1724efcca24c2e5706e122f13f6740bb9b4ee9
  • dev default protected
  • renovate/ghcr.io-browserless-chromium-2.x
  • 168-pro-connect
  • renovate/major-nest-monorepo
  • renovate/luxon-3.x
  • renovate/gouvfr-anct-timetable-to-osm-opening-hours-2.x
  • renovate/major-typescript-eslint-monorepo
  • renovate/npm-11.x
  • renovate/mysql-9.x
  • renovate/mongo-express-1.x
  • renovate/major-jest-monorepo
  • renovate/tsconfig-paths-4.x
  • renovate/jest-junit-16.x
  • renovate/express-5.x
  • renovate/elastic-elasticsearch-8.x
  • renovate/ghost-5.x
  • renovate/elasticsearch-7.x
  • renovate/devdependencies-(non-major)
  • 722-envsubst-client-side-conf
  • master protected
  • v4.0.3
  • v4.0.1
  • v4.0.0
  • v3.4.3
  • v3.4.2
  • v3.4.1
  • v3.4.0
  • v3.3.1
  • v3.3.0
  • v3.2.0
  • v3.1.0
  • v3.0.1
  • v3.0.0
  • v2.5.0
  • v2.4.2
  • v2.4.1
  • v2.4.0
  • v2.3.2
  • v2.3.1
  • v2.3.0
41 results

admin.controller.spec.ts

Blame
  • user avatar
    Antonin Coquet authored
    1b1724ef
    History
    admin.controller.spec.ts 2.84 KiB
    import { HttpException, HttpModule, HttpStatus } from '@nestjs/common';
    import { getModelToken } from '@nestjs/mongoose';
    import { Test, TestingModule } from '@nestjs/testing';
    import { ConfigurationModule } from '../configuration/configuration.module';
    import { MailerService } from '../mailer/mailer.service';
    import { CreateStructureDto } from '../structures/dto/create-structure.dto';
    import { structureDto } from '../structures/dto/structure.dto';
    import { Structure } from '../structures/schemas/structure.schema';
    import { StructuresService } from '../structures/services/structures.service';
    import { User } from '../users/schemas/user.schema';
    import { UsersService } from '../users/users.service';
    import { AdminController } from './admin.controller';
    import { PendingStructureDto } from './dto/pending-structure.dto';
    
    describe('AdminController', () => {
      let controller: AdminController;
    
      beforeEach(async () => {
        const module: TestingModule = await Test.createTestingModule({
          imports: [ConfigurationModule, HttpModule],
          providers: [
            UsersService,
            StructuresService,
            MailerService,
            {
              provide: getModelToken('User'),
              useValue: User,
            },
            {
              provide: getModelToken('Structure'),
              useValue: Structure,
            },
          ],
          controllers: [AdminController],
        }).compile();
    
        controller = module.get<AdminController>(AdminController);
      });
    
      it('should be defined', () => {
        expect(controller).toBeDefined();
      });
    
      it('should get pending attachments', async () => {
        const result = [{name: "MJC Route de vienne", address: "14 chemin des platanes"}, {name: "Mairie Lyon 7eme", address: "21 boulevard martin"}];
        jest.spyOn(controller, 'getPendingAttachments').mockImplementation(async (): Promise<any> => result);
        expect(await controller.getPendingAttachments()).toBe(result);
      });
    
      it('should validate pending structure', async () => {
        const result = [{name: "MJC Route de vienne", address: "14 chemin des platanes"}];
        const structure: PendingStructureDto = {userEmail:"martin@mjc.fr", structureId: "1", structureName:"MJC Route de vienne"};
        jest.spyOn(controller, 'validatePendingStructure').mockImplementation(async (): Promise<any> => result);
        expect(await controller.validatePendingStructure(structure)).toBe(result);
      });
    
      it('should refuse pending structure', async () => {
        const result = [{name: "MJC Route de vienne", address: "14 chemin des platanes"}, {name: "Mairie Lyon 7eme", address: "21 boulevard martin"}];
        const structure: PendingStructureDto = {userEmail:"martin@mjc.fr", structureId: "1", structureName:"MJC Route de vienne"};
        jest.spyOn(controller, 'refusePendingStructure').mockImplementation(async (): Promise<any> => result);
        expect(await controller.refusePendingStructure(structure)).toBe(result);
      });
    });