mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 18:01:36 +03:00
e0178099a2
refs https://github.com/TryGhost/Ghost/issues/12567 - Changing unique constraint from slug to slug+type should allow for posts and pages to be created with the same slug - The constraint will be present on application layer for API v4 while we figure out how to deal with it in API v5
96 lines
2.7 KiB
JavaScript
96 lines
2.7 KiB
JavaScript
const url = require('url');
|
|
const _ = require('lodash');
|
|
const testUtils = require('../../utils');
|
|
const schema = require('../../../core/server/data/schema').tables;
|
|
const API_URL = '/ghost/api/canary/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()
|
|
.filter(key => key.indexOf('@@') === -1)
|
|
// 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
|
|
.concat('url')
|
|
// v2 API doesn't return unused fields
|
|
.without('locale')
|
|
// These fields aren't useful as they always have known values
|
|
.without('status')
|
|
// v2 API doesn't return new type field
|
|
.without('type')
|
|
// @TODO: https://github.com/TryGhost/Ghost/issues/10335
|
|
// .without('page')
|
|
// v2 returns a calculated excerpt field
|
|
.concat('excerpt')
|
|
// Access is a calculated property in >= v3
|
|
.concat('access')
|
|
// returns meta fields from `posts_meta` schema
|
|
.concat(
|
|
..._(schema.posts_meta).keys().without('post_id', 'id')
|
|
)
|
|
.concat('reading_time')
|
|
,
|
|
author: _(schema.users)
|
|
.keys()
|
|
.without(
|
|
'password',
|
|
'email',
|
|
'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')
|
|
};
|
|
|
|
_.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;
|
|
}
|
|
};
|