diff --git a/resources/dist/index.js b/resources/dist/index.js index db7e34be5..057b2c9b1 100644 Binary files a/resources/dist/index.js and b/resources/dist/index.js differ diff --git a/resources/dist/index.js.map.json b/resources/dist/index.js.map.json index 2433fcc0e..17ec8f3cf 100644 Binary files a/resources/dist/index.js.map.json and b/resources/dist/index.js.map.json differ diff --git a/src/actions.js b/src/actions.js index 83641d669..fd7d44e1f 100644 --- a/src/actions.js +++ b/src/actions.js @@ -110,7 +110,7 @@ export function fetch( gateway, title, el, token ) { namespaceId = title.namespace; return ( dispatch ) => { - const xhr = gateway.getPageSummary( titleText ); + const xhr = gateway.getPageSummary( title ); dispatch( timedAction( { type: types.FETCH_START, diff --git a/src/gateway/index.js b/src/gateway/index.js index 5ebdab624..89ed873db 100644 --- a/src/gateway/index.js +++ b/src/gateway/index.js @@ -28,7 +28,7 @@ const mw = mediaWiki, * If the underlying request is successful and contains data about the page, * then the resulting promise will resolve. If not, then it will reject. * - * @typedef {Function(string): AbortPromise} GetPageSummary + * @typedef {Function(mw.Title): AbortPromise} GetPageSummary */ /** diff --git a/src/gateway/mediawiki.js b/src/gateway/mediawiki.js index fe52c2ae0..2ec69c466 100644 --- a/src/gateway/mediawiki.js +++ b/src/gateway/mediawiki.js @@ -62,8 +62,12 @@ export default function createMediaWikiApiGateway( api, config ) { } ); } + /** + * @param {mw.Title} title + * @returns {AbortPromise} + */ function getPageSummary( title ) { - const xhr = fetch( title ); + const xhr = fetch( title.getPrefixedDb() ); return xhr.then( ( data ) => { const page = extractPageFromResponse( data ); const plainTextExtract = formatPlainTextExtract( page ); diff --git a/src/gateway/rest.js b/src/gateway/rest.js index 05ada48c8..eac53ace4 100644 --- a/src/gateway/rest.js +++ b/src/gateway/rest.js @@ -48,12 +48,17 @@ export default function createRESTBaseGateway( ajax, config, extractParser ) { } ); } + /** + * @param {mw.Title} title + * @returns {AbortPromise} + */ function getPageSummary( title ) { - const xhr = fetch( title ); + const titleText = title.getPrefixedDb(), + xhr = fetch( titleText ); return xhr.then( ( page ) => { // Endpoint response may be empty or simply missing a title. if ( !page || !page.title ) { - page = $.extend( true, page || {}, { title } ); + page = $.extend( true, page || {}, { title: titleText } ); } // And extract may be omitted if empty string if ( page.extract === undefined ) { diff --git a/tests/node-qunit/actions.test.js b/tests/node-qunit/actions.test.js index b407d5a5f..306710456 100644 --- a/tests/node-qunit/actions.test.js +++ b/tests/node-qunit/actions.test.js @@ -4,7 +4,8 @@ import * as WaitModule from '../../src/wait'; import actionTypes from '../../src/actionTypes'; const mw = mediaWiki, - REFERRER = 'https://en.wikipedia.org/wiki/Kitten'; + REFERRER = 'https://en.wikipedia.org/wiki/Kitten', + TEST_TITLE = createStubTitle( 1, 'Foo' ); function generateToken() { return 'ABC'; @@ -82,7 +83,7 @@ function setupWait( module ) { * @return {void} */ function setupEl( module ) { - module.title = createStubTitle( 1, 'Foo' ); + module.title = TEST_TITLE; module.el = $( '' ).eq( 0 ); } @@ -279,7 +280,7 @@ QUnit.test( 'it should fetch data from the gateway immediately', function ( asse this.fetch(); assert.ok( - this.gateway.getPageSummary.calledWith( 'Foo' ), + this.gateway.getPageSummary.calledWith( TEST_TITLE ), 'The gateway was called with the correct arguments.' ); diff --git a/tests/node-qunit/gateway/mediawiki.test.js b/tests/node-qunit/gateway/mediawiki.test.js index da183c818..1ad9fbc43 100644 --- a/tests/node-qunit/gateway/mediawiki.test.js +++ b/tests/node-qunit/gateway/mediawiki.test.js @@ -1,3 +1,4 @@ +import { createStubTitle } from '../stubs'; import { createModel } from '../../../src/preview/model'; import createMediaWikiApiGateway from '../../../src/gateway/mediawiki'; @@ -166,7 +167,7 @@ QUnit.test( 'MediaWiki API gateway handles API failure', function ( assert ) { }, gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS ); - return gateway.getPageSummary( 'Test Title' ).catch( () => { + return gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ).catch( () => { assert.ok( true, 'The gateway threw an error.' ); } ); } ); @@ -179,7 +180,7 @@ QUnit.test( 'MediaWiki API gateway returns the correct data', function ( assert }, gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS ); - return gateway.getPageSummary( 'Test Title' ).then( ( result ) => { + return gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ).then( ( result ) => { assert.deepEqual( result, MEDIAWIKI_API_RESPONSE_PREVIEW_MODEL, @@ -221,7 +222,7 @@ QUnit.test( 'MediaWiki API gateway handles missing pages', function ( assert ) { }, gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS ); - return gateway.getPageSummary( 'Test Title' ).then( ( result ) => { + return gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ).then( ( result ) => { assert.deepEqual( result, model, @@ -240,7 +241,7 @@ QUnit.test( 'MediaWiki API gateway is abortable', function ( assert ) { }, gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS ); - const xhr = gateway.getPageSummary( 'Test Title' ); + const xhr = gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ); const chain = xhr.then( () => { assert.ok( false, 'It never calls a thenable after rejection' ); diff --git a/tests/node-qunit/gateway/rest.test.js b/tests/node-qunit/gateway/rest.test.js index 719ddc5d4..40ca4841f 100644 --- a/tests/node-qunit/gateway/rest.test.js +++ b/tests/node-qunit/gateway/rest.test.js @@ -1,3 +1,4 @@ +import { createStubTitle } from '../stubs'; import { createModel } from '../../../src/preview/model'; import createRESTBaseGateway from '../../../src/gateway/rest'; @@ -357,7 +358,7 @@ QUnit.test( 'RESTBase gateway handles API failure', function ( assert ) { .returns( $.Deferred().reject( { status: 500 } ).promise() ), gateway = createRESTBaseGateway( api, {} ); - return gateway.getPageSummary( 'Test Title' ).catch( () => { + return gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ).catch( () => { assert.ok( true, 'The gateway threw an error.' ); } ); } ); @@ -367,7 +368,7 @@ QUnit.test( 'RESTBase gateway handles 404 as a failure', function ( assert ) { .returns( $.Deferred().reject( { status: 404 } ).promise() ), gateway = createRESTBaseGateway( api, {} ); - return gateway.getPageSummary( 'Test Title' ).catch( () => { + return gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ).catch( () => { assert.ok( true, 'The gateway threw an error.' ); } ); } ); @@ -379,7 +380,7 @@ QUnit.test( 'RESTBase gateway returns the correct data ', function ( assert ) { gateway = createRESTBaseGateway( api, DEFAULT_CONSTANTS, provideParsedExtract ); - return gateway.getPageSummary( 'Test Title' ).then( ( result ) => { + return gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ).then( ( result ) => { assert.deepEqual( result, RESTBASE_RESPONSE_PREVIEW_MODEL, @@ -406,7 +407,7 @@ QUnit.test( 'RESTBase gateway handles missing extracts', function ( assert ) { gateway = createRESTBaseGateway( api, DEFAULT_CONSTANTS, provideParsedExtract ); - return gateway.getPageSummary( 'Test Title with missing extract' ) + return gateway.getPageSummary( createStubTitle( 1, 'Test Title with missing extract' ) ) .then( ( result ) => { assert.strictEqual( result.title, 'Test Title with missing extract', 'Title' ); assert.strictEqual( result.extract, '!!', 'Extract' ); @@ -419,7 +420,7 @@ QUnit.test( 'RESTBase gateway handles no content success responses', function ( gateway = createRESTBaseGateway( api, DEFAULT_CONSTANTS, provideParsedExtract ); - return gateway.getPageSummary( 'Test Title with empty response' ) + return gateway.getPageSummary( createStubTitle( 1, 'Test Title with empty response' ) ) .then( ( result ) => { assert.strictEqual( result.title, 'Test Title with empty response', 'Title' ); assert.strictEqual( result.extract, '!!', 'Extract' ); @@ -439,7 +440,7 @@ QUnit.test( 'RESTBase gateway is abortable', function ( assert ) { gateway = createRESTBaseGateway( api, DEFAULT_CONSTANTS, provideParsedExtract ); - const xhr = gateway.getPageSummary( 'Test Title' ); + const xhr = gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ); const chain = xhr.then( () => { assert.ok( false, 'It never calls a thenable after rejection' );