Skip to content

Commit

Permalink
Added some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
allouis committed Mar 14, 2024
1 parent 2e61eeb commit ffbee6c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ghost/core/core/frontend/helpers/get.js
Expand Up @@ -364,3 +364,5 @@ module.exports = async function get(resource, options) {
};

module.exports.async = true;

module.exports.optimizeFilterCacheablity = optimizeFilterCacheablity;
39 changes: 39 additions & 0 deletions ghost/core/test/unit/frontend/helpers/get.test.js
Expand Up @@ -39,6 +39,45 @@ describe('{{#get}} helper', function () {
sinon.restore();
});

describe('cacheablity optimisation', function () {
it('Ignores non posts', function () {
const apiOptions = {
filter: 'id:-abcdef1234567890abcdef12'
};
const {
options,
parseResult
} = get.optimizeFilterCacheablity('not-posts', apiOptions);
assert.equal(options.filter, 'id:-abcdef1234567890abcdef12');
assert.deepEqual(parseResult({not: 'modified'}), {not: 'modified'});
});
it('Changes the filter for simple id negations', function () {
const apiOptions = {
filter: 'id:-abcdef1234567890abcdef12',
limit: 1
};
const {
options,
parseResult
} = get.optimizeFilterCacheablity('posts', apiOptions);
assert.equal(options.filter, 'id:-null');
assert.deepEqual(parseResult({
posts: [{
id: 'abcdef1234567890abcdef12'
}, {
id: '1234567890abcdef12345678'
}]
}), {
posts: [{
id: '1234567890abcdef12345678'
}],
meta: {
cacheablityOptimisation: true
}
});
});
});

describe('context preparation', function () {
const meta = {pagination: {}};

Expand Down

0 comments on commit ffbee6c

Please sign in to comment.