Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions cypress/e2e/fetch-status.cy.js
Original file line number Diff line number Diff line change
@@ -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");
});

})
14 changes: 14 additions & 0 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/dataProvider/SparqlDataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down