Newer
Older
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/services/users.service';
import { CreateStructureDto } from './dto/create-structure.dto';
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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,
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...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,
personalOffers: null,
email: user.email,
name: user.name,
surname: user.surname,
emailVerified: true,
createdAt: new Date('2022-05-25T09:48:28.824Z'),
password: user.password,
validationToken: null,
role: null,
employer: {
name: 'test',
validated: true,
},
job: {
name: 'test',
validated: true,
hasPersonalOffer: false,
},
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
});
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,
personalOffers: null,
email: user.email,
name: user.name,
surname: user.surname,
emailVerified: true,
createdAt: new Date('2022-05-25T09:48:28.824Z'),
password: user.password,
validationToken: null,
role: null,
employer: {
name: 'test',
validated: true,
},
job: {
name: 'test',
validated: true,
hasPersonalOffer: false,
},
});
expect(res).toBeTruthy();
res = controller.join('', null);
expect(res).toBeTruthy();
res = controller.join('6093ba0e2ab5775cfc01ed3e', null);
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();
});
//updateAccountVerified,
//updateStructureLinkedClaim