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

Merge branch 'fix/code-coverage' into 'dev'

Fix/code coverage

See merge request web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server!99
parents 8d6056af 9f820939
No related branches found
No related tags found
2 merge requests!104Dev,!99Fix/code coverage
Showing
with 1144 additions and 89 deletions
......@@ -87,7 +87,7 @@ services:
- db-ghost:/var/lib/mysql
es01:
image: elasticsearch:7.6.1
image: elasticsearch:7.16.2
restart: unless-stopped
environment:
node.name: es01
......
......@@ -4448,6 +4448,12 @@
"integrity": "sha512-59SgoZ3EXbkfSX7b63tsou/SDGzwUEK6MuB5sKqgVK1/XE0fxmpsOb9DQI8LXW3KfGnAjImCGhhEb7uPPAUVNA==",
"dev": true
},
"@golevelup/ts-jest": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/@golevelup/ts-jest/-/ts-jest-0.3.2.tgz",
"integrity": "sha512-hv+j/vau2oj5CuhY1CrTs48Qu+ZVXpm/56OzKcL2KVN8+yc0ZIMbvTIld1wbrT1RrvAuwfDmUM2s3aSy7veuwg==",
"dev": true
},
"@hutson/parse-repository-url": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/@hutson/parse-repository-url/-/parse-repository-url-3.0.2.tgz",
......
......@@ -60,6 +60,7 @@
},
"devDependencies": {
"@compodoc/compodoc": "^1.1.16",
"@golevelup/ts-jest": "^0.3.2",
"@nestjs/cli": "^7.5.1",
"@nestjs/schematics": "^7.1.3",
"@nestjs/testing": "^7.5.1",
......
......@@ -183,6 +183,6 @@ export class AdminController {
@Delete('newsletterSubscription/:email')
@ApiParam({ name: 'email', type: String, required: true })
public async unsubscribeUserFromNewsletter(@Param() params): Promise<NewsletterSubscription> {
return this.newsletterService.deleteOneEmail(params.email);
return this.newsletterService.newsletterUnsubscribe(params.email);
}
}
import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing';
import { CategoriesAccompagnement } from '../schemas/categoriesAccompagnement.schema';
import { CreateCategoriesAccompagnement } from '../dto/create-categoriesAccompagnement.dto';
import { CategoriesAccompagnementService } from './categories-accompagnement.service';
describe('CategoriesAccompagnementService', () => {
let service: CategoriesAccompagnementService;
const mockCategoriesAccompagnementModel = {
create: jest.fn(),
find: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [],
......@@ -13,7 +18,7 @@ describe('CategoriesAccompagnementService', () => {
CategoriesAccompagnementService,
{
provide: getModelToken('CategoriesAccompagnement'),
useValue: CategoriesAccompagnement,
useValue: mockCategoriesAccompagnementModel,
},
],
}).compile();
......@@ -24,4 +29,20 @@ describe('CategoriesAccompagnementService', () => {
it('should be defined', () => {
expect(service).toBeDefined();
});
it('should create categorie accompagnement', async () => {
const data: CreateCategoriesAccompagnement = { name: 'test', modules: [{ id: 'Test', text: 'Text du test' }] };
const _doc = { _id: '5fbb92ef80a5c257dc0161f2', ...data };
mockCategoriesAccompagnementModel.create.mockResolvedValueOnce(_doc);
expect(await service.create(data)).toEqual(_doc);
});
it('should findAll structures', async () => {
const data: CreateCategoriesAccompagnement[] = [
{ name: 'test', modules: [{ id: 'Test', text: 'Text du test' }] },
{ name: 'test2', modules: [{ id: 'Test2', text: 'Text du test test 2' }] },
];
mockCategoriesAccompagnementModel.find.mockResolvedValueOnce(data);
expect(await service.findAll()).toEqual(data);
});
});
......@@ -11,11 +11,10 @@ export class CategoriesAccompagnementService {
) {}
public async create(createDto: CreateCategoriesAccompagnement): Promise<CategoriesAccompagnement> {
const createdStructure = new this.structureModel(createDto);
return createdStructure.save();
return this.structureModel.create(createDto);
}
public async findAll(): Promise<CategoriesAccompagnement[]> {
return this.structureModel.find().exec();
return this.structureModel.find();
}
}
import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing';
import { CategoriesFormations } from '../schemas/categoriesFormations.schema';
import { CreateCategoriesFormations } from '../dto/create-categoriesFormations.dto';
import { CategoriesFormationsService } from './categories-formations.service';
describe('CategoriesFormationsService', () => {
let service: CategoriesFormationsService;
const mockCategoriesFormationModel = {
create: jest.fn(),
find: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [],
......@@ -13,7 +18,7 @@ describe('CategoriesFormationsService', () => {
CategoriesFormationsService,
{
provide: getModelToken('CategoriesFormations'),
useValue: CategoriesFormations,
useValue: mockCategoriesFormationModel,
},
],
}).compile();
......@@ -24,4 +29,53 @@ describe('CategoriesFormationsService', () => {
it('should be defined', () => {
expect(service).toBeDefined();
});
it('should create categorie formation', async () => {
const data: CreateCategoriesFormations = {
name: 'test',
modules: [
{
id: '2',
display_id: '2',
display_name: 'Modules APTIC - n°2',
text: 'Les conduites à risques et les bons usages du numérique',
digest: 'Les conduites à risques et les bons usages du numérique - 02',
},
],
};
const _doc = { _id: '5fbb92ef80a5c257dc0161f2', ...data };
mockCategoriesFormationModel.create.mockResolvedValueOnce(_doc);
expect(await service.create(data)).toEqual(_doc);
});
it('should findAll structures', async () => {
const data: CreateCategoriesFormations[] = [
{
name: 'test',
modules: [
{
id: '2',
display_id: '2',
display_name: 'Modules APTIC - n°2',
text: 'Les conduites à risques et les bons usages du numérique',
digest: 'Les conduites à risques et les bons usages du numérique - 02',
},
],
},
{
name: 'test',
modules: [
{
id: '1',
display_id: '1',
display_name: 'Modules APTIC - n°1',
text: 'Les conduites à risques et les bons usages',
digest: 'Les conduites à risques et les bons usages - 01',
},
],
},
];
mockCategoriesFormationModel.find.mockResolvedValueOnce(data);
expect(await service.findAll()).toEqual(data);
});
});
......@@ -9,15 +9,14 @@ export class CategoriesFormationsService {
constructor(@InjectModel(CategoriesFormations.name) private structureModel: Model<CategoriesFormationsDocument>) {}
public async create(createDto: CreateCategoriesFormations): Promise<CategoriesFormations> {
const createdStructure = new this.structureModel(createDto);
return createdStructure.save();
return this.structureModel.create(createDto);
}
public async findAll(): Promise<CategoriesFormations[]> {
return this.structureModel.find().exec();
return this.structureModel.find();
}
public findOne(categoryId: string): Promise<any> {
public findOne(categoryId: string): Promise<CategoriesFormations> {
return this.structureModel.findOne({ id: categoryId }).select({ 'modules.id': 1 }).exec();
}
}
import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing';
import { CategoriesOthers } from '../schemas/categoriesOthers.schema';
import { CreateCategoriesOthers } from '../dto/create-categoriesOthers.dto';
import { CategoriesOthersService } from './categories-others.service';
describe('CategoriesFormationsService', () => {
let service: CategoriesOthersService;
const mockCategoriesOthersModel = {
create: jest.fn(),
find: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [],
......@@ -13,7 +18,7 @@ describe('CategoriesFormationsService', () => {
CategoriesOthersService,
{
provide: getModelToken('CategoriesOthers'),
useValue: CategoriesOthers,
useValue: mockCategoriesOthersModel,
},
],
}).compile();
......@@ -24,4 +29,20 @@ describe('CategoriesFormationsService', () => {
it('should be defined', () => {
expect(service).toBeDefined();
});
it('should create categorie accompagnement', async () => {
const data: CreateCategoriesOthers = { name: 'test', modules: [{ id: 'Test', text: 'Text du test' }] };
const _doc = { _id: '5fbb92ef80a5c257dc0161f2', ...data };
mockCategoriesOthersModel.create.mockResolvedValueOnce(_doc);
expect(await service.create(data)).toEqual(_doc);
});
it('should findAll structures', async () => {
const data: CreateCategoriesOthers[] = [
{ name: 'test', modules: [{ id: 'Test', text: 'Text du test' }] },
{ name: 'test2', modules: [{ id: 'Test2', text: 'Text du test test 2' }] },
];
mockCategoriesOthersModel.find.mockResolvedValueOnce(data);
expect(await service.findAll()).toEqual(data);
});
});
......@@ -9,11 +9,10 @@ export class CategoriesOthersService {
constructor(@InjectModel(CategoriesOthers.name) private structureModel: Model<CategoriesOthersDocument>) {}
public async create(createDto: CreateCategoriesOthers): Promise<CategoriesOthers> {
const createdStructure = new this.structureModel(createDto);
return createdStructure.save();
return this.structureModel.create(createDto);
}
public async findAll(): Promise<CategoriesOthers[]> {
return this.structureModel.find().exec();
return this.structureModel.find();
}
}
import { HttpModule, HttpStatus } from '@nestjs/common';
import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing';
import { INewsletterSubscription } from './interface/newsletter-subscription.interface';
import { NewsletterSubscription } from './newsletter-subscription.schema';
import { NewsletterService } from './newsletter.service';
describe('NewsletterService', () => {
let service: NewsletterService;
const mockNewsletterModel = {
create: jest.fn(),
deleteOne: jest.fn(),
countDocuments: jest.fn(),
findOne: jest.fn(),
exec: jest.fn(),
find: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [HttpModule],
providers: [
NewsletterService,
{
provide: getModelToken(NewsletterSubscription.name),
useValue: mockNewsletterModel,
},
],
}).compile();
service = module.get<NewsletterService>(NewsletterService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
describe('newsletterSubscribe', () => {
it('it should not add subscription for email test2@test.com : already exist', async () => {
const result = { email: 'test2@test.com' } as INewsletterSubscription;
jest
.spyOn(service, 'findOne')
.mockImplementationOnce(async (): Promise<INewsletterSubscription | undefined> => result);
try {
await service.newsletterSubscribe('test2@test.com');
// Fail test if above expression doesn't throw anything.
expect(true).toBe(false);
} catch (e) {
expect(e.message).toEqual('Email already exists');
expect(e.status).toEqual(HttpStatus.BAD_REQUEST);
}
});
it('it should add a subscription for email test2@test.com', async () => {
const result: INewsletterSubscription = { email: 'test2@test.com' } as INewsletterSubscription;
const _doc = { _id: 'a1aaaaa1a1', email: 'test2@test.com' };
jest
.spyOn(service, 'findOne')
.mockImplementationOnce(async (): Promise<INewsletterSubscription | undefined> => undefined)
.mockImplementationOnce(async (): Promise<INewsletterSubscription | undefined> => result);
mockNewsletterModel.create.mockResolvedValueOnce(_doc);
const subscription = await service.newsletterSubscribe('test2@test.com');
expect(subscription).toEqual({ email: 'test2@test.com' });
});
});
describe('newsletterUnsubscribe', () => {
it('it should not remove subscription for email test@test.com : does not exist', async () => {
const result: INewsletterSubscription = undefined;
jest
.spyOn(service, 'findOne')
.mockImplementationOnce(async (): Promise<INewsletterSubscription | undefined> => result);
try {
await service.newsletterUnsubscribe('test@test.com');
// Fail test if above expression doesn't throw anything.
expect(true).toBe(false);
} catch (e) {
expect(e.message).toEqual('Invalid email');
expect(e.status).toEqual(HttpStatus.BAD_REQUEST);
}
});
it('it should remove a subscription for email test2@test.com', async () => {
const _doc = { _id: 'a1aaaaa1a1', email: 'test2@test.com' };
const result = {
email: 'test2@test.com',
deleteOne: async () => _doc,
} as INewsletterSubscription;
jest
.spyOn(service, 'findOne')
.mockImplementationOnce(async (): Promise<INewsletterSubscription | undefined> => result);
const subscription = await service.newsletterUnsubscribe('test2@test.com');
expect(subscription).toEqual(_doc);
});
});
describe('countNewsletterSubscriptions', () => {
it('it should count subscriptions', async () => {
mockNewsletterModel.countDocuments.mockResolvedValueOnce(69);
const count = await service.countNewsletterSubscriptions();
expect(count).toEqual(69);
});
});
describe('findOne', () => {
it('it should not find a subscription with email test@test.com', async () => {
mockNewsletterModel.findOne.mockResolvedValueOnce(undefined);
const findOneEmail = await service.findOne('test@test.com');
expect(findOneEmail).toEqual(undefined);
});
it('it should find a subscription with email test2@test.com', async () => {
const _doc = { _id: 'a1aaaaa1a1', email: 'test2@test.com' } as INewsletterSubscription;
mockNewsletterModel.findOne.mockResolvedValueOnce(_doc);
const findOneEmail = await service.findOne('test2@test.com');
expect(findOneEmail).toEqual(_doc);
});
});
describe('findAll', () => {
it('it should find all', async () => {
const _docs = [{ _id: 'a1aaaaa1a1', email: 'test2@test.com' } as INewsletterSubscription];
mockNewsletterModel.find.mockResolvedValueOnce(_docs);
const findOneEmail = await service.findAll();
expect(findOneEmail).toEqual(_docs);
});
});
describe('searchNewsletterSubscription', () => {
it('it should find 2 search result', async () => {
const _docs = [
{ _id: 'a1aaaaa1a1', email: 'test2@test.com' } as INewsletterSubscription,
{ _id: 'bbbbb', email: 'test@test.com' } as INewsletterSubscription,
];
mockNewsletterModel.find.mockResolvedValueOnce(_docs);
const findOneEmail = await service.searchNewsletterSubscription('test');
expect(findOneEmail.length).toBe(2);
});
});
});
......@@ -15,40 +15,31 @@ export class NewsletterService {
if (existingEmail) {
throw new HttpException('Email already exists', HttpStatus.BAD_REQUEST);
}
const createSubscription = new this.newsletterSubscriptionModel({ email: email });
createSubscription.save();
return await this.findOne(email);
await this.newsletterSubscriptionModel.create({ email: email });
return this.findOne(email);
}
public async newsletterUnsubscribe(email: string): Promise<NewsletterSubscription> {
const subscription = await this.newsletterSubscriptionModel.findOne({ email: email }).exec();
const subscription = await this.findOne(email);
if (!subscription) {
throw new HttpException('Invalid email', HttpStatus.BAD_REQUEST);
}
return subscription.deleteOne();
}
public async findOne(mail: string): Promise<NewsletterSubscription | undefined> {
return this.newsletterSubscriptionModel.findOne({ email: mail }).exec();
public async findOne(mail: string): Promise<INewsletterSubscription | undefined> {
return this.newsletterSubscriptionModel.findOne({ email: mail });
}
public async searchNewsletterSubscription(searchString: string): Promise<NewsletterSubscriptionDocument[]> {
return this.newsletterSubscriptionModel.find({ email: new RegExp(searchString, 'i') }).exec();
return this.newsletterSubscriptionModel.find({ email: new RegExp(searchString, 'i') });
}
public async countNewsletterSubscriptions(): Promise<number> {
return this.newsletterSubscriptionModel.countDocuments({}).exec();
}
public async deleteOneEmail(mail: string): Promise<NewsletterSubscription | undefined> {
const subscription = await this.newsletterSubscriptionModel.findOne({ email: mail }).exec();
if (!subscription) {
throw new HttpException('Invalid email', HttpStatus.BAD_REQUEST);
}
return subscription.deleteOne();
return this.newsletterSubscriptionModel.countDocuments({});
}
public async findAll(): Promise<NewsletterSubscription[]> {
return await this.newsletterSubscriptionModel.find().exec();
return this.newsletterSubscriptionModel.find();
}
}
import { HttpModule } from '@nestjs/common';
import { HttpModule, HttpService } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { of } from 'rxjs';
import { ConfigurationModule } from '../configuration/configuration.module';
import { PostsController } from './posts.controller';
import { PostsService } from './posts.service';
import { PostWithMeta } from './schemas/postWithMeta.schema';
import { AxiosResponse } from 'axios';
describe('PostsController', () => {
let controller: PostsController;
const httpServiceMock = {
get: jest.fn(),
};
const postServiceMock = {
getLocationTags: jest.fn(),
getPublicTags: jest.fn(),
getRegularTags: jest.fn(),
formatPosts: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigurationModule, HttpModule],
providers: [PostsService],
providers: [
{
provide: PostsService,
useValue: postServiceMock,
},
{
provide: HttpService,
useValue: httpServiceMock,
},
],
controllers: [PostsController],
}).compile();
......@@ -22,23 +43,383 @@ describe('PostsController', () => {
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);
describe('findAll', () => {
it('should get all posts', async () => {
const query = '';
const result: AxiosResponse = {
data: {
posts: [
{
id: '61c4847b0ff4550001505090',
uuid: 'f4ee5a37-a343-4cad-8a32-3f6cf87f9569',
title: 'Only feature image',
slug: 'only-feature-image',
html: '<p>Test</p>',
comment_id: '61c4847b0ff4550001505090',
feature_image: 'http://localhost:2368/content/images/2021/12/dacc-4.png',
featured: false,
visibility: 'public',
email_recipient_filter: 'none',
created_at: '2021-12-23T14:15:23.000+00:00',
updated_at: '2021-12-23T14:15:45.000+00:00',
published_at: '2021-12-23T14:15:45.000+00:00',
custom_excerpt: null,
codeinjection_head: null,
codeinjection_foot: null,
custom_template: null,
canonical_url: null,
tags: [Array],
authors: [Array],
primary_author: [Object],
primary_tag: [Object],
url: 'http://localhost:2368/only-feature-image/',
excerpt:
'« Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.\n' +
'Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed,\n' +
'dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper\n' +
'congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est\n' +
'eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu\n' +
'massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut\n' +
'in risus volutpat libero pharetra tem',
reading_time: 2,
access: true,
send_email_when_published: false,
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
email_subject: null,
frontmatter: null,
},
{
id: '61c4847b0ff4550001505090',
uuid: 'f4ee5a37-a343-4cad-8a32-3f6cf87f9569',
title: 'Only test image',
slug: 'only-test-image',
html: '<p>Test 2</p>',
comment_id: '61c4847b0ff4550001505090',
feature_image: 'http://localhost:2368/content/images/2021/12/test.png',
featured: false,
visibility: 'public',
email_recipient_filter: 'none',
created_at: '2021-12-23T14:15:23.000+00:00',
updated_at: '2021-12-23T14:15:45.000+00:00',
published_at: '2021-12-23T14:15:45.000+00:00',
custom_excerpt: null,
codeinjection_head: null,
codeinjection_foot: null,
custom_template: null,
canonical_url: null,
tags: [Array],
authors: [Array],
primary_author: [Object],
primary_tag: [Object],
url: 'http://localhost:2368/only-feature-image/',
excerpt:
'« Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.\n' +
'Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed,\n' +
'dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper\n' +
'congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est\n' +
'eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu\n' +
'massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut\n' +
'in risus volutpat libero pharetra tem',
reading_time: 2,
access: true,
send_email_when_published: false,
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
email_subject: null,
frontmatter: null,
},
{
id: '61c4847b0ff4550001505090',
uuid: 'f4ee5a37-a343-4cad-8a32-3f6cf87f9569',
title: 'Only toto image',
slug: 'only-toto-image',
html: '<p>Test 3</p>',
comment_id: '61c4847b0ff4550001505090',
feature_image: 'http://localhost:2368/content/images/2021/12/dacc-4.png',
featured: false,
visibility: 'public',
email_recipient_filter: 'none',
created_at: '2021-12-23T14:15:23.000+00:00',
updated_at: '2021-12-23T14:15:45.000+00:00',
published_at: '2021-12-23T14:15:45.000+00:00',
custom_excerpt: null,
codeinjection_head: null,
codeinjection_foot: null,
custom_template: null,
canonical_url: null,
tags: [Array],
authors: [Array],
primary_author: [Object],
primary_tag: [Object],
url: 'http://localhost:2368/only-feature-image/',
excerpt:
'« Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.\n' +
'Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed,\n' +
'dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper\n' +
'congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est\n' +
'eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu\n' +
'massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut\n' +
'in risus volutpat libero pharetra tem',
reading_time: 2,
access: true,
send_email_when_published: false,
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
email_subject: null,
frontmatter: null,
},
],
meta: { pagination: { page: 1, limit: 15, pages: 1, total: 2, next: null, prev: null } },
},
status: 200,
statusText: 'OK',
headers: {},
config: {},
};
jest.spyOn(httpServiceMock, 'get').mockImplementationOnce(() => of(result));
const response = await controller.findAll(query);
expect(response.posts.length).toEqual(3);
expect(response.meta.pagination.limit).toEqual(15);
expect(response.meta.pagination.page).toEqual(1);
expect(response.meta.pagination.total).toEqual(2);
});
});
it('should get pending attachments', async () => {
const result = { posts:[] };
jest.spyOn(controller, 'findAllTags').mockImplementation(async (): Promise<any> => result);
expect(await controller.findAllTags()).toBe(result);
describe('findAllTags', () => {
it('should get all tags', async () => {
postServiceMock.getLocationTags.mockImplementationOnce(() => [
{
id: '61b74b2c0d3b9800018ca3df',
name: 'oullins',
slug: 'oullins',
description: 'commune',
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:24.000Z',
updated_at: '2021-12-13T13:31:25.000Z',
url: 'http://localhost:2368/tag/oullins/',
},
{
id: '61b74b2c0d3b9800018ca3df',
name: 'oullins',
slug: 'oullins',
description: 'commune',
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:24.000Z',
updated_at: '2021-12-13T13:31:25.000Z',
url: 'http://localhost:2368/tag/oullins/',
},
{
id: '61b74b2c0d3b9800018ca3e0',
name: 'Bron',
slug: 'bron',
description: 'commune',
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:24.000Z',
updated_at: '2021-12-13T13:31:24.000Z',
url: 'http://localhost:2368/404/',
},
]);
postServiceMock.getPublicTags.mockImplementationOnce(() => [
{
id: '61b74b2d0d3b9800018ca3f6',
name: 'Séniors (+ de 65ans)',
slug: 'seniors-de-65ans',
description: 'public',
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:25.000Z',
updated_at: '2021-12-13T13:31:25.000Z',
url: 'http://localhost:2368/404/',
},
{
id: '61b74b2d0d3b9800018ca3f7',
name: 'Allophones',
slug: 'allophones',
description: 'public',
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:25.000Z',
updated_at: '2021-12-13T13:31:25.000Z',
url: 'http://localhost:2368/404/',
},
]);
postServiceMock.getRegularTags.mockImplementationOnce(() => [
{
id: '61b74b2d0d3b9800018ca3fa',
name: 'Études',
slug: 'etudes',
description: null,
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:25.000Z',
updated_at: '2021-12-13T13:31:25.000Z',
url: 'http://localhost:2368/tag/etudes/',
},
]);
const result = await controller.findAllTags();
expect(result.commune.length).toBe(3);
expect(result.others.length).toBe(1);
expect(result.public.length).toBe(2);
});
});
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);
describe('getPostbyId', () => {
it('should get post Hello by id 61c4847b0ff4550001505090', async () => {
const data = [
{
id: '61c4847b0ff4550001505090',
uuid: 'f4ee5a37-a343-4cad-8a32-3f6cf87f9569',
title: 'Hello',
slug: 'hello',
html: '<p>Test</p>',
comment_id: '61c4847b0ff4550001505090',
feature_image: 'http://localhost:2368/content/images/2021/12/dacc-4.png',
featured: false,
visibility: 'public',
email_recipient_filter: 'none',
created_at: '2021-12-23T14:15:23.000+00:00',
updated_at: '2021-12-23T14:15:45.000+00:00',
published_at: '2021-12-23T14:15:45.000+00:00',
custom_excerpt: null,
codeinjection_head: null,
codeinjection_foot: null,
custom_template: null,
canonical_url: null,
tags: [Array],
authors: [Array],
primary_author: [Object],
primary_tag: [Object],
url: 'http://localhost:2368/hello/',
excerpt:
'« Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.\n' +
'Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed,\n' +
'dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper\n' +
'congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est\n' +
'eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu\n' +
'massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut\n' +
'in risus volutpat libero pharetra tem',
reading_time: 2,
access: true,
send_email_when_published: false,
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
email_subject: null,
frontmatter: null,
},
];
const axiosResult: AxiosResponse = {
data: {
posts: data,
},
status: 200,
statusText: 'OK',
headers: {},
config: {},
};
httpServiceMock.get.mockImplementationOnce(() => of(axiosResult));
postServiceMock.formatPosts.mockImplementationOnce(() => data);
const result = await (await controller.getPostbyId('61c4847b0ff4550001505090')).toPromise();
expect(result).toStrictEqual({ posts: [data] });
});
});
});
......@@ -9,6 +9,7 @@ import { PostWithMeta } from './schemas/postWithMeta.schema';
@Controller('posts')
export class PostsController {
private readonly logger = new Logger(PostsController.name);
constructor(private readonly httpService: HttpService, private readonly postsService: PostsService) {}
@Get()
......@@ -36,7 +37,7 @@ export class PostsController {
.pipe(
map((response) => response.data),
catchError((err) => {
Logger.error(err);
this.logger.error(err);
throw new HttpException('Invalid ghost configuration', HttpStatus.BAD_REQUEST);
})
);
......
import { HttpModule } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigurationModule } from '../configuration/configuration.module';
import { TagEnum } from './enums/tag.enum';
import { PostsService } from './posts.service';
import { Tag } from './schemas/tag.schema';
import * as _ from 'lodash';
import { Post } from './schemas/post.schema';
describe('PostsService', () => {
let service: PostsService;
// let configService: ConfigurationServiceMock;
const locationtags = [
{
id: '61b74b2c0b9800018ca3df',
name: 'oullins',
slug: 'oullins',
description: 'commune',
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:24.000Z',
updated_at: '2021-12-13T13:31:25.000Z',
url: 'http://localhost:2368/tag/oullins/',
},
{
id: '61b74b2c0d9800018ca3df',
name: 'oullins',
slug: 'oullins',
description: 'commune',
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:24.000Z',
updated_at: '2021-12-13T13:31:25.000Z',
url: 'http://localhost:2368/tag/oullins/',
},
{
id: '61b74b2d3b9800018ca3e0',
name: 'Bron',
slug: 'bron',
description: 'commune',
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:24.000Z',
updated_at: '2021-12-13T13:31:24.000Z',
url: 'http://localhost:2368/404/',
},
];
const publictags = [
{
id: '61b74b2d0d3b9800018ca3f6',
name: 'Séniors (+ de 65ans)',
slug: 'seniors-de-65ans',
description: 'public',
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:25.000Z',
updated_at: '2021-12-13T13:31:25.000Z',
url: 'http://localhost:2368/404/',
},
{
id: '61b74b2d0d3b98000ca3f7',
name: 'Allophones',
slug: 'allophones',
description: 'public',
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:25.000Z',
updated_at: '2021-12-13T13:31:25.000Z',
url: 'http://localhost:2368/404/',
},
];
const otherTags = [
{
id: '61b74b2d0d3b980001a3fa',
name: 'Études',
slug: 'etudes',
description: null,
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:25.000Z',
updated_at: '2021-12-13T13:31:25.000Z',
url: 'http://localhost:2368/tag/etudes/',
},
{
id: '61b74b2d0d3b980001a3fa',
name: 'A la une',
slug: 'a-la-une',
description: null,
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:25.000Z',
updated_at: '2021-12-13T13:31:25.000Z',
url: 'http://localhost:2368/tag/a-la-une/',
},
{
id: '61b74b2d0d3b980001a3fa',
name: 'Infos',
slug: 'infos',
description: null,
feature_image: null,
visibility: 'public',
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
codeinjection_head: null,
codeinjection_foot: null,
canonical_url: null,
accent_color: null,
created_at: '2021-12-13T13:31:25.000Z',
updated_at: '2021-12-13T13:31:25.000Z',
url: 'http://localhost:2368/tag/infos/',
},
];
const tagsData = [...locationtags, ...publictags, ...otherTags];
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
......@@ -13,9 +213,114 @@ describe('PostsService', () => {
}).compile();
service = module.get<PostsService>(PostsService);
jest.spyOn(service, 'getTags').mockImplementationOnce(async (): Promise<Tag[]> => tagsData);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
it('should get tags', async () => {
expect(await service.getTags()).toEqual(tagsData);
});
it('should get location tags', async () => {
expect(await service.getLocationTags()).toEqual(locationtags);
});
it('should get public tags', async () => {
expect(await service.getPublicTags()).toEqual(publictags);
});
it('should get regular tags', async () => {
expect(await service.getRegularTags()).toEqual([otherTags[1], otherTags[2], otherTags[0]]);
});
describe('arraymove', () => {
it('should order tags for display: A La Une tag should be set to first index', () => {
const dataCopy = [...otherTags];
service.arraymove(dataCopy, _.findIndex(dataCopy, { slug: TagEnum.aLaUne }), 0);
expect(dataCopy).toEqual([otherTags[1], otherTags[0], otherTags[2]]);
});
it('should order tags for display: Info tag should be set to second index', () => {
const dataCopy = [...otherTags];
expect(service.arraymove(dataCopy, _.findIndex(dataCopy, { slug: TagEnum.infos }), 1)).toEqual([
otherTags[0],
otherTags[2],
otherTags[1],
]);
});
it('should order tags for display: A La Une tag should be set to first index and Info to second', () => {
const dataCopy = [...otherTags];
service.arraymove(dataCopy, _.findIndex(dataCopy, { slug: TagEnum.aLaUne }), 0);
expect(service.arraymove(dataCopy, _.findIndex(dataCopy, { slug: TagEnum.infos }), 1)).toEqual([
otherTags[1],
otherTags[2],
otherTags[0],
]);
});
});
describe('formatPosts', () => {
const postToFormat: Post = {
id: '61c4847b0ff4550001505090',
uuid: 'f4ee5a37-a343-4cad-8a32-3f6cf87f9569',
title: 'Only feature image',
slug: 'only-feature-image',
html: '<p>Test</p>',
comment_id: '61c4847b0ff4550001505090',
feature_image: 'http://localhost:2368/content/images/2021/12/dacc-4.png',
featured: false,
visibility: 'public',
email_recipient_filter: 'none',
created_at: '2021-12-23T14:15:23.000+00:00',
updated_at: '2021-12-23T14:15:45.000+00:00',
published_at: '2021-12-23T14:15:45.000+00:00',
custom_excerpt: null,
codeinjection_head: null,
codeinjection_foot: null,
custom_template: null,
canonical_url: null,
tags: [],
authors: [],
primary_author: [],
primary_tag: [],
url: 'http://localhost:2368/only-feature-image/',
excerpt:
'« Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.\n' +
'Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed,\n' +
'dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper\n' +
'congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est\n' +
'eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu\n' +
'massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut\n' +
'in risus volutpat libero pharetra tem',
reading_time: '2',
access: true,
send_email_when_published: false,
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
email_subject: null,
frontmatter: null,
};
it('should format post with no custom expert', () => {
const objCp = { ...postToFormat };
let result = { ...postToFormat };
result.excerpt = 'Inconnu';
result.feature_image = 'https://localhost/blog/content/images/2021/12/dacc-4.png';
expect(service.formatPosts(objCp)).toEqual(result);
});
it('should format post with custom expert', () => {
let objCp = { ...postToFormat };
objCp.custom_excerpt = 'Toto';
let result = { ...postToFormat };
result.custom_excerpt = 'Toto';
result.feature_image = 'https://localhost/blog/content/images/2021/12/dacc-4.png';
expect(service.formatPosts(objCp)).toEqual(result);
});
});
});
......@@ -27,4 +27,13 @@ export class Post {
meta_title: string;
meta_description: string;
email_subject: string;
codeinjection_head: string;
codeinjection_foot: string;
custom_template: string;
canonical_url: string;
tags: [];
authors: [];
primary_author: [];
primary_tag: [];
frontmatter: [];
}
......@@ -17,6 +17,7 @@ import { StructuresSearchService } from './structures-search.service';
@Injectable()
export class ApticStructuresService {
private readonly logger = new Logger(ApticStructuresService.name);
constructor(
private readonly httpService: HttpService,
private readonly userService: UsersService,
......@@ -46,13 +47,15 @@ export class ApticStructuresService {
this.createApticStructures(structure);
},
(err) => {
Logger.log(err);
this.logger.log(err);
}
);
});
},
(err) => {
Logger.log(`getApticStructures error on postal code: ${postalCode}. Code: ${err}`);
this.logger.log(
`formatApticStructures | getApticStructures error on postal code: ${postalCode}. Code: ${err}`
);
}
);
});
......@@ -65,7 +68,7 @@ export class ApticStructuresService {
private async createApticStructures(structure: ApticStructure): Promise<any> {
this.structureAlreadyExist(structure).then(async (exist) => {
if (!exist) {
Logger.log(`Create structure : ${structure.name}`, 'ApticStructuresService - createApticStructures');
this.logger.log(`createApticStructures | Create structure : ${structure.name}`);
const createdStructure = new this.structureModel();
// Known fields
createdStructure.structureName = structure.name;
......@@ -183,7 +186,7 @@ export class ApticStructuresService {
public getMetopoleMunicipality(): void {
const req =
'https://download.data.grandlyon.com/ws/grandlyon/adr_voie_lieu.adrcomgl/all.json?maxfeatures=-1&start=1';
Logger.log(`Request : ${req}`, 'ApticStructuresService - getMetopoleMunicipality');
this.logger.log(`getMetopoleMunicipality | Request : ${req}`, '');
this.httpService.get(encodeURI(req)).subscribe(
(data) => {
const inseeArray = data.data.values.map((municipality) => {
......@@ -196,19 +199,19 @@ export class ApticStructuresService {
this.formatApticStructures(postalCodeArray);
});
},
(err) => Logger.error(err)
(err) => this.logger.error(err)
);
}
public getPostalCodeWithINSEE(inseeCode: string): Observable<AxiosResponse<any>> {
const req = `https://geo.api.gouv.fr/communes/${inseeCode}?fields=codesPostaux&format=json`;
Logger.log(`Request : ${req}`, 'ApticStructuresService - getMetopoleMunicipality');
this.logger.debug(`getMetopoleMunicipality | Request : ${req}`);
return this.httpService.get(encodeURI(req));
}
public getApticStructures(postalCodeData: string): Observable<AxiosResponse<{ presencePoints: ApticStructure[] }>> {
const req = `https://aptisearch-api.aptic.fr/v1/postal-code/${postalCodeData}`;
Logger.log(`Request : ${req}`, 'ApticStructuresService');
this.logger.debug(`getApticStructures | Request : ${req}`);
return this.httpService.get(req, {
headers: {
api_key: process.env.APTIC_TOKEN,
......@@ -221,7 +224,7 @@ export class ApticStructuresService {
rejectUnauthorized: false,
});
const req = `https://aptisearch-api.aptic.fr/v1/catalog/${catalogId}/services`;
Logger.log(`Request : ${req}`, 'ApticStructuresService');
this.logger.log(`getApticStructureOffer | Request : ${req}`);
return this.httpService.get(req, {
httpsAgent: agent,
headers: {
......
import { HttpModule, HttpStatus } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ElasticsearchService } from '@nestjs/elasticsearch';
import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing';
import { UsersServiceMock } from '../../../test/mock/services/user.mock.service';
import { ConfigurationService } from '../../configuration/configuration.service';
import { MailerModule } from '../../mailer/mailer.module';
import { MailerService } from '../../mailer/mailer.service';
import { SearchModule } from '../../search/search.module';
import { UsersService } from '../../users/users.service';
import { structureDto } from '../dto/structure.dto';
import { Structure } from '../schemas/structure.schema';
import { StructuresSearchService } from './structures-search.service';
import { StructuresService } from './structures.service';
describe('StructuresService', () => {
let service: StructuresService;
const mockStructureModel = {
create: jest.fn(),
deleteOne: jest.fn(),
countDocuments: jest.fn(),
findOne: jest.fn(),
exec: jest.fn(),
find: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [HttpModule, MailerModule, SearchModule, ConfigModule],
providers: [
StructuresService,
ConfigurationService,
StructuresSearchService,
{
provide: getModelToken(Structure.name),
useValue: mockStructureModel,
},
{
provide: UsersService,
useClass: UsersServiceMock,
},
],
}).compile();
service = module.get<StructuresService>(StructuresService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
it('should Initiate structure', () => {
const res = service.initiateStructureIndex();
expect(res).toBeTruthy();
});
it('should searchForStructures', () => {
let res = service.searchForStructures('a', [{ nbPrinters: '1' }]);
expect(res).toBeTruthy();
res = service.searchForStructures('a');
expect(res).toBeTruthy();
});
it('should create structure', () => {
const structure = new structureDto();
let res = service.create(null, structure);
expect(res).toBeTruthy();
res = service.create('tsfsf6296', structure);
expect(res).toBeTruthy();
});
it('should search structure', () => {
const filters = [{ nbPrinters: '1' }];
let res = service.search('', filters);
expect(res).toBeTruthy();
res = service.search(null, filters);
expect(res).toBeTruthy();
res = service.search(null);
expect(res).toBeTruthy();
});
it('should find all structures', () => {
const res = service.findAll();
expect(res).toBeTruthy();
});
it('should find all unclaimed structures', () => {
const res = service.findAllUnclaimed();
expect(res).toBeTruthy();
});
it('should find all formated structures', () => {
const res = service.findAllFormated(null, null, null);
expect(res).toBeTruthy();
});
it('should populate ES', () => {
const res = service.populateES();
expect(res).toBeTruthy();
});
it('should report structure Error', () => {
let res = service.reportStructureError('6093ba0e2ab5775cfc01ed3e', '');
expect(res).toBeTruthy();
res = service.reportStructureError(null, '');
expect(res).toBeTruthy();
});
});
import { HttpModule } from '@nestjs/common';
import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing';
import { TclStopPoint } from './tclStopPoint.schema';
import { TclStopPointService } from './tclStopPoint.service';
describe('TclService', () => {
let service: TclStopPointService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [HttpModule],
providers: [
TclStopPointService,
{
provide: getModelToken('TclStopPoint'),
useValue: TclStopPoint,
},
],
}).compile();
service = module.get<TclStopPointService>(TclStopPointService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { HttpModule, HttpStatus } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { MailerModule } from '../mailer/mailer.module';
import { TempUserController } from './temp-user.controller';
import { TempUserService } from './temp-user.service';
describe('TempUserService', () => {
let controller: TempUserController;
const mockTempUserService = {
findById: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [HttpModule, MailerModule],
providers: [{ provide: TempUserService, useValue: mockTempUserService }],
controllers: [TempUserController],
}).compile();
controller = module.get<TempUserController>(TempUserController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
describe('getTempUser', () => {
it('should get temporary users', async () => {
const tmpUser = { email: 'test@test.com', pendingStructuresLink: [] };
mockTempUserService.findById.mockReturnValueOnce(tmpUser);
expect(await controller.getTempUser('addq651')).toEqual(tmpUser);
});
it('should throw error in cas of no users', async () => {
const tmpUser = null;
mockTempUserService.findById.mockReturnValueOnce(tmpUser);
try {
await controller.getTempUser('addq651');
// Fail test if above expression doesn't throw anything.
expect(true).toBe(false);
} catch (e) {
expect(e.message).toEqual('User does not exists');
expect(e.status).toEqual(HttpStatus.BAD_REQUEST);
}
});
});
});
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