0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/test/unit/metadata/url_spec.js
Aileen Nowak 19167c1af2 🐛 Fixed author helper not returning the correct url (#9102)
closes #9101

With 506a0c3e9e we don't expose the `status` field for author context anymore, which is used to determine the correct URL for the `{{url}}` helper in https://github.com/TryGhost/Ghost/blob/master/core/server/data/schema/checks.js#L13

This fix uses the field `profile_image` instead and adds a missing test for author context to the `{{url}}` helper test.
2017-10-05 13:50:55 +02:00

133 lines
4.2 KiB
JavaScript

var should = require('should'), // jshint ignore:line
getUrl = require('../../../server/data/meta/url'),
markdownToMobiledoc = require('../../utils/fixtures/data-generator').markdownToMobiledoc;
describe('getUrl', function () {
it('should return url for a post', function () {
var url = getUrl({
html: '<p>Welcome to my post.</p>',
mobiledoc: markdownToMobiledoc('Welcome to my post.'),
title: 'Welcome Post',
slug: 'welcome-post',
url: '/post/welcome-post/'
});
url.should.equal('/post/welcome-post/');
});
it('should return absolute url for a post', function () {
var url = getUrl({
html: '<p>Welcome to my post.</p>',
mobiledoc: markdownToMobiledoc('Welcome to my post.'),
title: 'Welcome Post',
slug: 'welcome-post',
url: '/post/welcome-post/'
}, true);
url.should.equal('http://127.0.0.1:2369/post/welcome-post/');
});
it('should return url for a post and remove /amp/ in url', function () {
var url = getUrl({
relativeUrl: '/welcome-post/amp/',
post: {
html: '<p>Welcome to my post.</p>',
title: 'Welcome Post',
slug: 'welcome-post',
url: '/welcome-post/amp/'
}
});
url.should.equal('/welcome-post/');
});
it('should return absolute url for a post and remove /amp/ in url', function () {
var url = getUrl({
relativeUrl: '/welcome-post/amp/',
post: {
html: '<p>Welcome to my post.</p>',
title: 'Welcome Post',
slug: 'welcome-post',
url: '/welcome-post/amp/'
}
}, true);
url.should.equal('http://127.0.0.1:2369/welcome-post/');
});
it('should return url for a tag', function () {
var url = getUrl({
name: 'Great',
slug: 'great',
description: 'My great tag',
parent: null
});
url.should.equal('/tag/great/');
});
it('should return secure absolute url for a tag', function () {
var url = getUrl({
name: 'Great',
slug: 'great',
description: 'My great tag',
parent: null,
secure: true
}, true);
url.should.equal('https://127.0.0.1:2369/tag/great/');
});
it('should return url for a author', function () {
var url = getUrl({
name: 'Author Name',
bio: 'I am fun bio!',
website: 'http://myoksite.com',
profile_image: null,
location: 'London',
slug: 'author-name'
});
url.should.equal('/author/author-name/');
});
it('should return secure absolute url for a author', function () {
var url = getUrl({
name: 'Author Name',
bio: 'I am fun bio!',
website: 'http://myoksite.com',
profile_image: null,
location: 'London',
slug: 'author-name',
secure: true
}, true);
url.should.equal('https://127.0.0.1:2369/author/author-name/');
});
it('should return url for a nav', function () {
var url = getUrl({
label: 'About Me',
url: '/about-me/',
slug: 'about-me',
current: true
});
url.should.equal('/about-me/');
});
it('should return absolute url for a nav', function () {
var url = getUrl({
label: 'About Me',
url: '/about-me/',
slug: 'about-me',
current: true
}, true);
url.should.equal('http://127.0.0.1:2369/about-me/');
});
it('should return url for a context object with relative url', function () {
var url = getUrl({
relativeUrl: '/my/relative/url/'
});
url.should.equal('/my/relative/url/');
});
it('should return url for a context object with relative url and remove /amp/ in url', function () {
var url = getUrl({
relativeUrl: '/my/relative/url/amp/'
});
url.should.equal('/my/relative/url/');
});
});