Skip to content

Commit 5b0ea40

Browse files
authored
Merge pull request #88 from SolidLabResearch/fix-59
Fix 59
2 parents c987073 + 2709224 commit 5b0ea40

File tree

3 files changed

+88
-2
lines changed

3 files changed

+88
-2
lines changed

cypress/e2e/fetch-status.cy.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
describe("Fetch Status", () => {
2+
3+
it("Fetch data with no authenticated user", () => {
4+
5+
cy.visit("/");
6+
7+
// Go immediately to query
8+
cy.contains("A book query testing sources with and without authentication required").click();
9+
10+
// Check if the public and restricted sources appear
11+
cy.get('[aria-label="Sources info"]').click();
12+
13+
cy.contains("http://localhost:8080/example/favourite-books");
14+
cy.contains("http://localhost:8080/example/wish-list");
15+
16+
// Check if the correct icons appear
17+
cy.get('[aria-label="Authentication required"]').should("exist");
18+
cy.get('[aria-label="Fetch failed"]').should("exist");
19+
20+
cy.get('[aria-label="No authentication required"]').should("exist");
21+
cy.get('[aria-label="Fetch was succesful"]').should("exist");
22+
23+
24+
// Checking that a non-authorized book is not appearing
25+
cy.contains("It Ends With Us").should("not.exist");
26+
27+
// Checking that a book that we may see appears
28+
cy.contains("Too Late");
29+
30+
});
31+
32+
it("Fetch data with authenticated user", () => {
33+
34+
cy.visit("/");
35+
36+
// Login as user 'example'
37+
cy.get('[aria-label="Profile"]').click();
38+
cy.contains('[role="menuitem"]', "Login").click();
39+
40+
cy.get('input[name="idp"]').clear();
41+
cy.get('input[name="idp"]').type("http://localhost:8080");
42+
cy.contains("Login").click();
43+
44+
cy.get("input#email").type("hello@example.com");
45+
cy.get("input#password").type("abc123");
46+
cy.contains("button", "Log in").click();
47+
cy.contains("button", "Authorize").click();
48+
49+
cy.url().should("eq", "http://localhost:5173/");
50+
51+
// Go to the mixed book query
52+
cy.contains("A book query testing sources with and without authentication required").click();
53+
54+
// Check if the public and restricted sources appear
55+
cy.get('[aria-label="Sources info"]').click();
56+
57+
cy.contains("http://localhost:8080/example/favourite-books");
58+
cy.contains("http://localhost:8080/example/wish-list");
59+
60+
// Check if the correct icons appear
61+
cy.get('[aria-label="Authentication required"]').should("exist");
62+
cy.get('[aria-label="Fetch Failed"]').should("not.exist");
63+
64+
cy.get('[aria-label="No authentication required"]').should("exist");
65+
cy.get('[aria-label="Fetch was succesful"]').should("exist");
66+
67+
// Checking that you see authorized books
68+
cy.contains("It Ends With Us");
69+
cy.contains("Too Late");
70+
});
71+
72+
})

src/config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@
7979
"sources": ["http://localhost:8080/example/wish-list"]
8080
}
8181
},
82+
{
83+
"queryLocation": "books.rq",
84+
"name": "A book query testing sources with and without authentication required",
85+
"description": "A short list of some of my favorite books and books I'd love to own",
86+
"icon": "MenuBookIcon",
87+
"id": "4200",
88+
"comunicaContext": {
89+
"sources": [
90+
"http://localhost:8080/example/favourite-books",
91+
"http://localhost:8080/example/wish-list"
92+
],
93+
"lenient": true
94+
}
95+
},
8296
{
8397
"queryLocation": "musicians.rq",
8498
"name": "My favourite musicians",

src/dataProvider/SparqlDataProvider.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ function generateContext(context) {
237237
function statusFetch(customFetch, context) {
238238
const wrappedFetchFunction = async (arg) => {
239239
try{
240-
const response = await customFetch(arg);
241-
context.fetchSuccess[arg] = true;
240+
const response = await customFetch(arg);
241+
context.fetchSuccess[arg] = response.ok;
242242
return response;
243243
}
244244
catch(error){

0 commit comments

Comments
 (0)