mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 01:03:23 +03:00
f566729ed6
fixes https://github.com/TryGhost/Product/issues/3851 - Order was not applied via the CRUD plugin - Removed usage of CRUD findAll, and swapped to Bookshelf fetchAll instead, to decrease dependencies of invisible Bookshelf plugins logic - Reverted page and limit options possibility via findAll method
67 lines
2.4 KiB
JavaScript
67 lines
2.4 KiB
JavaScript
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
|
const recommendationsService = require('../../../core/server/services/recommendations');
|
|
const {Recommendation} = require('@tryghost/recommendations');
|
|
const {anyObjectId, anyISODateTime} = matchers;
|
|
|
|
describe('Recommendations Content API', function () {
|
|
let agent;
|
|
|
|
before(async function () {
|
|
agent = await agentProvider.getContentAPIAgent();
|
|
await fixtureManager.init('api_keys');
|
|
await agent.authenticate();
|
|
|
|
// Clear placeholders
|
|
for (const recommendation of (await recommendationsService.repository.getAll())) {
|
|
recommendation.delete();
|
|
await recommendationsService.repository.save(recommendation);
|
|
}
|
|
|
|
// Add 7 recommendations using the repository
|
|
for (let i = 0; i < 7; i++) {
|
|
const recommendation = Recommendation.create({
|
|
title: `Recommendation ${i}`,
|
|
reason: `Reason ${i}`,
|
|
url: new URL(`https://recommendation${i}.com`),
|
|
favicon: null,
|
|
featuredImage: null,
|
|
excerpt: null,
|
|
oneClickSubscribe: false,
|
|
createdAt: new Date(i * 5000) // Reliable ordering
|
|
});
|
|
|
|
await recommendationsService.repository.save(recommendation);
|
|
}
|
|
});
|
|
|
|
it('Can paginate recommendations', async function () {
|
|
await agent.get(`recommendations/`)
|
|
.expectStatus(200)
|
|
.matchHeaderSnapshot({
|
|
'content-version': matchers.anyContentVersion,
|
|
etag: matchers.anyEtag
|
|
})
|
|
.matchBodySnapshot({
|
|
recommendations: new Array(5).fill({
|
|
id: anyObjectId,
|
|
created_at: anyISODateTime,
|
|
updated_at: anyISODateTime
|
|
})
|
|
});
|
|
|
|
await agent.get(`recommendations/?page=2`)
|
|
.expectStatus(200)
|
|
.matchHeaderSnapshot({
|
|
'content-version': matchers.anyContentVersion,
|
|
etag: matchers.anyEtag
|
|
})
|
|
.matchBodySnapshot({
|
|
recommendations: new Array(2).fill({
|
|
id: anyObjectId,
|
|
created_at: anyISODateTime,
|
|
updated_at: anyISODateTime
|
|
})
|
|
});
|
|
});
|
|
});
|