Added initial stats config to API (#20875)

closes https://linear.app/tryghost/issue/ANAL-8/flag-and-config

- This checks if tinybird:stats is set, and if so passes through the
config that is set via the config API
- This is used by Ghost admin to configure where to pull charts from
This commit is contained in:
Hannah Wolfe 2024-08-29 11:37:28 +01:00 committed by GitHub
parent 0a6cd75993
commit 3e25370ebe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 67 additions and 21 deletions

View File

@ -20,7 +20,8 @@ module.exports = {
'hostSettings', 'hostSettings',
'tenor', 'tenor',
'pintura', 'pintura',
'signupForm' 'signupForm',
'stats'
]; ];
frame.response = { frame.response = {

View File

@ -23,5 +23,10 @@ module.exports = function getConfigProperties() {
signupForm: config.get('signupForm') signupForm: config.get('signupForm')
}; };
// WIP tinybird stats feature - it's entirely config driven instead of using an alpha flag for now
if (config.get('tinybird') && config.get('tinybird:stats')) {
configProperties.stats = config.get('tinybird:stats');
}
return configProperties; return configProperties;
}; };

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Config API Can retrieve config and all expected properties 1: [body] 1`] = ` exports[`Config API As Owner Can retrieve config and all expected properties 1: [body] 1`] = `
Object { Object {
"config": Object { "config": Object {
"clientExtensions": Object {}, "clientExtensions": Object {},
@ -54,7 +54,7 @@ Object {
} }
`; `;
exports[`Config API Can retrieve config and all expected properties 2: [headers] 1`] = ` exports[`Config API As Owner Can retrieve config and all expected properties 2: [headers] 1`] = `
Object { Object {
"access-control-allow-origin": "http://127.0.0.1:2369", "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", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",

View File

@ -11,25 +11,37 @@ describe('Config API', function () {
before(async function () { before(async function () {
agent = await agentProvider.getAdminAPIAgent(); agent = await agentProvider.getAdminAPIAgent();
await fixtureManager.init(); await fixtureManager.init('users');
await agent.loginAsOwner();
}); });
it('Can retrieve config and all expected properties', async function () { describe('As Unauthorized User', function () {
await agent it('Cannot fetch the config endpoint', async function () {
.get('/config/') await agent.get('/config/')
.expectStatus(200) .expectStatus(403);
.matchBodySnapshot({ });
config: { });
database: stringMatching(/sqlite3|mysql|mysql2/),
environment: stringMatching(/^testing/), describe('As Owner', function () {
version: stringMatching(/\d+\.\d+\.\d+/) before(async function () {
} await agent.loginAsOwner();
}) });
.matchHeaderSnapshot({
'content-version': anyContentVersion, it('Can retrieve config and all expected properties', async function () {
'content-length': anyContentLength, // Length can differ slightly based on the database, environment and version values await agent
etag: anyEtag .get('/config/')
}); .expectStatus(200)
.matchBodySnapshot({
config: {
database: stringMatching(/sqlite3|mysql|mysql2/),
environment: stringMatching(/^testing/),
version: stringMatching(/\d+\.\d+\.\d+/)
}
})
.matchHeaderSnapshot({
'content-version': anyContentVersion,
'content-length': anyContentLength, // Length can differ slightly based on the database, environment and version values
etag: anyEtag
});
});
}); });
}); });

View File

@ -67,5 +67,33 @@ describe('Public-config Service', function () {
assert.equal(configProperties.mailgunIsConfigured, false); assert.equal(configProperties.mailgunIsConfigured, false);
}); });
it('should NOT return stats by default', function () {
let configProperties = getConfigProperties();
assert.equal(configProperties.stats, undefined);
});
it('should return stats when tinybird config is set with the stats key', function () {
configUtils.set('tinybird', {
stats: {
endpoint: 'xxx'
}
});
let configProperties = getConfigProperties();
assert.deepEqual(configProperties.stats, {endpoint: 'xxx'});
});
it('should NOT return stats when tinybird config is set without the stats key', function () {
configUtils.set('tinybird', {
url: 'xxx'
});
let configProperties = getConfigProperties();
assert.equal(configProperties.stats, undefined);
});
}); });
}); });