[MediaWiki-commits] [Gerrit] mediawiki...CirrusSearch[master]: Port update_redirect_api.feature to nodejs

2017-12-11 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/396471 )

Change subject: Port update_redirect_api.feature to nodejs
..


Port update_redirect_api.feature to nodejs

Mostly a straight copy from ruby. While most of the 'within ...' steps
could be removed unfortunately the one that waits for a redirect
converted to not a redirect couldn't be removed. This has to wait for
the previously redirected-to page to be updated. Rather than indirectly
waiting on search results added a new step that directly waits for the
redirect to be removed from the previously redirected to document.

Change-Id: I1febfdad9eac1f8e3577b545274378dd50ae5de0
---
M tests/integration/features/step_definitions/page_step_helpers.js
M tests/integration/features/step_definitions/page_steps.js
A tests/integration/features/update_redirect_api.feature
3 files changed, 44 insertions(+), 1 deletion(-)

Approvals:
  jenkins-bot: Verified
  DCausse: Looks good to me, approved



diff --git a/tests/integration/features/step_definitions/page_step_helpers.js 
b/tests/integration/features/step_definitions/page_step_helpers.js
index 7281da6..b5f39cc 100644
--- a/tests/integration/features/step_definitions/page_step_helpers.js
+++ b/tests/integration/features/step_definitions/page_step_helpers.js
@@ -296,7 +296,8 @@
// Is the requested page and the returned document dont 
have the same
// title that means we have a redirect. In that case 
the revision id
// wont match, but the backend api ensures the redirect 
is now contained
-   // within the document.
+   // within the document. Unfortunately if the page was 
just edited to
+   // now be a redirect anymore this is wrong ...
if ( isOk && revisionId && content[0].source.title === 
page.title ) {
isOk = parseInt( content[0].source.version, 10 
) === revisionId;
}
diff --git a/tests/integration/features/step_definitions/page_steps.js 
b/tests/integration/features/step_definitions/page_steps.js
index e60b56f..f3d7a83 100644
--- a/tests/integration/features/step_definitions/page_steps.js
+++ b/tests/integration/features/step_definitions/page_steps.js
@@ -486,4 +486,24 @@
let found = snippets.reduce( ( a, b ) => a || b.indexOf( within 
) > -1, false );
expect( found ).to.equal( !should_not );
} );
+
+   Then( /^I wait for (.+) to not be included in the redirects of (.+)$/, 
function ( source, redirect ) {
+   return Promise.coroutine( function* () {
+   let timeoutMs = 2;
+   let start = new Date();
+   while (true) {
+   let doc = yield 
this.stepHelpers.getCirrusIndexedContent( redirect );
+   if ( doc.cirrusdoc.length > 0 ) {
+   let exists = 
doc.cirrusdoc[0].source.redirect.reduce( ( a, b ) => a || b.title === source, 
false ); // jshint ignore:line
+   if ( !exists ) {
+   break;
+   }
+   }
+   if (new Date() - start >= timeoutMs) {
+   throw new Error( `Timed out waiting for 
${source} to not exist in document of ${redirect}` );
+   }
+   yield this.stepHelpers.waitForMs( 200 );
+   }
+   } ).call( this );
+   } );
 });
diff --git a/tests/integration/features/update_redirect_api.feature 
b/tests/integration/features/update_redirect_api.feature
new file mode 100644
index 000..50171ea
--- /dev/null
+++ b/tests/integration/features/update_redirect_api.feature
@@ -0,0 +1,22 @@
+@clean @api @redirect @update
+Feature: Updating a page from or to a redirect
+  Scenario: Turning a page into a redirect removes it from the search index
+Given a page named RedirectTarget exists
+ When a page named ToBeRedirect%{epoch} exists
+  And I api search for ToBeRedirect%{epoch}
+ Then ToBeRedirect%{epoch} is the first api search result
+ When a page named ToBeRedirect%{epoch} exists with contents #REDIRECT 
[[RedirectTarget]]
+  And I api search for ToBeRedirect%{epoch}
+ Then RedirectTarget is the first api search result
+  And ToBeRedirect%{epoch} is not in the api search results
+
+  Scenario: Turning a page from a redirect to a regular page puts it in the 
index
+Given a page named RedirectTarget exists
+ When a page named StartsAsRedirect%{epoch} exists with contents #REDIRECT 
[[RedirectTarget]]
+  And I api search for StartsAsRedirect%{epoch}
+

[MediaWiki-commits] [Gerrit] mediawiki...CirrusSearch[master]: Port update_redirect_api.feature to nodejs

2017-12-08 Thread EBernhardson (Code Review)
EBernhardson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/396471 )

Change subject: Port update_redirect_api.feature to nodejs
..

Port update_redirect_api.feature to nodejs

Mostly a straight copy from ruby. While most of the 'within ...' steps
could be removed unfortunately the one that waits for a redirect
converted to not a redirect couldn't be removed. This has to wait for
the previously redirected-to page to be updated. Rather than indirectly
waiting on search results added a new step that directly waits for the
redirect to be removed from the previously redirected to document.

Change-Id: I1febfdad9eac1f8e3577b545274378dd50ae5de0
---
M tests/integration/features/step_definitions/page_step_helpers.js
M tests/integration/features/step_definitions/page_steps.js
A tests/integration/features/update_redirect_api.feature
3 files changed, 44 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch 
refs/changes/71/396471/1

diff --git a/tests/integration/features/step_definitions/page_step_helpers.js 
b/tests/integration/features/step_definitions/page_step_helpers.js
index 7281da6..b5f39cc 100644
--- a/tests/integration/features/step_definitions/page_step_helpers.js
+++ b/tests/integration/features/step_definitions/page_step_helpers.js
@@ -296,7 +296,8 @@
// Is the requested page and the returned document dont 
have the same
// title that means we have a redirect. In that case 
the revision id
// wont match, but the backend api ensures the redirect 
is now contained
-   // within the document.
+   // within the document. Unfortunately if the page was 
just edited to
+   // now be a redirect anymore this is wrong ...
if ( isOk && revisionId && content[0].source.title === 
page.title ) {
isOk = parseInt( content[0].source.version, 10 
) === revisionId;
}
diff --git a/tests/integration/features/step_definitions/page_steps.js 
b/tests/integration/features/step_definitions/page_steps.js
index 9db07e3..522c8ac 100644
--- a/tests/integration/features/step_definitions/page_steps.js
+++ b/tests/integration/features/step_definitions/page_steps.js
@@ -484,4 +484,24 @@
let found = snippets.reduce( ( a, b ) => a || b.indexOf( within 
) > -1, false );
expect( found ).to.equal( !should_not );
} );
+
+   Then( /^I wait for (.+) to not be included in the redirects of (.+)$/, 
function ( source, redirect ) {
+   return Promise.coroutine( function* () {
+   let timeoutMs = 2;
+   let start = new Date();
+   while (true) {
+   let doc = yield 
this.stepHelpers.getCirrusIndexedContent( redirect );
+   if ( doc.cirrusdoc.length > 0 ) {
+   let exists = 
doc.cirrusdoc[0].source.redirect.reduce( ( a, b ) => a || b.title === source, 
false );
+   if ( !exists ) {
+   break;
+   }
+   }
+   if (new Date() - start >= timeoutMs) {
+   throw new Error( `Timed out waiting for 
${source} to not exist in document of ${redirect}` );
+   }
+   yield this.stepHelpers.waitForMs( 200 );
+   }
+   } ).call( this );
+   } );
 });
diff --git a/tests/integration/features/update_redirect_api.feature 
b/tests/integration/features/update_redirect_api.feature
new file mode 100644
index 000..50171ea
--- /dev/null
+++ b/tests/integration/features/update_redirect_api.feature
@@ -0,0 +1,22 @@
+@clean @api @redirect @update
+Feature: Updating a page from or to a redirect
+  Scenario: Turning a page into a redirect removes it from the search index
+Given a page named RedirectTarget exists
+ When a page named ToBeRedirect%{epoch} exists
+  And I api search for ToBeRedirect%{epoch}
+ Then ToBeRedirect%{epoch} is the first api search result
+ When a page named ToBeRedirect%{epoch} exists with contents #REDIRECT 
[[RedirectTarget]]
+  And I api search for ToBeRedirect%{epoch}
+ Then RedirectTarget is the first api search result
+  And ToBeRedirect%{epoch} is not in the api search results
+
+  Scenario: Turning a page from a redirect to a regular page puts it in the 
index
+Given a page named RedirectTarget exists
+ When a page named StartsAsRedirect%{epoch} exists with contents #REDIRECT 
[[RedirectTarget]]
+  And I api search for StartsAsRedirect%{epoch}
+