Skip to content

Commit 39575da

Browse files
Mise à jour du contrôleur d'identités
1 parent e85179f commit 39575da

File tree

1 file changed

+8
-34
lines changed

1 file changed

+8
-34
lines changed

src/management/identities/identities.controller.spec.ts

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,19 @@ describe('IdentitiesController', () => {
3838
identitiesModel = await mongoDbTestInstance.getModel<Identities>(Identities.name, IdentitiesSchema);
3939
_id = new Types.ObjectId();
4040

41-
// service = createMockService<IdentitiesService>(IdentitiesService, {
42-
// create: [{ ...identitiesCreated }, { ...identitiesAccepted }],
43-
// findAndCount: [{ data: [identitiesWithId], total: 1 }],
44-
// findOne: [{ ...identitiesWithId }],
45-
// update: [{ ...identitiesWithId }],
46-
// delete: [{ ...identitiesWithId }],
47-
// });
48-
4941
service = createMockService<IdentitiesService>(IdentitiesService, {
5042
create: [
51-
// First call returns a newly created identity with a status of CREATED
52-
Promise.resolve({ ...IdentitiesDtoStub(), _id, state: IdentityState.TO_VALIDATE }),
53-
// Second call simulates a scenario where creation leads to ACCEPTED status due to validations
54-
Promise.resolve({ ...IdentitiesDtoStub(), _id, state: IdentityState.TO_COMPLETE }),
43+
// Use functions that return promises for resolve or reject
44+
() => Promise.resolve({ ...IdentitiesDtoStub(), _id, state: IdentityState.TO_VALIDATE }),
45+
() => Promise.resolve({ ...IdentitiesDtoStub(), _id, state: IdentityState.TO_COMPLETE }),
5546
],
5647
findAndCount: [
57-
// Successful search, returns an array of identities and a total count
58-
Promise.resolve({ data: [{ ...IdentitiesDtoStub(), _id }], total: 1 }),
59-
// Simulate a failure in searching identities
60-
Promise.reject(new Error('Error')),
61-
],
62-
findOne: [
63-
// Successfully finds an identity
64-
Promise.resolve({ ...IdentitiesDtoStub(), _id }),
65-
// Simulates an error when finding an identity
66-
Promise.reject(new Error('Error')),
67-
],
68-
update: [
69-
// Successfully updates an identity
70-
Promise.resolve({ ...IdentitiesDtoStub(), _id }),
71-
// Simulates an error in updating an identity
72-
Promise.reject(new Error('Error')),
73-
],
74-
delete: [
75-
// Successfully deletes an identity
76-
Promise.resolve({ ...IdentitiesDtoStub(), _id }),
77-
// Simulates an error in deleting an identity
78-
Promise.reject(new Error('Error')),
48+
() => Promise.resolve({ data: [{ ...IdentitiesDtoStub(), _id }], total: 1 }),
49+
() => Promise.reject(new Error('Error')), // Function that throws an error
7950
],
51+
findOne: [() => Promise.resolve({ ...IdentitiesDtoStub(), _id }), () => Promise.reject(new Error('Error'))],
52+
update: [() => Promise.resolve({ ...IdentitiesDtoStub(), _id }), () => Promise.reject(new Error('Error'))],
53+
delete: [() => Promise.resolve({ ...IdentitiesDtoStub(), _id }), () => Promise.reject(new Error('Error'))],
8054
});
8155

8256
const module: TestingModule = await Test.createTestingModule({

0 commit comments

Comments
 (0)