2019-02-04 17:49:59 +03:00
|
|
|
const url = require('url');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const testUtils = require('../../../../utils');
|
2020-03-30 18:26:47 +03:00
|
|
|
const schema = require('../../../../../core/server/data/schema').tables;
|
2019-02-04 17:49:59 +03:00
|
|
|
const API_URL = '/ghost/api/v2/content/';
|
|
|
|
|
|
|
|
const expectedProperties = {
|
|
|
|
// API top level
|
|
|
|
posts: ['posts', 'meta'],
|
|
|
|
tags: ['tags', 'meta'],
|
|
|
|
authors: ['authors', 'meta'],
|
|
|
|
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
|
|
|
|
|
|
|
|
post: _(schema.posts)
|
|
|
|
.keys()
|
|
|
|
// by default we only return html
|
|
|
|
.without('mobiledoc', 'plaintext')
|
|
|
|
// v2 doesn't return author_id OR author
|
|
|
|
.without('author_id', 'author')
|
|
|
|
// and always returns computed properties: url, primary_tag, primary_author
|
|
|
|
.concat('url', 'primary_tag', 'primary_author')
|
|
|
|
// v2 API doesn't return unused fields
|
|
|
|
.without('locale', 'visibility')
|
2019-12-16 15:19:08 +03:00
|
|
|
// emails are not supported in API v2
|
2020-11-06 20:32:23 +03:00
|
|
|
.without('email_recipient_filter')
|
2019-02-04 17:49:59 +03:00
|
|
|
// These fields aren't useful as they always have known values
|
|
|
|
.without('status')
|
2019-10-16 11:32:50 +03:00
|
|
|
.concat('page')
|
2019-09-16 13:51:54 +03:00
|
|
|
.without('type')
|
2019-02-04 17:49:59 +03:00
|
|
|
// v2 returns a calculated excerpt field
|
|
|
|
.concat('excerpt')
|
2019-09-16 11:45:55 +03:00
|
|
|
// returns meta fields from `posts_meta` schema
|
|
|
|
.concat(
|
2019-12-16 15:19:08 +03:00
|
|
|
..._(schema.posts_meta).keys()
|
|
|
|
.without('post_id', 'id')
|
|
|
|
// emails are not supported in API v2
|
|
|
|
.without('email_subject')
|
2019-09-16 11:45:55 +03:00
|
|
|
)
|
2019-02-04 17:49:59 +03:00
|
|
|
,
|
|
|
|
author: _(schema.users)
|
|
|
|
.keys()
|
|
|
|
.without(
|
|
|
|
'password',
|
|
|
|
'email',
|
|
|
|
'ghost_auth_id',
|
|
|
|
'created_at',
|
|
|
|
'created_by',
|
|
|
|
'updated_at',
|
|
|
|
'updated_by',
|
|
|
|
'last_seen',
|
|
|
|
'status'
|
|
|
|
)
|
|
|
|
// v2 API doesn't return unused fields
|
|
|
|
.without('accessibility', 'locale', 'tour', 'visibility')
|
|
|
|
,
|
|
|
|
tag: _(schema.tags)
|
|
|
|
.keys()
|
|
|
|
// v2 Tag API doesn't return parent_id or parent
|
|
|
|
.without('parent_id', 'parent')
|
|
|
|
// v2 Tag API doesn't return date fields
|
|
|
|
.without('created_at', 'updated_at')
|
2020-08-31 09:46:35 +03:00
|
|
|
// v2 Tag API doesn't return extended meta fields
|
|
|
|
.without(
|
|
|
|
'og_image',
|
|
|
|
'og_title',
|
|
|
|
'og_description',
|
|
|
|
'twitter_image',
|
|
|
|
'twitter_title',
|
|
|
|
'twitter_description',
|
|
|
|
'codeinjection_head',
|
|
|
|
'codeinjection_foot',
|
|
|
|
'canonical_url',
|
|
|
|
'accent_color'
|
|
|
|
)
|
2019-02-04 17:49:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
_.each(expectedProperties, (value, key) => {
|
|
|
|
if (!value.__wrapped__) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated: x_by
|
|
|
|
*/
|
|
|
|
expectedProperties[key] = value
|
|
|
|
.without(
|
|
|
|
'created_by',
|
|
|
|
'updated_by',
|
|
|
|
'published_by'
|
|
|
|
)
|
|
|
|
.value();
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
API: {
|
|
|
|
getApiQuery(route) {
|
|
|
|
return url.resolve(API_URL, route);
|
|
|
|
},
|
|
|
|
|
|
|
|
checkResponse(...args) {
|
|
|
|
this.expectedProperties = expectedProperties;
|
|
|
|
return testUtils.API.checkResponse.call(this, ...args);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getValidKey() {
|
|
|
|
return testUtils.DataGenerator.Content.api_keys[1].secret;
|
|
|
|
}
|
|
|
|
};
|