2022-10-07 11:54:24 +03:00
|
|
|
const {agentProvider, mockManager, fixtureManager, matchers} = require('../utils/e2e-framework');
|
|
|
|
const {anyGhostAgent, anyObjectId, anyISODateTime, anyUuid, anyContentVersion, anyNumber} = matchers;
|
|
|
|
|
2023-06-28 15:16:50 +03:00
|
|
|
const buildNewsletterSnapshot = () => {
|
2022-10-12 16:35:24 +03:00
|
|
|
const newsLetterSnapshot = {
|
|
|
|
id: anyObjectId,
|
|
|
|
uuid: anyUuid,
|
|
|
|
created_at: anyISODateTime,
|
|
|
|
updated_at: anyISODateTime
|
|
|
|
};
|
|
|
|
|
|
|
|
return newsLetterSnapshot;
|
2022-10-07 11:54:24 +03:00
|
|
|
};
|
|
|
|
|
2023-06-28 15:16:50 +03:00
|
|
|
const buildMemberSnapshot = () => {
|
2022-10-12 16:35:24 +03:00
|
|
|
const memberSnapshot = {
|
|
|
|
id: anyObjectId,
|
|
|
|
uuid: anyUuid,
|
|
|
|
created_at: anyISODateTime,
|
|
|
|
updated_at: anyISODateTime,
|
2023-06-28 15:16:50 +03:00
|
|
|
newsletters: new Array(1).fill(buildNewsletterSnapshot())
|
2022-10-12 16:35:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return memberSnapshot;
|
2022-10-07 11:54:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
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: {
|
2022-10-12 16:35:24 +03:00
|
|
|
current: buildMemberSnapshot()
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('member.deleted event is triggered', async function () {
|
|
|
|
const webhookURL = 'https://test-webhook-receiver.com/member-deleted/';
|
|
|
|
await webhookMockReceiver.mock(webhookURL);
|
|
|
|
await fixtureManager.insertWebhook({
|
|
|
|
event: 'member.deleted',
|
|
|
|
url: webhookURL
|
|
|
|
});
|
|
|
|
|
|
|
|
const res = await adminAPIAgent
|
|
|
|
.post('members/')
|
|
|
|
.body({
|
|
|
|
members: [{
|
|
|
|
name: 'Test Member2',
|
|
|
|
email: 'testemail2@example.com',
|
|
|
|
note: 'test note2'
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
.expectStatus(201);
|
2023-06-28 15:16:50 +03:00
|
|
|
|
2022-10-12 16:35:24 +03:00
|
|
|
const id = res.body.members[0].id;
|
|
|
|
|
|
|
|
await adminAPIAgent
|
|
|
|
.delete('members/' + id)
|
|
|
|
.expectStatus(204);
|
|
|
|
|
|
|
|
await webhookMockReceiver.receivedRequest();
|
|
|
|
|
|
|
|
webhookMockReceiver
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
'content-length': anyNumber,
|
|
|
|
'user-agent': anyGhostAgent
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
member: {
|
|
|
|
current: {},
|
2023-06-28 15:16:50 +03:00
|
|
|
previous: buildMemberSnapshot()
|
2022-10-07 11:54:24 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2022-10-21 14:43:30 +03:00
|
|
|
|
|
|
|
it('member.edited event is triggered', async function () {
|
|
|
|
const webhookURL = 'https://test-webhook-receiver.com/member-edited/';
|
|
|
|
await webhookMockReceiver.mock(webhookURL);
|
|
|
|
await fixtureManager.insertWebhook({
|
|
|
|
event: 'member.edited',
|
|
|
|
url: webhookURL
|
|
|
|
});
|
|
|
|
|
|
|
|
const res = await adminAPIAgent
|
|
|
|
.post('members/')
|
|
|
|
.body({
|
|
|
|
members: [{
|
|
|
|
name: 'Test Member3',
|
|
|
|
email: 'testemail3@example.com',
|
|
|
|
note: 'test note3'
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
.expectStatus(201);
|
2023-06-28 15:16:50 +03:00
|
|
|
|
2022-10-21 14:43:30 +03:00
|
|
|
const id = res.body.members[0].id;
|
|
|
|
|
|
|
|
await adminAPIAgent
|
|
|
|
.put('members/' + id)
|
|
|
|
.body({
|
|
|
|
members: [{name: 'Ghost'}]
|
|
|
|
})
|
|
|
|
.expectStatus(200);
|
|
|
|
|
|
|
|
await webhookMockReceiver.receivedRequest();
|
|
|
|
|
|
|
|
webhookMockReceiver
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
'content-length': anyNumber,
|
|
|
|
'user-agent': anyGhostAgent
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
member: {
|
|
|
|
current: buildMemberSnapshot(),
|
|
|
|
previous: {
|
|
|
|
updated_at: anyISODateTime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-06-28 15:16:50 +03:00
|
|
|
});
|