mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
shared-code-webhooks
This commit is contained in:
42
test/common/ops/updateWebhook.test.js
Normal file
42
test/common/ops/updateWebhook.test.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import updateWebhook from '../../../common/script/ops/updateWebhook';
|
||||
import {
|
||||
BadRequest,
|
||||
} from '../../../common/script/libs/errors';
|
||||
import i18n from '../../../common/script/i18n';
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
|
||||
describe('shared.ops.updateWebhook', () => {
|
||||
let user;
|
||||
let req;
|
||||
let newUrl = 'http://new-url.com';
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser();
|
||||
req = { params: {
|
||||
id: 'this-id',
|
||||
}, body: {
|
||||
url: newUrl,
|
||||
enabled: true,
|
||||
} };
|
||||
});
|
||||
|
||||
it('validates body', (done) => {
|
||||
delete req.body.url;
|
||||
try {
|
||||
updateWebhook(user, req);
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(BadRequest);
|
||||
expect(err.message).to.equal(i18n.t('invalidUrl'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('succeeds', () => {
|
||||
let url = 'http://existing-url.com';
|
||||
user.preferences.webhooks = { 'this-id': { url } };
|
||||
updateWebhook(user, req);
|
||||
expect(user.preferences.webhooks['this-id'].url).to.eql(newUrl);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user