Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracted duplicate comments test dbFns to shared test util #21740

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 1 addition & 61 deletions ghost/core/test/e2e-api/admin/comments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,7 @@ const {
fixtureManager,
mockManager
} = require('../../utils/e2e-framework');
const models = require('../../../core/server/models');
let postId;
const dbFns = {
/**
* @typedef {Object} AddCommentData
* @property {string} [post_id=post_id]
* @property {string} member_id
* @property {string} [parent_id]
* @property {string} [html='This is a comment']
* @property {string} [status='published']
* @property {date} [created_at]
*/
/**
* @typedef {Object} AddCommentReplyData
* @property {string} member_id
* @property {string} [html='This is a reply']
* @property {date} [created_at]
*/
/**
* @typedef {AddCommentData & {replies: AddCommentReplyData[]}} AddCommentWithRepliesData
*/

/**
* @param {AddCommentData} data
* @returns {Promise<any>}
*/
addComment: async (data) => {
return await models.Comment.add({
post_id: data.post_id || postId,
member_id: data.member_id,
parent_id: data.parent_id,
html: data.html || '<p>This is a comment</p>',
created_at: data.created_at,
status: data.status || 'published'
});
},
/**
* @param {AddCommentWithRepliesData} data
* @returns {Promise<any>}
*/
addCommentWithReplies: async (data) => {
const {replies, ...commentData} = data;

const parent = await dbFns.addComment(commentData);
const createdReplies = [];

for (const reply of replies) {
const createdReply = await dbFns.addComment({
post_id: parent.get('post_id'),
member_id: reply.member_id,
parent_id: parent.get('id'),
html: reply.html || '<p>This is a reply</p>',
status: reply.status || 'published',
created_at: reply.created_at || new Date()
});
createdReplies.push(createdReply);
}

return {parent, replies: createdReplies};
}
};
const dbFns = require('../../utils/db-fns/comments');

describe('Admin Comments API', function () {
let adminApi;
Expand Down
Loading