Webhook improvements (#7879)

* refactor: Move translate test utility to helpers directory

* Add kind property to webhooks

* feat: Add options to create webhook route

* refactor: Move webhook ops into single file

* refactor: Create webhook objects for specific webhook behavior

* chore(tests): Add default sleep helper value of 1 second

* feat(api): Add method for groups to send out webhook

* feat(api): Add taskCreated webhook task creation

* feat(api): Send chat webhooks after a chat is sent

* refactor: Move webhook routes to own controller

* lint: Correct linting errors

* fix(api): Correct taskCreated webhook method

* fix(api): Fix webhook logging to only log when there is an error

* fix: Update groupChatRecieved webhook creation

* chore: Add integration tests for webhooks

* fix: Set webhook creation response to 201

* fix: Correct how task scored webhook data is sent

* Revert group chat recieved webhook to only support one group

* Remove quest activity option for webhooks

* feat: Send webhook for each task created

* feat: Allow webhooks without a type to default to taskScored

* feat: Add logic for adding ids to webhook

* feat: optimize webhook url check by shortcircuiting if no url is passed

* refactor: Use full name for webhook variable

* feat: Add missing params to client webhook

* lint: Add missing semicolon

* chore(tests): Fix inccorect webhook tests

* chore: Add migration to update task scored webhooks

* feat: Allow default value of webhook add route to be enabled

* chore: Update webhook documentation

* chore: Remove special handling for v2

* refactor: adjust addComputedStatsToJSONObject to work for webhooks

* refactor: combine taskScored and taskActivity webhooks

* feat(api): Add task activity to task update and delete routes

* chore: Change references to taskScored to taskActivity

* fix: Correct stats object being passed in for transform

* chore: Remove extra line break

* fix: Pass in the language to use for the translations

* refactor(api): Move webhooks from user.preferences.webhooks to user.webhooks

* chore: Update migration to set webhook array

* lint: Correct brace spacing

* chore: convert webhook lib to use user.webhooks

* refactor(api): Consolidate filters

* chore: clarify migration instructions

* fix(test): Correct user creation in user anonymized tests

* chore: add test that webhooks cannot be updated via PUT /user

* refactor: Simplify default webhook id value

* refactor(client): Push newly created webhook instead of doing a sync

* chore(test): Add test file for webhook model

* refactor: Remove webhook validation

* refactor: Remove need for watch on webhooks

* refactor(client): Update webhooks object without syncing

* chore: update webhook documentation

* Fix migrations issues

* chore: remove v2 test helper

* fix(api): Provide webhook type in task scored webhook

* fix(client): Fix webhook deletion appearing to delete all webhooks

* feat(api): add optional label field for webhooks

* feat: provide empty string as default for webhook label

* chore: Update webhook migration

* chore: update webhook migration name
This commit is contained in:
Blade Barringer
2016-10-02 09:16:22 -05:00
committed by GitHub
parent 556a7e5229
commit 35b92f13a3
46 changed files with 2044 additions and 527 deletions

View File

@@ -1,57 +0,0 @@
import addWebhook from '../../../website/common/script/ops/addWebhook';
import {
BadRequest,
} from '../../../website/common/script/libs/errors';
import i18n from '../../../website/common/script/i18n';
import {
generateUser,
} from '../../helpers/common.helper';
describe('shared.ops.addWebhook', () => {
let user;
let req;
beforeEach(() => {
user = generateUser();
req = { body: {
enabled: true,
url: 'http://some-url.com',
} };
});
context('adds webhook', () => {
it('validates req.body.url', (done) => {
delete req.body.url;
try {
addWebhook(user, req);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('invalidUrl'));
done();
}
});
it('validates req.body.enabled', (done) => {
delete req.body.enabled;
try {
addWebhook(user, req);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('invalidEnabled'));
done();
}
});
it('calls marksModified()', () => {
user.markModified = sinon.spy();
addWebhook(user, req);
expect(user.markModified.called).to.eql(true);
});
it('succeeds', () => {
expect(user.preferences.webhooks).to.eql({});
addWebhook(user, req);
expect(user.preferences.webhooks).to.not.eql({});
});
});
});

View File

@@ -1,21 +0,0 @@
import deleteWebhook from '../../../website/common/script/ops/deleteWebhook';
import {
generateUser,
} from '../../helpers/common.helper';
describe('shared.ops.deleteWebhook', () => {
let user;
let req;
beforeEach(() => {
user = generateUser();
req = { params: { id: 'some-id' } };
});
it('succeeds', () => {
user.preferences.webhooks = { 'some-id': {}, 'another-id': {} };
let [data] = deleteWebhook(user, req);
expect(user.preferences.webhooks).to.eql({'another-id': {}});
expect(data).to.equal(user.preferences.webhooks);
});
});

View File

@@ -1,42 +0,0 @@
import updateWebhook from '../../../website/common/script/ops/updateWebhook';
import {
BadRequest,
} from '../../../website/common/script/libs/errors';
import i18n from '../../../website/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);
});
});