mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Refactored webhook acceptance test suite
no issue - Refactored a test as it was using outdated `done()` convention instead of relying on promises - Removed linting warnings for variable shadowing - This is precursor work for webhook regression test updates needed in near future work
This commit is contained in:
parent
8d989bd3c3
commit
256b407dd2
1 changed files with 42 additions and 64 deletions
|
@ -21,7 +21,7 @@ describe('Webhooks API', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('Can creates a webhook', function (done) {
|
||||
it('Can creates a webhook', function () {
|
||||
let webhookData = {
|
||||
event: 'test.create',
|
||||
target_url: 'http://example.com/webhooks/test/extra/1',
|
||||
|
@ -30,17 +30,13 @@ describe('Webhooks API', function () {
|
|||
api_version: 'v2'
|
||||
};
|
||||
|
||||
request.post(localUtils.API.getApiQuery('webhooks/'))
|
||||
return request.post(localUtils.API.getApiQuery('webhooks/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({webhooks: [webhookData]})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(201)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
.then((res) => {
|
||||
const jsonResponse = res.body;
|
||||
|
||||
should.exist(jsonResponse.webhooks);
|
||||
|
@ -52,13 +48,14 @@ describe('Webhooks API', function () {
|
|||
jsonResponse.webhooks[0].secret.should.equal(webhookData.secret);
|
||||
jsonResponse.webhooks[0].name.should.equal(webhookData.name);
|
||||
jsonResponse.webhooks[0].api_version.should.equal(webhookData.api_version);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Can edit a webhook', function (done) {
|
||||
request.post(localUtils.API.getApiQuery('integrations/'))
|
||||
it('Can edit a webhook', function () {
|
||||
let createdIntegration;
|
||||
let createdWebhook;
|
||||
|
||||
return request.post(localUtils.API.getApiQuery('integrations/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({
|
||||
integrations: [{
|
||||
|
@ -66,14 +63,10 @@ describe('Webhooks API', function () {
|
|||
}]
|
||||
})
|
||||
.expect(201)
|
||||
.end(function (err, {body}) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
.then(({body}) => {
|
||||
[createdIntegration] = body.integrations;
|
||||
|
||||
const [createdIntegration] = body.integrations;
|
||||
|
||||
request.post(localUtils.API.getApiQuery('webhooks/'))
|
||||
return request.post(localUtils.API.getApiQuery('webhooks/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({
|
||||
webhooks: [{
|
||||
|
@ -84,40 +77,35 @@ describe('Webhooks API', function () {
|
|||
}]
|
||||
})
|
||||
.expect(201)
|
||||
.end(function (err, {body}) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
})
|
||||
.then(({body}) => {
|
||||
[createdWebhook] = body.webhooks;
|
||||
|
||||
const [createdWebhook] = body.webhooks;
|
||||
return request.put(localUtils.API.getApiQuery(`webhooks/${createdWebhook.id}/`))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({
|
||||
webhooks: [{
|
||||
name: 'Edit Test',
|
||||
event: 'subscriber.added',
|
||||
target_url: 'https://example.com/new-subscriber'
|
||||
}]
|
||||
})
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private);
|
||||
})
|
||||
.then(({body}) => {
|
||||
const [updatedWebhook] = body.webhooks;
|
||||
|
||||
request.put(localUtils.API.getApiQuery(`webhooks/${createdWebhook.id}/`))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({
|
||||
webhooks: [{
|
||||
name: 'Edit Test',
|
||||
event: 'subscriber.added',
|
||||
target_url: 'https://example.com/new-subscriber'
|
||||
}]
|
||||
})
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.then(({body}) => {
|
||||
const [updatedWebhook] = body.webhooks;
|
||||
|
||||
should.equal(updatedWebhook.id, createdWebhook.id);
|
||||
should.equal(updatedWebhook.name, 'Edit Test');
|
||||
should.equal(updatedWebhook.event, 'subscriber.added');
|
||||
should.equal(updatedWebhook.target_url, 'https://example.com/new-subscriber');
|
||||
should.equal(updatedWebhook.integration_id, createdIntegration.id);
|
||||
done();
|
||||
});
|
||||
});
|
||||
should.equal(updatedWebhook.id, createdWebhook.id);
|
||||
should.equal(updatedWebhook.name, 'Edit Test');
|
||||
should.equal(updatedWebhook.event, 'subscriber.added');
|
||||
should.equal(updatedWebhook.target_url, 'https://example.com/new-subscriber');
|
||||
should.equal(updatedWebhook.integration_id, createdIntegration.id);
|
||||
});
|
||||
});
|
||||
|
||||
it('Can delete a webhook', function (done) {
|
||||
it('Can delete a webhook', function () {
|
||||
const newWebhook = {
|
||||
event: 'test.create',
|
||||
// a different target_url from above is needed to avoid an "already exists" error
|
||||
|
@ -125,17 +113,13 @@ describe('Webhooks API', function () {
|
|||
};
|
||||
|
||||
// create the webhook that is to be deleted
|
||||
request.post(localUtils.API.getApiQuery('webhooks/'))
|
||||
return request.post(localUtils.API.getApiQuery('webhooks/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({webhooks: [newWebhook]})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(201)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
.then((res) => {
|
||||
const location = res.headers.location;
|
||||
const jsonResponse = res.body;
|
||||
|
||||
|
@ -145,18 +129,12 @@ describe('Webhooks API', function () {
|
|||
jsonResponse.webhooks[0].target_url.should.equal(newWebhook.target_url);
|
||||
|
||||
// begin delete test
|
||||
request.del(localUtils.API.getApiQuery('webhooks/' + jsonResponse.webhooks[0].id + '/'))
|
||||
return request.del(localUtils.API.getApiQuery('webhooks/' + jsonResponse.webhooks[0].id + '/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect(204)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
res.body.should.be.empty();
|
||||
|
||||
done();
|
||||
});
|
||||
.expect(204);
|
||||
})
|
||||
.then((res) => {
|
||||
res.body.should.be.empty();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue