diff --git a/test/api-acceptance/admin/members_spec.js b/test/api-acceptance/admin/members_spec.js index bbd77a56da..bfe6fe2eef 100644 --- a/test/api-acceptance/admin/members_spec.js +++ b/test/api-acceptance/admin/members_spec.js @@ -6,6 +6,7 @@ const testUtils = require('../../utils'); const localUtils = require('./utils'); const config = require('../../../core/shared/config'); const labs = require('../../../core/server/services/labs'); +const Papa = require('papaparse'); const ghost = testUtils.startGhost; @@ -326,20 +327,23 @@ describe('Members API', function () { }); }); - it('Can export CSV', function () { - return request + it('Can export CSV', async function () { + const res = await request .get(localUtils.API.getApiQuery(`members/upload/`)) .set('Origin', config.get('url')) .expect('Content-Type', /text\/csv/) .expect('Cache-Control', testUtils.cacheRules.private) - .expect(200) - .then((res) => { - should.not.exist(res.headers['x-cache-invalidate']); - res.headers['content-disposition'].should.match(/Attachment;\sfilename="members/); - res.text.should.match(/id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at/); - res.text.should.match(/member1@test.com/); - res.text.should.match(/Mr Egg/); - }); + .expect(200); + + should.not.exist(res.headers['x-cache-invalidate']); + res.headers['content-disposition'].should.match(/Attachment;\sfilename="members/); + res.text.should.match(/id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at/); + + 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 === 'Egon Spengler')); + should.exist(csv.data.find(row => row.name === 'Ray Stantz')); + should.exist(csv.data.find(row => row.email === 'member2@test.com')); }); it('Can import CSV', function () {