diff --git a/core/server/api/canary/members.js b/core/server/api/canary/members.js index 06857ac274..9be4b562c8 100644 --- a/core/server/api/canary/members.js +++ b/core/server/api/canary/members.js @@ -365,27 +365,6 @@ module.exports = { } }, - stats: { - options: [ - 'days' - ], - permissions: { - method: 'browse' - }, - validation: { - options: { - days: { - values: ['30', '90', '365', 'all-time'] - } - } - }, - async query(frame) { - const days = frame.options.days === 'all-time' ? 'all-time' : Number(frame.options.days || 30); - - return await membersService.stats.fetch(days); - } - }, - memberStats: { permissions: { method: 'browse' diff --git a/core/server/web/api/canary/admin/routes.js b/core/server/web/api/canary/admin/routes.js index f51d4902f8..9808c86955 100644 --- a/core/server/web/api/canary/admin/routes.js +++ b/core/server/web/api/canary/admin/routes.js @@ -95,7 +95,6 @@ module.exports = function apiRoutes() { router.get('/members/stats/mrr', mw.authAdminApi, http(apiCanary.members.mrrStats)); router.get('/members/stats/subscribers', mw.authAdminApi, http(apiCanary.members.subscriberStats)); router.get('/members/stats/gross_volume', mw.authAdminApi, http(apiCanary.members.grossVolumeStats)); - router.get('/members/stats', mw.authAdminApi, http(apiCanary.members.stats)); router.get('/members/events', mw.authAdminApi, http(apiCanary.members.activityFeed)); diff --git a/test/api-acceptance/admin/members_spec.js b/test/api-acceptance/admin/members_spec.js index 2d35f20435..579d40c344 100644 --- a/test/api-acceptance/admin/members_spec.js +++ b/test/api-acceptance/admin/members_spec.js @@ -376,9 +376,9 @@ describe('Members API', function () { importedMember2.subscriptions.length.should.equal(0); }); - async function fetchStats() { + it('Can fetch member counts stats', async function () { const res = await request - .get(localUtils.API.getApiQuery('members/stats/')) + .get(localUtils.API.getApiQuery('members/stats/count/')) .set('Origin', config.get('url')) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) @@ -386,85 +386,14 @@ describe('Members API', function () { should.not.exist(res.headers['x-cache-invalidate']); const jsonResponse = res.body; - should.exist(jsonResponse); should.exist(jsonResponse.total); - should.exist(jsonResponse.total_in_range); - should.exist(jsonResponse.total_on_date); - should.exist(jsonResponse.new_today); - - // 5 from fixtures, 2 from above posts, 2 from above import - jsonResponse.total.should.equal(9); - - return jsonResponse; - } - - function parseTotalOnDate(jsonResponse) { - // replicate default look back date of 30 days - const days = 30; - // grab the timezone as mocked above - const siteTimezone = settingsCache.get('timezone'); - - // rebuild a valid response object such that works on any date-time... - // get the start date - let currentRangeDate = moment.tz(siteTimezone).subtract(days - 1, 'days'); - // get the end date but ignore today because we want to set that value ourselves - let endDate = moment.tz(siteTimezone).subtract(1, 'hour'); - - const output = {}; - let dateStr; - - // set user count to be 1 for all dates before today to match date as outlined - // for the user in valid-members-import.csv who was imported with a start date of '91 - while (currentRangeDate.isBefore(endDate)) { - dateStr = currentRangeDate.format('YYYY-MM-DD'); - output[dateStr] = 1; - - currentRangeDate = currentRangeDate.add(1, 'day'); - } - - // format the date for the end date (right now) - dateStr = currentRangeDate.format('YYYY-MM-DD'); - - // set the end date to match the number of members added from fixtures posts and imports - // 5 from fixtures, 2 from above posts, 2 from above import - output[dateStr] = 9; - - // deep equality check that the objects match... - jsonResponse.total_on_date.should.eql(output); - } - - it('Can fetch stats', function () { - return fetchStats(); - }); - - it('Can render stats in GMT -X timezones', async function () { - // stub the method - const stub = sinon.stub(settingsCache, 'get'); - - // this was just a GMT -X Timezone picked at random for the test below... - stub - .withArgs('timezone') - .returns('America/Caracas'); - - const jsonResponse = await fetchStats(); - parseTotalOnDate(jsonResponse); - // restore the stub so we can use it in other tests - stub.restore(); - }); - - it('Can render stats in GMT +X timezones', async function () { - // stub the method - const stub = sinon.stub(settingsCache, 'get'); - - // the tester that wrote this lives in Adelaide so shoutout to this (random) timezone! - stub - .withArgs('timezone') - .returns('Australia/Adelaide'); - - const jsonResponse = await fetchStats(); - parseTotalOnDate(jsonResponse); - // restore the stub so we can use it in other tests - stub.restore(); + should.exist(jsonResponse.resource); + should.exist(jsonResponse.data); + const data = jsonResponse.data; + // 2 from above posts, 2 from above import + data[0].free.should.equal(4); + data[0].paid.should.equal(0); + data[0].comped.should.equal(0); }); }); diff --git a/test/regression/api/canary/admin/members_spec.js b/test/regression/api/canary/admin/members_spec.js index 8405fb2f42..1398ed7e40 100644 --- a/test/regression/api/canary/admin/members_spec.js +++ b/test/regression/api/canary/admin/members_spec.js @@ -562,78 +562,6 @@ describe('Members API', function () { }); }); - it('Can fetch stats with no ?days param', function () { - return request - .get(localUtils.API.getApiQuery('members/stats/')) - .set('Origin', config.get('url')) - .expect('Content-Type', /json/) - .expect('Cache-Control', testUtils.cacheRules.private) - // .expect(200) - doesn't surface underlying errors in tests - .then((res) => { - res.status.should.equal(200, JSON.stringify(res.body)); - - should.not.exist(res.headers['x-cache-invalidate']); - const jsonResponse = res.body; - - should.exist(jsonResponse); - should.exist(jsonResponse.total); - should.exist(jsonResponse.total_in_range); - should.exist(jsonResponse.total_on_date); - should.exist(jsonResponse.new_today); - - // 5 from fixtures and 6 imported in previous tests - jsonResponse.total.should.equal(11); - }); - }); - - it('Can fetch stats with ?days=90', function () { - return request - .get(localUtils.API.getApiQuery('members/stats/?days=90')) - .set('Origin', config.get('url')) - .expect('Content-Type', /json/) - .expect('Cache-Control', testUtils.cacheRules.private) - // .expect(200) - doesn't surface underlying errors in tests - .then((res) => { - res.status.should.equal(200, JSON.stringify(res.body)); - - should.not.exist(res.headers['x-cache-invalidate']); - const jsonResponse = res.body; - - should.exist(jsonResponse); - should.exist(jsonResponse.total); - should.exist(jsonResponse.total_in_range); - should.exist(jsonResponse.total_on_date); - should.exist(jsonResponse.new_today); - - // 5 from fixtures and 6 imported in previous tests - jsonResponse.total.should.equal(11); - }); - }); - - it('Can fetch stats with ?days=all-time', function () { - return request - .get(localUtils.API.getApiQuery('members/stats/?days=all-time')) - .set('Origin', config.get('url')) - .expect('Content-Type', /json/) - .expect('Cache-Control', testUtils.cacheRules.private) - // .expect(200) - doesn't surface underlying errors in tests - .then((res) => { - res.status.should.equal(200, JSON.stringify(res.body)); - - should.not.exist(res.headers['x-cache-invalidate']); - const jsonResponse = res.body; - - should.exist(jsonResponse); - should.exist(jsonResponse.total); - should.exist(jsonResponse.total_in_range); - should.exist(jsonResponse.total_on_date); - should.exist(jsonResponse.new_today); - - // 5 from fixtures and 6 imported in previous tests - jsonResponse.total.should.equal(11); - }); - }); - it('Errors when fetching stats with unknown days param value', function () { return request .get(localUtils.API.getApiQuery('members/stats/?days=nope'))