mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-05-20 20:58:51 +00:00
Merge branch '11290-get-webhooks-api' of https://github.com/cvuorinen/habitica into cvuorinen-11290-get-webhooks-api
This commit is contained in:
commit
7b69967412
2 changed files with 51 additions and 0 deletions
33
test/api/v3/integration/webhook/GET-user-webhook.test.js
Normal file
33
test/api/v3/integration/webhook/GET-user-webhook.test.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { generateUser } from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('GET /user/webhook', () => {
|
||||
let user, webhooks;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
|
||||
webhooks = [];
|
||||
webhooks.push(await user.post('/user/webhook', {
|
||||
url: 'http://some-url.com',
|
||||
label: 'Label',
|
||||
enabled: true,
|
||||
type: 'taskActivity',
|
||||
options: { created: true, scored: true },
|
||||
}));
|
||||
webhooks.push(await user.post('/user/webhook', {
|
||||
url: 'http://some-other-url.com',
|
||||
enabled: false,
|
||||
}));
|
||||
|
||||
await user.sync();
|
||||
});
|
||||
|
||||
it('returns users webhooks', async () => {
|
||||
let response = await user.get('/user/webhook');
|
||||
|
||||
// updatedAt times don't match for some reason, so need to omit those from comparison
|
||||
let omitUpdatedAt = a => a.map(v => _.omit(v, 'updatedAt'));
|
||||
|
||||
expect(omitUpdatedAt(response)).to.eql(omitUpdatedAt(webhooks));
|
||||
});
|
||||
});
|
||||
|
|
@ -95,6 +95,24 @@ api.addWebhook = {
|
|||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @api {get} /api/v3/user/webhook Get webhooks - BETA
|
||||
* @apiName UserGetWebhook
|
||||
* @apiGroup Webhook
|
||||
*
|
||||
* @apiSuccess {Array} data User's webhooks
|
||||
*/
|
||||
api.getWebhook = {
|
||||
method: 'GET',
|
||||
middlewares: [authWithHeaders()],
|
||||
url: '/user/webhook',
|
||||
async handler (req, res) {
|
||||
let user = res.locals.user;
|
||||
|
||||
res.respond(200, user.webhooks);
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @api {put} /api/v3/user/webhook/:id Edit a webhook - BETA
|
||||
* @apiName UserUpdateWebhook
|
||||
|
|
|
|||
Loading…
Reference in a new issue