mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Updated route to be named /emails/unsubscribe and other minor fixes
This commit is contained in:
68
test/api/v3/integration/emails/GET-email-unsubscribe.test.js
Normal file
68
test/api/v3/integration/emails/GET-email-unsubscribe.test.js
Normal file
@@ -0,0 +1,68 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-v3-integration.helper';
|
||||
import { encrypt } from '../../../../../website/src/libs/api-v3/encryption';
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
|
||||
describe('GET /email/unsubscribe', () => {
|
||||
let user;
|
||||
let testEmail = 'test@habitica.com';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
it('return error when code is not provided', async () => {
|
||||
await expect(user.get('/email/unsubscribe')).to.eventually.be.rejected.and.eql({
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
message: 'Invalid request parameters.',
|
||||
});
|
||||
});
|
||||
|
||||
it('return error when user is not found', async () => {
|
||||
let code = encrypt(JSON.stringify({
|
||||
_id: generateUUID(),
|
||||
}));
|
||||
|
||||
await expect(user.get(`/email/unsubscribe?code=${code}`)).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('userNotFound'),
|
||||
});
|
||||
});
|
||||
|
||||
it('unsubscribes a user from email notifications', async () => {
|
||||
let code = encrypt(JSON.stringify({
|
||||
_id: user._id,
|
||||
email: user.email,
|
||||
}));
|
||||
|
||||
await user.get(`/email/unsubscribe?code=${code}`);
|
||||
|
||||
let unsubscribedUser = await user.get('/user');
|
||||
|
||||
expect(unsubscribedUser.preferences.emailNotifications.unsubscribeFromAll).to.be.true;
|
||||
});
|
||||
|
||||
it('unsubscribes an email from notifications', async () => {
|
||||
let code = encrypt(JSON.stringify({
|
||||
email: testEmail,
|
||||
}));
|
||||
|
||||
let unsubscribedMessage = await user.get(`/email/unsubscribe?code=${code}`);
|
||||
|
||||
expect(unsubscribedMessage).to.equal('<h1>Unsubscribed successfully!</h1> You won\'t receive any other email from Habitica.');
|
||||
});
|
||||
|
||||
it('returns okay when email is already unsubscribed', async () => {
|
||||
let code = encrypt(JSON.stringify({
|
||||
email: testEmail,
|
||||
}));
|
||||
|
||||
let unsubscribedMessage = await user.get(`/email/unsubscribe?code=${code}`);
|
||||
|
||||
expect(unsubscribedMessage).to.equal('<h1>Unsubscribed successfully!</h1> You won\'t receive any other email from Habitica.');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user