diff --git a/cypress/e2e/fetch-status.cy.js b/cypress/e2e/fetch-status.cy.js new file mode 100644 index 00000000..e1b0e451 --- /dev/null +++ b/cypress/e2e/fetch-status.cy.js @@ -0,0 +1,72 @@ +describe("Fetch Status", () => { + + it("Fetch data with no authenticated user", () => { + + cy.visit("/"); + + // Go immediately to query + cy.contains("A book query testing sources with and without authentication required").click(); + + // Check if the public and restricted sources appear + cy.get('[aria-label="Sources info"]').click(); + + cy.contains("http://localhost:8080/example/favourite-books"); + cy.contains("http://localhost:8080/example/wish-list"); + + // Check if the correct icons appear + cy.get('[aria-label="Authentication required"]').should("exist"); + cy.get('[aria-label="Fetch failed"]').should("exist"); + + cy.get('[aria-label="No authentication required"]').should("exist"); + cy.get('[aria-label="Fetch was succesful"]').should("exist"); + + + // Checking that a non-authorized book is not appearing + cy.contains("It Ends With Us").should("not.exist"); + + // Checking that a book that we may see appears + cy.contains("Too Late"); + + }); + + it("Fetch data with authenticated user", () => { + + cy.visit("/"); + + // Login as user 'example' + cy.get('[aria-label="Profile"]').click(); + cy.contains('[role="menuitem"]', "Login").click(); + + cy.get('input[name="idp"]').clear(); + cy.get('input[name="idp"]').type("http://localhost:8080"); + cy.contains("Login").click(); + + cy.get("input#email").type("hello@example.com"); + cy.get("input#password").type("abc123"); + cy.contains("button", "Log in").click(); + cy.contains("button", "Authorize").click(); + + cy.url().should("eq", "http://localhost:5173/"); + + // Go to the mixed book query + cy.contains("A book query testing sources with and without authentication required").click(); + + // Check if the public and restricted sources appear + cy.get('[aria-label="Sources info"]').click(); + + cy.contains("http://localhost:8080/example/favourite-books"); + cy.contains("http://localhost:8080/example/wish-list"); + + // Check if the correct icons appear + cy.get('[aria-label="Authentication required"]').should("exist"); + cy.get('[aria-label="Fetch Failed"]').should("not.exist"); + + cy.get('[aria-label="No authentication required"]').should("exist"); + cy.get('[aria-label="Fetch was succesful"]').should("exist"); + + // Checking that you see authorized books + cy.contains("It Ends With Us"); + cy.contains("Too Late"); + }); + +}) \ No newline at end of file diff --git a/src/config.json b/src/config.json index 9a3363af..a1d0a900 100644 --- a/src/config.json +++ b/src/config.json @@ -79,6 +79,20 @@ "sources": ["http://localhost:8080/example/wish-list"] } }, + { + "queryLocation": "books.rq", + "name": "A book query testing sources with and without authentication required", + "description": "A short list of some of my favorite books and books I'd love to own", + "icon": "MenuBookIcon", + "id": "4200", + "comunicaContext": { + "sources": [ + "http://localhost:8080/example/favourite-books", + "http://localhost:8080/example/wish-list" + ], + "lenient": true + } + }, { "queryLocation": "musicians.rq", "name": "My favourite musicians", diff --git a/src/dataProvider/SparqlDataProvider.js b/src/dataProvider/SparqlDataProvider.js index 8edf40bc..181762eb 100644 --- a/src/dataProvider/SparqlDataProvider.js +++ b/src/dataProvider/SparqlDataProvider.js @@ -237,8 +237,8 @@ function generateContext(context) { function statusFetch(customFetch, context) { const wrappedFetchFunction = async (arg) => { try{ - const response = await customFetch(arg); - context.fetchSuccess[arg] = true; + const response = await customFetch(arg); + context.fetchSuccess[arg] = response.ok; return response; } catch(error){