BearND has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/368972 )
Change subject: Hygiene: refactor mobile-sections tests ...................................................................... Hygiene: refactor mobile-sections tests so most of the test cases can be shared later. Moved unrelated tests (for formatted-lead and reference endpoints) to new files. Take advantage of localUri function to build URIs for testing. Change-Id: If9fc0665778fa82e0f57df77a5175a1a2f468082 --- A test/features/formatted-lead/pagecontent.js M test/features/mobile-sections/pagecontent-v2.js M test/features/mobile-sections/pagecontent.js A test/features/references/pagecontent.js 4 files changed, 291 insertions(+), 176 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps refs/changes/72/368972/1 diff --git a/test/features/formatted-lead/pagecontent.js b/test/features/formatted-lead/pagecontent.js new file mode 100644 index 0000000..ac4a339 --- /dev/null +++ b/test/features/formatted-lead/pagecontent.js @@ -0,0 +1,48 @@ +'use strict'; + +const preq = require('preq'); +const assert = require('../../utils/assert.js'); +const headers = require('../../utils/headers.js'); +const server = require('../../utils/server.js'); + +describe('formatted-lead', function() { + + this.timeout(20000); // eslint-disable-line no-invalid-this + + before(() => { return server.start(); }); + + const localUri = (title, domain = 'en.wikipedia.org') => { + return `${server.config.uri}${domain}/v1/page/formatted-lead/${title}`; + }; + + it('should respond to GET request with expected headers, incl. CORS and CSP headers', () => { + const uri = localUri('Foobar'); + return headers.checkHeaders(uri); + }); + + it('File pages have a file property', () => { + const title = 'File:Charlie_and_the_Chocolate_Factory_original_cover.jpg'; + const uri = localUri(title); + return preq.get({ uri }) + .then((res) => { + assert.deepEqual(res.status, 200); + assert.ok(res.body.userinfo === undefined, 'userinfo property should be undefined'); + assert.ok(res.body.imageinfo !== undefined, 'imageinfo property should defined'); + assert.ok(res.body.imageinfo.thumburl !== undefined, + 'thumbnail url property is defined'); + }); + }); + + it('User pages have a userinfo property', () => { + const uri = localUri('User:Jdlrobson'); + return preq.get({ uri }) + .then((res) => { + assert.deepEqual(res.status, 200); + assert.ok(res.body.imageinfo === undefined, 'imageinfo property should undefined'); + assert.ok(res.body.userinfo !== undefined, 'userinfo property should defined'); + assert.ok(res.body.userinfo.registration !== undefined, + 'userinfo property should have date of registration'); + assert.ok(res.body.userinfo.name === 'Jdlrobson', 'userinfo property should have name'); + }); + }); +}); diff --git a/test/features/mobile-sections/pagecontent-v2.js b/test/features/mobile-sections/pagecontent-v2.js index e434c13..a445d35 100644 --- a/test/features/mobile-sections/pagecontent-v2.js +++ b/test/features/mobile-sections/pagecontent-v2.js @@ -5,41 +5,127 @@ const preq = require('preq'); const server = require('../../utils/server.js'); -const enWikiHost = 'en.wikipedia.org/v1'; - describe('mobile-sections-v2', function() { this.timeout(20000); // eslint-disable-line no-invalid-this before(() => { return server.start(); }); + const localUri = (title, domain = 'en.wikipedia.org') => { + return `${server.config.uri}${domain}/v1/page/formatted/${title}`; + }; + it('should respond to GET request with expected headers, incl. CORS and CSP headers', () => { - const uri = `${server.config.uri}${enWikiHost}/page/formatted/Foobar`; + const uri = localUri('Foobar'); return headers.checkHeaders(uri); }); it('Supports revision number in request URL', () => { const title = '%2Fr%2FThe_Donald'; const rev = 764101607; - const uri = `${server.config.uri}${enWikiHost}/page/formatted/${title}/${rev}`; + const uri = localUri(`${title}/${rev}`); return preq.get({ uri }) - .then((res) => { - assert.equal(res.body.lead.revision, rev, - 'We return the page with requested revision'); - }); + .then((res) => { + assert.equal(res.body.lead.revision, rev, + 'the requested revision should be returned'); + }); }); it('Supports revision number and tid string in request URL', () => { const title = '%2Fr%2FThe_Donald'; const rev = 764101607; const tid = 'b24de3d0-ecde-11e6-a863-ed5fc1010eed'; - const uri = `${server.config.uri}${enWikiHost}/page/formatted/${title}/${rev}/${tid}`; + const uri = localUri(`${title}/${rev}/${tid}`); return preq.get({ uri }) - .then((res) => { - assert.equal(res.body.lead.revision, rev, - 'We return the page with requested revision and tid'); - }); + .then((res) => { + assert.equal(res.body.lead.revision, rev, + 'We return the page with requested revision and tid'); + }); }); + + it('Mixmatch valid title and valid revision id gives 404', () => { + const title = '%2Fr%2FThe_Donald'; + const rev = 752758357; // belongs to Roald Dahl + const uri = localUri(`${title}/${rev}`); + return preq.get({ uri }) + .catch((res) => { + assert.equal(res.status, 404); + }); + }); + + it('Bad revision id gives bad request', () => { + const title = '%2Fr%2FThe_Donald'; // belongs to Roald Dahl + const rev = 'Reddit'; + const uri = localUri(`${title}/${rev}`); + return preq.get({ uri }) + .catch((res) => { + assert.equal(res.status, 400, 'Should be integer'); + }); + }); + + it('Check content of fixed revision', () => { + const title = 'Leonard_Cohen'; + const rev = 747517267; // revision before his death. + const uri = localUri(`${title}/${rev}`); + return preq.get({ uri }) + .then((res) => { + let hasDeathSection = false; + res.body.remaining.sections.forEach((section) => { + if (section.line === 'Death') { + hasDeathSection = true; + } + }); + assert.ok(!hasDeathSection, + 'Leonard Cohen did not use to be dead. RIP dear man...'); + }); + }); + + it('Check content of fresh revision', () => { + const title = 'Leonard_Cohen'; + const uri = localUri(title); + return preq.get({ uri }) + .then((res) => { + let hasDeathSection = false; + res.body.remaining.sections.forEach((section) => { + if (section.line === 'Death') { + hasDeathSection = true; + } + }); + assert.ok(hasDeathSection, + '... but he is now which makes me sad.'); + }); + }); + + it('Missing title should respond with 404', () => { + const uri = localUri('weoiuyrxcmxn', 'test.wikipedia.org'); + return preq.get({ uri }) + .then(() => { + assert.fail("expected an exception to be thrown"); + }).catch((res) => { + // Most checks are commented out here because the error messages are inconsistent. + + // const body = res.body; + assert.deepEqual(res.status, 404); + // assert.deepEqual(body.type, 'missingtitle'); + // assert.deepEqual(body.title, 'Not found.'); + // assert.deepEqual(body.detail, 'Page or revision not found.'); + }); + }); + + // slightly different + + it('Page with IPA content', () => { + const title = 'Sunderland_A.F.C./738562635'; + const uri = localUri(title); + return preq.get({ uri }) + .then((res) => { + const text = res.body.lead.intro; + const regex = /<span class="nowrap mcs-ipa">/; + assert.ok(regex.test(text), `mcs-ipa class should be in ${text}`); + }); + }); + + // special it('Hatnotes do not appear in the lead object', () => { const title = 'Chivalric%20order/699553745'; @@ -56,6 +142,17 @@ }); }); + it('Page issues do not appear in the lead', () => { + const title = `User:Jdlrobson%2Fmcs-tests%2Fissues_bug`; + const uri = localUri(title); + return preq.get({ uri }) + .then((res) => { + assert.deepEqual(res.status, 200); + assert.ok(res.body.lead.text.indexOf('ambox-multiple_issues') === -1, + 'No ambox multiple issues class in response.'); + }); + }); + it('Pages with only one section do not have an infobox or intro', () => { const title = 'Wikipedia:Today\'s%20featured%20article%2FNovember%207,%202016'; const uri = `${server.config.uri}en.wikipedia.org/v1/page/formatted/${title}`; @@ -68,7 +165,7 @@ }); it('Main pages do not have an infobox or intro', () => { - const uri = `${server.config.uri}en.wikipedia.org/v1/page/formatted/Main_Page`; + const uri = localUri('Main_Page'); return preq.get({ uri }) .then((res) => { assert.deepEqual(res.status, 200); @@ -78,7 +175,7 @@ }); it('Enwiki Barack Obama page has an infobox', () => { - const uri = `${server.config.uri}en.wikipedia.org/v1/page/formatted/Barack_Obama`; + const uri = localUri('Barack_Obama'); return preq.get({ uri }) .then((res) => { assert.deepEqual(res.status, 200); @@ -88,20 +185,8 @@ }); }); - it('Page issues do not appear in the lead', () => { - const title = `User:Jdlrobson%2Fmcs-tests%2Fissues_bug`; - const uri = `${server.config.uri}en.wikipedia.org/v1/page/formatted/${title}`; - return preq.get({ uri }) - .then((res) => { - assert.deepEqual(res.status, 200); - assert.ok(res.body.lead.text.indexOf('ambox-multiple_issues') === -1, - 'No ambox multiple issues class in response.'); - }); - }); - it('Barack Obama page lead paragraph', () => { - const uri = `${server.config.uri}en.wikipedia.org/v1/page/formatted/` - + 'Barack_Obama/760534941'; + const uri = localUri('Barack_Obama/760534941'); return preq.get({ uri }) .then((res) => { const intro = res.body.lead.intro; @@ -121,7 +206,7 @@ }); it('Planet introduction contains nodes other than P (T111958)', () => { - const uri = `${server.config.uri}en.wikipedia.org/v1/page/formatted/Planet`; + const uri = localUri('Planet'); return preq.get({ uri }) .then((res) => { const intro = res.body.lead.intro; @@ -131,17 +216,6 @@ assert.ok(intro.indexOf('stellar remnant') > -1); assert.ok(intro.indexOf('</ul>') > -1, 'List element is bundled into paragraph'); - }); - }); - - it('Page with IPA content', () => { - const title = 'Sunderland_A.F.C.'; - const uri = `${server.config.uri}en.wikipedia.org/v1/page/formatted/${title}`; - return preq.get({ uri }) - .then((res) => { - const text = res.body.lead.intro; - const regex = /<span class="nowrap mcs-ipa">/; - assert.ok(regex.test(text), `mcs-ipa class should be in ${text}`); }); }); }); diff --git a/test/features/mobile-sections/pagecontent.js b/test/features/mobile-sections/pagecontent.js index 08ca17f..8f06c22 100644 --- a/test/features/mobile-sections/pagecontent.js +++ b/test/features/mobile-sections/pagecontent.js @@ -1,11 +1,9 @@ 'use strict'; -const preq = require('preq'); const assert = require('../../utils/assert.js'); const headers = require('../../utils/headers.js'); +const preq = require('preq'); const server = require('../../utils/server.js'); - -const enWikiHost = 'en.wikipedia.org/v1'; describe('mobile-sections', function() { @@ -13,19 +11,23 @@ before(() => { return server.start(); }); + const localUri = (title, domain = 'en.wikipedia.org') => { + return `${server.config.uri}${domain}/v1/page/mobile-sections/${title}`; + }; + it('should respond to GET request with expected headers, incl. CORS and CSP headers', () => { - const uri = `${server.config.uri}${enWikiHost}/page/mobile-sections/Foobar`; + const uri = localUri('Foobar'); return headers.checkHeaders(uri); }); it('Supports revision number in request URL', () => { const title = '%2Fr%2FThe_Donald'; const rev = 764101607; - const uri = `${server.config.uri}${enWikiHost}/page/mobile-sections/${title}/${rev}`; + const uri = localUri(`${title}/${rev}`); return preq.get({ uri }) .then((res) => { assert.equal(res.body.lead.revision, rev, - 'We return the page with requested revision'); + 'the requested revision should be returned'); }); }); @@ -33,19 +35,18 @@ const title = '%2Fr%2FThe_Donald'; const rev = 764101607; const tid = 'b24de3d0-ecde-11e6-a863-ed5fc1010eed'; - const uri = `${server.config.uri}${enWikiHost}/page/mobile-sections/${title}/${rev}/${tid}`; + const uri = localUri(`${title}/${rev}/${tid}`); return preq.get({ uri }) .then((res) => { assert.equal(res.body.lead.revision, rev, - 'We return the page with requested revision'); + 'We return the page with requested revision and tid'); }); }); it('Mixmatch valid title and valid revision id gives 404', () => { const title = '%2Fr%2FThe_Donald'; - // belongs to Roald Dahl - const rev = 752758357; - const uri = `${server.config.uri}${enWikiHost}/page/mobile-sections/${title}/${rev}`; + const rev = 752758357; // belongs to Roald Dahl + const uri = localUri(`${title}/${rev}`); return preq.get({ uri }) .catch((res) => { assert.equal(res.status, 404); @@ -53,79 +54,105 @@ }); it('Bad revision id gives bad request', () => { - const title = '%2Fr%2FThe_Donald'; - // belongs to Roald Dahl + const title = '%2Fr%2FThe_Donald'; // belongs to Roald Dahl const rev = 'Reddit'; - const uri = `${server.config.uri}${enWikiHost}/page/mobile-sections/${title}/${rev}`; + const uri = localUri(`${title}/${rev}`); return preq.get({ uri }) .catch((res) => { assert.equal(res.status, 400, 'Should be integer'); }); }); - it('Check content of revision', () => { + it('Check content of fixed revision', () => { const title = 'Leonard_Cohen'; - // revision before his death. - const rev = 747517267; - const uri = `${server.config.uri}${enWikiHost}/page/mobile-sections/${title}/${rev}`; + const rev = 747517267; // revision before his death. + const uri = localUri(`${title}/${rev}`); return preq.get({ uri }) - .then((res) => { - let hasDeathSection = false; - res.body.remaining.sections.forEach((section) => { - if (section.line === 'Death') { - hasDeathSection = true; - } - }); - assert.ok(!hasDeathSection, - 'Leonard Cohen did not use to be dead. RIP dear man...'); + .then((res) => { + let hasDeathSection = false; + res.body.remaining.sections.forEach((section) => { + if (section.line === 'Death') { + hasDeathSection = true; + } }); + assert.ok(!hasDeathSection, + 'Leonard Cohen did not use to be dead. RIP dear man...'); + }); }); it('Check content of fresh revision', () => { const title = 'Leonard_Cohen'; - const uri = `${server.config.uri}${enWikiHost}/page/mobile-sections/${title}`; + const uri = localUri(title); return preq.get({ uri }) - .then((res) => { - let hasDeathSection = false; - res.body.remaining.sections.forEach((section) => { - if (section.line === 'Death') { - hasDeathSection = true; - } - }); - assert.ok(hasDeathSection, - '... but he is now which makes me sad.'); + .then((res) => { + let hasDeathSection = false; + res.body.remaining.sections.forEach((section) => { + if (section.line === 'Death') { + hasDeathSection = true; + } }); + assert.ok(hasDeathSection, + '... but he is now which makes me sad.'); + }); }); - it('should respond to GET request with expected headers, incl. CORS and CSP headers', () => { - const uri = `${server.config.uri}en.wikipedia.org/v1/page/mobile-sections/Foobar`; - return headers.checkHeaders(uri); + it('Missing title should respond with 404', () => { + const uri = localUri('weoiuyrxcmxn', 'test.wikipedia.org'); + return preq.get({ uri }) + .then(() => { + assert.fail("expected an exception to be thrown"); + }).catch((res) => { + // Most checks are commented out here because the error messages are inconsistent. + + // const body = res.body; + assert.deepEqual(res.status, 404); + // assert.deepEqual(body.type, 'missingtitle'); + // assert.deepEqual(body.title, 'Not found.'); + // assert.deepEqual(body.detail, 'Page or revision not found.'); + }); }); + + // slightly different + + it('Page with IPA content', () => { + const title = 'Sunderland_A.F.C./738562635'; + const uri = localUri(title); + return preq.get({ uri }) + .then((res) => { + const text = res.body.lead.sections[0].text; + const expected = 'style="display: none;"><span class="IPA'; + assert.equal(res.status, 200); + assert.ok(text.indexOf(expected) > -1, + 'IPA information should be wrapped in hidden container'); + }); + }); + + // special it('Sections/deep page should have a lead object with expected properties', () => { const title = 'Sections%2Fdeep'; - const uri = `${server.config.uri}test.wikipedia.org/v1/page/mobile-sections/${title}`; + const uri = localUri(title, 'test.wikipedia.org'); return preq.get({ uri }) - .then((res) => { - const lead = res.body.lead; - const lastMod = lead.lastmodified; - const prot = lead.protection; - assert.deepEqual(res.status, 200); - assert.ok(lastMod.startsWith('201'), `${lastMod} should start with 201`); // 2015- - assert.deepEqual(lead.displaytitle, 'Sections/deep'); - assert.equal(lead.wikibase_item, undefined); - assert.equal(lead.description, undefined); - assert.ok(prot.constructor === Object, 'lead.protection should be an Object'); - assert.ok(!Object.keys(lead.protection).length, 'Page should not be protected'); - assert.deepEqual(lead.editable, true); - assert.ok(lead.sections.length >= 6, 'Expected at least six section elements'); - assert.deepEqual(lead.sections[0].id, 0); - assert.ok(lead.sections[0].text.length > 0, 'Expected text to be non-empty'); - }); + .then((res) => { + const lead = res.body.lead; + const lastMod = lead.lastmodified; + const prot = lead.protection; + assert.deepEqual(res.status, 200); + assert.ok(lastMod.startsWith('201'), `${lastMod} should start with 201`); // 2015- + assert.deepEqual(lead.displaytitle, 'Sections/deep'); + assert.equal(lead.wikibase_item, undefined); + assert.equal(lead.description, undefined); + assert.ok(prot.constructor === Object, 'lead.protection should be an Object'); + assert.ok(!Object.keys(lead.protection).length, 'Page should not be protected'); + assert.deepEqual(lead.editable, true); + assert.ok(lead.sections.length >= 6, 'Expected at least six section elements'); + assert.deepEqual(lead.sections[0].id, 0); + assert.ok(lead.sections[0].text.length > 0, 'Expected text to be non-empty'); + }); }); it('en Main page should have a lead object with expected properties', () => { - const uri = `${server.config.uri}en.wikipedia.org/v1/page/mobile-sections/Main_Page`; + const uri = localUri('Main_Page'); return preq.get({ uri }) .then((res) => { const lead = res.body.lead; @@ -154,7 +181,7 @@ }); it('Titles with special chars should not error out when parsing pronunciation files', () => { - const uri = `${server.config.uri}vi.wikipedia.org/v1/page/mobile-sections/Sunn_O)))`; + const uri = localUri('Sunn_O)))', 'vi.wikipedia.org'); return preq.get({ uri }) .then((res) => { const lead = res.body.lead; @@ -169,25 +196,9 @@ }); }); - it('Missing title should respond with 404', () => { - const uri = `${server.config.uri}test.wikipedia.org/v1/page/mobile-sections/weoiuyrxcmxn`; - return preq.get({ uri }) - .then(() => { - assert.fail("expected an exception to be thrown"); - }).catch((res) => { - // Most checks are commented out here because the error messages are inconsistent. - - // const body = res.body; - assert.deepEqual(res.status, 404); - // assert.deepEqual(body.type, 'missingtitle'); - // assert.deepEqual(body.title, 'Not found.'); - // assert.deepEqual(body.detail, 'Page or revision not found.'); - }); - }); - it('Page with known past \'text-decoration\' error should load successfully', () => { const title = `%E6%9F%A5%E5%85%8B%C2%B7%E8%91%9B%E9%87%8C%E8%8A%AC%E7%B4%8D%E5%A5%87`; - const uri = `${server.config.uri}zh.wikipedia.org/v1/page/mobile-sections/${title}`; + const uri = localUri(title, 'zh.wikipedia.org'); return preq.get({ uri }) .then((res) => { assert.deepEqual(res.status, 200); @@ -195,8 +206,7 @@ }); it('Beta cluster request should load successfully', () => { - const domain = `en.wikipedia.beta.wmflabs.org`; - const uri = `${server.config.uri}${domain}/v1/page/mobile-sections/Foobar`; + const uri = localUri('Foobar', 'en.wikipedia.beta.wmflabs.org'); return preq.get({ uri }) .then((res) => { assert.deepEqual(res.status, 200); @@ -206,7 +216,7 @@ it('Page with irregular Spoken Wikipedia template usage should load correctly', () => { const filename = `File:En-Alliterative_verse-article.ogg`; const title = `Alliterative_verse`; - const uri = `${server.config.uri}en.wikipedia.org/v1/page/mobile-sections/${title}`; + const uri = localUri(title); return preq.get({ uri }) .then((res) => { assert.deepEqual(res.status, 200); @@ -216,7 +226,7 @@ it('Page with HTML entity in redirected page title should load', () => { const title = `User:BSitzmann_%28WMF%29%2FMCS%2FTest%2FA%26B_redirect`; - const uri = `${server.config.uri}test.wikipedia.org/v1/page/mobile-sections/${title}`; + const uri = localUri(title, 'test.wikipedia.org'); return preq.get({ uri }) .then((res) => { const lead = res.body.lead; @@ -229,9 +239,8 @@ }); it('Page with % in redirected page title should load [beta cluster]', () => { - const domain = `en.wikipedia.beta.wmflabs.org`; const title = `User:Pchelolo%2fRedirect_Test`; - const uri = `${server.config.uri}${domain}/v1/page/mobile-sections/${title}`; + const uri = localUri(title, 'en.wikipedia.beta.wmflabs.org'); return preq.get({ uri }) .then((res) => { assert.deepEqual(res.status, 200); @@ -245,7 +254,7 @@ const title = `User:BSitzmann_%28WMF%29%2FMCS%2FTest%2Fredirect_test2`; const normalizedTitle = 'User:BSitzmann (WMF)/MCS/Test/redirect test2'; const displayTitle = 'User:BSitzmann (WMF)/MCS/Test/redirect test2 target %'; - const uri = `${server.config.uri}test.wikipedia.org/v1/page/mobile-sections/${title}`; + const uri = localUri(title, 'test.wikipedia.org'); return preq.get({ uri }) .then((res) => { assert.deepEqual(res.status, 200); @@ -260,7 +269,7 @@ const normalizedTitle = 'User:BSitzmann (WMF)/MCS/Test/redirect test3'; const displayTitle = 'User:BSitzmann (WMF)/MCS/Test/redirect test3 target'; const titleWithFragment = 'User:BSitzmann (WMF)/MCS/Test/redirect test3 target#Section_.25'; - const uri = `${server.config.uri}test.wikipedia.org/v1/page/mobile-sections/${title}`; + const uri = localUri(title, 'test.wikipedia.org'); return preq.get({ uri }) .then((res) => { assert.deepEqual(res.status, 200); @@ -272,7 +281,7 @@ it('Internal links should have title attribute', () => { const title = `User:BSitzmann_%28WMF%29%2FMCS%2FTest%2FTitleLinkEncoding`; - const uri = `${server.config.uri}en.wikipedia.org/v1/page/mobile-sections/${title}`; + const uri = localUri(title); const expectedText = '<a href="/wiki/Sort_(C++)" title="Sort (C++)"'; return preq.get({ uri }) .then((res) => { @@ -280,8 +289,9 @@ assert.contains(res.body.lead.sections[0].text, expectedText); }); }); + it('Any sections that contain references should have a reference flag', () => { - const uri = `${server.config.uri}en.wikipedia.org/v1/page/mobile-sections/Barack_Obama`; + const uri = localUri('Barack_Obama'); const sections = [ 'Notes and references', 'Notes', 'References', 'Further reading' ]; return preq.get({ uri }) .then((res) => { @@ -298,17 +308,8 @@ }); }); - it('Requesting just references returns only sections with references', () => { - const uri = `${server.config.uri}en.wikipedia.org/v1/page/references/Barack_Obama`; - return preq.get({ uri }) - .then((res) => { - assert.equal(res.status, 200); - assert.equal(res.body.sections.length, 4, 'Barack Obama has 4 reference sections'); - }); - }); - it('The last section can be marked as a reference section', () => { - const uri = `${server.config.uri}en.wikipedia.org/v1/page/mobile-sections/Vallejo_(ferry)`; + const uri = localUri('Vallejo_(ferry)'); return preq.get({ uri }) .then((res) => { assert.equal(res.status, 200); @@ -326,49 +327,10 @@ it('Page with math formulas should load without error', () => { const title = `Verallgemeinerter_Laplace-Operator`; - const uri = `${server.config.uri}de.wikipedia.org/v1/page/mobile-sections/${title}`; + const uri = localUri(title, 'de.wikipedia.org'); return preq.get({ uri }) .then((res) => { assert.equal(res.status, 200); - }); - }); - - it('Page with IPA content', () => { - const title = 'Sunderland_A.F.C./738562635'; - const uri = `${server.config.uri}en.wikipedia.org/v1/page/mobile-sections/${title}`; - return preq.get({ uri }) - .then((res) => { - const text = res.body.lead.sections[0].text; - const expected = 'style="display: none;"><span class="IPA'; - assert.equal(res.status, 200); - assert.ok(text.indexOf(expected) > -1, - 'IPA information should be wrapped in hidden container'); - }); - }); - - it('File pages have a file property', () => { - const title = 'File:Charlie_and_the_Chocolate_Factory_original_cover.jpg'; - const uri = `${server.config.uri}en.wikipedia.org/v1/page/formatted-lead/${title}`; - return preq.get({ uri }) - .then((res) => { - assert.deepEqual(res.status, 200); - assert.ok(res.body.userinfo === undefined, 'userinfo property is undefined'); - assert.ok(res.body.imageinfo !== undefined, 'imageinfo property is defined'); - assert.ok(res.body.imageinfo.thumburl !== undefined, - 'thumbnail url property is defined'); - }); - }); - - it('User pages have a userinfo property', () => { - const uri = `${server.config.uri}en.wikipedia.org/v1/page/formatted-lead/User:Jdlrobson`; - return preq.get({ uri }) - .then((res) => { - assert.deepEqual(res.status, 200); - assert.ok(res.body.imageinfo === undefined, 'imageinfo property is undefined'); - assert.ok(res.body.userinfo !== undefined, 'userinfo property is defined'); - assert.ok(res.body.userinfo.registration !== undefined, - 'userinfo property has date of registration'); - assert.ok(res.body.userinfo.name === 'Jdlrobson', 'userinfo property has name'); }); }); }); diff --git a/test/features/references/pagecontent.js b/test/features/references/pagecontent.js new file mode 100644 index 0000000..b31e69a --- /dev/null +++ b/test/features/references/pagecontent.js @@ -0,0 +1,31 @@ +'use strict'; + +const preq = require('preq'); +const assert = require('../../utils/assert.js'); +const headers = require('../../utils/headers.js'); +const server = require('../../utils/server.js'); + +describe('references', function() { + + this.timeout(20000); // eslint-disable-line no-invalid-this + + before(() => { return server.start(); }); + + const localUri = (title, domain = 'en.wikipedia.org') => { + return `${server.config.uri}${domain}/v1/page/references/${title}`; + }; + + it('should respond to GET request with expected headers, incl. CORS and CSP headers', () => { + const uri = localUri('Foobar'); + return headers.checkHeaders(uri); + }); + + it('Requesting just references returns only sections with references', () => { + const uri = localUri('Barack_Obama/793008506'); + return preq.get({ uri }) + .then((res) => { + assert.equal(res.status, 200); + assert.equal(res.body.sections.length, 4, 'Barack Obama has 4 reference sections'); + }); + }); +}); -- To view, visit https://gerrit.wikimedia.org/r/368972 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If9fc0665778fa82e0f57df77a5175a1a2f468082 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/mobileapps Gerrit-Branch: master Gerrit-Owner: BearND <bsitzm...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits