jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/366947 )
Change subject: Define response behaviour for summary endpoint ...................................................................... Define response behaviour for summary endpoint Per the spec [1] Define responses for: * For a page outside of the wiki's content namespaces * For a page in the wiki's content namespace(s) * For a page that doesn't use the wikitext, wikibase-item, or wikibase-property content model * For a page that doesn't exist * For a page that is a redirect [1] https://www.mediawiki.org/wiki/User:Phuedx_(WMF)/Reading/Web/Page_Preview_API Change-Id: I9264e1b55c1742c3aa5a021ef1154007af83b76f --- M routes/mobile-sections.js A test/features/mobile-sections-lead/previewHtml.js 2 files changed, 73 insertions(+), 10 deletions(-) Approvals: BearND: Looks good to me, approved jenkins-bot: Verified diff --git a/routes/mobile-sections.js b/routes/mobile-sections.js index 4117a6d..e35b6df 100644 --- a/routes/mobile-sections.js +++ b/routes/mobile-sections.js @@ -373,15 +373,21 @@ */ function buildSummary(req) { return buildLeadObject(req, false).then((lead) => { - const intro = lead && lead.intro; - if (intro) { - return { - html: transforms.summarize(intro), - revision: lead.revision - }; - } else { + let summary = ''; + let code = 200; + + if (!lead) { return false; + } else if (lead.contentmodel || lead.ns !== 0) { + code = 204; + } else if (lead.intro) { + summary = transforms.summarize(lead.intro); } + return { + code, + html: summary, + revision: lead.revision + }; }); } @@ -438,9 +444,12 @@ router.get('/preview-html/:title', (req, res) => { return buildSummary(req).then((summary) => { if (summary) { - res.status(200); - mUtil.setETag(res, summary.revision); - res.send(summary.html).end(); + res.status(summary.code); + if (summary.code === 200) { + mUtil.setETag(res, summary.revision); + res.send(summary.html); + } + res.end(); } else { res.status(404); } diff --git a/test/features/mobile-sections-lead/previewHtml.js b/test/features/mobile-sections-lead/previewHtml.js new file mode 100644 index 0000000..0b95a0f --- /dev/null +++ b/test/features/mobile-sections-lead/previewHtml.js @@ -0,0 +1,54 @@ +'use strict'; + +const assert = require('../../utils/assert.js'); +const preq = require('preq'); +const server = require('../../utils/server.js'); + +describe('preview-html', function() { + + this.timeout(20000); // eslint-disable-line no-invalid-this + + before(() => { return server.start(); }); + + it('200 For a page that does exist', () => { + const uri = `${server.config.uri}en.wikipedia.org/v1/page/preview-html/Barack Obama`; + return preq.get({ uri }) + .then((res) => { + assert.ok(res.status === 200); + }); + }); + + it('404 For a page that doesn\'t exist', () => { + const uri = `${server.config.uri}en.wikipedia.org/v1/page/preview-html/ashsahahash`; + return preq.get({ uri }) + .catch((res) => { + assert.ok(res.status === 404, 'Pages that do not exist 404'); + }); + }); + + it('204 for pages that are not wikitext', () => { + const title = 'Schema:RelatedArticles'; + const uri = `${server.config.uri}meta.wikimedia.org/v1/page/preview-html/${title}`; + return preq.get({ uri }) + .then((res) => { + assert.ok(res.status === 204, 'If not wikitext we send 204'); + }); + }); + + it('204 for pages outside content namespace', () => { + const title = 'Talk:Barack Obama'; + const uri = `${server.config.uri}en.wikipedia.org/v1/page/preview-html/${title}`; + return preq.get({ uri }) + .then((res) => { + assert.ok(res.status === 204, 'If not in main namespace we send 204'); + }); + }); + + it('200/302 for pages that are redirects', () => { + const uri = `${server.config.uri}en.wikipedia.org/v1/page/preview-html/Barack`; + return preq.get({ uri }) + .then((res) => { + assert.ok(res.status === 200, 'Redirect pages are resolved to 200 via a 302'); + }); + }); +}); -- To view, visit https://gerrit.wikimedia.org/r/366947 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I9264e1b55c1742c3aa5a021ef1154007af83b76f Gerrit-PatchSet: 10 Gerrit-Project: mediawiki/services/mobileapps Gerrit-Branch: master Gerrit-Owner: Jdlrobson <[email protected]> Gerrit-Reviewer: BearND <[email protected]> Gerrit-Reviewer: Dbrant <[email protected]> Gerrit-Reviewer: Fjalapeno <[email protected]> Gerrit-Reviewer: GWicke <[email protected]> Gerrit-Reviewer: Jdlrobson <[email protected]> Gerrit-Reviewer: Jhernandez <[email protected]> Gerrit-Reviewer: Mholloway <[email protected]> Gerrit-Reviewer: Mhurd <[email protected]> Gerrit-Reviewer: Mobrovac <[email protected]> Gerrit-Reviewer: Niedzielski <[email protected]> Gerrit-Reviewer: Ppchelko <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
