mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-01 02:41:39 -05:00
added mentions admin browse api e2e tests (#16177)
refs TryGhost/Team#2468 -added simple browse api tests for webmentions -need to add user access tests and possibly site access (private sites)
This commit is contained in:
parent
19b9696fe2
commit
477295a262
4 changed files with 146 additions and 0 deletions
|
@ -0,0 +1,46 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Mentions API Can browse with limits 1: [body] 1`] = `
|
||||
Object {
|
||||
"mentions": Array [
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"payload": null,
|
||||
"resource_id": null,
|
||||
"source": Any<String>,
|
||||
"source_author": null,
|
||||
"source_excerpt": null,
|
||||
"source_favicon": null,
|
||||
"source_featured_image": null,
|
||||
"source_site_title": null,
|
||||
"source_title": Any<String>,
|
||||
"target": Any<String>,
|
||||
"timestamp": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"payload": null,
|
||||
"resource_id": null,
|
||||
"source": Any<String>,
|
||||
"source_author": null,
|
||||
"source_excerpt": null,
|
||||
"source_favicon": null,
|
||||
"source_featured_image": null,
|
||||
"source_site_title": null,
|
||||
"source_title": Any<String>,
|
||||
"target": Any<String>,
|
||||
"timestamp": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||
},
|
||||
],
|
||||
"meta": Object {
|
||||
"pagination": Object {
|
||||
"limit": 2,
|
||||
"next": 2,
|
||||
"page": 1,
|
||||
"pages": 2,
|
||||
"prev": null,
|
||||
"total": 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
40
ghost/core/test/e2e-api/admin/mentions.test.js
Normal file
40
ghost/core/test/e2e-api/admin/mentions.test.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
const {agentProvider, fixtureManager, mockManager, matchers} = require('../../utils/e2e-framework');
|
||||
const {anyObjectId, anyISODateTime, anyString} = matchers;
|
||||
|
||||
const matchMentionShallowIncludes = {
|
||||
id: anyObjectId,
|
||||
source: anyString,
|
||||
target: anyString,
|
||||
timestamp: anyISODateTime,
|
||||
source_title: anyString
|
||||
};
|
||||
|
||||
describe('Mentions API', function () {
|
||||
let agent;
|
||||
|
||||
before(async function () {
|
||||
agent = await agentProvider.getAdminAPIAgent();
|
||||
mockManager.mockLabsEnabled('webmentions');
|
||||
// TODO: test various users' access
|
||||
await fixtureManager.init('users','mentions');
|
||||
await agent.loginAsOwner();
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
mockManager.restore();
|
||||
});
|
||||
|
||||
it('Can browse with limits', async function () {
|
||||
const res = await agent.get('mentions/?limit=2')
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
mentions: new Array(2).fill(matchMentionShallowIncludes)
|
||||
});
|
||||
});
|
||||
|
||||
it('Cannot browse when lab disabled', async function () {
|
||||
mockManager.mockLabsDisabled('webmentions');
|
||||
const res = await agent.get('mentions/')
|
||||
.expectStatus(404);
|
||||
});
|
||||
});
|
|
@ -460,6 +460,12 @@ const fixtures = {
|
|||
}));
|
||||
},
|
||||
|
||||
insertMentions: function insertMentions() {
|
||||
return Promise.all(DataGenerator.forKnex.mentions.map((mention) => {
|
||||
return models.Mention.add(mention, context.internal);
|
||||
}));
|
||||
},
|
||||
|
||||
insertEmails: function insertEmails() {
|
||||
return Promise.all(DataGenerator.forKnex.emails.map((email) => {
|
||||
return models.Email.add(email, context.internal);
|
||||
|
@ -826,6 +832,9 @@ const toDoList = {
|
|||
},
|
||||
links: function insertLinks() {
|
||||
return fixtures.insertLinks();
|
||||
},
|
||||
mentions: function insertMentions() {
|
||||
return fixtures.insertMentions();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -890,6 +890,42 @@ DataGenerator.Content = {
|
|||
created_at: null,
|
||||
updated_at: null
|
||||
}
|
||||
],
|
||||
|
||||
// TODO: build mentions for testing browse endpoint
|
||||
mentions: [
|
||||
// source: webmention.source,
|
||||
// target: webmention.target,
|
||||
// timestamp: new Date(),
|
||||
// payload: webmention.payload,
|
||||
// resourceId: resourceInfo.type === 'post' ? resourceInfo.id : null,
|
||||
// sourceTitle: metadata.title,
|
||||
// sourceSiteTitle: metadata.siteTitle,
|
||||
// sourceAuthor: metadata.author,
|
||||
// sourceExcerpt: metadata.excerpt,
|
||||
// sourceFavicon: metadata.favicon,
|
||||
// sourceFeaturedImage: metadata.image
|
||||
{
|
||||
id: ObjectId().toHexString(),
|
||||
source: 'https://source.com',
|
||||
target: 'https://target.com',
|
||||
sourceTitle: 'Title!',
|
||||
sourceExcerpt: 'Excerpt!'
|
||||
},
|
||||
{
|
||||
id: ObjectId().toHexString(),
|
||||
source: 'https://anothersource.com',
|
||||
target: 'https://anothertarget.com',
|
||||
sourceTitle: 'Another Title!',
|
||||
sourceExcerpt: 'Another Excerpt!'
|
||||
},
|
||||
{
|
||||
id: ObjectId().toHexString(),
|
||||
source: 'https://src.com',
|
||||
target: 'https://target.com',
|
||||
sourceTitle: 'Title goes here',
|
||||
sourceExcerpt: 'Excerpt goes here'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
|
@ -1340,6 +1376,13 @@ DataGenerator.forKnex = (function () {
|
|||
});
|
||||
}
|
||||
|
||||
function createMention(overrides) {
|
||||
const newObj = _.cloneDeep(overrides);
|
||||
return _.defaults(newObj, {
|
||||
created_at: new Date()
|
||||
});
|
||||
}
|
||||
|
||||
const posts = [
|
||||
createPost(DataGenerator.Content.posts[0]),
|
||||
createPost(DataGenerator.Content.posts[1]),
|
||||
|
@ -1849,6 +1892,12 @@ DataGenerator.forKnex = (function () {
|
|||
createLink(DataGenerator.Content.links[2])
|
||||
];
|
||||
|
||||
const mentions = [
|
||||
createMention(DataGenerator.Content.mentions[0]),
|
||||
createMention(DataGenerator.Content.mentions[1]),
|
||||
createMention(DataGenerator.Content.mentions[2])
|
||||
];
|
||||
|
||||
return {
|
||||
createPost,
|
||||
createGenericPost,
|
||||
|
@ -1880,6 +1929,7 @@ DataGenerator.forKnex = (function () {
|
|||
createNewsletter,
|
||||
createOffer,
|
||||
createComment,
|
||||
createMention,
|
||||
|
||||
invites,
|
||||
posts,
|
||||
|
@ -1912,6 +1962,7 @@ DataGenerator.forKnex = (function () {
|
|||
comments,
|
||||
redirects,
|
||||
links,
|
||||
mentions,
|
||||
|
||||
members_paid_subscription_events,
|
||||
members_created_events,
|
||||
|
|
Loading…
Add table
Reference in a new issue