7e9880ce8d
Closes #2606 - Refactor settings api responses to { settings: [ ] } format - Update all code using api.settings to handle new response format - Update test stubs to return new format - Update client site settings model to parse new format into one object of key/value pairs - Refactor to include all setting values - Remove unused settingsCollection method - Update settingsCache to store all attributes - Update settingsResult to send all attributes - Remove unnecessary when() wraps - Reject if editing a setting that doesn't exist - Reject earlier if setting key is empty - Update tests with new error messages - Use setting.add instead of edit that was incorrectly adding - Update importer to properly import activePlugins and installedPlugins - Update expected setting result fields - Fix a weird situation where hasOwnProperty didn't exist 🤷
61 lines
2.4 KiB
JavaScript
61 lines
2.4 KiB
JavaScript
var _ = require('lodash'),
|
|
url = require('url'),
|
|
ApiRouteBase = '/ghost/api/v0.1/',
|
|
host = 'localhost',
|
|
port = '2369';
|
|
schema = "http://",
|
|
expectedProperties = {
|
|
posts: ['posts', 'meta'],
|
|
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
|
|
post: ['id', 'uuid', 'title', 'slug', 'markdown', 'html', 'meta_title', 'meta_description',
|
|
'featured', 'image', 'status', 'language', 'created_at', 'created_by', 'updated_at',
|
|
'updated_by', 'published_at', 'published_by', 'page', 'author', 'tags', 'fields'],
|
|
settings: ['settings'],
|
|
setting: ['id','uuid','key','value','type','created_at','created_by','updated_at','updated_by'],
|
|
tag: ['id', 'uuid', 'name', 'slug', 'description', 'parent',
|
|
'meta_title', 'meta_description', 'created_at', 'created_by', 'updated_at', 'updated_by'],
|
|
user: ['id', 'uuid', 'name', 'slug', 'email', 'image', 'cover', 'bio', 'website',
|
|
'location', 'accessibility', 'status', 'language', 'meta_title', 'meta_description',
|
|
'created_at', 'updated_at'],
|
|
notification: ['type', 'message', 'status', 'id']
|
|
};
|
|
|
|
function getApiQuery (route) {
|
|
return url.resolve(ApiRouteBase, route);
|
|
}
|
|
|
|
function getApiURL (route) {
|
|
var baseURL = url.resolve(schema + host + ':' + port, ApiRouteBase);
|
|
return url.resolve(baseURL, route);
|
|
}
|
|
function getSigninURL () {
|
|
return url.resolve(schema + host + ':' + port, 'ghost/signin/');
|
|
}
|
|
function getAdminURL () {
|
|
return url.resolve(schema + host + ':' + port, 'ghost/');
|
|
}
|
|
|
|
// make sure the API only returns expected properties only
|
|
function checkResponse (jsonResponse, objectType) {
|
|
checkResponseValue(jsonResponse, expectedProperties[objectType]);
|
|
}
|
|
function checkResponseValue (jsonResponse, properties) {
|
|
Object.keys(jsonResponse).length.should.eql(properties.length);
|
|
for(var i=0; i<properties.length; i = i + 1) {
|
|
// For some reason, settings response objects do not have the 'hasOwnProperty' method
|
|
if (Object.prototype.hasOwnProperty.call(jsonResponse, properties[i])) {
|
|
continue;
|
|
}
|
|
jsonResponse.should.have.property(properties[i]);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
getApiURL: getApiURL,
|
|
getApiQuery: getApiQuery,
|
|
getSigninURL: getSigninURL,
|
|
getAdminURL: getAdminURL,
|
|
checkResponse: checkResponse,
|
|
checkResponseValue: checkResponseValue,
|
|
};
|