0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Added support for filtering Members CSV exports

no-issue

Adding these options to the endpoint will pass them to the model layer,
allowing us to filter members CSV exports
This commit is contained in:
Fabien O'Carroll 2020-09-23 11:46:08 +01:00 committed by Fabien 'egg' O'Carroll
parent 800ffc2e8f
commit 171908cefa
2 changed files with 23 additions and 1 deletions

View file

@ -399,7 +399,10 @@ module.exports = {
exportCSV: {
options: [
'limit'
'limit',
'filter',
'search',
'paid'
],
headers: {
disposition: {

View file

@ -346,6 +346,25 @@ describe('Members API', function () {
should.exist(csv.data.find(row => row.email === 'member2@test.com'));
});
it('Can export a filtered CSV', async function () {
const res = await request
.get(localUtils.API.getApiQuery(`members/upload/?search=Egg`))
.set('Origin', config.get('url'))
.expect('Content-Type', /text\/csv/)
.expect('Cache-Control', testUtils.cacheRules.private)
.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.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'));
});
it('Can import CSV', function () {
return request
.post(localUtils.API.getApiQuery(`members/upload/`))