2019-08-09 17:25:12 +03:00
|
|
|
const url = require('url');
|
2022-02-06 19:18:41 +03:00
|
|
|
const testUtils = require('../../../utils');
|
2021-05-12 17:15:54 +03:00
|
|
|
|
2022-03-11 14:27:43 +03:00
|
|
|
const API_URL = '/ghost/api/admin/';
|
2019-08-09 17:25:12 +03:00
|
|
|
|
|
|
|
const expectedProperties = {
|
|
|
|
posts: ['posts', 'meta'],
|
|
|
|
tags: ['tags', 'meta'],
|
|
|
|
users: ['users', 'meta'],
|
|
|
|
settings: ['settings', 'meta'],
|
|
|
|
subscribers: ['subscribers', 'meta'],
|
|
|
|
roles: ['roles'],
|
|
|
|
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
|
|
|
|
slugs: ['slugs'],
|
|
|
|
slug: ['slug'],
|
|
|
|
invites: ['invites', 'meta'],
|
|
|
|
themes: ['themes'],
|
2020-05-28 12:14:02 +03:00
|
|
|
members: ['members', 'meta'],
|
2021-05-19 14:46:40 +03:00
|
|
|
site: [
|
|
|
|
'title',
|
|
|
|
'description',
|
|
|
|
'logo',
|
|
|
|
'icon',
|
|
|
|
'accent_color',
|
|
|
|
'url',
|
|
|
|
'version'
|
|
|
|
],
|
2021-05-12 17:15:54 +03:00
|
|
|
post: [
|
|
|
|
'id',
|
|
|
|
'uuid',
|
|
|
|
'title',
|
|
|
|
'slug',
|
|
|
|
'mobiledoc',
|
|
|
|
'comment_id',
|
|
|
|
'feature_image',
|
2021-06-10 22:35:56 +03:00
|
|
|
'feature_image_alt',
|
|
|
|
'feature_image_caption',
|
2021-05-12 17:15:54 +03:00
|
|
|
'featured',
|
|
|
|
'status',
|
|
|
|
'visibility',
|
|
|
|
'email_recipient_filter',
|
|
|
|
'created_at',
|
|
|
|
'updated_at',
|
|
|
|
'published_at',
|
|
|
|
'custom_excerpt',
|
|
|
|
'codeinjection_head',
|
|
|
|
'codeinjection_foot',
|
|
|
|
'custom_template',
|
|
|
|
'canonical_url',
|
|
|
|
'url',
|
|
|
|
'primary_tag',
|
|
|
|
'primary_author',
|
|
|
|
'excerpt',
|
|
|
|
'tags',
|
|
|
|
'authors',
|
|
|
|
'email',
|
|
|
|
'og_image',
|
|
|
|
'og_title',
|
|
|
|
'og_description',
|
|
|
|
'twitter_image',
|
|
|
|
'twitter_title',
|
|
|
|
'twitter_description',
|
|
|
|
'meta_title',
|
|
|
|
'meta_description',
|
|
|
|
'email_subject',
|
2021-08-04 14:00:32 +03:00
|
|
|
'frontmatter',
|
2022-01-31 10:49:46 +03:00
|
|
|
'email_only',
|
|
|
|
'tiers'
|
2021-05-12 17:15:54 +03:00
|
|
|
],
|
2021-05-19 14:46:40 +03:00
|
|
|
user: [
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'slug',
|
|
|
|
'email',
|
|
|
|
'profile_image',
|
|
|
|
'cover_image',
|
|
|
|
'bio',
|
|
|
|
'website',
|
|
|
|
'location',
|
|
|
|
'facebook',
|
|
|
|
'twitter',
|
|
|
|
'accessibility',
|
|
|
|
'status',
|
|
|
|
'meta_title',
|
|
|
|
'meta_description',
|
|
|
|
'tour',
|
|
|
|
'last_seen',
|
|
|
|
'created_at',
|
|
|
|
'updated_at',
|
|
|
|
'url'
|
|
|
|
],
|
|
|
|
tag: [
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'slug',
|
|
|
|
'description',
|
|
|
|
'feature_image',
|
|
|
|
'visibility',
|
|
|
|
'og_image',
|
|
|
|
'og_title',
|
|
|
|
'og_description',
|
|
|
|
'twitter_image',
|
|
|
|
'twitter_title',
|
|
|
|
'twitter_description',
|
|
|
|
'meta_title',
|
|
|
|
'meta_description',
|
|
|
|
'codeinjection_head',
|
|
|
|
'codeinjection_foot',
|
|
|
|
'canonical_url',
|
|
|
|
'accent_color',
|
|
|
|
'created_at',
|
|
|
|
'updated_at'
|
|
|
|
],
|
|
|
|
setting: [
|
|
|
|
'id',
|
|
|
|
'group',
|
|
|
|
'key',
|
|
|
|
'value',
|
|
|
|
'type',
|
|
|
|
'flags',
|
|
|
|
'created_at',
|
|
|
|
'updated_at'
|
|
|
|
],
|
2021-05-12 17:15:54 +03:00
|
|
|
|
2021-05-19 14:46:40 +03:00
|
|
|
member: [
|
|
|
|
'id',
|
|
|
|
'uuid',
|
|
|
|
'email',
|
|
|
|
'status',
|
|
|
|
'name',
|
|
|
|
'note',
|
|
|
|
'geolocation',
|
|
|
|
'subscribed',
|
|
|
|
'email_count',
|
|
|
|
'email_opened_count',
|
|
|
|
'email_open_rate',
|
|
|
|
'created_at',
|
|
|
|
'updated_at',
|
|
|
|
'avatar_image',
|
2021-06-03 20:28:14 +03:00
|
|
|
'labels',
|
|
|
|
'comped'
|
2021-05-19 14:46:40 +03:00
|
|
|
],
|
2020-02-27 06:48:02 +03:00
|
|
|
member_signin_url: ['member_id', 'url'],
|
2021-05-19 14:46:40 +03:00
|
|
|
role: ['id', 'name', 'description', 'created_at', 'updated_at'],
|
|
|
|
permission: [
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'object_type',
|
|
|
|
'action_type',
|
|
|
|
'object_id',
|
|
|
|
'created_at',
|
|
|
|
'updated_at'
|
|
|
|
],
|
|
|
|
notification: [
|
|
|
|
'type',
|
|
|
|
'message',
|
|
|
|
'status',
|
|
|
|
'id',
|
|
|
|
'dismissible',
|
|
|
|
'location',
|
|
|
|
'custom'
|
|
|
|
],
|
2019-08-09 17:25:12 +03:00
|
|
|
theme: ['name', 'package', 'active'],
|
2021-05-19 14:46:40 +03:00
|
|
|
invite: [
|
|
|
|
'id',
|
|
|
|
'role_id',
|
|
|
|
'status',
|
|
|
|
'email',
|
|
|
|
'expires',
|
|
|
|
'created_at',
|
|
|
|
'updated_at'
|
|
|
|
],
|
|
|
|
webhook: [
|
|
|
|
'id',
|
|
|
|
'event',
|
|
|
|
'target_url',
|
|
|
|
'name',
|
|
|
|
'secret',
|
|
|
|
'api_version',
|
|
|
|
'integration_id',
|
|
|
|
'status',
|
|
|
|
'last_triggered_at',
|
|
|
|
'last_triggered_status',
|
|
|
|
'last_triggered_error',
|
|
|
|
'created_at',
|
|
|
|
'updated_at'
|
|
|
|
],
|
2019-11-08 07:37:53 +03:00
|
|
|
email_preview: ['html', 'subject', 'plaintext']
|
2019-08-09 17:25:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
API: {
|
|
|
|
getApiQuery(route) {
|
|
|
|
return url.resolve(API_URL, route);
|
|
|
|
},
|
|
|
|
|
|
|
|
checkResponse(...args) {
|
|
|
|
this.expectedProperties = expectedProperties;
|
|
|
|
return testUtils.API.checkResponse.call(this, ...args);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
doAuth(...args) {
|
|
|
|
return testUtils.API.doAuth(`${API_URL}session/`, ...args);
|
|
|
|
},
|
|
|
|
|
2021-11-24 16:29:45 +03:00
|
|
|
async startGhost(overrides = {}) {
|
|
|
|
const defaults = {
|
|
|
|
backend: true,
|
|
|
|
frontend: false
|
|
|
|
};
|
|
|
|
|
|
|
|
return await testUtils.startGhost(Object.assign(defaults, overrides));
|
|
|
|
},
|
|
|
|
|
2019-08-09 17:25:12 +03:00
|
|
|
getValidAdminToken(endpoint, key) {
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
key = key || testUtils.DataGenerator.Content.api_keys[0];
|
|
|
|
|
|
|
|
const JWT_OPTIONS = {
|
|
|
|
keyid: key.id,
|
|
|
|
algorithm: 'HS256',
|
|
|
|
expiresIn: '5m',
|
|
|
|
audience: endpoint
|
|
|
|
};
|
|
|
|
|
|
|
|
return jwt.sign(
|
|
|
|
{},
|
|
|
|
Buffer.from(key.secret, 'hex'),
|
|
|
|
JWT_OPTIONS
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|