2018-10-07 17:36:02 +03:00
|
|
|
const url = require('url');
|
|
|
|
const _ = require('lodash');
|
2019-09-20 18:02:45 +03:00
|
|
|
const testUtils = require('../../utils');
|
2020-03-30 18:26:47 +03:00
|
|
|
const schema = require('../../../core/server/data/schema').tables;
|
2019-09-20 18:02:45 +03:00
|
|
|
const API_URL = '/ghost/api/canary/content/';
|
2018-10-07 17:36:02 +03:00
|
|
|
|
2018-12-17 18:14:36 +03:00
|
|
|
const expectedProperties = {
|
|
|
|
// API top level
|
|
|
|
posts: ['posts', 'meta'],
|
|
|
|
tags: ['tags', 'meta'],
|
|
|
|
authors: ['authors', 'meta'],
|
|
|
|
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
|
2018-12-17 19:45:07 +03:00
|
|
|
|
2018-12-17 18:14:36 +03:00
|
|
|
post: _(schema.posts)
|
|
|
|
.keys()
|
|
|
|
// by default we only return html
|
|
|
|
.without('mobiledoc', 'plaintext')
|
2019-01-04 14:21:21 +03:00
|
|
|
// v2 doesn't return author_id OR author
|
|
|
|
.without('author_id', 'author')
|
2019-09-20 18:02:45 +03:00
|
|
|
// and always returns computed properties: url
|
|
|
|
.concat('url')
|
2019-01-04 14:21:21 +03:00
|
|
|
// v2 API doesn't return unused fields
|
2019-10-11 15:16:54 +03:00
|
|
|
.without('locale')
|
2019-01-04 14:21:21 +03:00
|
|
|
// These fields aren't useful as they always have known values
|
2019-01-05 14:11:27 +03:00
|
|
|
.without('status')
|
2019-09-16 13:51:54 +03:00
|
|
|
// v2 API doesn't return new type field
|
|
|
|
.without('type')
|
2019-01-04 22:05:50 +03:00
|
|
|
// @TODO: https://github.com/TryGhost/Ghost/issues/10335
|
2019-01-05 14:11:27 +03:00
|
|
|
// .without('page')
|
2019-01-04 21:00:45 +03:00
|
|
|
// v2 returns a calculated excerpt field
|
|
|
|
.concat('excerpt')
|
2020-07-06 15:00:15 +03:00
|
|
|
// Access is a calculated property in >= v3
|
|
|
|
.concat('access')
|
2019-09-16 11:45:55 +03:00
|
|
|
// returns meta fields from `posts_meta` schema
|
|
|
|
.concat(
|
|
|
|
..._(schema.posts_meta).keys().without('post_id', 'id')
|
|
|
|
)
|
2019-10-10 12:37:42 +03:00
|
|
|
.concat('reading_time')
|
2018-12-17 19:45:07 +03:00
|
|
|
,
|
2018-12-17 18:14:36 +03:00
|
|
|
author: _(schema.users)
|
|
|
|
.keys()
|
|
|
|
.without(
|
|
|
|
'password',
|
|
|
|
'email',
|
|
|
|
'created_at',
|
|
|
|
'created_by',
|
|
|
|
'updated_at',
|
|
|
|
'updated_by',
|
|
|
|
'last_seen',
|
|
|
|
'status'
|
|
|
|
)
|
2019-01-04 14:21:21 +03:00
|
|
|
// v2 API doesn't return unused fields
|
2019-01-08 12:59:39 +03:00
|
|
|
.without('accessibility', 'locale', 'tour', 'visibility')
|
2018-12-17 18:14:36 +03:00
|
|
|
,
|
2018-12-17 19:45:07 +03:00
|
|
|
tag: _(schema.tags)
|
|
|
|
.keys()
|
2019-01-04 14:21:21 +03:00
|
|
|
// 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')
|
2018-12-17 18:14:36 +03:00
|
|
|
};
|
|
|
|
|
2018-12-17 19:45:07 +03:00
|
|
|
_.each(expectedProperties, (value, key) => {
|
|
|
|
if (!value.__wrapped__) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated: x_by
|
|
|
|
*/
|
|
|
|
expectedProperties[key] = value
|
|
|
|
.without(
|
|
|
|
'created_by',
|
|
|
|
'updated_by',
|
|
|
|
'published_by'
|
|
|
|
)
|
|
|
|
.value();
|
|
|
|
});
|
|
|
|
|
2018-10-07 17:36:02 +03:00
|
|
|
module.exports = {
|
|
|
|
API: {
|
|
|
|
getApiQuery(route) {
|
|
|
|
return url.resolve(API_URL, route);
|
2018-12-17 18:14:36 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
checkResponse(...args) {
|
|
|
|
this.expectedProperties = expectedProperties;
|
|
|
|
return testUtils.API.checkResponse.call(this, ...args);
|
2018-10-07 17:36:02 +03:00
|
|
|
}
|
2018-10-15 12:23:34 +03:00
|
|
|
},
|
|
|
|
getValidKey() {
|
2019-01-18 19:37:58 +03:00
|
|
|
return testUtils.DataGenerator.Content.api_keys[1].secret;
|
2018-10-07 17:36:02 +03:00
|
|
|
}
|
|
|
|
};
|