Skip to content

Commit

Permalink
Merge pull request #119 from Arquisoft/prueba-local
Browse files Browse the repository at this point in the history
This is a final merge to master to try to deploy all the "polished" stuff mentioned in the presentation that was already working.
UO276188 authored May 3, 2023
2 parents 81396be + 9e9e1fb commit 46ceb6f
Showing 14 changed files with 113 additions and 96 deletions.
14 changes: 8 additions & 6 deletions restapi/__test__/locationValidators.test.ts
Original file line number Diff line number Diff line change
@@ -14,8 +14,9 @@ test("valid location - 0 coordinates", () => {
longitude:0,
isShared: false,
isOwnLocation: true,
owner: "",
owner:"",
ownerName:""

}
expect(validateLocation(location))
});
@@ -29,8 +30,9 @@ test("valid location - max positive coordinates", () => {
longitude:180,
isShared: false,
isOwnLocation: true,
owner: "",
owner:"",
ownerName:""

}
expect(validateLocation(location))
});
@@ -44,7 +46,7 @@ test("valid location - max negative coordinates", () => {
longitude:-180,
isShared: false,
isOwnLocation: true,
owner: "",
owner:"",
ownerName:""
}
expect(validateLocation(location))
@@ -59,7 +61,7 @@ test("invalid location - max negative coordinates", () => {
longitude:-180.001,
isShared: false,
isOwnLocation: true,
owner: "",
owner:"",
ownerName:""
}
expect(!validateLocation(location))
@@ -74,7 +76,7 @@ test("invalid location - max positive coordinates", () => {
longitude:-180.001,
isShared: false,
isOwnLocation: true,
owner: "",
owner:"",
ownerName:""
}
expect(!validateLocation(location))
@@ -89,7 +91,7 @@ test("invalid location - empty name", ()=> {
longitude:-180.001,
isShared: false,
isOwnLocation: true,
owner: "",
owner:"",
ownerName:""
}
expect(!validateLocation(location))
28 changes: 14 additions & 14 deletions restapi/__test__/reviewValidator.test.ts
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@ test("valid review - only score", () => {
comment:undefined,
score: 4,
encodedPhoto: undefined,
owner: "",
ownerName:""
owner:"",
ownerName: ""
}
expect(validateReview(review)).toBeTruthy();
});
@@ -20,8 +20,8 @@ test("valid review - only image", () => {
comment:undefined,
score: undefined,
encodedPhoto: "encodedPhoto-5293084750924theiruh",
owner: "",
ownerName:""
owner:"",
ownerName: ""
}
expect(validateReview(review)).toBeTruthy();
});
@@ -32,8 +32,8 @@ test("valid review - only comment", () => {
comment:"comment",
score: undefined,
encodedPhoto: undefined,
owner: "",
ownerName:""
owner:"",
ownerName: ""
}
expect(validateReview(review)).toBeTruthy();
});
@@ -44,8 +44,8 @@ test("valid review - two elements", () => {
comment:"comment",
score: 3,
encodedPhoto: undefined,
owner: "",
ownerName:""
owner:"",
ownerName: ""
}
expect(validateReview(review)).toBeTruthy();
});
@@ -56,8 +56,8 @@ test("valid review - all elements", () => {
comment:"comment",
score: 3,
encodedPhoto: "encodedPhoto-2093485iughsidg",
owner: "",
ownerName:""
owner:"",
ownerName: ""
}
expect(validateReview(review)).toBeTruthy();
});
@@ -68,8 +68,8 @@ test("invalid review - no elements", () => {
comment:undefined,
score: undefined,
encodedPhoto: undefined,
owner: "",
ownerName:""
owner:"",
ownerName: ""
}
expect(validateReview(review)).toBeFalsy();
});
@@ -80,8 +80,8 @@ test("invalid review - no marker id", () => {
comment:"comment",
score: 3,
encodedPhoto: "encodedPhoto-2093485iughsidg",
owner: "",
ownerName:""
owner:"",
ownerName: ""
}
expect(validateReview(review)).toBeFalsy();
});
3 changes: 2 additions & 1 deletion restapi/src/server.ts
Original file line number Diff line number Diff line change
@@ -20,12 +20,13 @@ declare module 'express-session' {

//const connString = process.env.MONGO_CONN_STRING;
//FIXME: I will use this to try the connections

/*
const connString = 'mongodb+srv://admin:' +
'admin@musicstoreapp.cew3gcy.mongodb.net/' +
'prueba?retryWrites=true&w=majority';
*/
*/
const connString = "mongodb://35.180.234.117:27017/"

if(connString == undefined) throw new Error("MongoDB connection string is undefined")
23 changes: 18 additions & 5 deletions restapi/src/services/friendshipsService.ts
Original file line number Diff line number Diff line change
@@ -4,14 +4,19 @@ import {
saveSolidDatasetAt,
getPodUrlAll,
getThingAll,
getWebIdDataset,
Thing,
getThing,
getUrlAll,
} from "@inrupt/solid-client";
import {Session} from "@inrupt/solid-client-authn-node";
import {friendToThing, thingToFriend} from "../builders/friendBuilder";
import {friendToThing, thingToFriend, urlToFriend} from "../builders/friendBuilder";
import {validateFriend, validateFriendThing} from "../validators/friendValidator";
import {Friend} from "../types";
import {getOrCreateDataset} from "./util/podAccessUtil";
import {InvalidRequestBodyError, PodProviderError} from "./util/customErrors";
import MongoService from "./MongoService"
import { FOAF } from "@inrupt/vocab-common-rdf";

export default {

@@ -25,20 +30,24 @@ export default {
friendsDataset = friendsDataset!

//Get friends from profile
/*
const profile = await getWebIdDataset(decodeURIComponent(session.info.webId!));
const profileThing = getThing(profile, decodeURIComponent(session.info.webId!));
const profileFriends = getUrlAll(profileThing as Thing, FOAF.knows);
*/

//Get friends from extended profile
//TODO

return await Promise.all(
let aux = await Promise.all(
getThingAll(friendsDataset)
.filter(friendThing=>validateFriendThing(friendThing))
.map(async friendThing=>await thingToFriend(friendThing, true))
)
.concat(
profileFriends.map(async webId =>await urlToFriend(webId, false, "")))
)
console.log("friendshipService ==============")
console.log(aux)
console.log("friendshipService ==============")
return aux;
},

addFriend : async function (friend:Friend, session:Session){
@@ -54,6 +63,10 @@ export default {
const friendThing = friendToThing(friend);
friendsDataset = setThing(friendsDataset, friendThing);

console.log("friendshipService ==============")
console.log(friend)
console.log("friendshipService ==============")

await Promise.all([
saveSolidDatasetAt(
friendsURL,
4 changes: 2 additions & 2 deletions restapi/src/services/reviewsService.ts
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ export default {
? "Pod name not defined"
: name

MongoService.createReview(review);

const reviewThing = reviewToThing(review, session.info.webId!, imageURL);
reviewsDataset = setThing(reviewsDataset, reviewThing);
@@ -69,8 +70,7 @@ export default {
reviewsURL,
reviewsDataset,
{fetch: session.fetch}
),
MongoService.createReview(review)
)
])
return reviewThing.url;
},
4 changes: 2 additions & 2 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions webapp/src/__tests__/Map.test.tsx
Original file line number Diff line number Diff line change
@@ -20,7 +20,9 @@ const handlers = [
latitude: 43.36136284334129,
longitude: -5.851278233874803,
isShared: false,
isOwnLocation: false
owner: 'Yo',
isOwnLocation: false,
ownerName: 'OwnerName'
},
{
id: 'Test',
@@ -29,7 +31,9 @@ const handlers = [
latitude: 43.365143614762374,
longitude: -5.851593017578125,
isShared: false,
isOwnLocation: false
owner: 'Yo',
isOwnLocation: false,
ownerName: 'OwnerName'
}
]),
)
@@ -68,6 +72,11 @@ describe("Map tests", () =>{
test('Unchecking a filter, the markers of that category disappear', async () => {
const { getByLabelText, container } = render(<MapElement />);

await waitFor(() => {
const markers = container.querySelectorAll('.leaflet-marker-icon');
expect(markers.length).toBe(2);
});

const filterButton = screen.getByText("Filter Locations");
fireEvent.click(filterButton);

62 changes: 47 additions & 15 deletions webapp/src/__tests__/Profile.test.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
import ProfileView from "../components/ProfileView";
import { screen } from "@testing-library/react"
import { screen , waitFor } from "@testing-library/react"
import {BrowserRouter} from "react-router-dom";
import { render } from '../setupTests';
import '@testing-library/jest-dom';

import {rest} from "msw";
import {setupServer} from "msw/node";


/**
* verifies that the "NavBar" component renders correctly
*/
/*
const mockedUsedNavigate = jest.fn();
jest.mock("react-router-dom", () => ({
...(jest.requireActual("react-router-dom") as any),
useNavigate: () => mockedUsedNavigate
}));
*/

const postResolver = jest.fn()
const handlers = [
rest.get('*/userdata', (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json([
{
webId: 'WebIdPrueba',
name: 'Nombre de prueba'
},
]),
)
}),
rest.post('*/friendship', (req, res, ctx) => {
return res(postResolver());
})
]

const server = setupServer(...handlers)

beforeAll(() => server.listen())
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

describe("Profile tests", () => {
test("Test the corrent render of the component", () => {
test("Test the corrent render of the component", async () => {
const {container} = render(
<BrowserRouter>
<ProfileView />
@@ -29,23 +56,28 @@ describe("Profile tests", () => {
* - two text elements
*/

const friendsButton = screen.getByText("Friends"); // friends button
expect(friendsButton).toBeInTheDocument();
await waitFor(() => {
const friendsButton = screen.getByText("Friends"); // friends button
expect(friendsButton).toBeInTheDocument();

const mapButton = screen.getByText("Map"); // map button
expect(mapButton).toBeInTheDocument();

const mapButton = screen.getByText("Map"); // map button
expect(mapButton).toBeInTheDocument();

const avatar = screen.getAllByRole("img"); // there must be an avatar element
expect(avatar.length).toBe(1);

const buttons = screen.getAllByRole("button"); // there must be two buttons
expect(buttons.length).toBe(2);

const avatar = screen.getAllByRole("img"); // there must be an avatar element
expect(avatar.length).toBe(1);
const headingElements = container.getElementsByClassName('chakra-heading') // there must be two text elements
expect(headingElements.length).toBe(1);

const buttons = screen.getAllByRole("button"); // there must be two buttons
expect(buttons.length).toBe(2);
const pElements = container.getElementsByClassName('chakra-text') // there must be two text elements
expect(pElements.length).toBe(1);
});


const headingElements = container.getElementsByClassName('chakra-heading') // there must be two text elements
expect(headingElements.length).toBe(1);

const pElements = container.getElementsByClassName('chakra-text') // there must be two text elements
expect(pElements.length).toBe(1);
})
})
2 changes: 1 addition & 1 deletion webapp/src/app/services/Friend.tsx
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import {MapMarker} from "../../types";

export const friendApi = createApi({
reducerPath: 'friendship',
baseQuery: fetchBaseQuery({ baseUrl: 'http://localhost:8082/' }),
baseQuery: fetchBaseQuery({ baseUrl: 'http://api.lomap.mariopdev.com/' }),
tagTypes: ['Friends'],
endpoints: (builder ) => ({

2 changes: 1 addition & 1 deletion webapp/src/app/services/Reviews.tsx
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import {Review} from "../../types";

export const reviewApi = createApi({
reducerPath: 'review',
baseQuery: fetchBaseQuery({ baseUrl: 'http://localhost:8082/' }),
baseQuery: fetchBaseQuery({ baseUrl: 'http://api.lomap.mariopdev.com/' }),
tagTypes: ['Reviews'],
endpoints: (builder) => ({
getReviews: builder.query<Review[], string>({
2 changes: 1 addition & 1 deletion webapp/src/app/services/User.tsx
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import type { UserData } from '../../types'

export const userApi = createApi({
reducerPath: 'user',
baseQuery: fetchBaseQuery({ baseUrl: 'http://localhost:8082/' }),
baseQuery: fetchBaseQuery({ baseUrl: 'http://api.lomap.mariopdev.com/' }),
endpoints: (builder ) => ({
getUserData: builder.query<UserData, void>({
query: (name) => ({
42 changes: 4 additions & 38 deletions webapp/src/components/FriendsPage/FriendsView.tsx
Original file line number Diff line number Diff line change
@@ -48,17 +48,11 @@ export function AddFriendsView(){
addFriendMutation(newFriend);

};

handleSubmit(event)
/* TODO:
Right now when we do this, the textfield is not restored so:
- visually there is something written
- You can submit the form because the is something written
- But the field that is sent is empty
- We need to restore the textfield someway or dont erase the content here

setWebId("");
setNickName("");
*/
}}/>
<Box>
<FormControl isRequired>
@@ -67,6 +61,7 @@ export function AddFriendsView(){
placeholder="asdfghjkl123456"
_placeholder={{color: 'gray.500'}}
type="text"
value = {webId}
onChange={(e) => setWebId(e.currentTarget.value)}
/>
</FormControl>
@@ -78,6 +73,7 @@ export function AddFriendsView(){
placeholder="Motosarius"
_placeholder={{color: 'gray.500'}}
type="text"
value = {nickName}
onChange={(e) => setNickName(e.currentTarget.value)}
/>
</FormControl>
@@ -148,34 +144,4 @@ export default function FriendsView(): JSX.Element {
</Stack>
</Container>
);
}

const StatsText = ({ children }: { children: ReactNode }) => (
<Text as={'span'} fontWeight={700} color={'white'}>
{children}
</Text>
);

const stats = [
{
title: 'Team members',
content: (
<>
{/* <StatsText>Sara María Ramírez Perez</StatsText> alias motosara <br/>
<StatsText>Iván Vega García</StatsText> alias señor iván <br/>
<StatsText>Mario Pérez</StatsText> alias (...)<br/>
<StatsText>Elías Llera García-Riaño</StatsText> alias eli <br/>
<StatsText>Silvia Suárez Prendes</StatsText> alias laquellora <br/>
<StatsText>Dana</StatsText> alias cuac <br/> */}

Sara María Ramírez Perez UO276188 <br />
Iván Vega García UO276670 <br />
Mario Pérez Fernández UO283720 <br />
Elías Llera García-Riaño UO271407 <br />
Silvia Suárez Prendes UO277412 <br />
Andrés Álvarez Murillo UO278249 <br />

</>
),
},
];
}
4 changes: 2 additions & 2 deletions webapp/src/components/Map.tsx
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ export function LocationMarkerWithStore() {

export default function MapElement(): JSX.Element {
const escuela: LatLngExpression = {lat: 43.354, lng: -5.851};
const {data: locations, error, isLoading} = useGetLocationsQuery();
const {data: locations, error, isLoading, isFetching} = useGetLocationsQuery();
const dispatch = useDispatch()

const [showBars, setShowBars] = useState(true)
@@ -178,7 +178,7 @@ export default function MapElement(): JSX.Element {
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
noWrap = {true}
/>
{isLoading
{isLoading || isFetching
?
(<Alert zIndex={'1400'} status={'info'} variant='solid'>
<AlertIcon height='50px'/>
6 changes: 0 additions & 6 deletions webapp/src/components/ProfileView.tsx
Original file line number Diff line number Diff line change
@@ -59,12 +59,6 @@ export default function ProfileView() : JSX.Element {
<Text fontWeight={600} color={'gray.500'} mb={4}>
{user!.webId}
</Text>
<Text
textAlign={'center'}
color={textColor}
px={3}>

</Text>

<Stack mt={8} direction={'row'} spacing={4}>
<Button

0 comments on commit 46ceb6f

Please sign in to comment.