2020-07-08 10:40:48 +03:00
|
|
|
const should = require('should');
|
|
|
|
const unparse = require('../lib/unparse');
|
|
|
|
|
|
|
|
describe('unparse', function () {
|
|
|
|
it('serializes json to CSV and adds standard members fields', async function () {
|
2020-07-08 11:08:00 +03:00
|
|
|
const json = [{
|
|
|
|
email: 'email@example.com',
|
|
|
|
name: 'Sam Memberino',
|
|
|
|
note: 'Early supporter'
|
|
|
|
}];
|
2020-07-08 10:40:48 +03:00
|
|
|
|
|
|
|
const result = unparse(json);
|
|
|
|
|
|
|
|
should.exist(result);
|
|
|
|
|
2021-06-22 20:10:22 +03:00
|
|
|
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,,,,,,,`;
|
2020-07-08 10:40:48 +03:00
|
|
|
should.equal(result, expected);
|
|
|
|
});
|
2022-01-11 17:26:11 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2020-07-08 10:40:48 +03:00
|
|
|
});
|