Skip to content

Commit 48daae9

Browse files
committed
Added 100% unit test coverage to unparse
refs https://github.com/TryGhost/Team/issues/1076 - 100% is the golden standard. Easy to keep it this way once there
1 parent bd6735b commit 48daae9

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

packages/members-csv/test/unparse.test.js

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('unparse', function () {
1313

1414
assert.ok(result);
1515

16-
const expected = `id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,tiers\r\n,[email protected],Sam Memberino,Early supporter,,,,,,,`;
16+
const expected = `id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,products\r\n,[email protected],Sam Memberino,Early supporter,,,,,,,`;
1717
assert.equal(result, expected);
1818
});
1919

@@ -33,4 +33,74 @@ describe('unparse', function () {
3333

3434
assert.equal(result, expected);
3535
});
36+
37+
it('adds an error column to serialized CSV when present in columns and as a property', function () {
38+
const json = [{
39+
40+
error: 'things went south here!'
41+
}];
42+
const columns = [
43+
'email', 'error'
44+
];
45+
46+
const result = unparse(json, columns);
47+
const expected = `email,error\r\[email protected],things went south here!`;
48+
assert.equal(result, expected);
49+
});
50+
51+
it('adds an error column automatically even if not present in columns', function () {
52+
const json = [{
53+
54+
error: 'things went south here!'
55+
}];
56+
const columns = [
57+
'email'
58+
];
59+
60+
const result = unparse(json, columns);
61+
const expected = `email,error\r\[email protected],things went south here!`;
62+
assert.equal(result, expected);
63+
});
64+
65+
it('handles labels as strings and as objects', function () {
66+
const json = [{
67+
68+
labels: 'member-email-label'
69+
}, {
70+
71+
labels: [{
72+
name: 'second member label'
73+
}]
74+
}, {
75+
76+
labels: ['banana, avocado']
77+
}];
78+
const columns = [
79+
'email', 'labels'
80+
];
81+
82+
const result = unparse(json, columns);
83+
const expected = `email,labels\r
84+
[email protected],member-email-label\r
85+
[email protected],second member label\r
86+
[email protected],"banana, avocado"`;
87+
assert.equal(result, expected);
88+
});
89+
90+
it('handles the tiers to products property serialization', function () {
91+
const json = [{
92+
93+
tiers: [{
94+
name: 'Bronze Level'
95+
}]
96+
}];
97+
98+
const columns = [
99+
'email', 'products'
100+
];
101+
102+
const result = unparse(json, columns);
103+
const expected = `email,products\r\[email protected],Bronze Level`;
104+
assert.equal(result, expected);
105+
});
36106
});

0 commit comments

Comments
 (0)