-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added e2e tests for page.added webhook (#15548)
refs: #15537 - snapshot test created to add confidence to webhook stability and increase overall test coverage.
- Loading branch information
1 parent
dc8617a
commit c41f431
Showing
2 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
ghost/core/test/e2e-webhooks/__snapshots__/pages.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`page.* events page.added 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[`page.* events page.added event is triggered 2: [body] 1`] = ` | ||
Object { | ||
"page": 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": "[email protected]", | ||
"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", | ||
"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\\}/, | ||
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, | ||
"custom_excerpt": null, | ||
"custom_template": null, | ||
"email": Object {}, | ||
"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": "[email protected]", | ||
"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", | ||
"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": null, | ||
"slug": "testing-page-added-webhook", | ||
"status": "draft", | ||
"tags": Array [], | ||
"tiers": Array [ | ||
Object { | ||
"active": true, | ||
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, | ||
"description": null, | ||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/, | ||
"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_id": null, | ||
}, | ||
Object { | ||
"active": true, | ||
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, | ||
"description": null, | ||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/, | ||
"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_id": null, | ||
}, | ||
], | ||
"title": "testing page.added 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\\\\/\\\\w\\+\\\\//, | ||
"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 {}, | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const { | ||
agentProvider, | ||
mockManager, | ||
fixtureManager, | ||
matchers | ||
} = require('../utils/e2e-framework'); | ||
const { | ||
anyGhostAgent, | ||
anyUuid, | ||
anyLocalURL, | ||
anyISODateTime, | ||
anyObjectId, | ||
anyContentVersion, | ||
anyNumber | ||
} = matchers; | ||
|
||
const tierSnapshot = { | ||
id: anyObjectId, | ||
created_at: anyISODateTime, | ||
updated_at: anyISODateTime | ||
}; | ||
|
||
const buildAuthorSnapshot = (roles = false) => { | ||
const authorSnapshot = { | ||
last_seen: anyISODateTime, | ||
created_at: anyISODateTime, | ||
updated_at: anyISODateTime | ||
}; | ||
|
||
return authorSnapshot; | ||
}; | ||
|
||
const buildPageSnapshotWithTiers = ({ | ||
published, | ||
tiersCount, | ||
roles = false | ||
}) => { | ||
return { | ||
id: anyObjectId, | ||
uuid: anyUuid, | ||
comment_id: anyObjectId, | ||
published_at: published ? anyISODateTime : null, | ||
created_at: anyISODateTime, | ||
updated_at: anyISODateTime, | ||
url: anyLocalURL, | ||
tiers: new Array(tiersCount).fill(tierSnapshot), | ||
primary_author: buildAuthorSnapshot(roles), | ||
authors: new Array(1).fill(buildAuthorSnapshot(roles)) | ||
}; | ||
}; | ||
|
||
describe('page.* events', function () { | ||
let adminAPIAgent; | ||
let webhookMockReceiver; | ||
|
||
before(async function () { | ||
adminAPIAgent = await agentProvider.getAdminAPIAgent(); | ||
await fixtureManager.init('integrations'); | ||
await adminAPIAgent.loginAsOwner(); | ||
}); | ||
|
||
beforeEach(function () { | ||
webhookMockReceiver = mockManager.mockWebhookRequests(); | ||
}); | ||
|
||
afterEach(function () { | ||
mockManager.restore(); | ||
}); | ||
|
||
it('page.added event is triggered', async function () { | ||
const webhookURL = 'https://test-webhook-receiver.com/page-added/'; | ||
await webhookMockReceiver.mock(webhookURL); | ||
await fixtureManager.insertWebhook({ | ||
event: 'page.added', | ||
url: webhookURL | ||
}); | ||
|
||
await adminAPIAgent | ||
.post('pages/') | ||
.body({ | ||
pages: [ | ||
{ | ||
title: 'testing page.added webhook', | ||
status: 'draft', | ||
displayName: 'webhookz' | ||
} | ||
] | ||
}) | ||
.expectStatus(201); | ||
|
||
await webhookMockReceiver.receivedRequest(); | ||
|
||
webhookMockReceiver | ||
.matchHeaderSnapshot({ | ||
'content-version': anyContentVersion, | ||
'content-length': anyNumber, | ||
'user-agent': anyGhostAgent | ||
}) | ||
.matchBodySnapshot({ | ||
page: { | ||
current: buildPageSnapshotWithTiers({ | ||
published: false, | ||
tiersCount: 2 | ||
}) | ||
} | ||
}); | ||
}); | ||
}); |