Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const forPost = (id, attrs, frame, type = 'posts') => {
* Needs further discussion.
*/
if (!localUtils.isContentAPI(frame)) {
if (attrs.status !== 'published' && attrs.url.match(/\/404\//)) {
// Gate on status alone — the previous `/404/` URL check broke
// under `config.lazyRouting` (the lazy service returns `/{slug}/`).
if (attrs.status !== 'published') {
if (attrs.posts_meta && attrs.posts_meta.email_only) {
attrs.url = urlUtils.urlFor({
relativeUrl: urlUtils.urlJoin('/email', attrs.uuid, '/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,59 @@ describe('Unit: endpoints/utils/serializers/output/utils/url', function () {
assert.equal(resource.id, 'post-id');
assert.equal(resource.type, 'posts');
});

describe('preview URL override for non-published posts', function () {
it('sets /email/<uuid>/ for email-only sent posts regardless of the facade URL', function () {
getUrlForResourceStub.returns('http://localhost/the-slug/');

const post = {
id: 'post-id',
uuid: 'post-uuid',
slug: 'the-slug',
status: 'sent',
posts_meta: {email_only: true}
};

urlUtil.forPost(post.id, post, {options: {}});

assert.equal(post.url, 'urlFor');
const [args] = urlUtils.urlFor.firstCall.args;
assert.equal(args.relativeUrl, '/email/post-uuid/');
});

it('sets /p/<uuid>/ for draft posts regardless of the facade URL', function () {
getUrlForResourceStub.returns('http://localhost/the-slug/');

const post = {
id: 'post-id',
uuid: 'post-uuid',
slug: 'the-slug',
status: 'draft'
};

urlUtil.forPost(post.id, post, {options: {}});

assert.equal(post.url, 'urlFor');
const [args] = urlUtils.urlFor.firstCall.args;
assert.equal(args.relativeUrl, '/p/post-uuid/');
});

it('keeps the facade URL for published posts', function () {
getUrlForResourceStub.returns('http://localhost/the-slug/');

const post = {
id: 'post-id',
uuid: 'post-uuid',
slug: 'the-slug',
status: 'published'
};

urlUtil.forPost(post.id, post, {options: {}});

assert.equal(post.url, 'http://localhost/the-slug/');
sinon.assert.notCalled(urlUtils.urlFor);
});
});
});

describe('forTag', function () {
Expand Down
Loading