mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
Updated defaults handling for email property in posts (#11355)
no issue - Fixed default email property output when the empty value is returned - This is needed for consistency with other endpoint properties like primary_tag which are null when there is no value assigned - Updated acceptance tests to handle email property - Schema had to be updated to not use reference so that the information about email can be independent of the post - can still exist if the post is deleted
This commit is contained in:
parent
13a0108aac
commit
b48f1f4b2c
@ -60,6 +60,10 @@ const mapPost = (model, frame) => {
|
||||
if (relation === 'authors' && jsonModel.authors) {
|
||||
jsonModel.authors = jsonModel.authors.map(author => mapUser(author, frame));
|
||||
}
|
||||
|
||||
if (relation === 'email' && _.isEmpty(jsonModel.email)) {
|
||||
jsonModel.email = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -379,7 +379,7 @@ module.exports = {
|
||||
},
|
||||
emails: {
|
||||
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
||||
post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id', unique: true},
|
||||
post_id: {type: 'string', maxlength: 24, nullable: false, index: true, unique: true},
|
||||
uuid: {type: 'string', maxlength: 36, nullable: false, validations: {isUUID: true}},
|
||||
status: {
|
||||
type: 'string',
|
||||
|
@ -22,7 +22,7 @@ describe('Posts API', function () {
|
||||
request = supertest.agent(config.get('url'));
|
||||
})
|
||||
.then(function () {
|
||||
return localUtils.doAuth(request, 'users:extra', 'posts');
|
||||
return localUtils.doAuth(request, 'users:extra', 'posts', 'emails');
|
||||
})
|
||||
.then(function (cookie) {
|
||||
ownerCookie = cookie;
|
||||
@ -95,7 +95,7 @@ describe('Posts API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Can includes single relation', function (done) {
|
||||
it('Can include single relation', function (done) {
|
||||
request.get(localUtils.API.getApiQuery('posts/?include=tags'))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect('Content-Type', /json/)
|
||||
@ -115,7 +115,7 @@ describe('Posts API', function () {
|
||||
jsonResponse.posts[0],
|
||||
'post',
|
||||
null,
|
||||
['authors', 'primary_author']
|
||||
['authors', 'primary_author', 'email']
|
||||
);
|
||||
|
||||
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
|
||||
@ -232,7 +232,7 @@ describe('Posts API', function () {
|
||||
|
||||
it('Can include relations for a single post', function (done) {
|
||||
request
|
||||
.get(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/?include=authors,tags'))
|
||||
.get(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/?include=authors,tags,email'))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
@ -254,6 +254,9 @@ describe('Posts API', function () {
|
||||
|
||||
jsonResponse.posts[0].tags[0].should.be.an.Object();
|
||||
localUtils.API.checkResponse(jsonResponse.posts[0].tags[0], 'tag', ['url']);
|
||||
|
||||
jsonResponse.posts[0].email.should.be.an.Object();
|
||||
localUtils.API.checkResponse(jsonResponse.posts[0].email, 'email');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -37,7 +37,7 @@ const expectedProperties = {
|
||||
// always returns computed properties
|
||||
.concat('url', 'primary_tag', 'primary_author', 'excerpt')
|
||||
// returned by default
|
||||
.concat('tags', 'authors')
|
||||
.concat('tags', 'authors', 'email')
|
||||
// returns meta fields from `posts_meta` schema
|
||||
.concat(
|
||||
..._(schema.posts_meta).keys().without('post_id', 'id')
|
||||
|
@ -19,7 +19,7 @@ var should = require('should'),
|
||||
*/
|
||||
describe('DB version integrity', function () {
|
||||
// Only these variables should need updating
|
||||
const currentSchemaHash = 'ffc16afc9264ba20a0d8346387c163fb';
|
||||
const currentSchemaHash = '34f9620db05fc136fa9abb7133e21615';
|
||||
const currentFixturesHash = 'b1787330f042f3954d73c43aa8bfa915';
|
||||
|
||||
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
|
||||
|
Loading…
Reference in New Issue
Block a user