diff --git a/ghost/core/test/e2e-webhooks/__snapshots__/members.test.js.snap b/ghost/core/test/e2e-webhooks/__snapshots__/members.test.js.snap new file mode 100644 index 00000000000..46b7465e46c --- /dev/null +++ b/ghost/core/test/e2e-webhooks/__snapshots__/members.test.js.snap @@ -0,0 +1,67 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`member.* events member.added event is triggered 1: [headers] 1`] = ` +Object { + "accept-encoding": "gzip, deflate", + "content-length": Any, + "content-type": "application/json", + "content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/, + "user-agent": StringMatching /Ghost\\\\/\\\\d\\+\\\\\\.\\\\d\\+\\\\\\.\\\\d\\+\\\\s\\\\\\(https:\\\\/\\\\/github\\.com\\\\/TryGhost\\\\/Ghost\\\\\\)/, +} +`; + +exports[`member.* events member.added event is triggered 2: [body] 1`] = ` +Object { + "member": Object { + "current": Object { + "avatar_image": null, + "comped": false, + "created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, + "email": "testemail@example.com", + "email_count": 0, + "email_open_rate": null, + "email_opened_count": 0, + "geolocation": null, + "id": StringMatching /\\[a-f0-9\\]\\{24\\}/, + "last_seen_at": null, + "name": "Test Member", + "newsletters": Array [ + Object { + "body_font_category": "sans_serif", + "created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, + "description": null, + "footer_content": null, + "header_image": null, + "id": StringMatching /\\[a-f0-9\\]\\{24\\}/, + "name": "Default Newsletter", + "sender_email": null, + "sender_name": null, + "sender_reply_to": "newsletter", + "show_badge": true, + "show_feature_image": true, + "show_header_icon": true, + "show_header_name": true, + "show_header_title": true, + "slug": "default-newsletter", + "sort_order": 0, + "status": "active", + "subscribe_on_signup": true, + "title_alignment": "center", + "title_font_category": "sans_serif", + "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, + "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, + "visibility": "members", + }, + ], + "note": "test note", + "status": "free", + "subscribed": true, + "subscriptions": Array [], + "tiers": Array [], + "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, + "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, + }, + "previous": Object {}, + }, +} +`; diff --git a/ghost/core/test/e2e-webhooks/members.test.js b/ghost/core/test/e2e-webhooks/members.test.js new file mode 100644 index 00000000000..96feeec2140 --- /dev/null +++ b/ghost/core/test/e2e-webhooks/members.test.js @@ -0,0 +1,70 @@ +const {agentProvider, mockManager, fixtureManager, matchers} = require('../utils/e2e-framework'); +const {anyGhostAgent, anyObjectId, anyISODateTime, anyUuid, anyContentVersion, anyNumber} = matchers; + +const newsLetterSnapshot = { + id: anyObjectId, + uuid: anyUuid, + created_at: anyISODateTime, + updated_at: anyISODateTime +}; + +const memberSnapshot = { + id: anyObjectId, + uuid: anyUuid, + created_at: anyISODateTime, + updated_at: anyISODateTime, + newsletters: new Array(1).fill(newsLetterSnapshot) +}; + +describe('member.* 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('member.added event is triggered', async function () { + const webhookURL = 'https://test-webhook-receiver.com/member-added/'; + await webhookMockReceiver.mock(webhookURL); + await fixtureManager.insertWebhook({ + event: 'member.added', + url: webhookURL + }); + + await adminAPIAgent + .post('members/') + .body({ + members: [{ + name: 'Test Member', + email: 'testemail@example.com', + note: 'test note' + }] + }) + .expectStatus(201); + + await webhookMockReceiver.receivedRequest(); + + webhookMockReceiver + .matchHeaderSnapshot({ + 'content-version': anyContentVersion, + 'content-length': anyNumber, + 'user-agent': anyGhostAgent + }) + .matchBodySnapshot({ + member: { + current: memberSnapshot + } + }); + }); +}); \ No newline at end of file