mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 20:34:02 +03:00
f08a55c21f
refs: https://github.com/TryGhost/Team/issues/856 refs: https://github.com/TryGhost/Team/issues/756 - The .test.js extension is better than _spec.js as it's more obvious that it's an extension - It also meaans we can use the --extension parameter in mocha, which should result in a better default behaviour for `yarn test` - It also highlights that some of our tests were named incorrectly and were not (and still will not be) run (see https://github.com/TryGhost/Team/issues/856) - Note: even with this change, `yarn test` is throwing errors, I believe because of this issue https://github.com/TryGhost/Team/issues/756
178 lines
7.0 KiB
JavaScript
178 lines
7.0 KiB
JavaScript
const should = require('should');
|
|
const getStructuredData = require('../../../core/frontend/meta/structured-data');
|
|
|
|
describe('getStructuredData', function () {
|
|
it('should return structured data from metadata per post', function (done) {
|
|
const metadata = {
|
|
site: {
|
|
title: 'Site Title',
|
|
facebook: 'testuser',
|
|
twitter: '@testuser'
|
|
},
|
|
authorName: 'Test User',
|
|
ogType: 'article',
|
|
metaTitle: 'Post Title',
|
|
canonicalUrl: 'http://mysite.com/post/my-post-slug/',
|
|
publishedDate: '2015-12-25T05:35:01.234Z',
|
|
modifiedDate: '2016-01-21T22:13:05.412Z',
|
|
coverImage: {
|
|
url: 'http://mysite.com/content/image/mypostcoverimage.jpg',
|
|
dimensions: {
|
|
width: 500,
|
|
height: 500
|
|
}
|
|
},
|
|
ogImage: {
|
|
url: null
|
|
},
|
|
twitterImage: null,
|
|
ogTitle: 'Post Title',
|
|
ogDescription: 'Post meta description',
|
|
twitterTitle: 'Post Title',
|
|
twitterDescription: 'Post meta description',
|
|
authorFacebook: 'testpage',
|
|
creatorTwitter: '@twitterpage',
|
|
keywords: ['one', 'two', 'tag'],
|
|
metaDescription: 'Post meta description'
|
|
};
|
|
|
|
const structuredData = getStructuredData(metadata);
|
|
|
|
should.deepEqual(structuredData, {
|
|
'article:modified_time': '2016-01-21T22:13:05.412Z',
|
|
'article:published_time': '2015-12-25T05:35:01.234Z',
|
|
'article:tag': ['one', 'two', 'tag'],
|
|
'article:publisher': 'https://www.facebook.com/testuser',
|
|
'article:author': 'https://www.facebook.com/testpage',
|
|
'og:description': 'Post meta description',
|
|
'og:image': 'http://mysite.com/content/image/mypostcoverimage.jpg',
|
|
'og:image:width': 500,
|
|
'og:image:height': 500,
|
|
'og:site_name': 'Site Title',
|
|
'og:title': 'Post Title',
|
|
'og:type': 'article',
|
|
'og:url': 'http://mysite.com/post/my-post-slug/',
|
|
'twitter:card': 'summary_large_image',
|
|
'twitter:data1': 'Test User',
|
|
'twitter:data2': ['one', 'two', 'tag'].join(', '),
|
|
'twitter:description': 'Post meta description',
|
|
'twitter:image': 'http://mysite.com/content/image/mypostcoverimage.jpg',
|
|
'twitter:label1': 'Written by',
|
|
'twitter:label2': 'Filed under',
|
|
'twitter:title': 'Post Title',
|
|
'twitter:url': 'http://mysite.com/post/my-post-slug/',
|
|
'twitter:site': '@testuser',
|
|
'twitter:creator': '@twitterpage'
|
|
});
|
|
done();
|
|
});
|
|
|
|
it('should return structured data from metadata with provided og and twitter images only per post', function (done) {
|
|
const metadata = {
|
|
site: {
|
|
title: 'Site Title',
|
|
facebook: 'testuser',
|
|
twitter: '@testuser'
|
|
},
|
|
authorName: 'Test User',
|
|
ogType: 'article',
|
|
metaTitle: 'Post Title',
|
|
canonicalUrl: 'http://mysite.com/post/my-post-slug/',
|
|
publishedDate: '2015-12-25T05:35:01.234Z',
|
|
modifiedDate: '2016-01-21T22:13:05.412Z',
|
|
ogImage: {
|
|
url: 'http://mysite.com/content/image/mypostogimage.jpg',
|
|
dimensions: {
|
|
width: 20,
|
|
height: 100
|
|
}
|
|
},
|
|
twitterImage: 'http://mysite.com/content/image/myposttwitterimage.jpg',
|
|
ogTitle: 'Custom Facebook title',
|
|
ogDescription: 'Custom Facebook description',
|
|
twitterTitle: 'Custom Twitter title',
|
|
twitterDescription: 'Custom Twitter description',
|
|
authorFacebook: 'testpage',
|
|
creatorTwitter: '@twitterpage',
|
|
keywords: ['one', 'two', 'tag'],
|
|
metaDescription: 'Post meta description'
|
|
};
|
|
|
|
const structuredData = getStructuredData(metadata);
|
|
|
|
should.deepEqual(structuredData, {
|
|
'article:modified_time': '2016-01-21T22:13:05.412Z',
|
|
'article:published_time': '2015-12-25T05:35:01.234Z',
|
|
'article:tag': ['one', 'two', 'tag'],
|
|
'article:publisher': 'https://www.facebook.com/testuser',
|
|
'article:author': 'https://www.facebook.com/testpage',
|
|
'og:description': 'Custom Facebook description',
|
|
'og:image': 'http://mysite.com/content/image/mypostogimage.jpg',
|
|
'og:image:width': 20,
|
|
'og:image:height': 100,
|
|
'og:site_name': 'Site Title',
|
|
'og:title': 'Custom Facebook title',
|
|
'og:type': 'article',
|
|
'og:url': 'http://mysite.com/post/my-post-slug/',
|
|
'twitter:card': 'summary_large_image',
|
|
'twitter:data1': 'Test User',
|
|
'twitter:data2': ['one', 'two', 'tag'].join(', '),
|
|
'twitter:description': 'Custom Twitter description',
|
|
'twitter:image': 'http://mysite.com/content/image/myposttwitterimage.jpg',
|
|
'twitter:label1': 'Written by',
|
|
'twitter:label2': 'Filed under',
|
|
'twitter:title': 'Custom Twitter title',
|
|
'twitter:url': 'http://mysite.com/post/my-post-slug/',
|
|
'twitter:site': '@testuser',
|
|
'twitter:creator': '@twitterpage'
|
|
});
|
|
done();
|
|
});
|
|
|
|
it('should return structured data from metadata with no nulls', function (done) {
|
|
const metadata = {
|
|
site: {
|
|
title: 'Site Title',
|
|
facebook: '',
|
|
twitter: ''
|
|
},
|
|
authorName: 'Test User',
|
|
ogType: 'article',
|
|
metaTitle: 'Post Title',
|
|
canonicalUrl: 'http://mysite.com/post/my-post-slug/',
|
|
modifiedDate: '2016-01-21T22:13:05.412Z',
|
|
authorFacebook: null,
|
|
creatorTwitter: null,
|
|
coverImage: {
|
|
url: undefined
|
|
},
|
|
ogImage: {
|
|
url: null
|
|
},
|
|
twitterImage: null,
|
|
ogTitle: 'Post Title',
|
|
ogDescription: null,
|
|
twitterTitle: 'Post Title',
|
|
twitterDescription: null,
|
|
keywords: null,
|
|
metaDescription: null
|
|
};
|
|
|
|
const structuredData = getStructuredData(metadata);
|
|
|
|
should.deepEqual(structuredData, {
|
|
'article:modified_time': '2016-01-21T22:13:05.412Z',
|
|
'og:site_name': 'Site Title',
|
|
'og:title': 'Post Title',
|
|
'og:type': 'article',
|
|
'og:url': 'http://mysite.com/post/my-post-slug/',
|
|
'twitter:card': 'summary',
|
|
'twitter:data1': 'Test User',
|
|
'twitter:label1': 'Written by',
|
|
'twitter:title': 'Post Title',
|
|
'twitter:url': 'http://mysite.com/post/my-post-slug/'
|
|
});
|
|
done();
|
|
});
|
|
});
|