diff --git a/CONTRIBUTORS b/CONTRIBUTORS --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1,3 +1,4 @@ +Shankhadeep Dey Daniele Serafini Ishan Bhanuka Kalpit Kothari diff --git a/cypress/integration/origin-search.spec.js b/cypress/integration/origin-search.spec.js --- a/cypress/integration/origin-search.spec.js +++ b/cypress/integration/origin-search.spec.js @@ -1,5 +1,5 @@ /** - * Copyright (C) 2019 The Software Heritage developers + * Copyright (C) 2020 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information @@ -65,12 +65,12 @@ .find('i') .should('have.class', 'fa-check') .and('have.attr', 'title', - 'Origin has at least one full visit by Software Heritage'); + 'Origin has at least one full visit by Software Heritage'); }); it('should show not found message when no repo matches', function() { searchShouldShowNotFound(nonExistentText, - 'No origins matching the search criteria were found.'); + 'No origins matching the search criteria were found.'); }); it('should add appropriate URL parameters', function() { @@ -100,6 +100,23 @@ }); }); + it('should not send request to "/api/1/resolve/" endpoint', function() { + cy.server(); + + cy.route({ + method: 'GET', + url: '/api/1/resolve/**', + onResponse: function() { + expect("Unexpected Https call").to.be.false; + } + }); + + cy.get("#origins-url-patterns") + .type(origin.url); + cy.get('.swh-search-icon') + .click(); + }); + context('Test pagination', function() { it('should not paginate if there are not many results', function() { // Setup search @@ -345,6 +362,24 @@ searchShouldRedirect(persistentId, redirectUrl); }); + + it('should not send request to "/api/1/origin/search/" endpoint', function() { + cy.server(); + + cy.route({ + method: 'GET', + url: '/api/1/origin/search/**', + onResponse: function() { + expect("Unexpected Https call").to.be.false; + } + }); + + cy.get("#origins-url-patterns") + .type(`swh:1:dir:${origin.content[0].directory}`); + cy.get('.swh-search-icon') + .click(); + + }); }); context('Test invalid persistent ids', function() { diff --git a/swh/web/assets/src/bundles/browse/origin-search.js b/swh/web/assets/src/bundles/browse/origin-search.js --- a/swh/web/assets/src/bundles/browse/origin-search.js +++ b/swh/web/assets/src/bundles/browse/origin-search.js @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2019 The Software Heritage developers + * Copyright (C) 2018-2020 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information @@ -138,19 +138,18 @@ $('#swh-no-result').hide(); let searchQueryText = $('#origins-url-patterns').val(); inSearch = true; - // first try to resolve a swh persistent identifier - let resolvePidUrl = Urls.api_1_resolve_swh_pid(searchQueryText); - fetch(resolvePidUrl) - .then(handleFetchError) - .then(response => response.json()) - .then(data => { - // pid has been successfully resolved, - // so redirect to browse page - window.location = data.browse_url; - }) - .catch(response => { - // pid resolving failed - if (searchQueryText.startsWith('swh:')) { + if (searchQueryText.startsWith('swh:')) { + // searchQueryText may be a PID so sending search queries to PID resolve endpoint + let resolvePidUrl = Urls.api_1_resolve_swh_pid(searchQueryText); + fetch(resolvePidUrl) + .then(handleFetchError) + .then(response => response.json()) + .then(data => { + // pid has been successfully resolved, + // so redirect to browse page + window.location = data.browse_url; + }) + .catch(response => { // display a useful error message if the input // looks like a swh pid response.json().then(data => { @@ -159,13 +158,14 @@ $('#swh-no-result').text(data.reason); $('#swh-no-result').show(); }); - } else { - // otherwise, proceed with origins search - $('#swh-origin-search-results').show(); - $('.swh-search-pagination').show(); - searchOriginsFirst(searchQueryText, limit); - } - }); + + }); + } else { + // otherwise, proceed with origins search + $('#swh-origin-search-results').show(); + $('.swh-search-pagination').show(); + searchOriginsFirst(searchQueryText, limit); + } } export function initOriginSearch() {