2017-03-21 11:24:11 +03:00
|
|
|
var should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
2020-03-30 18:26:47 +03:00
|
|
|
models = require('../../../../core/server/models'),
|
|
|
|
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 () {
|
|
|
|
var keywords = getKeywords({
|
|
|
|
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 () {
|
2016-09-14 20:33:24 +03:00
|
|
|
var keywords = getKeywords({
|
|
|
|
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 () {
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|