0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Added test coverage to automatic collections

refs https://github.com/TryGhost/Team/issues/3170

- The test confirms relational filters like `tag:kitchen-sink` filtering works for automatic collections
This commit is contained in:
Naz 2023-06-05 16:37:17 +07:00
parent 3599cfdd7a
commit c86859d0a7
No known key found for this signature in database
2 changed files with 77 additions and 0 deletions

View file

@ -104,6 +104,48 @@ Object {
}
`;
exports[`Collections API Automatic Collection Filtering Creates an automatic Collection with a relational tag filter 1: [body] 1`] = `
Object {
"collections": Array [
Object {
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"description": "Test Collection Description with relational tag filter",
"feature_image": null,
"filter": "tag:kitchen-sink",
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"posts": Array [
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": 0,
},
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": 1,
},
],
"title": "Test Collection with relational tag filter",
"type": "automatic",
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
},
],
}
`;
exports[`Collections API Automatic Collection Filtering Creates an automatic Collection with a relational tag filter 2: [headers] 1`] = `
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "431",
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/collections\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
"vary": "Accept-Version, Origin, Accept-Encoding",
"x-cache-invalidate": "/*",
"x-powered-by": "Express",
}
`;
exports[`Collections API Can add a Collection 1: [body] 1`] = `
Object {
"collections": Array [

View file

@ -379,5 +379,40 @@ describe('Collections API', function () {
collections: [buildMatcher(7)]
});
});
it('Creates an automatic Collection with a relational tag filter', async function () {
const collection = {
title: 'Test Collection with relational tag filter',
description: 'Test Collection Description with relational tag filter',
type: 'automatic',
filter: 'tag:kitchen-sink'
};
const automaticTagCollection = await agent
.post('/collections/')
.body({
collections: [collection]
})
.expectStatus(201)
.matchHeaderSnapshot({
'content-version': anyContentVersion,
etag: anyEtag,
location: anyLocationFor('collections')
})
.matchBodySnapshot({
collections: [buildMatcher(2)]
});
const kitchenSinkTagPosts = await agent
.get('/posts/?filter=tag:kitchen-sink');
assert.equal(automaticTagCollection.body.collections[0].posts.length, 2);
assert.equal(kitchenSinkTagPosts.body.posts.length, 2);
const collectionPostIds = automaticTagCollection.body.collections[0].posts.map(p => p.id);
const tagFilteredPosts = kitchenSinkTagPosts.body.posts.map(p => p.id);
assert.deepEqual(collectionPostIds, tagFilteredPosts);
});
});
});