From 1b1724efcca24c2e5706e122f13f6740bb9b4ee9 Mon Sep 17 00:00:00 2001 From: Antonin Coquet <ext.sopra.acoquet@grandlyon.com> Date: Mon, 29 Mar 2021 15:32:01 +0200 Subject: [PATCH] feat: TU for admin mailer and posts --- src/admin/admin.controller.spec.ts | 25 ++++++++++++++++++++++++- src/mailer/mailer.service.spec.ts | 24 ++++++++++++++++++++++++ src/posts/posts.controller.spec.ts | 21 +++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/admin/admin.controller.spec.ts b/src/admin/admin.controller.spec.ts index 65e9b88e4..a93e257c8 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 086056cab..2fd12e466 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 0c5120801..39b091029 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); + }); }); -- GitLab