0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Resubscribe member to default newsletters after removing from suppression list (#15974)

refs TryGhost/Team#2372
This commit is contained in:
Elena Baidakova 2022-12-13 13:31:50 +04:00 committed by GitHub
parent 1c74d3304a
commit 9579791185
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 120 additions and 1 deletions

View file

@ -101,7 +101,13 @@ const getMemberData = async function (req, res) {
const deleteSuppression = async function (req, res) {
try {
const member = await membersService.ssr.getMemberDataFromSession(req, res);
const options = {
id: member.id,
withRelated: ['newsletters']
};
await emailSuppressionList.removeEmail(member.email);
await membersService.api.members.update({subscribed: true}, options);
res.writeHead(204);
res.end();
} catch (err) {

View file

@ -45,6 +45,83 @@ Object {
}
`;
exports[`Comments API when authenticated can remove member from suppression list and resubscribe to default newsletters 1: [body] 1`] = `
Object {
"avatar_image": null,
"email": "member@example.com",
"email_suppression": Object {
"info": null,
"suppressed": false,
},
"enable_comment_notifications": true,
"expertise": "test",
"firstname": "Test",
"name": "Test User",
"newsletters": Array [],
"paid": false,
"subscribed": false,
"subscriptions": Array [],
"uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
}
`;
exports[`Comments API when authenticated can remove member from suppression list and resubscribe to default newsletters 2: [headers] 1`] = `
Object {
"access-control-allow-origin": "*",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "310",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Accept-Encoding",
"x-powered-by": "Express",
}
`;
exports[`Comments API when authenticated can remove member from suppression list and resubscribe to default newsletters 3: [body] 1`] = `
Object {
"avatar_image": null,
"email": "member@example.com",
"email_suppression": Object {
"info": null,
"suppressed": false,
},
"enable_comment_notifications": true,
"expertise": "test",
"firstname": "Test",
"name": "Test User",
"newsletters": Array [
Object {
"description": null,
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"name": "Default Newsletter",
"sort_order": 0,
},
Object {
"description": null,
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"name": "Weekly newsletter",
"sort_order": 2,
},
],
"paid": false,
"subscribed": false,
"subscriptions": Array [],
"uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
}
`;
exports[`Comments API when authenticated can remove member from suppression list and resubscribe to default newsletters 4: [headers] 1`] = `
Object {
"access-control-allow-origin": "*",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "500",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Accept-Encoding",
"x-powered-by": "Express",
}
`;
exports[`Comments API when authenticated can update comment notifications 1: [body] 1`] = `
Object {
"avatar_image": null,

View file

@ -31,6 +31,10 @@ const memberMatcherUnserialised = (newslettersCount) => {
};
};
async function getDefaultNewsletters() {
return (await models.Newsletter.findAll({filter: 'status:active+subscribe_on_signup:true+visibility:members'})).models;
}
describe('Comments API', function () {
before(async function () {
membersAgent = await agentProvider.getMembersAPIAgent();
@ -197,11 +201,43 @@ describe('Comments API', function () {
member.get('enable_comment_notifications').should.eql(true);
});
it('can remove member from suppression list', async function () {
it('can remove member from suppression list and resubscribe to default newsletters', async function () {
const newsletters = await getDefaultNewsletters();
// unsubscribe member from all newsletters
await membersAgent
.put(`/api/member/`)
.body({
newsletters: []
})
.expectStatus(200)
.matchHeaderSnapshot({
etag: anyEtag
})
.matchBodySnapshot(memberMatcher(0))
.expect(({body}) => {
body.newsletters.should.eql([]);
});
// remove email from suppression list
await membersAgent
.delete(`/api/member/suppression`)
.expectStatus(204)
.expectEmptyBody();
// check that member re-subscribed to default newsletters after removing from suppression list
await membersAgent
.get(`/api/member/`)
.expectStatus(200)
.matchHeaderSnapshot({
etag: anyEtag
})
.matchBodySnapshot(memberMatcher(2))
.expect(({body}) => {
// body should contain default newsletters
body.newsletters[0].id.should.eql(newsletters[0].get('id'));
body.newsletters[1].id.should.eql(newsletters[1].get('id'));
});
});
});
});