diff options
author | daniel <dkinzler@wikimedia.org> | 2022-09-09 11:32:17 +0200 |
---|---|---|
committer | daniel <dkinzler@wikimedia.org> | 2022-09-29 19:52:27 +0200 |
commit | f31cd9f1d3621cfb99bdfaea16b947f8f258d660 (patch) | |
tree | 03b929ea3df05ddaf27ce99955a097cfe8fc4d57 /tests/api-testing/REST/Transform.js | |
parent | b6ce2f250ec4b67c9768bf235979126c8720e6df (diff) | |
download | mediawikicore-f31cd9f1d3621cfb99bdfaea16b947f8f258d660.tar.gz mediawikicore-f31cd9f1d3621cfb99bdfaea16b947f8f258d660.zip |
REST: HtmlInputTransformHelper: Load original data from stash
Parsoid needs the original rendering in order to apply
selective serialization (selser). The page/{title}/html endpoint
can stash the rendering, and now the transform endpoint can make use
of the stashed rendering.
Bug: T310464
Change-Id: Ia58043ed3aa1eb12731d82aa87606c82ec63f663
Diffstat (limited to 'tests/api-testing/REST/Transform.js')
-rw-r--r-- | tests/api-testing/REST/Transform.js | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/tests/api-testing/REST/Transform.js b/tests/api-testing/REST/Transform.js index 8df44040fb70..a9a8f66dfcaa 100644 --- a/tests/api-testing/REST/Transform.js +++ b/tests/api-testing/REST/Transform.js @@ -84,6 +84,7 @@ describe( '/transform/ endpoint', function () { const endpointPrefix = client.pathPrefix = 'rest.php/coredev/v0'; const page = utils.title( 'TransformSource ' ); const pageEncoded = encodeURIComponent( page ); + const pageContent = '{|\nhi\n|ho\n|}'; let revid; before( async function () { @@ -92,7 +93,7 @@ describe( '/transform/ endpoint', function () { const alice = await action.alice(); // Create pages - let edit = await alice.edit( page, { text: '{|\nhi\n|ho\n|}' } ); + let edit = await alice.edit( page, { text: pageContent } ); edit.result.should.equal( 'Success' ); revid = edit.newrevid; @@ -2273,4 +2274,85 @@ describe( '/transform/ endpoint', function () { .end( done ); } ); } ); + + describe( 'stashing with If-Match header', function () { + + // TODO: The /transform/html endpoint should handle the If-Match header + // by checking whether it has a rendering with the correct key + // stashed or cached. If so, it should be used for selser. + it.skip( 'should trigger on If-Match header', async () => { + const pageResponse = await client.req + .get( `rest.php/v1/page/${pageEncoded}/html` ) + .query( { stash: 'yes' } ); + + pageResponse.headers.should.have.property( 'etag' ); + const eTag = pageResponse.headers.etag; + const html = pageResponse.text; + + const transformResponse = await client.req + .post( endpointPrefix + '/transform/html/to/wikitext/' ) + .set( 'If-Match', eTag ) + .send( { + html + } ); + + transformResponse.status.should.equal( 200, transformResponse.text ); + + // Since the HTML didn't change, we should get back the original wikitext unchanged. + transformResponse.text.should.equal( pageContent ); + } ); + + it( 'should fail if eTag in If-Match header is unknown', async () => { + // request page HTML, but do not set 'stash' parameter! + const transformResponse = await client.req + .post( endpointPrefix + '/transform/html/to/wikitext/' ) + .set( 'If-Match', '"1234/dummy"' ) + .send( { + html: '<p>test</p>' + } ); + + transformResponse.status.should.equal( 412 ); + } ); + } ); + + describe( 'stashing with renderid in body', function () { + it( 'should trigger on renderid field in the body', async () => { + const pageResponse = await client.req + .get( `rest.php/v1/page/${pageEncoded}/html` ) + .query( { stash: 'yes' } ); + + pageResponse.headers.should.have.property( 'etag' ); + const eTag = pageResponse.headers.etag; + const html = pageResponse.text; + + const transformResponse = await client.req + .post( endpointPrefix + '/transform/html/to/wikitext/' ) + .send( { + html, + original: { + renderid: eTag + } + } ); + + transformResponse.status.should.equal( 200, transformResponse.text ); + + // Since the HTML didn't change, we should get back the original wikitext unchanged. + transformResponse.text.should.equal( pageContent ); + } ); + + it( 'should fail if stash key is unknown', async () => { + // request page HTML, but do not set 'stash' parameter! + const transformResponse = await client.req + .post( endpointPrefix + '/transform/html/to/wikitext/' ) + .send( { + html: '<p>test</p>', + original: { + renderid: '"1234/dummy"' + } + } ); + + transformResponse.status.should.equal( 412 ); + } ); + } ); + } ); |