Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added e2e tests for member.edited webhook #15620

Merged
merged 2 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions ghost/core/test/e2e-webhooks/__snapshots__/members.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,76 @@ Object {
},
}
`;

exports[`member.* events member.edited 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[`member.* events member.edited 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": "ghost@example.com",
"email_count": 0,
"email_open_rate": null,
"email_opened_count": 0,
"geolocation": null,
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"labels": Array [],
"last_seen_at": null,
"name": "Ghost",
"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,
"feedback_enabled": false,
"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": "ghost 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 {
"email": "testemail3@example.com",
"name": "Test Member3",
"note": "test note3",
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
},
},
}
`;
51 changes: 51 additions & 0 deletions ghost/core/test/e2e-webhooks/members.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,55 @@ describe('member.* events', function () {
}
});
});

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

const id = res.body.members[0].id;

const updatedMember = {...res.body.members[0]};
updatedMember.name = 'Ghost';
updatedMember.email = 'ghost@example.com';
updatedMember.note = 'ghost note';
illiteratewriter marked this conversation as resolved.
Show resolved Hide resolved

await adminAPIAgent
.put('members/' + id)
.body({
members: [updatedMember]
})
.expectStatus(200);

await webhookMockReceiver.receivedRequest();

webhookMockReceiver
.matchHeaderSnapshot({
'content-version': anyContentVersion,
'content-length': anyNumber,
'user-agent': anyGhostAgent
})
.matchBodySnapshot({
member: {
current: buildMemberSnapshot(),
previous: {
updated_at: anyISODateTime
}
}
});
});
});