Ghost/ghost/core/test/e2e-webhooks/members.test.js
illiteratewriter a0ec94fbfe
Added e2e test for member.added webhook (#15554)
refs https://github.com/TryGhost/Ghost/issues/15537

- this adds an e2e test and test snapshot for the `member.added` webhook so we can prevent regressions and bugs in the future
2022-10-07 15:54:24 +07:00

70 lines
2.0 KiB
JavaScript

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
}
});
});
});