mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
a0ec94fbfe
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
70 lines
2.0 KiB
JavaScript
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
|
|
}
|
|
});
|
|
});
|
|
}); |