Skip to content
Snippets Groups Projects
Commit 09bbe45a authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

Merge branch 'feat/TU-posts-and-admin' into 'dev'

feat: TU for admin mailer and posts

See merge request web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server!52
parents ef534033 1b1724ef
No related branches found
No related tags found
3 merge requests!96release V1.10.0,!62Dev,!52feat: TU for admin mailer and posts
import { HttpModule } from '@nestjs/common'; import { HttpException, HttpModule, HttpStatus } from '@nestjs/common';
import { getModelToken } from '@nestjs/mongoose'; import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing'; import { Test, TestingModule } from '@nestjs/testing';
import { ConfigurationModule } from '../configuration/configuration.module'; import { ConfigurationModule } from '../configuration/configuration.module';
import { MailerService } from '../mailer/mailer.service'; 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 { Structure } from '../structures/schemas/structure.schema';
import { StructuresService } from '../structures/services/structures.service'; import { StructuresService } from '../structures/services/structures.service';
import { User } from '../users/schemas/user.schema'; import { User } from '../users/schemas/user.schema';
import { UsersService } from '../users/users.service'; import { UsersService } from '../users/users.service';
import { AdminController } from './admin.controller'; import { AdminController } from './admin.controller';
import { PendingStructureDto } from './dto/pending-structure.dto';
describe('AdminController', () => { describe('AdminController', () => {
let controller: AdminController; let controller: AdminController;
...@@ -37,4 +40,24 @@ describe('AdminController', () => { ...@@ -37,4 +40,24 @@ describe('AdminController', () => {
it('should be defined', () => { it('should be defined', () => {
expect(controller).toBeDefined(); 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);
});
}); });
...@@ -18,4 +18,28 @@ describe('MailerService', () => { ...@@ -18,4 +18,28 @@ describe('MailerService', () => {
it('should be defined', () => { it('should be defined', () => {
expect(service).toBeDefined(); 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);
});
}); });
...@@ -3,6 +3,7 @@ import { Test, TestingModule } from '@nestjs/testing'; ...@@ -3,6 +3,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import { ConfigurationModule } from '../configuration/configuration.module'; import { ConfigurationModule } from '../configuration/configuration.module';
import { PostsController } from './posts.controller'; import { PostsController } from './posts.controller';
import { PostsService } from './posts.service'; import { PostsService } from './posts.service';
import { PostWithMeta } from './schemas/postWithMeta.schema';
describe('PostsController', () => { describe('PostsController', () => {
let controller: PostsController; let controller: PostsController;
...@@ -20,4 +21,24 @@ describe('PostsController', () => { ...@@ -20,4 +21,24 @@ describe('PostsController', () => {
it('should be defined', () => { it('should be defined', () => {
expect(controller).toBeDefined(); 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);
});
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment