0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/test/unit/data/meta/author_image_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

90 lines
2.8 KiB
JavaScript

var should = require('should'),
sinon = require('sinon'),
getAuthorImage = require('../../../../core/frontend/meta/author_image');
describe('getAuthorImage', function () {
afterEach(function () {
sinon.restore();
});
it('should return author image url if post and has url', function () {
var imageUrl = getAuthorImage({
context: ['post'],
post: {
primary_author: {
profile_image: '/content/images/2016/01/myimage.jpg'
}
}
}, false);
imageUrl.should.equal('/content/images/2016/01/myimage.jpg');
});
it('should return absolute author image url if post and has url', function () {
var imageUrl = getAuthorImage({
context: ['post'],
post: {
primary_author: {
profile_image: '/content/images/2016/01/myimage.jpg'
}
}
}, true);
imageUrl.should.not.equal('/content/images/2016/01/myimage.jpg');
imageUrl.should.match(/\/content\/images\/2016\/01\/myimage\.jpg$/);
});
it('should return author image url if AMP post and has url', function () {
var imageUrl = getAuthorImage({
context: ['amp', 'post'],
post: {
primary_author: {
profile_image: '/content/images/2016/01/myimage.jpg'
}
}
}, false);
imageUrl.should.equal('/content/images/2016/01/myimage.jpg');
});
it('should return absolute author image url if AMP post and has url', function () {
var imageUrl = getAuthorImage({
context: ['amp', 'post'],
post: {
primary_author: {
profile_image: '/content/images/2016/01/myimage.jpg'
}
}
}, true);
imageUrl.should.not.equal('/content/images/2016/01/myimage.jpg');
imageUrl.should.match(/\/content\/images\/2016\/01\/myimage\.jpg$/);
});
it('should return null if context does not contain author image url and is a post', function () {
var imageUrl = getAuthorImage({
context: ['post'],
post: {
primary_author: {
name: 'Test Author'
}
}
});
should(imageUrl).equal(null);
});
it('should return null if context does not contain author and is a post', function () {
var imageUrl = getAuthorImage({
context: ['post'],
post: {}
});
should(imageUrl).equal(null);
});
it('should return null if context is not a post', function () {
var imageUrl = getAuthorImage({
context: ['tag']
});
should(imageUrl).equal(null);
});
});