0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/test/regression/api/v2/content/utils.js
Fabien 'egg' O'Carroll 6140a98351
Updated newsletter functionality to use email_recipient_filter (#12343)
no-issue

* Used email_recipient_filter in MEGA

This officially decouples the newsletter recipients from the post
visibility allowing us to send emails to free members only

* Supported enum for send_email_when_published in model

This allows us to migrate from the previously used boolean to an enum
when we eventually rename the email_recipient_filter column to
send_email_when_published

* Updated the posts API to handle email_recipient_filter

We now no longer rely on the send_email_when_published property to send
newsletters, meaning we can remove the column and start cleaning up the
new columns name

* Handled draft status changes when emails not sent

We want to reset any concept of sending an email when a post is
transition to the draft status, if and only if, and email has not
already been sent. If an email has been sent, we should leave the email
related fields as they were.

* Removed send_email_when_published from add method

This is not supported at the model layer

* Removed email_recipient_filter from v2&Content API

This should not be exposed on previous api versions, or publicly

* Removed reference to send_email_when_published

This allows us to move completely to the email_recipient_filter
property, keeping the code clean and allowing us to delete the
send_email_when_published column in the database. We plan to then
migrate _back_ to the send_email_when_published name at both the
database and api level.
2020-11-06 17:32:23 +00:00

109 lines
3.2 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/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')
// emails are not supported in API v2
.without('send_email_when_published')
.without('email_recipient_filter')
// These fields aren't useful as they always have known values
.without('status')
.concat('page')
.without('type')
// v2 returns a calculated excerpt field
.concat('excerpt')
// returns meta fields from `posts_meta` schema
.concat(
..._(schema.posts_meta).keys()
.without('post_id', 'id')
// emails are not supported in API v2
.without('email_subject')
)
,
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')
// 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'
)
};
_.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;
}
};