DCausse has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/392987 )

Change subject: Port commons.feature to nodejs
......................................................................

Port commons.feature to nodejs

Change-Id: I43075458594338eab49375da1697ed5114583bea
---
A tests/integration/features/commons.feature
M tests/integration/features/step_definitions/page_step_helpers.js
M tests/integration/features/step_definitions/page_steps.js
3 files changed, 65 insertions(+), 11 deletions(-)


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

diff --git a/tests/integration/features/commons.feature 
b/tests/integration/features/commons.feature
new file mode 100644
index 0000000..b36867b
--- /dev/null
+++ b/tests/integration/features/commons.feature
@@ -0,0 +1,12 @@
+@clean @api @commons
+Feature: Searching for files on local wiki stored on commons
+  Scenario: A file that exists only on commons can be found on the local wiki
+    When I api search in namespace 6 for oncommons
+    Then File:OnCommons.svg is the first api search result
+
+  Scenario: A file that exists on commons and the local wiki returns the local 
result
+    When within 20 seconds File:DuplicatedLocally.svg has cirrustestwiki as 
local_sites_with_dupe
+    Then I api search in namespace 6 for duplicated
+    Then File:DuplicatedLocally.svg is the first api search result
+    And Locally stored file *duplicated* on commons is the highlighted snippet 
of the first api search result
+    And there are 1 api search results
diff --git a/tests/integration/features/step_definitions/page_step_helpers.js 
b/tests/integration/features/step_definitions/page_step_helpers.js
index 730e3b3..76c9074 100644
--- a/tests/integration/features/step_definitions/page_step_helpers.js
+++ b/tests/integration/features/step_definitions/page_step_helpers.js
@@ -163,7 +163,17 @@
                } ).call( this );
        }
 
-       checkExists( title ) {
+    /**
+        * Call query api with cirrusdoc prop to return the docs identified
+        * by title that are indexed in elasticsearch.
+        *
+        * NOTE: Multiple docs can be returned if the doc identified by title 
is indexed
+        * over multiple indices (content/general).
+        *
+     * @param {string} title page title
+        * @returns {Promise.<[]>} resolves to an array of indexed docs or null 
if title not indexed
+     */
+       getCirrusIndexedContent( title ) {
                return Promise.coroutine( function* () {
                        let client = yield this.apiPromise;
                        let response = yield client.request( {
@@ -183,15 +193,27 @@
                        }
                        for ( let page of response.query.pages ) {
                                if ( page.title === title ) {
-                                       // without boolean cast we could return 
undefined
-                                       return Boolean( page.cirrusdoc && 
page.cirrusdoc.length > 0 );
+                                       return page.cirrusdoc;
                                }
                        }
-                       return false;
+                       return null;
                } ).call( this );
        }
 
-       pageIdOf( title ) {
+    /**
+        * Check if title is indexed
+     * @param {string} title
+        * @returns {Promise.<boolean>} resolves to a boolean
+     */
+    checkExists( title ) {
+        return Promise.coroutine( function* () {
+            let content = yield this.getCirrusIndexedContent( title );
+            // without boolean cast we could return undefined
+            return Boolean(content && content.length > 0);
+        } ).call( this );
+    }
+
+    pageIdOf( title ) {
                return Promise.coroutine( function* () {
                        let client = yield this.apiPromise;
                        let response = yield client.request( { action: "query", 
titles: title, formatversion: 2 } );
diff --git a/tests/integration/features/step_definitions/page_steps.js 
b/tests/integration/features/step_definitions/page_steps.js
index c6ee18e..039b6a5 100644
--- a/tests/integration/features/step_definitions/page_steps.js
+++ b/tests/integration/features/step_definitions/page_steps.js
@@ -152,9 +152,9 @@
                                // Chai doesnt (yet) have a native assertion 
for this:
                                // https://github.com/chaijs/chai/issues/858
                                let ok = found.reduce( ( a, b ) => a || 
b.indexOf( title ) > -1, false );
-                               expect( ok, `expected ${JSON.stringify(found)} 
to include "${title}"` ).to.be.true; // jshint ignore:line
+                               return expect( ok, `expected 
${JSON.stringify(found)} to include "${title}"` ).to.be.true;
                        } else {
-                               expect( found ).to.include(title);
+                               return expect( found ).to.include(title);
                        }
                }
        }
@@ -173,9 +173,9 @@
                        let msg = `Expected ${JSON.stringify(found)} 
to${not_searching ? ' not' : ''} include ${title}`;
 
                        if ( not_searching ) {
-                               expect( ok, msg ).to.be.false; // jshint 
ignore:line
+                               return expect( ok, msg ).to.be.false;
                        } else {
-                               expect( ok, msg ).to.be.true; // jshint 
ignore:line
+                               return expect( ok, msg ).to.be.true;
                        }
                } );
        } );
@@ -209,7 +209,7 @@
 
        Then( /there are no errors reported by the api/, function () {
                return withApi( this, () => {
-                       expect( this.apiError ).to.be.undefined; // jshint 
ignore:line
+                       return expect( this.apiError ).to.be.undefined;
                } );
        } );
 
@@ -268,7 +268,7 @@
                // TODO: This is actually a *did you mean* suggestion
                return withApi( this, () => {
                        expect( this.apiResponse.query.searchinfo 
).to.include.any.keys( 'suggestionsnippet', 'rewrittenquerysnippet' );
-                       var suggestion = 
this.apiResponse.query.searchinfo.suggestionsnippet ||
+                       let suggestion = 
this.apiResponse.query.searchinfo.suggestionsnippet ||
                                
this.apiResponse.query.searchinfo.rewrittenquerysnippet;
                        suggestion = suggestion.replace(/<em>/g, 
"*").replace(/<\/em>/g, "*").replace(/&quot;/g, '"');
                        if ( second ) {
@@ -340,4 +340,24 @@
                }
                return stepHelpers.uploadFile( title, fileName, description );
        } );
+
+       Then(/^within (\d+) seconds (.*) has (.*) as local_sites_with_dupe$/, 
function (seconds, page, value) {
+               return Promise.coroutine( function* () {
+                       let stepHelpers = this.stepHelpers.onWiki( 'commons' );
+                       let time = new Date();
+                       let found = false;
+                       do {
+                               let content = yield 
stepHelpers.getCirrusIndexedContent( page );
+                               if ( content ) {
+                                       for ( let doc of content ) {
+                                               found = doc.source && 
doc.source.local_sites_with_dupe &&
+                                                       
doc.source.local_sites_with_dupe.indexOf( value ) > -1;
+                                               if ( found ) break;
+                                       }
+                               }
+                               yield stepHelpers.waitForMs( 100 );
+                       } while ( ( new Date() - time ) < ( seconds * 1000 ) );
+                       return expect( found, `Expected ${page} on commons to 
have ${value} in local_sites_with_dupe within ${seconds}s.` ).to.be.true;
+               } ).call( this );
+       } );
 });

-- 
To view, visit https://gerrit.wikimedia.org/r/392987
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I43075458594338eab49375da1697ed5114583bea
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: DCausse <dcau...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to