mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Renamed stats endpoint to /stats/member-count and added totals metadata
refs https://ghost.slack.com/archives/C02G9E68C/p1648737467414789?thread_ts=1648644801.253699&cid=C02G9E68C - Anything in the API should use snakeCase - Reduce amount of nesting in endpoint name - Added totals metadata
This commit is contained in:
parent
51550c8da3
commit
31c1d4f513
5 changed files with 20 additions and 9 deletions
|
@ -66,7 +66,8 @@ class MembersStatsService {
|
|||
const rows = await this.fetchAllStatusDeltas();
|
||||
|
||||
// Fetch current total amounts and start counting from there
|
||||
let {paid, free, comped} = await this.getCount();
|
||||
const totals = await this.getCount();
|
||||
let {paid, free, comped} = totals;
|
||||
|
||||
// Get today in UTC (default timezone for Luxon)
|
||||
const today = DateTime.local().toISODate();
|
||||
|
@ -120,7 +121,8 @@ class MembersStatsService {
|
|||
total: cumulativeResults.length,
|
||||
next: null,
|
||||
prev: null
|
||||
}
|
||||
},
|
||||
totals
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ module.exports = function apiRoutes() {
|
|||
router.get('/members/:id/signin_urls', mw.authAdminApi, http(api.memberSigninUrls.read));
|
||||
|
||||
// ## Stats
|
||||
router.get('/stats/members/count-history', mw.authAdminApi, http(api.stats.memberCountHistory));
|
||||
router.get('/stats/member-count', mw.authAdminApi, http(api.stats.memberCountHistory));
|
||||
|
||||
// ## Labels
|
||||
router.get('/labels', mw.authAdminApi, http(api.labels.browse));
|
||||
|
|
|
@ -11,6 +11,11 @@ Object {
|
|||
"prev": null,
|
||||
"total": 1,
|
||||
},
|
||||
"totals": Object {
|
||||
"comped": 0,
|
||||
"free": 3,
|
||||
"paid": 5,
|
||||
},
|
||||
},
|
||||
"stats": Array [
|
||||
Object {
|
||||
|
@ -29,7 +34,7 @@ exports[`Stats API Can fetch member count history 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",
|
||||
"content-length": "191",
|
||||
"content-length": "231",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
|
|
|
@ -12,7 +12,7 @@ describe('Stats API', function () {
|
|||
|
||||
it('Can fetch member count history', async function () {
|
||||
await agent
|
||||
.get(`/stats/members/count-history`)
|
||||
.get(`/stats/member-count`)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
stats: [{
|
||||
|
|
|
@ -43,7 +43,7 @@ describe('MembersStatsService', function () {
|
|||
currentCounts.free = 2;
|
||||
currentCounts.comped = 3;
|
||||
|
||||
const {data: results} = await membersStatsService.getCountHistory();
|
||||
const {data: results, meta} = await membersStatsService.getCountHistory();
|
||||
results.length.should.eql(1);
|
||||
results[0].should.eql({
|
||||
date: today,
|
||||
|
@ -53,6 +53,7 @@ describe('MembersStatsService', function () {
|
|||
paid_subscribed: 0,
|
||||
paid_canceled: 0
|
||||
});
|
||||
meta.totals.should.eql(currentCounts);
|
||||
|
||||
fakeStatuses.calledOnce.should.eql(true);
|
||||
fakeTotal.calledOnce.should.eql(true);
|
||||
|
@ -73,7 +74,7 @@ describe('MembersStatsService', function () {
|
|||
currentCounts.free = 2;
|
||||
currentCounts.comped = 3;
|
||||
|
||||
const {data: results} = await membersStatsService.getCountHistory();
|
||||
const {data: results, meta} = await membersStatsService.getCountHistory();
|
||||
results.length.should.eql(1);
|
||||
results[0].should.eql({
|
||||
date: today,
|
||||
|
@ -83,6 +84,7 @@ describe('MembersStatsService', function () {
|
|||
paid_subscribed: 4,
|
||||
paid_canceled: 3
|
||||
});
|
||||
meta.totals.should.eql(currentCounts);
|
||||
|
||||
fakeStatuses.calledOnce.should.eql(true);
|
||||
fakeTotal.calledOnce.should.eql(true);
|
||||
|
@ -112,7 +114,7 @@ describe('MembersStatsService', function () {
|
|||
currentCounts.free = 3;
|
||||
currentCounts.comped = 4;
|
||||
|
||||
const {data: results} = await membersStatsService.getCountHistory();
|
||||
const {data: results, meta} = await membersStatsService.getCountHistory();
|
||||
results.should.eql([
|
||||
{
|
||||
date: yesterday,
|
||||
|
@ -131,6 +133,7 @@ describe('MembersStatsService', function () {
|
|||
paid_canceled: 3
|
||||
}
|
||||
]);
|
||||
meta.totals.should.eql(currentCounts);
|
||||
fakeStatuses.calledOnce.should.eql(true);
|
||||
fakeTotal.calledOnce.should.eql(true);
|
||||
});
|
||||
|
@ -166,7 +169,7 @@ describe('MembersStatsService', function () {
|
|||
currentCounts.free = 2;
|
||||
currentCounts.comped = 3;
|
||||
|
||||
const {data: results} = await membersStatsService.getCountHistory();
|
||||
const {data: results, meta} = await membersStatsService.getCountHistory();
|
||||
results.should.eql([
|
||||
{
|
||||
date: yesterday,
|
||||
|
@ -185,6 +188,7 @@ describe('MembersStatsService', function () {
|
|||
paid_canceled: 3
|
||||
}
|
||||
]);
|
||||
meta.totals.should.eql(currentCounts);
|
||||
fakeStatuses.calledOnce.should.eql(true);
|
||||
fakeTotal.calledOnce.should.eql(true);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue