mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
no issue - There's no need to init whole models module in this test. Simplified mocks are easier to understand without any "magic" that's going on behind model's module "init()" call
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
|
|
const createWebhookService = require('../../../../../core/server/services/webhooks/webhooks-service');
|
|
|
|
describe('Webhook Service', function () {
|
|
const models = {
|
|
Webhook: {
|
|
getByEventAndTarget: () => {},
|
|
add: () => {}
|
|
}
|
|
};
|
|
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
it('re-throws any unhandled errors', async function () {
|
|
sinon.stub(models.Webhook, 'getByEventAndTarget').resolves(null);
|
|
sinon.stub(models.Webhook, 'add').throws('CustomTestError');
|
|
|
|
const webhookService = createWebhookService({WebhookModel: models.Webhook});
|
|
|
|
const fakeWebhook = {
|
|
webhooks: [
|
|
{
|
|
event: 'post.published',
|
|
target_url: 'http://example.com/webhook'
|
|
}
|
|
]
|
|
};
|
|
|
|
try {
|
|
await webhookService.add(fakeWebhook, {});
|
|
should.fail('should have thrown');
|
|
} catch (err) {
|
|
err.name.should.equal('CustomTestError');
|
|
}
|
|
});
|
|
});
|