Select Git revision
structures.controller.spec.ts 7.95 KiB
import { HttpService } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { CategoriesAccompagnementServiceMock } from '../../test/mock/services/categoriesAccompagnement.mock.service';
import { CategoriesFormationsServiceMock } from '../../test/mock/services/categoriesFormations.mock.service';
import { CategoriesOthersServiceMock } from '../../test/mock/services/categoriesOthers.mock.service';
import { HttpServiceMock } from '../../test/mock/services/http.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';
import { CategoriesAccompagnementService } from '../categories/services/categories-accompagnement.service';
import { CategoriesFormationsService } from '../categories/services/categories-formations.service';
import { CategoriesOthersService } from '../categories/services/categories-others.service';
import { TempUserService } from '../temp-user/temp-user.service';
import { UsersService } from '../users/users.service';
import { CreateStructureDto } from './dto/create-structure.dto';
import { StructuresService } from './services/structures.service';
import { StructuresController } from './structures.controller';
describe('AuthController', () => {
let controller: StructuresController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [],
controllers: [StructuresController],
providers: [
{
provide: HttpService,
useClass: HttpServiceMock,
},
{
provide: StructuresService,
useClass: StructuresServiceMock,
},
{
provide: UsersService,
useClass: UsersServiceMock,
},
{
provide: TempUserService,
useClass: TempUserServiceMock,
},
{
provide: CategoriesAccompagnementService,
useClass: CategoriesAccompagnementServiceMock,
},
{
provide: CategoriesOthersService,
useClass: CategoriesOthersServiceMock,
},
{
provide: CategoriesFormationsService,
useClass: CategoriesFormationsServiceMock,
},
],
}).compile();
controller = module.get<StructuresController>(StructuresController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
it('should get structure coordinates', async () => {
const coords = controller.getCoordinates('Lyon');
expect(coords).toBeTruthy();
});
it('should create structure', async () => {
const structure: CreateStructureDto = {
idUser: '1',
structure: null,
};
const res = controller.create(structure);
expect(res).toBeTruthy();
});
it('should update structure after ownerVerify', async () => {
const structureId = '1';
const res = controller.updateAfterOwnerVerify(structureId);
expect(res).toBeTruthy();
});
it('should update structure', async () => {
const structureService = new StructuresServiceMock();
const structure = structureService.findOne('6093ba0e2ab5775cfc01ed3e');
const structureId = '1';
const res = await controller.update(structureId, {
numero: null,
deletedAt: null,
remoteAccompaniment: null,
dataShareConsentDate: null,
...structure,
});
expect(res.structureName).toBe('a');
});
it('should get all structure', async () => {
const res = await controller.findAll();
expect(res.length).toBe(2);
});
it('should get all Formated structure', async () => {
const res = await controller.findAllFormated();
expect(res.length).toBe(2);
});
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 see if structure is claimed', async () => {
const res = controller.isClaimed('1');
expect(res).toBeTruthy();
});
it('should claim structure', async () => {
const userMock = new UsersServiceMock();
const user = userMock.findOne('pauline.dupont@mii.com');
const res = controller.claim('1', {
phone: null,
resetPasswordToken: null,
changeEmailToken: null,
newEmail: null,
pendingStructuresLink: null,
structuresLink: null,
structureOutdatedMailSent: null,
email: user.email,
name: user.name,
surname: user.surname,
emailVerified: true,
password: user.password,
validationToken: null,
role: null,
});
expect(res).toBeTruthy();
});
it('should count', async () => {
const res = controller.countCategories([{ id: 'equipmentsAndServices', text: 'wifiEnAccesLibre' }]);
expect(res).toBeTruthy();
});
it('should search an address', async () => {
const res = controller.searchAddress({ searchQuery: 'Rue Alphonse Daudet' });
expect(res).toBeTruthy();
});
it('should find struct', async () => {
let res = controller.find('6093ba0e2ab5775cfc01ed3e');
expect(res).toBeTruthy();
res = controller.find('');
expect(res).toBeTruthy();
});
it('should find struct with owners', async () => {
const res = controller.findWithOwners('6093ba0e2ab5775cfc01ed3e', { emailUser: 'pauline.dupont@mii.com' });
expect(res).toBeTruthy();
});
it('should delete struct', async () => {
const res = controller.delete('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();
});
it('should remove Owner', async () => {
let res = controller.removeOwner('6093ba0e2ab5775cfc01ed3e', 'tsfsf6296');
expect(res).toBeTruthy();
res = controller.removeOwner('6093ba0e2ab5775cfc01ed3e', '1');
expect(res).toBeTruthy();
res = controller.removeOwner('', '1');
expect(res).toBeTruthy();
});
it('should join user', async () => {
const userMock = new UsersServiceMock();
const user = userMock.findOne('pauline.dupont@mii.com');
let res = controller.join('6093ba0e2ab5775cfc01ed3e', {
phone: null,
resetPasswordToken: null,
changeEmailToken: null,
newEmail: null,
pendingStructuresLink: null,
structuresLink: null,
structureOutdatedMailSent: null,
email: user.email,
name: user.name,
surname: user.surname,
emailVerified: true,
password: user.password,
validationToken: null,
role: null,
});
expect(res).toBeTruthy();
res = controller.join('', null);
expect(res).toBeTruthy();
res = controller.join('6093ba0e2ab5775cfc01ed3e', null);
expect(res).toBeTruthy();
});
it('should join in struct', async () => {
let res = controller.joinValidation('6093ba0e2ab5775cfc01ed3e', 'true', 'tsfsf6296');
expect(res).toBeTruthy();
res = controller.joinValidation('6093ba0e2ab5775cfc01ed3e', 'true', '');
expect(res).toBeTruthy();
res = controller.joinValidation('', 'true', '');
expect(res).toBeTruthy();
});
it('should remove user from struct', async () => {
const res = controller.joinValidation('6093ba0e2ab5775cfc01ed3e', 'false', 'tsfsf6296');
expect(res).toBeTruthy();
});
it('should report any structure error', async () => {
const res = controller.reportStructureError({ structureId: '6093ba0e2ab5775cfc01ed3e', content: null });
expect(res).toBeTruthy();
});
//TODO: test structure controler endpoint
//updateAccountVerified,
//updateStructureLinkedClaim
});