From b552727b6924b11b77146b394b05fcfa20728ba6 Mon Sep 17 00:00:00 2001 From: Naz Date: Fri, 21 Oct 2022 17:45:02 +0800 Subject: [PATCH] Changed members export to contain tiers refs https://github.com/TryGhost/Team/issues/1076 - The "products" is a legacy term for what is now "tiers" since multiple tiers feature introduction in https://github.com/TryGhost/Ghost/releases/tag/v4.39.0 - Note, the "tiers" is a field meant for informational purposes and cannot be imported back into Ghost site. --- .../members-exporter.test.js.snap | 14 +++++----- .../admin/__snapshots__/members.test.js.snap | 2 +- .../e2e-api/admin/members-exporter.test.js | 26 +++++++++---------- ghost/core/test/e2e-api/admin/members.test.js | 10 +++---- ghost/members-csv/lib/unparse.js | 4 +-- ghost/members-csv/test/unparse.test.js | 6 ++--- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/ghost/core/test/e2e-api/admin/__snapshots__/members-exporter.test.js.snap b/ghost/core/test/e2e-api/admin/__snapshots__/members-exporter.test.js.snap index 25e7262a36..253fcf6d49 100644 --- a/ghost/core/test/e2e-api/admin/__snapshots__/members-exporter.test.js.snap +++ b/ghost/core/test/e2e-api/admin/__snapshots__/members-exporter.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Members API — exportCSV Can export a member without products 1: [headers] 1`] = ` +exports[`Members API — exportCSV Can export a member without tiers 1: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", @@ -13,7 +13,7 @@ Object { } `; -exports[`Members API — exportCSV Can export a member without products 2: [headers] 1`] = ` +exports[`Members API — exportCSV Can export a member without tiers 2: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", @@ -26,7 +26,7 @@ Object { } `; -exports[`Members API — exportCSV Can export a member without products 3: [headers] 1`] = ` +exports[`Members API — exportCSV Can export a member without tiers 3: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", @@ -234,7 +234,7 @@ Object { } `; -exports[`Members API — exportCSV Can export products 1: [headers] 1`] = ` +exports[`Members API — exportCSV Can export tiers 1: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", @@ -247,7 +247,7 @@ Object { } `; -exports[`Members API — exportCSV Can export products 2: [headers] 1`] = ` +exports[`Members API — exportCSV Can export tiers 2: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", @@ -260,7 +260,7 @@ Object { } `; -exports[`Members API — exportCSV Can export products 3: [headers] 1`] = ` +exports[`Members API — exportCSV Can export tiers 3: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", @@ -273,7 +273,7 @@ Object { } `; -exports[`Members API — exportCSV Can export products 4: [headers] 1`] = ` +exports[`Members API — exportCSV Can export tiers 4: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", diff --git a/ghost/core/test/e2e-api/admin/__snapshots__/members.test.js.snap b/ghost/core/test/e2e-api/admin/__snapshots__/members.test.js.snap index 4c8fa6b716..9d56a0e19e 100644 --- a/ghost/core/test/e2e-api/admin/__snapshots__/members.test.js.snap +++ b/ghost/core/test/e2e-api/admin/__snapshots__/members.test.js.snap @@ -2388,7 +2388,7 @@ Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", "content-disposition": Any, - "content-length": "215", + "content-length": "212", "content-type": "text/csv; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Accept-Version, Origin, Accept-Encoding", diff --git a/ghost/core/test/e2e-api/admin/members-exporter.test.js b/ghost/core/test/e2e-api/admin/members-exporter.test.js index ecd112d04c..7902a54aa6 100644 --- a/ghost/core/test/e2e-api/admin/members-exporter.test.js +++ b/ghost/core/test/e2e-api/admin/members-exporter.test.js @@ -51,7 +51,7 @@ async function testOutput(member, asserts, filters = []) { 'content-disposition': anyString }); - res.text.should.match(/id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,products/); + res.text.should.match(/id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,tiers/); let csv = Papa.parse(res.text, {header: true}); let row = csv.data.find(r => r.id === member.id); @@ -72,8 +72,8 @@ describe('Members API — exportCSV', function () { await agent.loginAsOwner(); await models.Product.add({ - name: 'Extra Paid Product', - slug: 'extra-product', + name: 'Extra Paid Tier', + slug: 'extra-tier', type: 'paid', active: true, visibility: 'public' @@ -106,8 +106,8 @@ describe('Members API — exportCSV', function () { mockManager.restore(); }); - it('Can export products', async function () { - // Create a new member with a product + it('Can export tiers', async function () { + // Create a new member with a product (to be renamed to "tiers" once the changes is done on model layer) const member = await createMember({ name: 'Test member', products: tiers @@ -119,11 +119,11 @@ describe('Members API — exportCSV', function () { basicAsserts(member, row); should(row.subscribed_to_emails).eql('false'); should(row.complimentary_plan).eql(''); - should(row.products.split(',').sort().join(',')).eql(tiersList); - }, [`filter=products:${tiers[0].get('slug')}`, 'filter=subscribed:false']); + should(row.tiers.split(',').sort().join(',')).eql(tiersList); + }, [`filter=tier:[${tiers[0].get('slug')}]`, 'filter=subscribed:false']); }); - it('Can export a member without products', async function () { + it('Can export a member without tiers', async function () { // Create a new member with a product const member = await createMember({ name: 'Test member 2', @@ -134,7 +134,7 @@ describe('Members API — exportCSV', function () { basicAsserts(member, row); should(row.subscribed_to_emails).eql('false'); should(row.complimentary_plan).eql(''); - should(row.products).eql(''); + should(row.tiers).eql(''); }, ['filter=subscribed:false']); }); @@ -157,7 +157,7 @@ describe('Members API — exportCSV', function () { should(row.subscribed_to_emails).eql('false'); should(row.complimentary_plan).eql(''); should(row.labels).eql(labelsList); - should(row.products).eql(''); + should(row.tiers).eql(''); }, [`filter=label:${labels[0].get('slug')}`, 'filter=subscribed:false']); }); @@ -174,7 +174,7 @@ describe('Members API — exportCSV', function () { should(row.subscribed_to_emails).eql('false'); should(row.complimentary_plan).eql('true'); should(row.labels).eql(''); - should(row.products).eql(''); + should(row.tiers).eql(''); }, ['filter=status:comped', 'filter=subscribed:false']); }); @@ -193,7 +193,7 @@ describe('Members API — exportCSV', function () { should(row.subscribed_to_emails).eql('true'); should(row.complimentary_plan).eql(''); should(row.labels).eql(''); - should(row.products).eql(''); + should(row.tiers).eql(''); }, ['filter=subscribed:true']); }); @@ -232,7 +232,7 @@ describe('Members API — exportCSV', function () { should(row.subscribed_to_emails).eql('false'); should(row.complimentary_plan).eql(''); should(row.labels).eql(''); - should(row.products).eql(''); + should(row.tiers).eql(''); should(row.stripe_customer_id).eql('cus_12345'); }, ['filter=subscribed:false', 'filter=subscriptions.subscription_id:sub_123']); }); diff --git a/ghost/core/test/e2e-api/admin/members.test.js b/ghost/core/test/e2e-api/admin/members.test.js index 11eaf32a98..0d2ae0c082 100644 --- a/ghost/core/test/e2e-api/admin/members.test.js +++ b/ghost/core/test/e2e-api/admin/members.test.js @@ -1469,7 +1469,7 @@ describe('Members API', function () { .expectStatus(200); const beforeMember = body2.members[0]; - assert.equal(beforeMember.tiers.length, 2, 'The member should have two products now'); + assert.equal(beforeMember.tiers.length, 2, 'The member should have two tiers now'); // Now try to remove only the complimentary one const compedPayload = { @@ -2100,14 +2100,14 @@ describe('Members API', function () { 'content-disposition': anyString }); - res.text.should.match(/id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,products/); + res.text.should.match(/id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,tiers/); const csv = Papa.parse(res.text, {header: true}); should.exist(csv.data.find(row => row.name === 'Mr Egg')); should.exist(csv.data.find(row => row.name === 'Winston Zeddemore')); should.exist(csv.data.find(row => row.name === 'Ray Stantz')); should.exist(csv.data.find(row => row.email === 'member2@test.com')); - should.exist(csv.data.find(row => row.products.length > 0)); + should.exist(csv.data.find(row => row.tiers.length > 0)); should.exist(csv.data.find(row => row.labels.length > 0)); }); @@ -2121,14 +2121,14 @@ describe('Members API', function () { 'content-disposition': anyString }); - res.text.should.match(/id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,products/); + res.text.should.match(/id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,tiers/); const csv = Papa.parse(res.text, {header: true}); should.exist(csv.data.find(row => row.name === 'Mr Egg')); should.not.exist(csv.data.find(row => row.name === 'Egon Spengler')); should.not.exist(csv.data.find(row => row.name === 'Ray Stantz')); should.not.exist(csv.data.find(row => row.email === 'member2@test.com')); - // note that this member doesn't have products + // note that this member doesn't have tiers should.exist(csv.data.find(row => row.labels.length > 0)); }); diff --git a/ghost/members-csv/lib/unparse.js b/ghost/members-csv/lib/unparse.js index e0fa910355..28aad9eae3 100644 --- a/ghost/members-csv/lib/unparse.js +++ b/ghost/members-csv/lib/unparse.js @@ -11,7 +11,7 @@ const DEFAULT_COLUMNS = [ 'created_at', 'deleted_at', 'labels', - 'products' + 'tiers' ]; const unparse = (members, columns = DEFAULT_COLUMNS.slice()) => { @@ -54,7 +54,7 @@ const unparse = (members, columns = DEFAULT_COLUMNS.slice()) => { created_at: member.created_at, deleted_at: member.deleted_at, labels: labels, - products: tiers, + tiers: tiers, error: member.error || null }; }); diff --git a/ghost/members-csv/test/unparse.test.js b/ghost/members-csv/test/unparse.test.js index e6e283479f..41b7ecdd1f 100644 --- a/ghost/members-csv/test/unparse.test.js +++ b/ghost/members-csv/test/unparse.test.js @@ -13,7 +13,7 @@ describe('unparse', function () { assert.ok(result); - 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,,,,,,,`; + 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); }); @@ -96,11 +96,11 @@ third-member-email@email.com,"banana, avocado"`; }]; const columns = [ - 'email', 'products' + 'email', 'tiers' ]; const result = unparse(json, columns); - const expected = `email,products\r\nmember-email@email.com,Bronze Level`; + const expected = `email,tiers\r\nmember-email@email.com,Bronze Level`; assert.equal(result, expected); }); });