2014-04-29 00:42:38 +04:00
|
|
|
var url = require('url'),
|
2013-11-03 21:13:19 +04:00
|
|
|
ApiRouteBase = '/ghost/api/v0.1/',
|
|
|
|
host = 'localhost',
|
2014-04-29 00:42:38 +04:00
|
|
|
port = '2369',
|
|
|
|
schema = 'http://',
|
2013-11-07 13:34:18 +04:00
|
|
|
expectedProperties = {
|
2014-04-19 19:03:20 +04:00
|
|
|
posts: ['posts', 'meta'],
|
2014-04-29 00:42:38 +04:00
|
|
|
users: ['users'],
|
2014-04-19 19:03:20 +04:00
|
|
|
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
|
2013-11-07 13:34:18 +04:00
|
|
|
post: ['id', 'uuid', 'title', 'slug', 'markdown', 'html', 'meta_title', 'meta_description',
|
2014-04-22 05:08:11 +04:00
|
|
|
'featured', 'image', 'status', 'language', 'created_at', 'created_by', 'updated_at',
|
2014-02-25 00:28:18 +04:00
|
|
|
'updated_by', 'published_at', 'published_by', 'page', 'author', 'tags', 'fields'],
|
2014-04-28 03:28:50 +04:00
|
|
|
settings: ['settings'],
|
2014-04-29 00:42:38 +04:00
|
|
|
setting: ['id', 'uuid', 'key', 'value', 'type', 'created_at', 'created_by', 'updated_at', 'updated_by'],
|
2014-04-23 10:46:53 +04:00
|
|
|
tag: ['id', 'uuid', 'name', 'slug', 'description', 'parent',
|
2013-11-07 13:34:18 +04:00
|
|
|
'meta_title', 'meta_description', 'created_at', 'created_by', 'updated_at', 'updated_by'],
|
|
|
|
user: ['id', 'uuid', 'name', 'slug', 'email', 'image', 'cover', 'bio', 'website',
|
2014-04-29 00:42:38 +04:00
|
|
|
'location', 'accessibility', 'status', 'language', 'meta_title', 'meta_description', 'last_login',
|
|
|
|
'created_at', 'created_by', 'updated_at', 'updated_by'],
|
2014-04-29 00:58:18 +04:00
|
|
|
notification: ['type', 'message', 'status', 'id', 'dismissable', 'location']
|
2013-11-07 13:34:18 +04:00
|
|
|
};
|
|
|
|
|
2014-04-29 00:42:38 +04:00
|
|
|
function getApiQuery(route) {
|
2014-04-07 17:50:18 +04:00
|
|
|
return url.resolve(ApiRouteBase, route);
|
|
|
|
}
|
2013-11-03 21:13:19 +04:00
|
|
|
|
2014-04-29 00:42:38 +04:00
|
|
|
function getApiURL(route) {
|
2013-11-03 21:13:19 +04:00
|
|
|
var baseURL = url.resolve(schema + host + ':' + port, ApiRouteBase);
|
|
|
|
return url.resolve(baseURL, route);
|
2013-10-08 05:39:33 +04:00
|
|
|
}
|
2014-04-29 00:42:38 +04:00
|
|
|
function getSigninURL() {
|
2013-11-03 21:13:19 +04:00
|
|
|
return url.resolve(schema + host + ':' + port, 'ghost/signin/');
|
2013-10-08 05:39:33 +04:00
|
|
|
}
|
2014-04-29 00:42:38 +04:00
|
|
|
function getAdminURL() {
|
2013-11-24 18:29:36 +04:00
|
|
|
return url.resolve(schema + host + ':' + port, 'ghost/');
|
|
|
|
}
|
2013-10-08 05:39:33 +04:00
|
|
|
|
2013-11-03 21:13:19 +04:00
|
|
|
// make sure the API only returns expected properties only
|
2014-04-29 00:42:38 +04:00
|
|
|
function checkResponseValue(jsonResponse, properties) {
|
2013-11-07 13:34:18 +04:00
|
|
|
Object.keys(jsonResponse).length.should.eql(properties.length);
|
2014-04-29 00:42:38 +04:00
|
|
|
for (var i = 0; i < properties.length; i = i + 1) {
|
2014-04-28 03:28:50 +04:00
|
|
|
// For some reason, settings response objects do not have the 'hasOwnProperty' method
|
|
|
|
if (Object.prototype.hasOwnProperty.call(jsonResponse, properties[i])) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-07 13:34:18 +04:00
|
|
|
jsonResponse.should.have.property(properties[i]);
|
2013-10-08 05:39:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-29 00:42:38 +04:00
|
|
|
function checkResponse(jsonResponse, objectType) {
|
|
|
|
checkResponseValue(jsonResponse, expectedProperties[objectType]);
|
|
|
|
}
|
|
|
|
|
2013-11-07 13:34:18 +04:00
|
|
|
module.exports = {
|
|
|
|
getApiURL: getApiURL,
|
2014-04-07 17:50:18 +04:00
|
|
|
getApiQuery: getApiQuery,
|
2013-11-07 13:34:18 +04:00
|
|
|
getSigninURL: getSigninURL,
|
2013-11-24 18:29:36 +04:00
|
|
|
getAdminURL: getAdminURL,
|
2013-11-07 13:34:18 +04:00
|
|
|
checkResponse: checkResponse,
|
2014-04-29 00:42:38 +04:00
|
|
|
checkResponseValue: checkResponseValue
|
2013-11-07 13:34:18 +04:00
|
|
|
};
|