Reformat code

This commit is contained in:
Santiago Lo Coco 2023-12-07 15:48:49 -03:00
parent 6302458c8f
commit 3188637d07
22 changed files with 163 additions and 197 deletions

View File

@ -88,18 +88,18 @@ export const createFlight = (
export const editFlight = (
flight_id:string,
flight_id: string,
fligth_data: FlightEdit,
token: string
):Promise<Flight> => {
return instance.patch("flights/" + flight_id , fligth_data, {
): Promise<Flight> => {
return instance.patch("flights/" + flight_id, fligth_data, {
headers: { Authorization: `Bearer ${token}` },
});
};
export const fetchFlight = (
flight_id:string,
):Promise<Flight> => {
flight_id: string,
): Promise<Flight> => {
return instance.get("flights/" + flight_id);
};
@ -117,14 +117,14 @@ export const getChatId = (user_id: number, token: string): Promise<Flight> => {
};
export const getSubscription = (subscription: SubscriptionsCreate, token: string): Promise<SubscriptionsCreate> => {
return instance.get("subscriptions?user_id=" + subscription.user_id + "&flight_id=" +subscription.flight_id, {
return instance.get("subscriptions?user_id=" + subscription.user_id + "&flight_id=" + subscription.flight_id, {
headers: { Authorization: `Bearer ${token}` },
});
};
export const unsubscribeFromFlight = (subscription: SubscriptionsCreate, token: string): Promise<any> => {
return instance.delete("subscriptions", {
headers: { Authorization: `Bearer ${token}`},
headers: { Authorization: `Bearer ${token}` },
data: subscription
});
};

View File

@ -1,12 +1,12 @@
import { LogIn } from "./components/LogIn/LogIn";
import { Navigate, Route, RouteProps, Routes, useNavigate, useParams } from "react-router";
import { SignUp } from "./components/SignUp/SignUp";
import { CreateAirline } from "./components/SignUp/CreateAirline";
import { CreateAirline } from "./components/CreateAirline/CreateAirline";
import { Home } from "./components/Home/Home";
import { CreateFlight } from "./components/CreateFlight/CreateFlight";
import { Button } from "antd";
import useAuth, { AuthProvider } from "./useAuth";
import { EditFlight } from "./components/CreateFlight/EditFlight";
import { EditFlight } from "./components/CreateFlight/EditFlight/EditFlight";
import LandingPage from "./components/Landing/Landing";
function Router() {
@ -18,29 +18,33 @@ function Router() {
<Routes>
<Route path="/login" element={!user ? <LogIn /> : <Navigate to="/flights" />} />
<Route path="/signup" element={<SignUp />} />
<Route path="/create-airline" element={!isAdmin ? (!user ? <Navigate to="/login" state={"/create-airline"} /> : <Navigate to="/flights" />) : <CreateAirline />} />
<Route path="/create-airline" element={
!isAdmin ? (!user ? <Navigate to="/login" state={"/create-airline"} /> : <Navigate to="/flights" />) : <CreateAirline />
} />
<Route path="/flights" element={<Home />} />
<Route path="/create-flight" element={!isAirline ? (!user ? <Navigate to="/login" state={"/create-flight"} /> : <Navigate to="/flights" />) : <CreateFlight />} />
<Route path="/create-flight" element={
!isAirline ? (!user ? <Navigate to="/login" state={"/create-flight"} /> : <Navigate to="/flights" />) : <CreateFlight />
} />
<Route path="/edit-flight/:id" element={<EditFlightComponent />} />
<Route path="/" element={<LandingPage />} />
<Route path="*" element={<Navigate to="/" />} />
</Routes>
{window.location.pathname != '/' &&
<div className="LogoutButton">
{!!!localStorage.getItem("token") ?
<Button
onClick={() => navigate("/login")}
>
Login
</Button>
:
<Button
onClick={logout}
>
Logout
</Button>
}
</div>
<div className="LogoutButton">
{!!!localStorage.getItem("token") ?
<Button
onClick={() => navigate("/login")}
>
Login
</Button>
:
<Button
onClick={logout}
>
Logout
</Button>
}
</div>
}
</div>
);
@ -51,15 +55,15 @@ const EditFlightComponent = () => {
const params = useParams();
if (!isAirline && !isAdmin) {
if (!user) {
return <Navigate to="/login" state={{ intendedPath: `/edit-flight/${params.id}` }} />;
} else {
return <Navigate to="/flights" />;
}
if (!user) {
return <Navigate to="/login" state={{ intendedPath: `/edit-flight/${params.id}` }} />;
} else {
return <Navigate to="/flights" />;
}
} else {
return <EditFlight />;
return <EditFlight />;
}
};
};
function App() {
return (

View File

@ -1,17 +0,0 @@
import "../../matchMedia.mock";
import "@testing-library/jest-dom";
import userEvent from "@testing-library/user-event";
import { render, screen } from "@testing-library/react";
import { Button } from "antd";
describe("Button Component Test", () => {
test("Display button label and clicked", async () => {
const onClick = jest.fn();
render(<Button onClick={() => onClick()}>Button</Button>);
expect(screen.getByText("Button")).toBeVisible();
await userEvent.click(screen.getByText("Button"));
expect(onClick).toBeCalled();
});
});

View File

@ -51,7 +51,7 @@ export const CreateFlight = () => {
.catch((error) => {
try {
setError(JSON.parse(error.response.data)["detail"] as string);
} catch {}
} catch { }
});
};

View File

@ -1,8 +1,8 @@
import React, { useState } from "react";
import { FlightEditNotNull, Flight } from "../../Types";
import { FlightEditNotNull, Flight } from "../../../Types";
import { useNavigate, useParams } from "react-router";
import "./FlightForm.css";
import { editFlight } from "../../Api";
import "../FlightForm.css";
import { editFlight } from "../../../Api";
interface Props {
flight?: Flight;
@ -35,14 +35,14 @@ export const EditFlight: React.FC<Props> = (props) => {
if (flightData.arrival_time != "") {
data["arrival_time"] = flightData.arrival_time
}
if (flightData.departure_time != ""){
if (flightData.departure_time != "") {
data["departure_time"] = flightData.departure_time
}
if (flightData.status != ""){
if (flightData.status != "") {
data["status"] = flightData.status
}
if (flightData.gate != ""){
if (flightData.gate != "") {
data["gate"] = flightData.gate
}
@ -57,7 +57,7 @@ export const EditFlight: React.FC<Props> = (props) => {
.catch((error) => {
try {
setError(JSON.parse(error.response.data)["detail"] as string);
} catch {}
} catch { }
});
};

View File

@ -5,10 +5,5 @@ import "../../../matchMedia.mock";
import { Card } from "./Card";
describe("Card Component Test", () => {
test("Display initial, name and icon", async () => {
// render(<Card name="Belgrano" />);
// expect(screen.getByText("Belgrano📍")).toBeVisible();
// expect(screen.getByText("B")).toBeVisible();
});
test("Display initial, name and icon", async () => { });
});

View File

@ -41,13 +41,13 @@ export const Card: React.FC<CardProps> = ({ flight, user, subscribed, refresh, r
.then(() => {
refresh()
getChatId(user.id, token)
.then(() => {})
.then(() => { })
.catch((error) => {
setModalVisible(true);
})
})
.catch((error) => {
});
});
};
const handleEdit = async (event: React.FormEvent) => {
@ -73,7 +73,7 @@ export const Card: React.FC<CardProps> = ({ flight, user, subscribed, refresh, r
})
.catch((error) => {
// console.log(error)
});
});
};
const handleModalClose = () => {
@ -99,7 +99,7 @@ export const Card: React.FC<CardProps> = ({ flight, user, subscribed, refresh, r
})
.catch((error) => {
// console.log(error)
});
});
};
return (
@ -140,34 +140,34 @@ export const Card: React.FC<CardProps> = ({ flight, user, subscribed, refresh, r
{((!isAirline && !isAdmin) || ((user && flight.user_id == user.id) || isAdmin)) && <br></br>}
</div>
{!isAirline && !isAdmin ?
(
!(subscribed) ?
<Space size={8} direction="horizontal" style={{ justifyContent: "center" }}>
<Button type="primary" onClick={handleSubscribe}>
Subscribe
</Button>
</Space>
(
!(subscribed) ?
<Space size={8} direction="horizontal" style={{ justifyContent: "center" }}>
<Button type="primary" onClick={handleSubscribe}>
Subscribe
</Button>
</Space>
:
<Space size={8} direction="horizontal" style={{ justifyContent: "center" }}>
<Button type="primary" onClick={handleUnsubscribe}>
Unsubscribe
</Button>
</Space>
)
:
<Space size={8} direction="horizontal" style={{ justifyContent: "center" }}>
<Button type="primary" onClick={handleUnsubscribe}>
Unsubscribe
</Button>
</Space>
)
:
(
(user && flight.user_id == user.id) || isAdmin ?
<Space size={8} direction="horizontal" style={{ justifyContent: "center" }}>
<Button type="primary" onClick={handleEdit}>
Edit
</Button>
<Button type="primary" onClick={handleDelete}>
Delete
</Button>
</Space>
:
<></>
)
(
(user && flight.user_id == user.id) || isAdmin ?
<Space size={8} direction="horizontal" style={{ justifyContent: "center" }}>
<Button type="primary" onClick={handleEdit}>
Edit
</Button>
<Button type="primary" onClick={handleDelete}>
Delete
</Button>
</Space>
:
<></>
)
}
<Modal
title="Attention"

View File

@ -7,22 +7,7 @@ jest.mock("react-router-dom", () => ({
import "../../matchMedia.mock";
import "@testing-library/jest-dom";
import { render, screen } from "@testing-library/react";
import { Home } from "./Home";
describe("Home View Test", () => {
test("Display initial, name and icon", async () => {
// render(
// <Home
// zones={[
// { id: 1, name: "Belgrano" },
// { id: 2, name: "San Isidro" },
// ]}
// />
// );
// expect(screen.getByText("Zones")).toBeVisible();
// expect(screen.getByText("Belgrano📍")).toBeVisible();
// expect(screen.getByText("San Isidro📍")).toBeVisible();
});
test("Display initial, name and icon", async () => { });
});

View File

@ -5,28 +5,28 @@
justify-content: center;
height: 100vh;
text-align: center;
}
}
.Title {
.Title {
font-size: 2.5em;
margin-bottom: 20px;
}
}
.Description {
.Description {
font-size: 1.2em;
margin-bottom: 20px;
}
}
.ButtonContainer {
.ButtonContainer {
display: flex;
gap: 20px;
}
}
.StyledLink {
.StyledLink {
text-decoration: none;
}
}
.StyledButton {
.StyledButton {
padding: 10px 20px;
font-size: 1.2em;
background-color: #3498db;
@ -34,5 +34,4 @@
border: none;
border-radius: 5px;
cursor: pointer;
}
}

View File

@ -3,37 +3,37 @@ import { Link, useNavigate } from "react-router-dom";
import "./Landing.css";
const LandingPage: React.FC = () => {
const navigate = useNavigate();
const navigate = useNavigate();
const handleSubscribeClick = () => {
navigate("/login");
};
const handleSubscribeClick = () => {
navigate("/login");
};
const handleGoToFlightsClick = () => {
navigate("/flights");
};
const handleGoToFlightsClick = () => {
navigate("/flights");
};
return (
<div className="LandingPageContainer">
<h1 className="Title">Welcome to FIDS!</h1>
<p className="Description">
If you want to subscribe to flights, please create or log in to your account.
</p>
<div className="ButtonContainer">
<Link to="/login" className="StyledLink">
<button className="StyledButton" onClick={handleSubscribeClick}>Create an Account</button>
</Link>
</div>
<p className="Description">
Otherwise, you can continue to the flights page.
</p>
<div className="ButtonContainer">
<button className="StyledButton" onClick={handleGoToFlightsClick}>
Go to Flights
</button>
</div>
</div>
);
return (
<div className="LandingPageContainer">
<h1 className="Title">Welcome to FIDS!</h1>
<p className="Description">
If you want to subscribe to flights, please create or log in to your account.
</p>
<div className="ButtonContainer">
<Link to="/login" className="StyledLink">
<button className="StyledButton" onClick={handleSubscribeClick}>Create an Account</button>
</Link>
</div>
<p className="Description">
Otherwise, you can continue to the flights page.
</p>
<div className="ButtonContainer">
<button className="StyledButton" onClick={handleGoToFlightsClick}>
Go to Flights
</button>
</div>
</div>
);
};
export default LandingPage;

View File

@ -32,7 +32,7 @@ export const LogIn = () => {
<Button
style={{ width: "100%" }}
onClick={async () =>
login({ email, password}, state)
login({ email, password }, state)
}
name="Login"
loading={loading}

View File

@ -3,7 +3,7 @@ import { useState } from "react";
import { Flight } from "../Types";
import { fetchFlight } from "../Api";
export const useFetchFlight = (id: string | undefined) => {
export const useFetchFlight = (id: string | undefined) => {
const [error, setError] = useState<string | null>(null);
const [flight, setFlight] = useState<Flight>();
const [count, setCount] = useState<number>(0);

View File

@ -1,9 +1,9 @@
import { useCallback, useEffect } from "react";
import { useState } from "react";
import { Flight } from "../Types";
import { Flight } from "../Types";
import { fetchFlights } from "../Api";
export const useFetchFlights = (page: number | null, search: string | null) => {
export const useFetchFlights = (page: number | null, search: string | null) => {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [flights, setFlights] = useState<Flight[]>([]);

View File

@ -3,7 +3,7 @@ import { useState } from "react";
import { User, Flight, SubscriptionsCreate } from "../Types";
import { fetchSubscriptions } from "../Api";
export const useFetchSubscriptions = (user: User | undefined, token: string | undefined, isUser: boolean) => {
export const useFetchSubscriptions = (user: User | undefined, token: string | undefined, isUser: boolean) => {
const [error, setError] = useState<string | null>(null);
const [subscriptions, setSubscriptions] = useState<SubscriptionsCreate[]>([]);
const [loading, setLoading] = useState<boolean>(true);

View File

@ -96,4 +96,4 @@ code {
padding: 15px;
margin-bottom: 15px;
border-radius: 4px;
}
}

View File

@ -42,12 +42,12 @@ describe('Flight API Endpoints', () => {
it('should retrieve the created flight by ID', async () => {
const response = await request(app)
.get(`/flights/${createdFlightId}`)
.set('Authorization', `Bearer ${authToken}`);
.get(`/flights/${createdFlightId}`)
.set('Authorization', `Bearer ${authToken}`);
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('id', createdFlightId);
});
});
it('should update a flight by ID', async () => {
const flightUpdate = {
@ -66,12 +66,12 @@ describe('Flight API Endpoints', () => {
it('should retrieve filtered flights', async () => {
const response = await request(app)
.get('/flights')
.query({ origin: 'Frankfurt' })
.set('Authorization', `Bearer ${authToken}`);
.get('/flights')
.query({ origin: 'Frankfurt' })
.set('Authorization', `Bearer ${authToken}`);
expect(response.statusCode).toBe(200);
expect(response.body).toBeInstanceOf(Array);
expect(response.body[0].id).toBe(createdFlightId)
});
});
});

View File

@ -88,7 +88,7 @@ export function AuthProvider({
.catch((error) => {
try {
setError(JSON.parse(error.response.data)["detail"] as string);
} catch {}
} catch { }
})
.finally(() => setLoading(false));
})
@ -96,7 +96,7 @@ export function AuthProvider({
setLoading(false)
try {
setError(JSON.parse(error.response.data)["detail"] as string);
} catch {}
} catch { }
})
// .finally(() => setLoading(false));
}

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -e
if [ "${TEST_TARGET:-}" = "INTEGRATION" ]; then
npm run test:integration

View File

@ -42,12 +42,12 @@ describe('Flight API Endpoints', () => {
it('should retrieve the created flight by ID', async () => {
const response = await request(app)
.get(`/flights/${createdFlightId}`)
.set('Authorization', `Bearer ${authToken}`);
.get(`/flights/${createdFlightId}`)
.set('Authorization', `Bearer ${authToken}`);
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('id', createdFlightId);
});
});
it('should update a flight by ID', async () => {
const flightUpdate = {
@ -66,12 +66,12 @@ describe('Flight API Endpoints', () => {
it('should retrieve filtered flights', async () => {
const response = await request(app)
.get('/flights')
.query({ origin: 'Frankfurt' })
.set('Authorization', `Bearer ${authToken}`);
.get('/flights')
.query({ origin: 'Frankfurt' })
.set('Authorization', `Bearer ${authToken}`);
expect(response.statusCode).toBe(200);
expect(response.body).toBeInstanceOf(Array);
expect(response.body[0].id).toBe(createdFlightId)
});
});
});

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -e
if [ "${TEST_TARGET:-}" = "INTEGRATION" ]; then
npm run test:integration