mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added e2e tests for post.rescheduled webhook (#15735)
refs: https://github.com/TryGhost/Ghost/issues/15537 - snapshot test created to add confidence to webhook stability and increase overall test coverage.
This commit is contained in:
parent
e8d8e07dad
commit
8c0b5520ce
2 changed files with 279 additions and 0 deletions
|
@ -894,6 +894,221 @@ Object {
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`post.* events post.rescheduled event is triggered 1: [headers] 1`] = `
|
||||||
|
Object {
|
||||||
|
"accept-encoding": "gzip, deflate",
|
||||||
|
"content-length": Any<Number>,
|
||||||
|
"content-type": "application/json",
|
||||||
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
|
"user-agent": StringMatching /Ghost\\\\/\\\\d\\+\\\\\\.\\\\d\\+\\\\\\.\\\\d\\+\\\\s\\\\\\(https:\\\\/\\\\/github\\.com\\\\/TryGhost\\\\/Ghost\\\\\\)/,
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`post.* events post.rescheduled event is triggered 2: [body] 1`] = `
|
||||||
|
Object {
|
||||||
|
"post": Object {
|
||||||
|
"current": Object {
|
||||||
|
"authors": Array [
|
||||||
|
Object {
|
||||||
|
"accessibility": null,
|
||||||
|
"bio": "bio",
|
||||||
|
"comment_notifications": true,
|
||||||
|
"cover_image": null,
|
||||||
|
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"email": "jbloggs@example.com",
|
||||||
|
"facebook": null,
|
||||||
|
"free_member_signup_notification": true,
|
||||||
|
"id": "1",
|
||||||
|
"last_seen": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"location": "location",
|
||||||
|
"meta_description": null,
|
||||||
|
"meta_title": null,
|
||||||
|
"name": "Joe Bloggs",
|
||||||
|
"paid_subscription_canceled_notification": false,
|
||||||
|
"paid_subscription_started_notification": true,
|
||||||
|
"profile_image": "https://example.com/super_photo.jpg",
|
||||||
|
"roles": Array [
|
||||||
|
Object {
|
||||||
|
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"description": "Blog Owner",
|
||||||
|
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||||
|
"name": "Owner",
|
||||||
|
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"slug": "joe-bloggs",
|
||||||
|
"status": "active",
|
||||||
|
"tour": null,
|
||||||
|
"twitter": null,
|
||||||
|
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"url": "http://127.0.0.1:2369/author/joe-bloggs/",
|
||||||
|
"website": null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"canonical_url": null,
|
||||||
|
"codeinjection_foot": null,
|
||||||
|
"codeinjection_head": null,
|
||||||
|
"comment_id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||||
|
"count": Object {
|
||||||
|
"clicks": 0,
|
||||||
|
"conversions": 0,
|
||||||
|
"negative_feedback": 0,
|
||||||
|
"positive_feedback": 0,
|
||||||
|
"sentiment": 0,
|
||||||
|
},
|
||||||
|
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"custom_excerpt": null,
|
||||||
|
"custom_template": null,
|
||||||
|
"email_only": false,
|
||||||
|
"email_segment": "all",
|
||||||
|
"email_subject": null,
|
||||||
|
"excerpt": null,
|
||||||
|
"feature_image": null,
|
||||||
|
"feature_image_alt": null,
|
||||||
|
"feature_image_caption": null,
|
||||||
|
"featured": false,
|
||||||
|
"frontmatter": null,
|
||||||
|
"html": null,
|
||||||
|
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||||
|
"meta_description": null,
|
||||||
|
"meta_title": null,
|
||||||
|
"mobiledoc": "{\\"version\\":\\"0.3.1\\",\\"ghostVersion\\":\\"4.0\\",\\"markups\\":[],\\"atoms\\":[],\\"cards\\":[],\\"sections\\":[[1,\\"p\\",[[0,[],0,\\"\\"]]]]}",
|
||||||
|
"og_description": null,
|
||||||
|
"og_image": null,
|
||||||
|
"og_title": null,
|
||||||
|
"primary_author": Object {
|
||||||
|
"accessibility": null,
|
||||||
|
"bio": "bio",
|
||||||
|
"comment_notifications": true,
|
||||||
|
"cover_image": null,
|
||||||
|
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"email": "jbloggs@example.com",
|
||||||
|
"facebook": null,
|
||||||
|
"free_member_signup_notification": true,
|
||||||
|
"id": "1",
|
||||||
|
"last_seen": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"location": "location",
|
||||||
|
"meta_description": null,
|
||||||
|
"meta_title": null,
|
||||||
|
"name": "Joe Bloggs",
|
||||||
|
"paid_subscription_canceled_notification": false,
|
||||||
|
"paid_subscription_started_notification": true,
|
||||||
|
"profile_image": "https://example.com/super_photo.jpg",
|
||||||
|
"roles": Array [
|
||||||
|
Object {
|
||||||
|
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"description": "Blog Owner",
|
||||||
|
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||||
|
"name": "Owner",
|
||||||
|
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"slug": "joe-bloggs",
|
||||||
|
"status": "active",
|
||||||
|
"tour": null,
|
||||||
|
"twitter": null,
|
||||||
|
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"url": "http://127.0.0.1:2369/author/joe-bloggs/",
|
||||||
|
"website": null,
|
||||||
|
},
|
||||||
|
"primary_tag": null,
|
||||||
|
"published_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"slug": "testing-post-rescheduled-webhook",
|
||||||
|
"status": "scheduled",
|
||||||
|
"tags": Array [],
|
||||||
|
"tiers": Array [
|
||||||
|
Object {
|
||||||
|
"active": true,
|
||||||
|
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"currency": "usd",
|
||||||
|
"description": null,
|
||||||
|
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||||
|
"monthly_price": 500,
|
||||||
|
"monthly_price_id": null,
|
||||||
|
"name": "Default Product",
|
||||||
|
"slug": "default-product",
|
||||||
|
"trial_days": 0,
|
||||||
|
"type": "paid",
|
||||||
|
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"visibility": "public",
|
||||||
|
"welcome_page_url": null,
|
||||||
|
"yearly_price": 5000,
|
||||||
|
"yearly_price_id": null,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"active": true,
|
||||||
|
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"currency": null,
|
||||||
|
"description": null,
|
||||||
|
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||||
|
"monthly_price": null,
|
||||||
|
"monthly_price_id": null,
|
||||||
|
"name": "Free",
|
||||||
|
"slug": "free",
|
||||||
|
"trial_days": 0,
|
||||||
|
"type": "free",
|
||||||
|
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"visibility": "public",
|
||||||
|
"welcome_page_url": null,
|
||||||
|
"yearly_price": null,
|
||||||
|
"yearly_price_id": null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"title": "testing post rescheduled webhook",
|
||||||
|
"twitter_description": null,
|
||||||
|
"twitter_image": null,
|
||||||
|
"twitter_title": null,
|
||||||
|
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"url": StringMatching /http:\\\\/\\\\/127\\.0\\.0\\.1:2369\\\\/\\[A-Za-z0-9_-\\]\\+\\\\//,
|
||||||
|
"uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
|
||||||
|
"visibility": "public",
|
||||||
|
},
|
||||||
|
"previous": Object {
|
||||||
|
"published_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"tiers": Array [
|
||||||
|
Object {
|
||||||
|
"active": true,
|
||||||
|
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"currency": "usd",
|
||||||
|
"description": null,
|
||||||
|
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||||
|
"monthly_price": 500,
|
||||||
|
"monthly_price_id": null,
|
||||||
|
"name": "Default Product",
|
||||||
|
"slug": "default-product",
|
||||||
|
"trial_days": 0,
|
||||||
|
"type": "paid",
|
||||||
|
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"visibility": "public",
|
||||||
|
"welcome_page_url": null,
|
||||||
|
"yearly_price": 5000,
|
||||||
|
"yearly_price_id": null,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"active": true,
|
||||||
|
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"currency": null,
|
||||||
|
"description": null,
|
||||||
|
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||||
|
"monthly_price": null,
|
||||||
|
"monthly_price_id": null,
|
||||||
|
"name": "Free",
|
||||||
|
"slug": "free",
|
||||||
|
"trial_days": 0,
|
||||||
|
"type": "free",
|
||||||
|
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
"visibility": "public",
|
||||||
|
"welcome_page_url": null,
|
||||||
|
"yearly_price": null,
|
||||||
|
"yearly_price_id": null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`post.* events post.scheduled event is triggered 1: [headers] 1`] = `
|
exports[`post.* events post.scheduled event is triggered 1: [headers] 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"accept-encoding": "gzip, deflate",
|
"accept-encoding": "gzip, deflate",
|
||||||
|
|
|
@ -99,6 +99,14 @@ const buildPreviousPostSnapshotWithTiersAndTags = ({tiersCount, tags}) => {
|
||||||
return previousSnapshot;
|
return previousSnapshot;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildPreviousPostSnapshotWithTiersPublished = ({tiersCount, published}) => {
|
||||||
|
return {
|
||||||
|
updated_at: anyISODateTime,
|
||||||
|
published_at: published ? anyISODateTime : null,
|
||||||
|
tiers: new Array(tiersCount).fill(tierSnapshot)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
describe('post.* events', function () {
|
describe('post.* events', function () {
|
||||||
let adminAPIAgent;
|
let adminAPIAgent;
|
||||||
let webhookMockReceiver;
|
let webhookMockReceiver;
|
||||||
|
@ -619,4 +627,60 @@ describe('post.* events', function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('post.rescheduled event is triggered', async function () {
|
||||||
|
const webhookURL = 'https://test-webhook-receiver.com/post-rescheduled/';
|
||||||
|
await webhookMockReceiver.mock(webhookURL);
|
||||||
|
await fixtureManager.insertWebhook({
|
||||||
|
event: 'post.rescheduled',
|
||||||
|
url: webhookURL
|
||||||
|
});
|
||||||
|
|
||||||
|
const published_at = moment().add(1, 'days').toISOString();
|
||||||
|
|
||||||
|
const res = await adminAPIAgent
|
||||||
|
.post('posts/')
|
||||||
|
.body({
|
||||||
|
posts: [{
|
||||||
|
title: 'testing post rescheduled webhook',
|
||||||
|
status: 'scheduled',
|
||||||
|
published_at: published_at
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
.expectStatus(201);
|
||||||
|
|
||||||
|
const id = res.body.posts[0].id;
|
||||||
|
const rescheduledPost = res.body.posts[0];
|
||||||
|
rescheduledPost.status = 'scheduled';
|
||||||
|
rescheduledPost.published_at = moment().add(2, 'days').toISOString();
|
||||||
|
|
||||||
|
await adminAPIAgent
|
||||||
|
.put('posts/' + id)
|
||||||
|
.body({
|
||||||
|
posts: [rescheduledPost]
|
||||||
|
})
|
||||||
|
.expectStatus(200);
|
||||||
|
|
||||||
|
await webhookMockReceiver.receivedRequest();
|
||||||
|
|
||||||
|
webhookMockReceiver
|
||||||
|
.matchHeaderSnapshot({
|
||||||
|
'content-version': anyContentVersion,
|
||||||
|
'content-length': anyNumber,
|
||||||
|
'user-agent': anyGhostAgent
|
||||||
|
})
|
||||||
|
.matchBodySnapshot({
|
||||||
|
post: {
|
||||||
|
current: buildPostSnapshotWithTiers({
|
||||||
|
published: true,
|
||||||
|
tiersCount: 2,
|
||||||
|
roles: true
|
||||||
|
}),
|
||||||
|
previous: buildPreviousPostSnapshotWithTiersPublished({
|
||||||
|
tiersCount: 2,
|
||||||
|
published: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue