Skip to content

Commit

Permalink
Merge branch 'main' into add-unsubscribe-key-member
Browse files Browse the repository at this point in the history
  • Loading branch information
9larsons authored Oct 16, 2024
2 parents 38fc321 + ea70631 commit a3a4f45
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
21 changes: 21 additions & 0 deletions ghost/core/test/unit/frontend/helpers/ghost_head.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const models = require('../../../../core/server/models');
const imageLib = require('../../../../core/server/lib/image');
const routing = require('../../../../core/frontend/services/routing');
const urlService = require('../../../../core/server/services/url');
const logging = require('@tryghost/logging');

const ghost_head = require('../../../../core/frontend/helpers/ghost_head');
const proxy = require('../../../../core/frontend/services/proxy');
Expand Down Expand Up @@ -393,19 +394,27 @@ describe('{{ghost_head}} helper', function () {
});

describe('without Code Injection', function () {
let loggingErrorStub; // assert # of calls if test throws errors, do not globally stub

beforeEach(function () {
configUtils.set({url: 'http://localhost:65530/'});
});

afterEach(function () {
sinon.restore();
});

it('returns meta tag string on paginated index page without structured data and schema', async function () {
// @TODO: later we can extend this fn with an `meta` object e.g. locals.meta
loggingErrorStub = sinon.stub(logging, 'error');
await testGhostHead(testUtils.createHbsResponse({
locals: {
relativeUrl: '/page/2/',
context: ['paged', 'index'],
safeVersion: '0.3'
}
}));
sinon.assert.calledOnce(loggingErrorStub);
});

it('returns structured data on first index page', async function () {
Expand Down Expand Up @@ -771,19 +780,27 @@ describe('{{ghost_head}} helper', function () {
});

it('disallows indexing for preview pages', async function () {
loggingErrorStub = sinon.stub(logging, 'error');
await testGhostHead(testUtils.createHbsResponse({
locals: {
context: ['preview', 'post']
}
}));
// Unknown Request error for favico
// TypeError for primary_author being undefined
sinon.assert.calledOnce(loggingErrorStub);
});

it('implicit indexing settings for non-preview pages', async function () {
loggingErrorStub = sinon.stub(logging, 'error');
await testGhostHead(testUtils.createHbsResponse({
locals: {
context: ['featured', 'paged', 'index', 'post', 'amp', 'home', 'unicorn']
}
}));
// Unknown Request error for favico
// TypeError for primary_author being undefined
sinon.assert.calledOnce(loggingErrorStub);
});

it('outputs structured data but not schema for custom collection', async function () {
Expand Down Expand Up @@ -951,6 +968,8 @@ describe('{{ghost_head}} helper', function () {
});

it('does not contain amphtml link', async function () {
let loggingErrorStub = sinon.stub(logging, 'error');

const renderObject = {
post: posts[1]
};
Expand All @@ -963,6 +982,8 @@ describe('{{ghost_head}} helper', function () {
safeVersion: '0.3'
}
}));

sinon.assert.calledOnce(loggingErrorStub);
});
});

Expand Down
19 changes: 18 additions & 1 deletion ghost/core/test/unit/frontend/helpers/readable_url.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
const should = require('should');
const readable_url = require('../../../../core/frontend/helpers/readable_url');
const logging = require('@tryghost/logging');
const sinon = require('sinon');
const errors = require('@tryghost/errors');

describe('{{#readable_url}} helper', function () {
let loggingErrorStub;

beforeEach(function () {
// Stub the logging.error method
loggingErrorStub = sinon.stub(logging, 'error');
});

afterEach(function () {
// Restore the original logging.error method
loggingErrorStub.restore();
});

it('renders a short URL, without protocol, www, query params nor hash fragments', function () {
const readable = readable_url.call(
{},
Expand All @@ -17,6 +31,9 @@ describe('{{#readable_url}} helper', function () {
{foo: 'bar'}
);

sinon.assert.calledOnce(loggingErrorStub);
sinon.assert.calledWith(loggingErrorStub, sinon.match.instanceOf(errors.IncorrectUsageError));

readable.string.should.equal('');
});

Expand Down

0 comments on commit a3a4f45

Please sign in to comment.