mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 05:14:12 +03:00
840deaf8d7
refs https://github.com/TryGhost/Team/issues/1076
refs 70229e4fd3 (diff-b67ecda91b5bd79c598e5c5a9ec2ccf28dbfab6a924b21352273865e07cd7ceaR57)
- The "products" column has not been doing any logic anything since at least 5.20.0 (see refed commit). The concept of columns in the export file was mostly there for analytical/data filtering reasons - so the user could analyze their exports. CSV was never a good suite for relational data that "products" (or now tiers) represent
- The "tiers" column will still be present in the exported CSV file, but there is not going to be any logic attached to it.
- The only columns that can effect the "tiers" state of the member are: "complimentary_plan" (assign default tier to the member) and "stripe_customer_id" (pulls in subscription/tier data from Stripe)
107 lines
3.3 KiB
JavaScript
107 lines
3.3 KiB
JavaScript
const assert = require('assert');
|
|
const {unparse} = require('../index');
|
|
|
|
describe('unparse', function () {
|
|
it('serializes json to CSV and adds standard members fields with no explicit columns parameter', async function () {
|
|
const json = [{
|
|
email: 'email@example.com',
|
|
name: 'Sam Memberino',
|
|
note: 'Early supporter'
|
|
}];
|
|
|
|
const result = unparse(json);
|
|
|
|
assert.ok(result);
|
|
|
|
const expected = `id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,tiers\r\n,email@example.com,Sam Memberino,Early supporter,,,,,,,`;
|
|
assert.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 = [
|
|
'email', 'subscribed'
|
|
];
|
|
|
|
const result = unparse(json, columns);
|
|
|
|
const expected = `email,subscribed_to_emails\r\ndo-not-email-me@email.com,false`;
|
|
|
|
assert.equal(result, expected);
|
|
});
|
|
|
|
it('adds an error column to serialized CSV when present in columns and as a property', function () {
|
|
const json = [{
|
|
email: 'member-email@email.com',
|
|
error: 'things went south here!'
|
|
}];
|
|
const columns = [
|
|
'email', 'error'
|
|
];
|
|
|
|
const result = unparse(json, columns);
|
|
const expected = `email,error\r\nmember-email@email.com,things went south here!`;
|
|
assert.equal(result, expected);
|
|
});
|
|
|
|
it('adds an error column automatically even if not present in columns', function () {
|
|
const json = [{
|
|
email: 'member-email@email.com',
|
|
error: 'things went south here!'
|
|
}];
|
|
const columns = [
|
|
'email'
|
|
];
|
|
|
|
const result = unparse(json, columns);
|
|
const expected = `email,error\r\nmember-email@email.com,things went south here!`;
|
|
assert.equal(result, expected);
|
|
});
|
|
|
|
it('handles labels as strings and as objects', function () {
|
|
const json = [{
|
|
email: 'member-email@email.com',
|
|
labels: 'member-email-label'
|
|
}, {
|
|
email: 'second-member-email@email.com',
|
|
labels: [{
|
|
name: 'second member label'
|
|
}]
|
|
}, {
|
|
email: 'third-member-email@email.com',
|
|
labels: ['banana, avocado']
|
|
}];
|
|
const columns = [
|
|
'email', 'labels'
|
|
];
|
|
|
|
const result = unparse(json, columns);
|
|
const expected = `email,labels\r
|
|
member-email@email.com,member-email-label\r
|
|
second-member-email@email.com,second member label\r
|
|
third-member-email@email.com,"banana, avocado"`;
|
|
assert.equal(result, expected);
|
|
});
|
|
|
|
it('handles the tiers property serialization', function () {
|
|
const json = [{
|
|
email: 'member-email@email.com',
|
|
tiers: [{
|
|
name: 'Bronze Level'
|
|
}]
|
|
}];
|
|
|
|
const columns = [
|
|
'email', 'tiers'
|
|
];
|
|
|
|
const result = unparse(json, columns);
|
|
const expected = `email,tiers\r\nmember-email@email.com,Bronze Level`;
|
|
assert.equal(result, expected);
|
|
});
|
|
});
|