Ghost/test/unit/data/meta/keywords_spec.js
Hannah Wolfe 7f1d3ebc07
Move tests from core to root (#11700)
- move all test files from core/test to test/
- updated all imports and other references
- all code inside of core/ is then application code
- tests are correctly at the root level
- consistent with other repos/projects

Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
2020-03-30 16:26:47 +01:00

65 lines
1.7 KiB
JavaScript

var should = require('should'),
sinon = require('sinon'),
models = require('../../../../core/server/models'),
getKeywords = require('../../../../core/frontend/meta/keywords');
describe('getKeywords', function () {
before(function () {
models.init();
});
afterEach(function () {
sinon.restore();
});
it('should return tags as keywords if post has tags', function () {
var keywords = getKeywords({
post: {
tags: [
{name: 'one'},
{name: 'two'},
{name: 'three'}
]
}
});
should.deepEqual(keywords, ['one', 'two', 'three']);
});
it('should only return visible tags', function () {
var keywords = getKeywords({
post: {
tags: [
{name: 'one', visibility: 'public'},
{name: 'two', visibility: 'internal'},
{name: 'three'},
{name: 'four', visibility: 'internal'}
]
}
});
should.deepEqual(keywords, ['one', 'three']);
});
it('should return null if post has tags is empty array', function () {
var keywords = getKeywords({
post: {
tags: []
}
});
should.equal(keywords, null);
});
it('should return null if post has no tags', function () {
var keywords = getKeywords({
post: {}
});
should.equal(keywords, null);
});
it('should return null if not a post', function () {
var keywords = getKeywords({
author: {}
});
should.equal(keywords, null);
});
});