2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
2021-06-30 18:51:48 +03:00
|
|
|
const models = require('../../../core/server/models');
|
|
|
|
const getKeywords = require('../../../core/frontend/meta/keywords');
|
2016-01-17 13:07:52 +03:00
|
|
|
|
|
|
|
describe('getKeywords', function () {
|
2017-12-13 15:19:51 +03:00
|
|
|
before(function () {
|
|
|
|
models.init();
|
|
|
|
});
|
|
|
|
|
2016-09-14 20:33:24 +03:00
|
|
|
afterEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2016-09-14 20:33:24 +03:00
|
|
|
});
|
2017-12-13 15:19:51 +03:00
|
|
|
|
2016-01-17 13:07:52 +03:00
|
|
|
it('should return tags as keywords if post has tags', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const keywords = getKeywords({
|
2016-01-17 13:07:52 +03:00
|
|
|
post: {
|
|
|
|
tags: [
|
|
|
|
{name: 'one'},
|
|
|
|
{name: 'two'},
|
|
|
|
{name: 'three'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
should.deepEqual(keywords, ['one', 'two', 'three']);
|
|
|
|
});
|
|
|
|
|
2016-10-10 11:51:03 +03:00
|
|
|
it('should only return visible tags', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const keywords = getKeywords({
|
2016-09-14 20:33:24 +03:00
|
|
|
post: {
|
|
|
|
tags: [
|
|
|
|
{name: 'one', visibility: 'public'},
|
|
|
|
{name: 'two', visibility: 'internal'},
|
|
|
|
{name: 'three'},
|
|
|
|
{name: 'four', visibility: 'internal'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
should.deepEqual(keywords, ['one', 'three']);
|
|
|
|
});
|
|
|
|
|
2016-01-17 13:07:52 +03:00
|
|
|
it('should return null if post has tags is empty array', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const keywords = getKeywords({
|
2016-01-17 13:07:52 +03:00
|
|
|
post: {
|
|
|
|
tags: []
|
|
|
|
}
|
|
|
|
});
|
|
|
|
should.equal(keywords, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return null if post has no tags', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const keywords = getKeywords({
|
2016-01-17 13:07:52 +03:00
|
|
|
post: {}
|
|
|
|
});
|
|
|
|
should.equal(keywords, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return null if not a post', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const keywords = getKeywords({
|
2016-01-17 13:07:52 +03:00
|
|
|
author: {}
|
|
|
|
});
|
|
|
|
should.equal(keywords, null);
|
|
|
|
});
|
|
|
|
});
|