Skip to content

Commit

Permalink
test ok
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-pages committed Sep 12, 2024
1 parent 8578e49 commit 01c316a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion server/__tests__/notification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,27 @@ describe('Notification api test', () => {
expect(updatedNotifications).toMatchObject(updateData);
});

// TODO: Add a request with a user with commentary to true and expect received a mail
it('should handle error during notification preferences update', async () => {
const app = await getApp();

const updateData = {
commentary: true,
reaction: true,
};

// Simuler une erreur sur la fonction `EditNotificationPreferences`
jest.spyOn(AppDataSource.getRepository(Notifications), 'save').mockImplementationOnce(() => {
throw new Error('Database error');
});

const response = await supertest(app)
.put('/api/notifications/suscribe/1')
.set('authorization', `Bearer ${accessToken}`)
.send({ data: updateData })
.expect(500);

expect(response.body.message).toEqual('erreur de sauvegarde de vos choix, veuillez réessayer ultérieurement');
});

it("hasSubscribed should send false if the user's commentary is false", async () => {
const userRepository = AppDataSource.getRepository(User);
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ notificationsController.put({ path: '/suscribe/:userId' }, async (req: Request,
try {
await EditNotificationPreferences(newNotification);
} catch (e) {
res.status(500).json({ message: 'erreur de sauvegarde de vos choix, veuillez réessayer ultérieurement' });
return res.status(500).json({ message: 'erreur de sauvegarde de vos choix, veuillez réessayer ultérieurement' });
}
res.status(200).json({ message: 'Notifications mises à jour' });
});
Expand Down

0 comments on commit 01c316a

Please sign in to comment.