Simplified returned data from api key extraction

refs https://github.com/TryGhost/Toolbox/issues/292

- We can query the data base by the API key itself, there's no need for type of the API  at any point yet
This commit is contained in:
Naz 2022-05-10 14:44:55 +08:00
parent ef0de40228
commit 988acff403
2 changed files with 7 additions and 17 deletions

View File

@ -1,24 +1,16 @@
/**
* @typedef {object} ApiKey
* @prop {string} key
* @prop {string} type
*/
/**
*
* @param {import('express').Request} req
* @returns {ApiKey}
* @returns {string}
*/
const extractAPIKey = (req) => {
let key = null;
let type = null;
let keyValue = null;
if (req.query && req.query.key) {
type = 'content';
key = req.query.key;
keyValue = req.query.key;
}
return {key, type};
return keyValue;
};
module.exports = extractAPIKey;

View File

@ -2,25 +2,23 @@ const assert = require('assert');
const extractApiKey = require('../index');
describe('Extract API Key', function () {
it('returns nulls for a request without any key', function () {
const {key, type} = extractApiKey({
it('Returns nulls for a request without any key', function () {
const key = extractApiKey({
query: {
filter: 'status:active'
}
});
assert.equal(key, null);
assert.equal(type, null);
});
it('Extracts Content API key from the request', function () {
const {key, type} = extractApiKey({
const key = extractApiKey({
query: {
key: '123thekey'
}
});
assert.equal(key, '123thekey');
assert.equal(type, 'content');
});
});