0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Added missing tests from previous commit

refs 3288e5bf33

- These tests do not use the new e2e framework given it doesn't support file attachments yet
This commit is contained in:
Thibaut Patel 2022-02-14 14:43:26 +01:00
parent 3288e5bf33
commit 531ec579a2

View file

@ -419,294 +419,294 @@ describe('Members API', function () {
}); });
//TODO: migrate once we have a way to attach files in the new e2e testing framework //TODO: migrate once we have a way to attach files in the new e2e testing framework
// describe('Members API', function () { describe('Members API', function () {
// let request; let request;
// before(async function () { before(async function () {
// await localUtils.startGhost(); await localUtils.startGhost();
// request = supertest.agent(config.get('url')); request = supertest.agent(config.get('url'));
// await localUtils.doAuth(request, 'members', 'members:emails'); await localUtils.doAuth(request, 'members', 'members:emails');
// }); });
// beforeEach(function () { beforeEach(function () {
// mockManager.mockLabsEnabled('multipleProducts'); mockManager.mockLabsEnabled('multipleProducts');
// }); });
// afterEach(function () { afterEach(function () {
// mockManager.restore(); mockManager.restore();
// }); });
// it('Can import CSV', async function () { it('Can import CSV', async function () {
// const res = await request const res = await request
// .post(localUtils.API.getApiQuery(`members/upload/`)) .post(localUtils.API.getApiQuery(`members/upload/`))
// .attach('membersfile', path.join(__dirname, '/../../utils/fixtures/csv/valid-members-import.csv')) .attach('membersfile', path.join(__dirname, '/../../utils/fixtures/csv/valid-members-import.csv'))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(201); .expect(201);
// should.not.exist(res.headers['x-cache-invalidate']); should.not.exist(res.headers['x-cache-invalidate']);
// const jsonResponse = res.body; const jsonResponse = res.body;
// should.exist(jsonResponse); should.exist(jsonResponse);
// should.exist(jsonResponse.meta); should.exist(jsonResponse.meta);
// should.exist(jsonResponse.meta.stats); should.exist(jsonResponse.meta.stats);
// jsonResponse.meta.stats.imported.should.equal(2); jsonResponse.meta.stats.imported.should.equal(2);
// jsonResponse.meta.stats.invalid.length.should.equal(0); jsonResponse.meta.stats.invalid.length.should.equal(0);
// jsonResponse.meta.import_label.name.should.match(/^Import \d{4}-\d{2}-\d{2} \d{2}:\d{2}$/); jsonResponse.meta.import_label.name.should.match(/^Import \d{4}-\d{2}-\d{2} \d{2}:\d{2}$/);
// const importLabel = jsonResponse.meta.import_label; const importLabel = jsonResponse.meta.import_label;
// // check that members had the auto-generated label attached // check that members had the auto-generated label attached
// const res2 = await request.get(localUtils.API.getApiQuery(`members/?filter=label:${importLabel.slug}`)) const res2 = await request.get(localUtils.API.getApiQuery(`members/?filter=label:${importLabel.slug}`))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(200); .expect(200);
// const jsonResponse2 = res2.body; const jsonResponse2 = res2.body;
// should.exist(jsonResponse2); should.exist(jsonResponse2);
// should.exist(jsonResponse2.members); should.exist(jsonResponse2.members);
// jsonResponse2.members.should.have.length(2); jsonResponse2.members.should.have.length(2);
// const importedMember1 = jsonResponse2.members.find(m => m.email === 'jbloggs@example.com'); const importedMember1 = jsonResponse2.members.find(m => m.email === 'jbloggs@example.com');
// should.exist(importedMember1); should.exist(importedMember1);
// importedMember1.name.should.equal('joe'); importedMember1.name.should.equal('joe');
// should(importedMember1.note).equal(null); should(importedMember1.note).equal(null);
// importedMember1.subscribed.should.equal(true); importedMember1.subscribed.should.equal(true);
// importedMember1.labels.length.should.equal(1); importedMember1.labels.length.should.equal(1);
// testUtils.API.isISO8601(importedMember1.created_at).should.be.true(); testUtils.API.isISO8601(importedMember1.created_at).should.be.true();
// importedMember1.comped.should.equal(false); importedMember1.comped.should.equal(false);
// importedMember1.subscriptions.should.not.be.undefined(); importedMember1.subscriptions.should.not.be.undefined();
// importedMember1.subscriptions.length.should.equal(0); importedMember1.subscriptions.length.should.equal(0);
// const importedMember2 = jsonResponse2.members.find(m => m.email === 'test@example.com'); const importedMember2 = jsonResponse2.members.find(m => m.email === 'test@example.com');
// should.exist(importedMember2); should.exist(importedMember2);
// importedMember2.name.should.equal('test'); importedMember2.name.should.equal('test');
// should(importedMember2.note).equal('test note'); should(importedMember2.note).equal('test note');
// importedMember2.subscribed.should.equal(false); importedMember2.subscribed.should.equal(false);
// importedMember2.labels.length.should.equal(2); importedMember2.labels.length.should.equal(2);
// testUtils.API.isISO8601(importedMember2.created_at).should.be.true(); testUtils.API.isISO8601(importedMember2.created_at).should.be.true();
// importedMember2.created_at.should.equal('1991-10-02T20:30:31.000Z'); importedMember2.created_at.should.equal('1991-10-02T20:30:31.000Z');
// importedMember2.comped.should.equal(false); importedMember2.comped.should.equal(false);
// importedMember2.subscriptions.should.not.be.undefined(); importedMember2.subscriptions.should.not.be.undefined();
// importedMember2.subscriptions.length.should.equal(0); importedMember2.subscriptions.length.should.equal(0);
// }); });
// it('Can import CSV and bulk destroy via auto-added label', function () { it('Can import CSV and bulk destroy via auto-added label', function () {
// // HACK: mock dates otherwise we'll often get unexpected members appearing // HACK: mock dates otherwise we'll often get unexpected members appearing
// // from previous tests with the same import label due to auto-generated // from previous tests with the same import label due to auto-generated
// // import labels only including minutes // import labels only including minutes
// sinon.stub(Date, 'now').returns(new Date('2021-03-30T17:21:00.000Z')); sinon.stub(Date, 'now').returns(new Date('2021-03-30T17:21:00.000Z'));
// // import our dummy data for deletion // import our dummy data for deletion
// return request return request
// .post(localUtils.API.getApiQuery(`members/upload/`)) .post(localUtils.API.getApiQuery(`members/upload/`))
// .attach('membersfile', path.join(__dirname, '/../../utils/fixtures/csv/valid-members-for-bulk-delete.csv')) .attach('membersfile', path.join(__dirname, '/../../utils/fixtures/csv/valid-members-for-bulk-delete.csv'))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .then((res) => { .then((res) => {
// should.not.exist(res.headers['x-cache-invalidate']); should.not.exist(res.headers['x-cache-invalidate']);
// const jsonResponse = res.body; const jsonResponse = res.body;
// should.exist(jsonResponse); should.exist(jsonResponse);
// should.exist(jsonResponse.meta); should.exist(jsonResponse.meta);
// should.exist(jsonResponse.meta.stats); should.exist(jsonResponse.meta.stats);
// should.exist(jsonResponse.meta.import_label); should.exist(jsonResponse.meta.import_label);
// jsonResponse.meta.stats.imported.should.equal(8); jsonResponse.meta.stats.imported.should.equal(8);
// return jsonResponse.meta.import_label; return jsonResponse.meta.import_label;
// }) })
// .then((importLabel) => { .then((importLabel) => {
// // check that the import worked by checking browse response with filter // check that the import worked by checking browse response with filter
// return request.get(localUtils.API.getApiQuery(`members/?filter=label:${importLabel.slug}`)) return request.get(localUtils.API.getApiQuery(`members/?filter=label:${importLabel.slug}`))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(200) .expect(200)
// .then((res) => { .then((res) => {
// should.not.exist(res.headers['x-cache-invalidate']); should.not.exist(res.headers['x-cache-invalidate']);
// const jsonResponse = res.body; const jsonResponse = res.body;
// should.exist(jsonResponse); should.exist(jsonResponse);
// should.exist(jsonResponse.members); should.exist(jsonResponse.members);
// jsonResponse.members.should.have.length(8); jsonResponse.members.should.have.length(8);
// }) })
// .then(() => importLabel); .then(() => importLabel);
// }) })
// .then((importLabel) => { .then((importLabel) => {
// // perform the bulk delete // perform the bulk delete
// return request return request
// .del(localUtils.API.getApiQuery(`members/?filter=label:'${importLabel.slug}'`)) .del(localUtils.API.getApiQuery(`members/?filter=label:'${importLabel.slug}'`))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(200) .expect(200)
// .then((res) => { .then((res) => {
// should.not.exist(res.headers['x-cache-invalidate']); should.not.exist(res.headers['x-cache-invalidate']);
// const jsonResponse = res.body; const jsonResponse = res.body;
// should.exist(jsonResponse); should.exist(jsonResponse);
// should.exist(jsonResponse.meta); should.exist(jsonResponse.meta);
// should.exist(jsonResponse.meta.stats); should.exist(jsonResponse.meta.stats);
// should.exist(jsonResponse.meta.stats.successful); should.exist(jsonResponse.meta.stats.successful);
// should.equal(jsonResponse.meta.stats.successful, 8); should.equal(jsonResponse.meta.stats.successful, 8);
// }) })
// .then(() => importLabel); .then(() => importLabel);
// }) })
// .then((importLabel) => { .then((importLabel) => {
// // check that the bulk delete worked by checking browse response with filter // check that the bulk delete worked by checking browse response with filter
// return request.get(localUtils.API.getApiQuery(`members/?filter=label:${importLabel.slug}`)) return request.get(localUtils.API.getApiQuery(`members/?filter=label:${importLabel.slug}`))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(200) .expect(200)
// .then((res) => { .then((res) => {
// const jsonResponse = res.body; const jsonResponse = res.body;
// should.exist(jsonResponse); should.exist(jsonResponse);
// should.exist(jsonResponse.members); should.exist(jsonResponse.members);
// jsonResponse.members.should.have.length(0); jsonResponse.members.should.have.length(0);
// }); });
// }); });
// }); });
// it('Can bulk unsubscribe members with filter', async function () { it('Can bulk unsubscribe members with filter', async function () {
// // import our dummy data for deletion // import our dummy data for deletion
// await request await request
// .post(localUtils.API.getApiQuery(`members/upload/`)) .post(localUtils.API.getApiQuery(`members/upload/`))
// .attach('membersfile', path.join(__dirname, '/../../utils/fixtures/csv/members-for-bulk-unsubscribe.csv')) .attach('membersfile', path.join(__dirname, '/../../utils/fixtures/csv/members-for-bulk-unsubscribe.csv'))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private); .expect('Cache-Control', testUtils.cacheRules.private);
// const browseResponse = await request const browseResponse = await request
// .get(localUtils.API.getApiQuery('members/?filter=label:bulk-unsubscribe-test')) .get(localUtils.API.getApiQuery('members/?filter=label:bulk-unsubscribe-test'))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(200); .expect(200);
// browseResponse.body.members.should.have.length(8); browseResponse.body.members.should.have.length(8);
// const allMembersSubscribed = browseResponse.body.members.every((member) => { const allMembersSubscribed = browseResponse.body.members.every((member) => {
// return member.subscribed; return member.subscribed;
// }); });
// should.ok(allMembersSubscribed); should.ok(allMembersSubscribed);
// const bulkUnsubscribeResponse = await request const bulkUnsubscribeResponse = await request
// .put(localUtils.API.getApiQuery('members/bulk/?filter=label:bulk-unsubscribe-test')) .put(localUtils.API.getApiQuery('members/bulk/?filter=label:bulk-unsubscribe-test'))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .send({ .send({
// bulk: { bulk: {
// action: 'unsubscribe' action: 'unsubscribe'
// } }
// }) })
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(200); .expect(200);
// should.exist(bulkUnsubscribeResponse.body.bulk); should.exist(bulkUnsubscribeResponse.body.bulk);
// should.exist(bulkUnsubscribeResponse.body.bulk.meta); should.exist(bulkUnsubscribeResponse.body.bulk.meta);
// should.exist(bulkUnsubscribeResponse.body.bulk.meta.stats); should.exist(bulkUnsubscribeResponse.body.bulk.meta.stats);
// should.exist(bulkUnsubscribeResponse.body.bulk.meta.stats.successful); should.exist(bulkUnsubscribeResponse.body.bulk.meta.stats.successful);
// should.equal(bulkUnsubscribeResponse.body.bulk.meta.stats.successful, 8); should.equal(bulkUnsubscribeResponse.body.bulk.meta.stats.successful, 8);
// const postUnsubscribeBrowseResponse = await request const postUnsubscribeBrowseResponse = await request
// .get(localUtils.API.getApiQuery('members/?filter=label:bulk-unsubscribe-test')) .get(localUtils.API.getApiQuery('members/?filter=label:bulk-unsubscribe-test'))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(200); .expect(200);
// postUnsubscribeBrowseResponse.body.members.should.have.length(8); postUnsubscribeBrowseResponse.body.members.should.have.length(8);
// const allMembersUnsubscribed = postUnsubscribeBrowseResponse.body.members.every((member) => { const allMembersUnsubscribed = postUnsubscribeBrowseResponse.body.members.every((member) => {
// return !member.subscribed; return !member.subscribed;
// }); });
// should.ok(allMembersUnsubscribed); should.ok(allMembersUnsubscribed);
// }); });
// it('Can bulk add and remove labels to members with filter', async function () { it('Can bulk add and remove labels to members with filter', async function () {
// // import our dummy data for deletion // import our dummy data for deletion
// await request await request
// .post(localUtils.API.getApiQuery('members/upload/')) .post(localUtils.API.getApiQuery('members/upload/'))
// .attach('membersfile', path.join(__dirname, '/../../utils/fixtures/csv/members-for-bulk-add-labels.csv')) .attach('membersfile', path.join(__dirname, '/../../utils/fixtures/csv/members-for-bulk-add-labels.csv'))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private); .expect('Cache-Control', testUtils.cacheRules.private);
// const newLabelResponse = await request const newLabelResponse = await request
// .post(localUtils.API.getApiQuery('labels')) .post(localUtils.API.getApiQuery('labels'))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .send({ .send({
// labels: [{ labels: [{
// name: 'Awesome Label For Testing Bulk Add' name: 'Awesome Label For Testing Bulk Add'
// }] }]
// }); });
// const labelToAdd = newLabelResponse.body.labels[0]; const labelToAdd = newLabelResponse.body.labels[0];
// const bulkAddLabelResponse = await request const bulkAddLabelResponse = await request
// .put(localUtils.API.getApiQuery('members/bulk/?filter=label:bulk-add-labels-test')) .put(localUtils.API.getApiQuery('members/bulk/?filter=label:bulk-add-labels-test'))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .send({ .send({
// bulk: { bulk: {
// action: 'addLabel', action: 'addLabel',
// meta: { meta: {
// label: labelToAdd label: labelToAdd
// } }
// } }
// }) })
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(200); .expect(200);
// should.exist(bulkAddLabelResponse.body.bulk); should.exist(bulkAddLabelResponse.body.bulk);
// should.exist(bulkAddLabelResponse.body.bulk.meta); should.exist(bulkAddLabelResponse.body.bulk.meta);
// should.exist(bulkAddLabelResponse.body.bulk.meta.stats); should.exist(bulkAddLabelResponse.body.bulk.meta.stats);
// should.exist(bulkAddLabelResponse.body.bulk.meta.stats.successful); should.exist(bulkAddLabelResponse.body.bulk.meta.stats.successful);
// should.equal(bulkAddLabelResponse.body.bulk.meta.stats.successful, 8); should.equal(bulkAddLabelResponse.body.bulk.meta.stats.successful, 8);
// const postLabelAddBrowseResponse = await request const postLabelAddBrowseResponse = await request
// .get(localUtils.API.getApiQuery(`members/?filter=label:${labelToAdd.slug}`)) .get(localUtils.API.getApiQuery(`members/?filter=label:${labelToAdd.slug}`))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(200); .expect(200);
// postLabelAddBrowseResponse.body.members.should.have.length(8); postLabelAddBrowseResponse.body.members.should.have.length(8);
// const labelToRemove = newLabelResponse.body.labels[0]; const labelToRemove = newLabelResponse.body.labels[0];
// const bulkRemoveLabelResponse = await request const bulkRemoveLabelResponse = await request
// .put(localUtils.API.getApiQuery('members/bulk/?filter=label:bulk-add-labels-test')) .put(localUtils.API.getApiQuery('members/bulk/?filter=label:bulk-add-labels-test'))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .send({ .send({
// bulk: { bulk: {
// action: 'removeLabel', action: 'removeLabel',
// meta: { meta: {
// label: labelToRemove label: labelToRemove
// } }
// } }
// }) })
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(200); .expect(200);
// should.exist(bulkRemoveLabelResponse.body.bulk); should.exist(bulkRemoveLabelResponse.body.bulk);
// should.exist(bulkRemoveLabelResponse.body.bulk.meta); should.exist(bulkRemoveLabelResponse.body.bulk.meta);
// should.exist(bulkRemoveLabelResponse.body.bulk.meta.stats); should.exist(bulkRemoveLabelResponse.body.bulk.meta.stats);
// should.exist(bulkRemoveLabelResponse.body.bulk.meta.stats.successful); should.exist(bulkRemoveLabelResponse.body.bulk.meta.stats.successful);
// should.equal(bulkRemoveLabelResponse.body.bulk.meta.stats.successful, 8); should.equal(bulkRemoveLabelResponse.body.bulk.meta.stats.successful, 8);
// const postLabelRemoveBrowseResponse = await request const postLabelRemoveBrowseResponse = await request
// .get(localUtils.API.getApiQuery(`members/?filter=label:${labelToRemove.slug}`)) .get(localUtils.API.getApiQuery(`members/?filter=label:${labelToRemove.slug}`))
// .set('Origin', config.get('url')) .set('Origin', config.get('url'))
// .expect('Content-Type', /json/) .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(200); .expect(200);
// postLabelRemoveBrowseResponse.body.members.should.have.length(0); postLabelRemoveBrowseResponse.body.members.should.have.length(0);
// }); });
// }); });