mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed CSV unparsing for subscribed flag
no-issue We have a special mapping for subscribed_to_emails -> subscribed in the parse method, but were not mapping it in the unparse method, which meant we were losing information during CSV imports.
This commit is contained in:
parent
379fbc7f13
commit
b1cc2a8ea8
2 changed files with 21 additions and 0 deletions
|
@ -15,6 +15,12 @@ const DEFAULT_COLUMNS = [
|
|||
];
|
||||
|
||||
const unparse = (members, columns = DEFAULT_COLUMNS.slice()) => {
|
||||
columns = columns.map((column) => {
|
||||
if (column === 'subscribed') {
|
||||
return 'subscribed_to_emails';
|
||||
}
|
||||
return column;
|
||||
});
|
||||
const mappedMembers = members.map((member) => {
|
||||
if (member.error) {
|
||||
columns.push('error');
|
||||
|
|
|
@ -16,4 +16,19 @@ describe('unparse', function () {
|
|||
const expected = `id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,products\r\n,email@example.com,Sam Memberino,Early supporter,,,,,,,`;
|
||||
should.equal(result, expected);
|
||||
});
|
||||
|
||||
it('maps the subscribed property to subscribed_to_emails', function () {
|
||||
const json = [{
|
||||
email: 'do-not-email-me@email.com',
|
||||
subscribed: false
|
||||
}];
|
||||
|
||||
const columns = Object.keys(json[0]);
|
||||
|
||||
const result = unparse(json, columns);
|
||||
|
||||
const expected = `email,subscribed_to_emails\r\ndo-not-email-me@email.com,false`;
|
||||
|
||||
should.equal(result, expected);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue