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 @@ -163,6 +163,29 @@ }); }); + it('should search in origin intrinsic metadata', function() { + cy.intercept('GET', '**/origin/metadata-search/**').as( + 'originMetadataSearch' + ); + cy.get('#swh-search-origins-with-visit') + .check({force: true}) + .get('#swh-filter-empty-visits') + .check({force: true}) + .get('#swh-search-origin-metadata') + .check({force: true}) + .then(() => { + const searchText = 'plugin'; + doSearch(searchText); + console.log(searchText); + cy.wait('@originMetadataSearch').then((req) => { + expect(req.response.body[0].metadata.metadata.description).to.equal( + 'Line numbering plugin for Highlight.js' + // metadata is defined in _TEST_ORIGINS variable in swh/web/tests/data.py + ); + }); + }); + }); + it('should not send request to the resolve endpoint', function() { cy.server(); diff --git a/swh/web/tests/api/views/test_origin.py b/swh/web/tests/api/views/test_origin.py --- a/swh/web/tests/api/views/test_origin.py +++ b/swh/web/tests/api/views/test_origin.py @@ -4,6 +4,7 @@ # See top-level LICENSE file for more information from datetime import timedelta +import json from hypothesis import given import pytest @@ -615,14 +616,21 @@ "configuration": INDEXER_TOOL["tool_configuration"], "id": INDEXER_TOOL["id"], }, - "metadata": {ORIGIN_METADATA_KEY: ORIGIN_METADATA_VALUE}, "mappings": [], }, } for origin_url, master_rev in ORIGIN_MASTER_REVISION.items() ] - assert rv.data == expected_data + for i in range(len(expected_data)): + expected = expected_data[i] + response = rv.data[i] + metadata = response["metadata"].pop("metadata") + + assert any( + [ORIGIN_METADATA_VALUE in json.dumps(val) for val in metadata.values()] + ) + assert response == expected def test_api_origin_metadata_search_limit(api_client, mocker): diff --git a/swh/web/tests/data.py b/swh/web/tests/data.py --- a/swh/web/tests/data.py +++ b/swh/web/tests/data.py @@ -121,11 +121,15 @@ "highlightjs-line-numbers.js.zip", "highlightjs-line-numbers.js_visit2.zip", ], + "metadata": {"description": "Line numbering plugin for Highlight.js",}, }, { "type": "git", "url": "repo_with_submodules", "archives": ["repo_with_submodules.tgz"], + "metadata": { + "description": "This is just a sample repository with submodules", + }, }, ] @@ -229,7 +233,7 @@ content_path = {} # Get all objects loaded into the test archive - metadata = {ORIGIN_METADATA_KEY: ORIGIN_METADATA_VALUE} + common_metadata = {ORIGIN_METADATA_KEY: ORIGIN_METADATA_VALUE} for origin in _TEST_ORIGINS: snp = snapshot_get_latest(storage, origin["url"]) snapshots.add(hash_to_hex(snp.id)) @@ -239,6 +243,8 @@ revisions.add(branch_data.target) if b"master" in branch_name: # Add some origin intrinsic metadata for tests + metadata = common_metadata + metadata.update(origin.get("metadata", {})) origin_metadata = OriginIntrinsicMetadataRow( id=origin["url"], from_revision=branch_data.target,