Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server
1 result
Show changes
Commits on Source (56)
Showing
with 317 additions and 358 deletions
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
project: true,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
......
......@@ -74,7 +74,7 @@ deploy_dev:
test:
stage: test
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:14.15.4
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:18.17.0
services:
- name: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/elasticsearch:7.16.2
alias: elasticsearch
......@@ -120,7 +120,7 @@ sonarqube:
-Dsonar.projectKey=${SONAR_PROJECT_KEY}
-Dsonar.login=${SONAR_TOKEN}
-Dsonar.cpd.exclusions=test/**,scripts/**,src/**/*.spec.ts*
-Dsonar.exclusions=test/**,scripts/**,src/**/*.spec.ts*,src/migrations/scripts/**
-Dsonar.exclusions=test/**,scripts/**,src/**/*.spec.ts*,src/migrations/scripts/**
-Dsonar.qualitygate.wait=true
sonarqube-mr:
......
v14
18
......@@ -49,6 +49,8 @@
"nestjs",
"orientator",
"permanences",
"photonban"
"photonban",
"spyer",
"Unvalidated"
]
}
FROM node:14.20-slim
FROM node:18-bullseye
# Create app directory
WORKDIR /app
......
import type { Config } from 'jest';
const config: Config = {
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: '/src/.*\\.(test|spec).(ts|tsx|js)$',
collectCoverageFrom: ['src/**/*.{js,jsx,tsx,ts}', '!**/node_modules/**', '!**/vendor/**'],
reporters: ['default', 'jest-junit'],
};
export default config;
{
"moduleFileExtensions": ["ts", "tsx", "js", "json"],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "/src/.*\\.(test|spec).(ts|tsx|js)$",
"collectCoverageFrom": ["src/**/*.{js,jsx,tsx,ts}", "!**/node_modules/**", "!**/vendor/**"],
"coverageReporters": ["json", "lcov"],
"reporters": ["default", "jest-junit"]
}
......@@ -5049,18 +5049,18 @@
}
},
"@nestjs/schedule": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/@nestjs/schedule/-/schedule-0.4.1.tgz",
"integrity": "sha512-pj+zo3DJnoyGQKGguyLn9Nv1KEHZO2vNNGhtrZCIn74GsJL+CkDnd+fpgV85mypaJzjjGRogbMvXUW2UFnJAfg==",
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@nestjs/schedule/-/schedule-2.2.3.tgz",
"integrity": "sha512-PxoGdoBwZQ6SzGfFcERTk7mDxrmesNt2cfqKgtLsFpjYNpV6ZYlKw9Ku8C0ZIjdhy0tBbysj+Fsi3sYua6o6Eg==",
"requires": {
"cron": "1.7.2",
"uuid": "8.3.0"
"cron": "2.3.1",
"uuid": "9.0.0"
},
"dependencies": {
"uuid": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.0.tgz",
"integrity": "sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ=="
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz",
"integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg=="
}
}
},
......@@ -5599,9 +5599,9 @@
"dev": true
},
"@types/node": {
"version": "14.14.6",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.6.tgz",
"integrity": "sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw=="
"version": "18.17.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.17.1.tgz",
"integrity": "sha512-xlR1jahfizdplZYRU59JlUx9uzF1ARa8jbhM11ccpCJya8kvos5jwdm2ZAgxSCwOl0fq21svP18EVwPBXMQudw=="
},
"@types/normalize-package-data": {
"version": "2.4.0",
......@@ -7659,11 +7659,18 @@
"dev": true
},
"cron": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/cron/-/cron-1.7.2.tgz",
"integrity": "sha512-+SaJ2OfeRvfQqwXQ2kgr0Y5pzBR/lijf5OpnnaruwWnmI799JfWr2jN2ItOV9s3A/+TFOt6mxvKzQq5F0Jp6VQ==",
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/cron/-/cron-2.3.1.tgz",
"integrity": "sha512-1eRRlIT0UfIqauwbG9pkg3J6CX9A6My2ytJWqAXoK0T9oJnUZTzGBNPxao0zjodIbPgf8UQWjE62BMb9eVllSQ==",
"requires": {
"moment-timezone": "^0.5.x"
"luxon": "^3.2.1"
},
"dependencies": {
"luxon": {
"version": "3.4.1",
"resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.1.tgz",
"integrity": "sha512-2USspxOCXWGIKHwuQ9XElxPPYrDOJHDQ5DQ870CoD+CxJbBnRDIBCfhioUJJjct7BKOy80Ia8cVstIcIMb/0+Q=="
}
}
},
"cross-spawn": {
......@@ -13463,19 +13470,6 @@
"integrity": "sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw==",
"dev": true
},
"moment": {
"version": "2.29.4",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w=="
},
"moment-timezone": {
"version": "0.5.38",
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.38.tgz",
"integrity": "sha512-nMIrzGah4+oYZPflDvLZUgoVUO4fvAqHstvG3xAUnMolWncuAiLDWNnJZj6EwJGMGfb1ZcuTFE6GI3hNOVWI/Q==",
"requires": {
"moment": ">= 2.9.0"
}
},
"mongodb": {
"version": "4.11.0",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.11.0.tgz",
......
......@@ -20,12 +20,12 @@
"release": "standard-version",
"start:debug": "nodemon --config nodemon-debug.json",
"start:dev": "nodemon",
"test": "jest --runInBand --config ./jest.json",
"start:prod": "npm run migrate:up && node dist/src/main",
"test:cov": "jest --config ./jest.json --coverage --ci --reporters=default --reporters=jest-junit",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test": "jest --runInBand --config ./jest.config.ts",
"test:cov": "jest --config ./jest.config.ts --coverage --ci --reporters=default --reporters=jest-junit",
"test:debug": "node --config ./jest.config.ts --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:watch": "jest --config ./jest.json --watch --coverage"
"test:watch": "jest --config ./jest.config.ts --watch --coverage"
},
"dependencies": {
"@elastic/elasticsearch": "~8.5.0",
......@@ -40,7 +40,7 @@
"@nestjs/mongoose": "^9.2.1",
"@nestjs/passport": "^9.0.0",
"@nestjs/platform-express": "^9.2.0",
"@nestjs/schedule": "^0.4.1",
"@nestjs/schedule": "^2.2.3",
"@nestjs/swagger": "^6.1.3",
"@tryghost/admin-api": "^1.13.1",
"@types/bcrypt": "^5.0.0",
......@@ -72,7 +72,7 @@
"@nestjs/testing": "^9.0.11",
"@types/express": "^4.17.8",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.6",
"@types/node": "^18.0.0",
"@types/passport-local": "^1.0.33",
"@types/supertest": "^2.0.10",
"@typescript-eslint/eslint-plugin": "^5.37",
......@@ -91,22 +91,5 @@
"ts-node": "^10.9.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.2.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
......@@ -2,6 +2,7 @@ import { HttpModule } from '@nestjs/axios';
import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing';
import { Types } from 'mongoose';
import { structuresDocumentDataMock } from '../../test/mock/data/structures.mock.data';
import { mockJwtAuthGuard } from '../../test/mock/guards/jwt-auth.mock.guard';
import { mockRoleGuard } from '../../test/mock/guards/role.mock.guard';
import { NewsletterServiceMock } from '../../test/mock/services/newsletter.mock.service';
......@@ -9,6 +10,8 @@ import { StructuresServiceMock } from '../../test/mock/services/structures.mock.
import { UsersServiceMock } from '../../test/mock/services/user.mock.service';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { ConfigurationModule } from '../configuration/configuration.module';
import { EspaceCoopCNFS } from '../espaceCoop/schemas/espaceCoopCNFS.schema';
import { EspaceCoopService } from '../espaceCoop/services/espaceCoop.service';
import { MailerService } from '../mailer/mailer.service';
import { NewsletterSubscription } from '../newsletter/newsletter-subscription.schema';
import { NewsletterService } from '../newsletter/newsletter.service';
......@@ -25,8 +28,6 @@ import { UsersService } from '../users/services/users.service';
import { AdminController } from './admin.controller';
import { AdminService } from './admin.service';
import { PendingStructureDto } from './dto/pending-structure.dto';
import { EspaceCoopService } from '../espaceCoop/services/espaceCoop.service';
import { EspaceCoopCNFS } from '../espaceCoop/schemas/espaceCoopCNFS.schema';
describe('AdminController', () => {
let controller: AdminController;
......@@ -65,6 +66,20 @@ describe('AdminController', () => {
mergeJob: jest.fn(),
deleteInvalidJob: jest.fn(),
};
const mockStructureService = {
findOne: jest.fn(),
deleteOne: jest.fn(),
findAll: jest.fn(),
getAllUserCompletedStructures: jest.fn(),
findAllUnclaimed: jest.fn(),
};
const mockAdminService = {
isDateOutdated: jest.fn(),
getLastUpdateDate: jest.fn(),
};
const pendingStructureTest: PendingStructureDto = {
structureId: new Types.ObjectId('6093ba0e2ab5775cfc01ed3e'),
structureName: 'test',
......@@ -82,7 +97,7 @@ describe('AdminController', () => {
},
{
provide: StructuresService,
useClass: StructuresServiceMock,
useValue: mockStructureService,
},
{
provide: NewsletterService,
......@@ -90,7 +105,7 @@ describe('AdminController', () => {
},
{
provide: AdminService,
useClass: AdminService,
useValue: mockAdminService,
},
StructuresSearchService,
MailerService,
......@@ -141,12 +156,14 @@ describe('AdminController', () => {
});
it('should get pending attachments', async () => {
mockStructureService.findOne.mockResolvedValue({ structureName: 'structure', updatedAt: '' });
expect((await controller.getPendingAttachments()).length).toBe(2);
expect(Object.keys((await controller.getPendingAttachments())[0]).length).toBe(5);
});
describe('Pending structures validation', () => {
it('should validate pending structure', async () => {
mockStructureService.findOne.mockResolvedValue({ structureName: 'structure' });
expect((await controller.validatePendingStructure(pendingStructureTest)).length).toBe(2);
expect(Object.keys((await controller.validatePendingStructure(pendingStructureTest))[0]).length).toBe(5);
});
......@@ -163,6 +180,7 @@ describe('AdminController', () => {
describe('Pending structures cancel', () => {
it('should refuse pending structure', async () => {
mockStructureService.findOne.mockResolvedValue({ structureName: 'structure' });
expect((await controller.refusePendingStructure(pendingStructureTest)).length).toBe(2);
expect(Object.keys((await controller.refusePendingStructure(pendingStructureTest))[0]).length).toBe(5);
});
......@@ -179,11 +197,13 @@ describe('AdminController', () => {
describe('Delete user', () => {
it('should delete user', async () => {
expect((await controller.deleteUser({ id: 'tsfsf6296' })).email).toBe('pauline.dupont@mii.com');
jest.spyOn(StructuresServiceMock.prototype, 'deleteOne').mockImplementationOnce(() => null);
const user = await controller.deleteUser({ id: 'tsfsf6296' });
expect(user.email).toBe('pauline.dupont@mii.com');
});
it('should return unexisting user', async () => {
it('should return nonexisting user', async () => {
try {
await controller.deleteUser({ id: 'userdoesnotexist' });
await controller.deleteUser({ id: 'userDoesNotExist' });
} catch (e) {
expect(e.message).toBe('Invalid user id');
expect(e.status).toBe(400);
......@@ -234,7 +254,7 @@ describe('AdminController', () => {
it('should not set a new employer to the user if the user does not exist', async () => {
const spyer = jest.spyOn(userService, 'updateUserEmployer');
const mockUserId = 'thisuserdoesnotexist';
const mockUserId = 'thisUserDoesNotExist';
const mockEmployer = {
_id: new Types.ObjectId('6231aefe76598527c8d0b5ba'),
name: 'Sopra',
......@@ -344,20 +364,39 @@ describe('AdminController', () => {
try {
await controller.unsubscribeUserFromNewsletter('test@test.com');
} catch (e) {
expect(e.message).toBe('Invalid email');
expect(e.message).toBe('Invalid email');
expect(e.status).toBe(401);
}
});
});
it('should get pending structure list for admin', async () => {
expect((await controller.getAdminStructuresList()).inClaim.length).toBe(2);
expect((await controller.getAdminStructuresList()).toClaim.length).toEqual(2);
expect((await controller.getAdminStructuresList()).claimed.length).toEqual(2);
expect((await controller.getAdminStructuresList()).incomplete.length).toEqual(2);
mockAdminService.isDateOutdated.mockReturnValue(false);
mockAdminService.getLastUpdateDate.mockReturnValue('');
mockStructureService.findOne.mockResolvedValue({ structureName: 'structure' });
// using _id for unclaimed
mockStructureService.findAllUnclaimed.mockResolvedValueOnce([
{ structureName: 'name', structureId: 'a', _id: 'a' },
{ structureName: 'name', structureId: 'b', _id: 'b' },
]);
mockStructureService.findAll.mockResolvedValueOnce([
{ structureName: 'name', structureId: 'c' },
{ structureName: 'name', structureId: 'd' },
]);
mockStructureService.findAll.mockResolvedValueOnce([
{ structureName: 'name', structureId: 'e', id: 'e' },
{ structureName: 'name', structureId: 'f', id: 'f' },
]);
const adminList = await controller.getAdminStructuresList();
expect(adminList.inClaim.length).toBe(2);
expect(adminList.toClaim.length).toBe(2);
expect(adminList.claimed.length).toBe(2);
expect(adminList.incomplete.length).toBe(2);
});
it('should find attached users', async () => {
mockStructureService.getAllUserCompletedStructures.mockResolvedValueOnce([]);
expect((await controller.findAttachedUsers()).length).toBe(0);
});
......@@ -366,11 +405,13 @@ describe('AdminController', () => {
});
it('should find unverified users', async () => {
mockStructureService.getAllUserCompletedStructures.mockResolvedValueOnce([]);
expect((await controller.findUnVerifiedUsers()).length).toBe(0);
});
describe('should test getDeletedStructures()', () => {
it('should find getDeletedStructures', async () => {
mockStructureService.findAll.mockResolvedValue(structuresDocumentDataMock);
expect((await controller.getDeletedStructures()).length).toBeGreaterThan(0);
});
});
......
......@@ -14,6 +14,8 @@ import {
import { ApiBearerAuth, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
import { validate } from 'class-validator';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { EspaceCoopCNFS } from '../espaceCoop/schemas/espaceCoopCNFS.schema';
import { EspaceCoopService } from '../espaceCoop/services/espaceCoop.service';
import { NewsletterSubscription } from '../newsletter/newsletter-subscription.schema';
import { NewsletterService } from '../newsletter/newsletter.service';
import { Structure, StructureDocument } from '../structures/schemas/structure.schema';
......@@ -28,8 +30,6 @@ import { AdminService } from './admin.service';
import { PendingStructureDto } from './dto/pending-structure.dto';
import { SetUserEmployerDto } from './dto/set-user-employer.dto';
import { SetUserJobDto } from './dto/set-user-job.dto';
import { EspaceCoopCNFS } from '../espaceCoop/schemas/espaceCoopCNFS.schema';
import { EspaceCoopService } from '../espaceCoop/services/espaceCoop.service';
@ApiTags('admin')
@Controller('admin')
......
......@@ -11,7 +11,6 @@ import { UsersServiceMock } from '../../test/mock/services/user.mock.service';
import { StructuresServiceMock } from '../../test/mock/services/structures.mock.service';
import * as ejs from 'ejs';
jest.mock('ejs');
describe('userRegistryService', () => {
let service: AppointmentService;
const mockAppointmentModel = {
......@@ -36,7 +35,6 @@ describe('userRegistryService', () => {
};
const ejsSpy = jest.spyOn(ejs, 'renderFile');
const mailerSpy = jest.spyOn(mockMailService, 'send');
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
......@@ -87,7 +85,7 @@ describe('userRegistryService', () => {
ejsSpy.mockResolvedValueOnce('coucou');
mockAppointmentModel.create.mockResolvedValueOnce(res);
expect(await service.create(res)).toStrictEqual(res);
expect(mailerSpy).toHaveBeenCalledTimes(1);
expect(mockMailService.send).toHaveBeenCalledTimes(1);
});
});
});
......@@ -40,6 +40,7 @@ describe('NewsletterService', () => {
process.env.MC_LIST_ID = 'abcde';
process.env.MC_API_KEY = 'k3y';
process.env.MC_SERVER = 's3rv3r';
jest.clearAllMocks();
});
afterAll(() => {
......@@ -168,7 +169,7 @@ describe('NewsletterService', () => {
});
});
describe('updateNewsletterSubscription', () => {
it('should update existing user subscription', () => {
it('should update existing user subscription', async () => {
mailchimp.lists.getListMembersInfo.mockResolvedValueOnce({ total_items: 10 }).mockResolvedValueOnce({
members: [
{ email_address: 'a@a.com', status: 'subscribed' },
......@@ -176,11 +177,12 @@ describe('NewsletterService', () => {
{ email_address: 'test2@test.com', status: 'unsubscribed' },
],
});
const result = { email: 'test2@test.com' } as INewsletterSubscription;
const spyer = jest.spyOn(mockNewsletterModel, 'findOne');
mockNewsletterModel.findOne.mockResolvedValueOnce(result).mockResolvedValueOnce(null);
service.updateNewsletterSubscription();
expect(spyer).toBeCalledTimes(3);
const result = { email: 'test2@test.com', deleteOne: jest.fn() };
mockNewsletterModel.findOne.mockReturnThis();
mockNewsletterModel.exec.mockResolvedValueOnce(result).mockResolvedValueOnce(null);
await service.updateNewsletterSubscription();
expect(mockNewsletterModel.findOne).toBeCalledTimes(2);
// Remove subscription is not tested
// expect(spyerDelete).toBeCalledTimes(1);
});
});
......
......@@ -6,8 +6,9 @@ import { MailerModule } from '../../mailer/mailer.module';
import { SearchModule } from '../../search/search.module';
import { StructuresSearchService } from './structures-search.service';
import { StructuresService } from './structures.service';
describe('StructuresSearchService', () => {
let service: StructuresSearchService;
let structureSearchService: StructuresSearchService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
......@@ -21,90 +22,91 @@ describe('StructuresSearchService', () => {
],
}).compile();
service = module.get<StructuresSearchService>(StructuresSearchService);
service['index'] = 'structures-unit-test';
await service.dropIndex();
await service.createStructureIndex();
structureSearchService = module.get<StructuresSearchService>(StructuresSearchService);
structureSearchService['index'] = 'structures-unit-test';
await structureSearchService.dropIndex();
await structureSearchService.createStructureIndex();
// init str
const structuresForSearchService = new StructuresForSearchServiceMock();
const structures = structuresForSearchService.findAll();
await Promise.all(
structures.map((structure) => {
service.indexStructure(structure);
structureSearchService.indexStructure(structure);
})
);
// wait for the new structures to be indexed before search
await service.refreshIndexStructure();
await structureSearchService.refreshIndexStructure();
await new Promise((r) => setTimeout(r, 2000));
}, 10000);
it('should be defined', () => {
expect(service).toBeDefined();
});
it('should find maisons de la métropole', async () => {
const res = await service.search('maison de la');
//Logger.log(JSON.stringify(res));
expect(res[0].structureName).toContain('Maison de la Métropole');
expect(res[1].structureName).toContain('Maison de la Métropole');
});
it('should find metropole', async () => {
const res = await service.search('metropole');
expect(res[0].structureName).toContain('Métropole');
});
it('should find structure with stopword "son"', async () => {
const res = await service.search('son');
expect(res[0].structureName).toContain('Le Son du Clic');
});
it('should find structure with stopword "mais"', async () => {
const res = await service.search('mais');
expect(res[0].structureName.toLowerCase()).toContain('maison');
});
it('should find structure with stopword "le"', async () => {
const res = await service.search('le');
expect(res.length).toBeGreaterThanOrEqual(1);
});
it('should find structure with partial word "oull"', async () => {
const res = await service.search('oull');
expect(res[0].structureName.toLowerCase()).toContain('oullins');
});
it('should find structure with partial word "vill"', async () => {
const res = await service.search('vill');
expect(res[0].structureName.toLowerCase()).toContain('villeurbanne');
});
it('should find structure with partial word "asso"', async () => {
const res = await service.search('asso');
Logger.log(JSON.stringify(res));
expect(res[0].structureName.toLowerCase()).toContain('association');
});
it('should find text in description', async () => {
const res = await service.search('liseuse');
expect(res.length).toBe(1);
expect(res[0].structureName).toContain("Médiathèque d'Ecully");
});
it('should not find text in description when search by name', async () => {
const res = await service.search('liseuse', ['structureName']);
expect(res.length).toBe(0);
expect(structureSearchService).toBeDefined();
});
it('should find structure when search by name', async () => {
const res = await service.search('le son', ['structureName']);
expect(res[0].structureName).toContain('Le Son du Clic');
describe('search method', () => {
it('should find maisons de la métropole', async () => {
const res = await structureSearchService.search('maison de la');
expect(res[0].structureName).toContain('Maison de la Métropole');
expect(res[1].structureName).toContain('Maison de la Métropole');
});
it('should find metropole', async () => {
const res = await structureSearchService.search('metropole');
expect(res[0].structureName).toContain('Métropole');
});
it('should find structure with stopword "son"', async () => {
const res = await structureSearchService.search('son');
expect(res[0].structureName).toContain('Le Son du Clic');
});
it('should find structure with stopword "mais"', async () => {
const res = await structureSearchService.search('mais');
expect(res[0].structureName.toLowerCase()).toContain('maison');
});
it('should find structure with stopword "le"', async () => {
const res = await structureSearchService.search('le');
expect(res.length).toBeGreaterThanOrEqual(1);
});
it('should find structure with partial word "oull"', async () => {
const res = await structureSearchService.search('oull');
expect(res[0].structureName.toLowerCase()).toContain('oullins');
});
it('should find structure with partial word "vill"', async () => {
const res = await structureSearchService.search('vill');
expect(res[0].structureName.toLowerCase()).toContain('villeurbanne');
});
it('should find structure with partial word "asso"', async () => {
const res = await structureSearchService.search('asso');
Logger.log(JSON.stringify(res));
expect(res[0].structureName.toLowerCase()).toContain('association');
});
it('should find text in description', async () => {
const res = await structureSearchService.search('liseuse');
expect(res.length).toBe(1);
expect(res[0].structureName).toContain("Médiathèque d'Ecully");
});
it('should not find text in description when search by name', async () => {
const res = await structureSearchService.search('liseuse', ['structureName']);
expect(res.length).toBe(0);
});
it('should find structure when search by name', async () => {
const res = await structureSearchService.search('le son', ['structureName']);
expect(res[0].structureName).toContain('Le Son du Clic');
});
});
it('should drop index', async () => {
const res = await service.dropIndex();
const res = await structureSearchService.dropIndex();
expect(res).toBeTruthy();
});
});
......@@ -38,20 +38,21 @@ function hashPassword() {
jest.mock('axios');
const mockStructureModel = {
countDocuments: jest.fn(),
create: jest.fn(),
deleteOne: jest.fn(),
countDocuments: jest.fn(),
findOne: jest.fn(),
findById: jest.fn(),
limit: jest.fn(),
findByIdAndUpdate: jest.fn(),
exec: jest.fn(),
find: jest.fn(),
findById: jest.fn(),
findByIdAndUpdate: jest.fn(),
findOne: jest.fn(),
limit: jest.fn(),
populate: jest.fn(),
save: jest.fn(),
select: jest.fn().mockReturnThis(),
};
const structuresSearchServiceMock = {
const mockStructuresSearchService = {
search: jest.fn().mockReturnValue([
{
_id: '6903ba0e2ab5775cfc01ed4d',
......@@ -253,7 +254,7 @@ describe('StructuresService', () => {
},
{
provide: StructuresSearchService,
useValue: structuresSearchServiceMock,
useValue: mockStructuresSearchService,
},
{
provide: getModelToken(Structure.name),
......@@ -280,6 +281,7 @@ describe('StructuresService', () => {
service = module.get<StructuresService>(StructuresService);
service['structuresSearchService']['index'] = 'structures-unit-test';
service['sendToBeDeletedNotification'] = jest.fn();
});
it('should be defined', () => {
......@@ -287,13 +289,10 @@ describe('StructuresService', () => {
});
it('should Initiate structure index', async () => {
const spyerIndex = jest.spyOn(structuresSearchServiceMock, 'indexStructure');
const spyerDrop = jest.spyOn(structuresSearchServiceMock, 'dropIndex');
const spyerCreate = jest.spyOn(structuresSearchServiceMock, 'createStructureIndex');
await service.initiateStructureIndex();
expect(spyerCreate).toBeCalledTimes(1);
expect(spyerDrop).toBeCalledTimes(1);
expect(spyerIndex).toBeCalledTimes(1);
expect(mockStructuresSearchService.createStructureIndex).toBeCalledTimes(1);
expect(mockStructuresSearchService.dropIndex).toBeCalledTimes(1);
expect(mockStructuresSearchService.indexStructure).toBeCalledTimes(1);
});
describe('searchForStructures', () => {
......@@ -370,15 +369,15 @@ describe('StructuresService', () => {
]);
it('should find 1 structure', async () => {
const res = await service.searchForStructures('a', [[{ nbPrinters: '1' }], []]);
const res = await service.searchForStructures('a', [[{ nbPrinters: '1' }]]);
expect(res.length).toBe(1);
});
it('should find 1 structure', async () => {
const res = await service.searchForStructures('a', [[{ nbPrinters: '1' }, { '': 'baseSkills' }], []]);
const res = await service.searchForStructures('a', [[{ nbPrinters: '1' }, { '': 'baseSkills' }]]);
expect(res.length).toBe(1);
});
it('should find 1 structure', async () => {
const res = await service.searchForStructures('a', [[{ '': 'baseSkills' }], []]);
const res = await service.searchForStructures('a', [[{ '': 'baseSkills' }]]);
expect(res.length).toBe(1);
});
it('should find 1 structure', async () => {
......@@ -389,9 +388,8 @@ describe('StructuresService', () => {
describe('create', () => {
it('should return invalid profile', async () => {
const structure = structureMockDto;
try {
await service.create('test@test.com', structure);
await service.create('test@test.com', structureMockDto);
expect(true).toBe(false);
} catch (e) {
expect(e.message).toEqual('Invalid profile');
......@@ -434,6 +432,7 @@ describe('StructuresService', () => {
});
it('should find all formatted structures', () => {
mockStructureModel.exec.mockResolvedValue([]);
expect(service.findConsentingStructures(null)).toBeTruthy();
});
});
......@@ -548,11 +547,8 @@ describe('StructuresService', () => {
});
});
it('should report structure Error', () => {
let res = service.reportStructureError('6093ba0e2ab5775cfc01ed3e', '');
expect(res).toBeTruthy();
res = service.reportStructureError(null, '');
expect(res).toBeTruthy();
describe('reportStructureError', () => {
// to be implemented
});
describe('addPersonalOffer', () => {
......
......@@ -22,10 +22,10 @@ import { StructureDto } from '../dto/structure.dto';
import { UpdateStructureDto } from '../dto/update-structure.dto';
import { EquipmentsServicesEnum } from '../enum/equipmentsServices';
import { CNFSStructure } from '../interfaces/cnfs-structure.interface';
import { PhotonPoints } from '../interfaces/photon-response.interface';
import { Address } from '../schemas/address.schema';
import { Structure, StructureDocument } from '../schemas/structure.schema';
import { StructuresSearchService } from './structures-search.service';
import { PhotonPoints } from '../interfaces/photon-response.interface';
import { JobsService } from '../../users/services/jobs.service';
@Injectable()
......
import { HttpService } from '@nestjs/axios';
import { HttpStatus } from '@nestjs/common';
import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing';
import { Types } from 'mongoose';
import { of } from 'rxjs';
import { PhotonResponseMock } from '../../test/mock/data/dataPhoton.mock.data';
import { structureDtoMock } from '../../test/mock/data/structure.mock.dto';
import { CategoriesServiceMock } from '../../test/mock/services/categories.mock.service';
import { HttpServiceMock } from '../../test/mock/services/http.mock.service';
import {
StructuresExportServiceMock,
mockFormattedStructures,
} from '../../test/mock/services/structures-export.mock.service';
import { StructuresServiceMock } from '../../test/mock/services/structures.mock.service';
import { TempUserServiceMock } from '../../test/mock/services/tempUser.mock.service';
import { UsersServiceMock } from '../../test/mock/services/user.mock.service';
......@@ -11,28 +18,40 @@ import { CategoriesService } from '../categories/services/categories.service';
import { PersonalOffersService } from '../personal-offers/personal-offers.service';
import { TempUserService } from '../temp-user/temp-user.service';
import { UserRole } from '../users/enum/user-role.enum';
import { JobDocument } from '../users/schemas/job.schema';
import { UsersService } from '../users/services/users.service';
import { PersonalOffersServiceMock } from './../../test/mock/services/personalOffers.mock.service';
import { PersonalOffer, PersonalOfferDocument } from './../personal-offers/schemas/personal-offer.schema';
import { CreateStructureDto } from './dto/create-structure.dto';
import { StructuresService } from './services/structures.service';
import { StructuresController } from './structures.controller';
import { StructuresExportService } from './services/structures-export.service';
import {
StructuresExportServiceMock,
mockFormattedStructures,
} from '../../test/mock/services/structures-export.mock.service';
import { StructureFormatted } from './interfaces/structure-formatted.interface';
import { JobDocument } from '../users/schemas/job.schema';
import { StructuresImportService } from './services/structures-import.service';
import { getModelToken } from '@nestjs/mongoose';
import { Structure } from './schemas/structure.schema';
import { StructuresExportService } from './services/structures-export.service';
import { StructuresImportService } from './services/structures-import.service';
import { StructuresService } from './services/structures.service';
import { StructuresController } from './structures.controller';
import { mockDeletedStructure, mockStructure } from '../../test/mock/data/structures.mock.data';
describe('StructuresController', () => {
let controller: StructuresController;
let usersService: UsersService;
let structuresExportService: StructuresExportService;
let personalOffersService: PersonalOffersService;
const mockHttpService = {
get: jest.fn(),
};
const mockStructureService = {
create: jest.fn(),
deleteOne: jest.fn(),
findAll: jest.fn(),
findAllUnclaimed: jest.fn(),
findOne: jest.fn(),
getAllUserCompletedStructures: jest.fn(),
update: jest.fn(),
updateAccountVerified: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [],
......@@ -40,11 +59,11 @@ describe('StructuresController', () => {
providers: [
{
provide: HttpService,
useClass: HttpServiceMock,
useValue: mockHttpService,
},
{
provide: StructuresService,
useClass: StructuresServiceMock,
useValue: mockStructureService,
},
{
provide: UsersService,
......@@ -77,6 +96,7 @@ describe('StructuresController', () => {
usersService = module.get<UsersService>(UsersService);
structuresExportService = module.get<StructuresExportService>(StructuresExportService);
personalOffersService = module.get<PersonalOffersService>(PersonalOffersService);
jest.clearAllMocks();
});
it('should be defined', () => {
......@@ -84,14 +104,15 @@ describe('StructuresController', () => {
});
it('should get structure coordinates', async () => {
const coords = controller.getCoordinates('Lyon');
mockHttpService.get.mockImplementationOnce(() => of(PhotonResponseMock));
const coords = await controller.getCoordinates('Lyon');
expect(coords).toBeTruthy();
});
it('should create structure', async () => {
const structure: CreateStructureDto = {
userEmail: 'admin@admin.com',
structure: null,
structure: structureDtoMock,
};
const res = controller.create(structure);
expect(res).toBeTruthy();
......@@ -104,21 +125,17 @@ describe('StructuresController', () => {
});
it('should update structure', async () => {
const structureService = new StructuresServiceMock();
const structure = structureService.findOne(new Types.ObjectId('6093ba0e2ab5775cfc01ed3e'));
const structureId = '1';
const res = await controller.update(structureId, {
await controller.update('azerty', {
deletedAt: null,
remoteAccompaniment: null,
dataShareConsentDate: null,
personalOffers: [],
...structure,
});
expect(res.structureName).toBe('a');
expect(mockStructureService.update).toBeCalled();
});
it('should get all structure', async () => {
mockStructureService.findAll.mockResolvedValueOnce([{ structureName: 'a' }, { structureName: 'b' }]);
const res = await controller.findAll();
expect(res.length).toBe(2);
});
......@@ -132,16 +149,6 @@ describe('StructuresController', () => {
expect(result).toEqual(mockResult);
});
it('should search structure', async () => {
const res = controller.search(null, null);
expect(res).toBeTruthy();
});
it('should reset Search Index', async () => {
const res = controller.resetES();
expect(res).toBeTruthy();
});
it('should claim structure', async () => {
const userMock = new UsersServiceMock();
const user = userMock.findOne('pauline.dupont@mii.com');
......@@ -178,23 +185,11 @@ describe('StructuresController', () => {
expect(res).toBeTruthy();
});
it('should search an address', async () => {
const res = controller.searchAddress({ searchQuery: 'Rue Alphonse Daudet' });
expect(res).toBeTruthy();
});
describe('find(structureId)', () => {
it('should find structure', async () => {
let res = controller.find({ user: {} }, '6093ba0e2ab5775cfc01ed3e');
expect(res).toBeTruthy();
res = controller.find({ user: {} }, '');
expect(res).toBeTruthy();
});
it('should find deleted structure as an admin', async () => {
const response = controller.find({ user: { role: UserRole.admin } }, '6093ba0e2ab5775cfc01ed33');
expect(response).toBeTruthy();
expect((await response).deletedAt).toBeTruthy();
mockStructureService.findOne.mockResolvedValue(mockDeletedStructure);
const response = await controller.find({ user: { role: UserRole.admin } }, '6093ba0e2ab5775cfc01ed33');
expect(response.deletedAt).toBeTruthy();
});
it('should not find deleted structure as anonymous', async () => {
......@@ -207,34 +202,9 @@ describe('StructuresController', () => {
});
});
it('should find struct with owners', async () => {
const res = controller.findWithOwners('6093ba0e2ab5775cfc01ed3e');
expect(res).toBeTruthy();
});
it('should delete struct', async () => {
const req = { user: { _id: '6036721022462b001334c4bb' } };
const res = controller.delete(req, '6093ba0e2ab5775cfc01ed3e');
expect(res).toBeTruthy();
});
it('should cancel struct delete', async () => {
const req = { user: { _id: '6036721022462b001334c4bb' } };
const res = controller.cancelDelete(req, '6093ba0e2ab5775cfc01ed3e');
expect(res).toBeTruthy();
});
it('should add Owner', async () => {
let res = controller.addOwner('6093ba0e2ab5775cfc01ed3e', { email: 'pauline.dupont@mii.com' });
expect(res).toBeTruthy();
res = controller.addOwner('6093ba0e2ab5775cfc01ed3e', { email: 'pauline.dupont@mii.fr' });
expect(res).toBeTruthy();
res = controller.addOwner('', { email: 'pauline.dupont@mii.fr' });
expect(res).toBeTruthy();
});
describe('removeOwner', () => {
it('should return invalid structure', async () => {
mockStructureService.findOne.mockResolvedValueOnce(null);
try {
await controller.removeOwner('invalidstructure', '63639058685ba134c32bc495');
expect(true).toBe(false);
......@@ -244,6 +214,7 @@ describe('StructuresController', () => {
}
});
it('should return invalid user', async () => {
mockStructureService.findOne.mockResolvedValue(mockStructure);
try {
await controller.removeOwner('6093ba0e2ab5775cfc01ed3e', 'invaliduser');
expect(true).toBe(false);
......@@ -253,6 +224,7 @@ describe('StructuresController', () => {
}
});
it('should remove structure link without offer', async () => {
mockStructureService.findOne.mockResolvedValue(mockStructure);
jest.spyOn(usersService, 'getPersonalOfferInStructure').mockImplementationOnce(() => null);
const removeFromStructureLinkedSpyer = jest.spyOn(usersService, 'removeFromStructureLinked');
const deleteOfferSpyer = jest.spyOn(personalOffersService, 'delete');
......@@ -262,6 +234,7 @@ describe('StructuresController', () => {
});
it('should remove structure link with offer', async () => {
mockStructureService.findOne.mockResolvedValue(mockStructure);
const result = ({
_id: '2345ba0e2ab5775cfc01ed4d',
categories: {
......@@ -280,19 +253,4 @@ describe('StructuresController', () => {
expect(deleteOfferSpyer).toBeCalledTimes(1);
});
});
it('should remove temp user', async () => {
const res = controller.removeTempUser('6093ba0e2ab5775cfc01ed3e', 'tsfsf6296');
expect(res).toBeTruthy();
});
it('should remove user from struct', async () => {
const res = controller.removeOwner('6093ba0e2ab5775cfc01ed3e', 'tsfsf6296');
expect(res).toBeTruthy();
});
it('should report any structure error', async () => {
const res = controller.reportStructureError({ structureId: '6093ba0e2ab5775cfc01ed3e', content: null });
expect(res).toBeTruthy();
});
});
......@@ -40,8 +40,8 @@ import { QueryStructure } from './dto/query-structure.dto';
import { UpdateStructureDto } from './dto/update-structure.dto';
import { PhotonPoints } from './interfaces/photon-response.interface';
import { Structure, StructureDocument } from './schemas/structure.schema';
import { StructuresService } from './services/structures.service';
import { StructuresExportService } from './services/structures-export.service';
import { StructuresService } from './services/structures.service';
import { StructureFormatted } from './interfaces/structure-formatted.interface';
import { StructuresImportService } from './services/structures-import.service';
......
......@@ -2,9 +2,13 @@ import { HttpModule } from '@nestjs/axios';
import { HttpStatus } from '@nestjs/common';
import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing';
import * as ejs from 'ejs';
import { MailerModule } from '../mailer/mailer.module';
import { MailerService } from '../mailer/mailer.service';
import { TempUserService } from './temp-user.service';
const ejsSpy = jest.spyOn(ejs, 'renderFile');
describe('TempUserService', () => {
let service: TempUserService;
......@@ -19,6 +23,24 @@ describe('TempUserService', () => {
updateOne: jest.fn(),
};
const mockMailService = {
send: jest.fn(),
getTemplateLocation: jest.fn(),
loadJsonConfig: jest.fn().mockReturnValue({ subject: 'subject' }),
config: {
templates: {
userAddedToStructure: {
ejs: 'userAddedToStructure.ejs',
json: 'userAddedToStructure.json',
},
tempUserRegistration: {
ejs: 'tempUserRegistration.ejs',
json: 'tempUserRegistration.json',
},
},
},
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [HttpModule, MailerModule],
......@@ -28,6 +50,7 @@ describe('TempUserService', () => {
provide: getModelToken('TempUser'),
useValue: tempUserModelMock,
},
{ provide: MailerService, useValue: mockMailService },
],
}).compile();
......@@ -52,9 +75,12 @@ describe('TempUserService', () => {
});
it('should create temporary user', async () => {
tempUserModelMock.findOne.mockReturnThis();
tempUserModelMock.exec.mockResolvedValueOnce(null).mockResolvedValueOnce(tmpUser);
tempUserModelMock.exec.mockResolvedValueOnce(null);
tempUserModelMock.create.mockResolvedValueOnce(tmpUser);
tempUserModelMock.exec.mockResolvedValueOnce(tmpUser);
ejsSpy.mockResolvedValue('mock');
expect(await service.create(tmpUser, 'PIMMS Framboise')).toEqual(tmpUser);
expect(mockMailService.send).toHaveBeenCalled();
});
});
it('should find one', async () => {
......
import { HttpModule, HttpService } from '@nestjs/axios';
import { HttpModule } from '@nestjs/axios';
import { HttpStatus } from '@nestjs/common';
import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing';
import { AxiosResponse } from 'axios';
import * as ejs from 'ejs';
import { Types } from 'mongoose';
import { of } from 'rxjs';
import { ConfigurationModule } from '../../configuration/configuration.module';
import { MailerService } from '../../mailer/mailer.service';
import { CreateJobDto } from '../dto/create-job.dto';
import { JobDocument } from '../schemas/job.schema';
import { JobsService } from './jobs.service';
import { UsersService } from './users.service';
import { JobsGroupsService } from './jobsGroups.service';
import { UsersService } from './users.service';
const ejsSpy = jest.spyOn(ejs, 'renderFile');
const mockSingleAdminResponse = [
{
_id: '6231aefe76598527c8d0b5bc',
validationToken:
'cf1c74c22cedb6b575945098db42d2f493fb759c9142c6aff7980f252886f36ee086574ee99a06bc99119079257116c959c8ec870949cebdef2b293666dbca42',
emailVerified: true,
email: 'admin@admin.com',
password: '$2a$12$vLQjJ9zAWyUwiFLeQDa6w.XzrlgPBhw.2GWrjog/yuEjIaZnQwmZu',
role: 0,
name: 'admin',
surname: 'admin',
personalOffers: [],
},
];
describe('JobsService', () => {
let service: JobsService;
let httpService: HttpService;
let mailer: MailerService;
const mockJobModel = {
create: jest.fn(),
......@@ -43,6 +57,19 @@ describe('JobsService', () => {
replaceJobs: jest.fn(),
getAdmins: jest.fn(),
};
const mockMailService = {
send: jest.fn(),
getTemplateLocation: jest.fn().mockReturnValue('location'),
loadJsonConfig: jest.fn().mockReturnValue({ subject: 'subject' }),
config: {
templates: {
adminJobCreate: {
ejs: 'adminJobCreate.ejs',
json: 'adminJobCreate.json',
},
},
},
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
......@@ -65,12 +92,12 @@ describe('JobsService', () => {
provide: getModelToken('User'),
useValue: mockUserModel,
},
MailerService,
{ provide: MailerService, useValue: mockMailService },
],
}).compile();
service = module.get<JobsService>(JobsService);
mailer = module.get<MailerService>(MailerService);
httpService = module.get<HttpService>(HttpService);
ejsSpy.mockResolvedValue('mock');
jest.clearAllMocks();
});
it('should be defined', () => {
......@@ -159,42 +186,10 @@ describe('JobsService', () => {
hasPersonalOffer: false,
jobsGroup: null,
};
mockUserService.getAdmins.mockResolvedValueOnce([
{
_id: '6231aefe76598527c8d0b5bc',
validationToken:
'cf1c74c22cedb6b575945098db42d2f493fb759c9142c6aff7980f252886f36ee086574ee99a06bc99119079257116c959c8ec870949cebdef2b293666dbca42',
emailVerified: true,
email: 'admin@admin.com',
password: '$2a$12$vLQjJ9zAWyUwiFLeQDa6w.XzrlgPBhw.2GWrjog/yuEjIaZnQwmZu',
role: 0,
name: 'admin',
surname: 'admin',
personalOffers: [],
},
]);
mockUserService.getAdmins.mockResolvedValueOnce(mockSingleAdminResponse);
const reply = await service.create(createJob);
expect(reply).toBeTruthy();
});
it('should send an email to admins', async () => {
//todo fetch admin infos and check httpservice is called further
const result: AxiosResponse = {
data: {
status: 200,
content: {
success: true,
response: [7010],
},
},
status: 200,
statusText: 'OK',
headers: {},
config: {},
};
jest.spyOn(httpService, 'post').mockImplementationOnce(() => of(result));
expect(await mailer.send('a@a.com', 'test', '<p>This is a test</p>')).toBe(result.data);
});
});
it('createFromAdmin', async () => {
......@@ -210,20 +205,7 @@ describe('JobsService', () => {
hasPersonalOffer: false,
jobsGroup: null,
};
mockUserService.getAdmins.mockResolvedValueOnce([
{
_id: '6231aefe76598527c8d0b5bc',
validationToken:
'cf1c74c22cedb6b575945098db42d2f493fb759c9142c6aff7980f252886f36ee086574ee99a06bc99119079257116c959c8ec870949cebdef2b293666dbca42',
emailVerified: true,
email: 'admin@admin.com',
password: '$2a$12$vLQjJ9zAWyUwiFLeQDa6w.XzrlgPBhw.2GWrjog/yuEjIaZnQwmZu',
role: 0,
name: 'admin',
surname: 'admin',
personalOffers: [],
},
]);
mockUserService.getAdmins.mockResolvedValueOnce(mockSingleAdminResponse);
const reply = await service.create(createJob);
expect(reply).toBeTruthy();
});
......@@ -235,37 +217,9 @@ describe('JobsService', () => {
name: 'Metro',
validated: true,
};
const result: AxiosResponse = {
data: {
status: 200,
content: {
success: true,
response: [7010],
},
},
status: 200,
statusText: 'OK',
headers: {},
config: {},
};
jest.spyOn(mailer, 'send').mockResolvedValueOnce(result);
const spyer = jest.spyOn(mailer, 'send');
mockUserService.getAdmins.mockResolvedValueOnce([
{
_id: '6231aefe76598527c8d0b5bc',
validationToken:
'cf1c74c22cedb6b575945098db42d2f493fb759c9142c6aff7980f252886f36ee086574ee99a06bc99119079257116c959c8ec870949cebdef2b293666dbca42',
emailVerified: true,
email: 'admin@admin.com',
password: '$2a$12$vLQjJ9zAWyUwiFLeQDa6w.XzrlgPBhw.2GWrjog/yuEjIaZnQwmZu',
role: 0,
name: 'admin',
surname: 'admin',
personalOffers: [],
},
]);
mockUserService.getAdmins.mockResolvedValueOnce(mockSingleAdminResponse);
await service.sendAdminCreateNotification(job as JobDocument, 'adminJobCreate.ejs', 'adminJobCreate.json');
expect(spyer.mock.calls.length).toBe(1);
expect(mockMailService.send).toBeCalledTimes(1);
});
});
......