diff --git a/src/admin/admin.controller.spec.ts b/src/admin/admin.controller.spec.ts index 65e9b88e4fb7b56a04dfa670134a6d6a69475f55..a93e257c82092e840f22326d70dbb637a97470a6 100644 --- a/src/admin/admin.controller.spec.ts +++ b/src/admin/admin.controller.spec.ts @@ -1,13 +1,16 @@ -import { HttpModule } from '@nestjs/common'; +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; @@ -37,4 +40,24 @@ describe('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); + }); }); diff --git a/src/mailer/mailer.service.spec.ts b/src/mailer/mailer.service.spec.ts index 086056cab0a7d8efe90a3fde1e61ac0b833e84ee..2fd12e46668bdc0cc4a32940715c2a7fc9043cdf 100644 --- a/src/mailer/mailer.service.spec.ts +++ b/src/mailer/mailer.service.spec.ts @@ -18,4 +18,28 @@ describe('MailerService', () => { it('should be defined', () => { expect(service).toBeDefined(); }); + + it('should send email', async () => { + const result = "AxiosResponse" + jest.spyOn(service, 'send').mockImplementation(async (): Promise<any> => result); + expect(await service.send("to", "subject", "html")).toBe(result); + }); + + it('should get template location', async () => { + const result = "/path/to/template"; + jest.spyOn(service, 'getTemplateLocation').mockImplementation(() => {return result}); + expect(await service.getTemplateLocation("filename")).toBe(result); + }); + + it('should load Json Config', async () => { + const result = null; + jest.spyOn(service, 'loadJsonConfig').mockImplementation(async (): Promise<any> => result); + expect(await service.loadJsonConfig("filename")).toBe(result); + }); + + it('should add signature', async () => { + const result = "signed html"; + jest.spyOn(service, 'addSignature').mockImplementation(() => {return result}); + expect(await service.addSignature("html")).toBe(result); + }); }); diff --git a/src/posts/posts.controller.spec.ts b/src/posts/posts.controller.spec.ts index 0c512080183b819060a4fe2451f6433a4a784e8a..39b091029861448339fa4a8c755dd634664a6d77 100644 --- a/src/posts/posts.controller.spec.ts +++ b/src/posts/posts.controller.spec.ts @@ -3,6 +3,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ConfigurationModule } from '../configuration/configuration.module'; import { PostsController } from './posts.controller'; import { PostsService } from './posts.service'; +import { PostWithMeta } from './schemas/postWithMeta.schema'; describe('PostsController', () => { let controller: PostsController; @@ -20,4 +21,24 @@ describe('PostsController', () => { it('should be defined', () => { expect(controller).toBeDefined(); }); + + it('should get pending attachments', async () => { + const result:PostWithMeta = {posts:[], meta:{pagination: null}}; + const query = ""; + jest.spyOn(controller, 'findAll').mockImplementation(async (): Promise<any> => result); + expect(await controller.findAll(query)).toBe(result); + }); + + it('should get pending attachments', async () => { + const result = { posts:[] }; + jest.spyOn(controller, 'findAllTags').mockImplementation(async (): Promise<any> => result); + expect(await controller.findAllTags()).toBe(result); + }); + + it('should get pending attachments', async () => { + const result = { public:[], comune:[], others:[] }; + const id = "78945945" + jest.spyOn(controller, 'getPostbyId').mockImplementation(async (): Promise<any> => result); + expect(await controller.getPostbyId(id)).toBe(result); + }); });