From bc7ba30fa10764988fec52c92c20f331a6778b2f Mon Sep 17 00:00:00 2001 From: uo287841 Date: Tue, 16 Apr 2024 16:23:23 +0200 Subject: [PATCH 1/7] created user_profile --- webapp/src/components/UserProfile.jsx | 75 +++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 webapp/src/components/UserProfile.jsx diff --git a/webapp/src/components/UserProfile.jsx b/webapp/src/components/UserProfile.jsx new file mode 100644 index 0000000..97776cb --- /dev/null +++ b/webapp/src/components/UserProfile.jsx @@ -0,0 +1,75 @@ +import React, { useEffect, useState, useCallback } from "react"; +import axios from "axios"; +import useAuthUser from "react-auth-kit/hooks/useAuthUser"; +import userAvatar from "./ranking/profile_img.webp"; + +const UserProfile = () => { + const auth = useAuthUser(); + const [category, setCategory] = useState('global'); + const [questions, setQuestions] = useState(0); + const [right, setRight] = useState(0); + const [wrong, setWrong] = useState(0); + + const apiEndpoint = process.env.REACT_APP_API_ENDPOINT ||'http://localhost:8000'; + + + const handleCategoryChange = useCallback(async (newCategory) => { + try { + const result = await axios.get(`${apiEndpoint}/ranking/user`, { + params: { + username: auth.username, + category: newCategory + } + }); + + setQuestions(result.data.questions); + setRight(result.data.correct); + setWrong(result.data.wrong); + setCategory(newCategory); + } catch (error) { + console.error('Error fetching question:', error); + } + }, [apiEndpoint, auth.username]); + + useEffect(() => { + handleCategoryChange(category); + }, [handleCategoryChange, category]); + + + return ( +
+
+
+ User Avatar +

Username: {auth.username}

+ +

Email: {auth.email}

+

Joined: {new Date(auth.createdAt).toLocaleDateString()}

+ + + {/* Buttons to change category */} +
+ + + + + + +
+ +
+

{category} Ranking

+
+

Total Answered Questions: {questions}

+

Right Answers: {right}

+

Wrong Answers: {wrong}

+
+
+ +
+
+
+ ); +}; + +export default UserProfile; From c1f98ab948cf67288195b052e3c3742c6c7a875b Mon Sep 17 00:00:00 2001 From: uo287841 Date: Tue, 16 Apr 2024 16:23:58 +0200 Subject: [PATCH 2/7] user profile services --- gatewayservice/gateway-service.js | 21 ++++++++++++++++ users/userservice/user-service.js | 32 +++++++++++++++++++++++++ webapp/e2e/steps/register-form.steps.js | 2 +- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 7b96b97..229cd8b 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -127,6 +127,27 @@ app.get('/rankings/:filter', async (req, res) => { } }); + +app.get('/ranking/user', async (req, res) => { + const username = req.query.username; + const category = req.query.category; + + try { + // Forward the request to the user service + const result = await axios.get(`${userServiceUrl}/ranking/user`, { + params: { + username: username, + category: category + } + }); + + res.json(result.data); + + } catch (error) { + res.status(error.response.status).json({ error: error.response.data.error }); + } +}); + // Read the OpenAPI YAML file synchronously openapiPath='./openapi.yaml' if (fs.existsSync(openapiPath)) { diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index 521ab55..a8989c6 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -54,6 +54,38 @@ app.get('/rankings/:filter', async (req, res) => { }) +// Get the ranking info for a specified category and user +app.get('/ranking/user', async (req, res) => { + const username = req.query.username; + const category = req.query.category; + + try { + // Fetch the user with the specified username + const user = await User.findOne({ username }); + + // If user not found, return error + if (!user) { + return res.status(400).json("Error: User not found"); + } + + // Extract ranking info for the specified category + const rankingInfo = { + username: user.username, + category, + points: user.ranking[category].points, + questions: user.ranking[category].questions, + correct: user.ranking[category].correct, + wrong: user.ranking[category].wrong + }; + + res.status(200).json(rankingInfo); + } catch (error) { + res.status(400).json({ error: error.message }); + } +}); + + + app.post("/addpoints", async (req, res) => { const username = req.body.username; const category = req.body.category; diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index d00172c..ad9e64f 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -15,7 +15,7 @@ defineFeature(feature, test => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS ? await puppeteer.launch() - : await puppeteer.launch({ headless: false, slowMo:5 }); + : await puppeteer.launch({ headless: false, slowMo:60 }); page = await browser.newPage(); //Way of setting up the timeout setDefaultOptions({ timeout: 10000 }) From 5ac7fea83b26f3f8e198d7d4bbbc5a44ceb8db3e Mon Sep 17 00:00:00 2001 From: uo287841 Date: Tue, 16 Apr 2024 16:24:21 +0200 Subject: [PATCH 3/7] user image and modification of navbar and app --- webapp/src/App.jsx | 2 ++ webapp/src/components/Navbar.jsx | 7 ++++++- webapp/src/components/ranking/profile_img.webp | Bin 0 -> 7626 bytes 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 webapp/src/components/ranking/profile_img.webp diff --git a/webapp/src/App.jsx b/webapp/src/App.jsx index 80e81ba..bd0c101 100644 --- a/webapp/src/App.jsx +++ b/webapp/src/App.jsx @@ -6,6 +6,7 @@ import Login from './components/Login'; import RankingsLayout from './components/ranking/RankingLayout'; import Game from './components/Game'; import MainPage from './components/MainPage'; +import UserProfile from './components/UserProfile'; function App() { // const isAuthenticated = useIsAuthenticated() // True if user has logged in @@ -23,6 +24,7 @@ function App() { } /> } /> } /> + } /> ) diff --git a/webapp/src/components/Navbar.jsx b/webapp/src/components/Navbar.jsx index 9726c12..809073d 100644 --- a/webapp/src/components/Navbar.jsx +++ b/webapp/src/components/Navbar.jsx @@ -21,9 +21,14 @@ function Navbar() {
  • Play
  • Rankings
  • + + {isAuthenticated() && ( +
  • UserProfile
  • + )} {isAuthenticated() ? :
  • Sign in
  • } + + :
  • Sign in
  • }
diff --git a/webapp/src/components/ranking/profile_img.webp b/webapp/src/components/ranking/profile_img.webp new file mode 100644 index 0000000000000000000000000000000000000000..4a19dcd59b033f46050561ed5a1f37d94d14d3db GIT binary patch literal 7626 zcmcIo1y>xwvR)h#+%-76xO;Gi;9+rs1r`VpED#)mFAfRr9z3`PcL*NbA-D(2!agGR zz555=oayPB?&|9Ls=hisXS9^$<-4c=09`q04X}og-V*=-K>FBp5r5xOFEkV}aRC4X z%3k|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P_eyY_rpU52LytU*OCp9&W}z?tFp2Fuhmd*?1bhay!rH$hta5#G6mc_}q^z@q9< zc?r^_M%K^bK5XFI!q@Y-sg|_zu?Mq5JR)X}(f+Uz{s?L_BoC&_H@$?*74~oiRkQJA z5Q<9ri;w|4v^gq#NJ}6FJ$V*_5}YP>ef;3DrL<1-l60jlh{xL?75*3+Y4Hqz`y zzEu68Q@b)fqKF1vo~i`u?)Udhn+~l^&Bg(uxs=o25ky#zSon%VRg8n_E>y%2QLPFa zt_j!xNp1as&j_Z7E>^ky5UXdw;NfjaHy$)nMvolFT0vG-U4QhL$h^b(#dx{PgM}Uc zyIBJk0WTVKW6cY%&8!S)7!5pdgk$kqL6X!DCbI#*36;d5exN~yZ``v^V`<-F? zqx8dZ&*2ZW Date: Sun, 21 Apr 2024 12:14:44 +0200 Subject: [PATCH 4/7] Line 28: changed {isAuthenticated() ? :
  • Sign in
  • } diff --git a/webapp/src/components/Navbar.test.js b/webapp/src/components/Navbar.test.js new file mode 100644 index 0000000..0c00b9b --- /dev/null +++ b/webapp/src/components/Navbar.test.js @@ -0,0 +1,46 @@ +import React from 'react'; +import { render, fireEvent } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import Navbar from './Navbar'; +import useIsAuthenticated from 'react-auth-kit/hooks/useIsAuthenticated'; +import useSignOut from 'react-auth-kit/hooks/useSignOut'; + +jest.mock('react-auth-kit/hooks/useIsAuthenticated'); +jest.mock('react-auth-kit/hooks/useSignOut'); + +describe('Navbar', () => { + + beforeEach(() => { + // Reset mock function calls before each test + jest.clearAllMocks(); + }); + + it('renders authenticated user links and logout button', () => { + useIsAuthenticated.mockReturnValue(() => true); + const { getByText } = render( + + + + ); + + expect(getByText('WIQ')).toBeInTheDocument(); + expect(getByText('Play')).toBeInTheDocument(); + expect(getByText('Rankings')).toBeInTheDocument(); + expect(getByText('UserProfile')).toBeInTheDocument(); + expect(getByText('Logout')).toBeInTheDocument(); + }); + + it('renders unauthenticated user links and sign-in link', () => { + useIsAuthenticated.mockReturnValue(() => false); + const { getByText } = render( + + + + ); + + expect(getByText('WIQ')).toBeInTheDocument(); + expect(getByText('Play')).toBeInTheDocument(); + expect(getByText('Rankings')).toBeInTheDocument(); + expect(getByText('Sign in')).toBeInTheDocument(); + }); +}); diff --git a/webapp/src/components/UserProfile.test.js b/webapp/src/components/UserProfile.test.js new file mode 100644 index 0000000..4215e00 --- /dev/null +++ b/webapp/src/components/UserProfile.test.js @@ -0,0 +1,59 @@ +import React from 'react'; +import { render, waitFor, fireEvent } from '@testing-library/react'; +import UserProfile from './UserProfile'; +import axios from 'axios'; +import useAuthUser from 'react-auth-kit/hooks/useAuthUser'; + +jest.mock('axios'); +jest.mock('react-auth-kit/hooks/useAuthUser', () => jest.fn()); + +describe('UserProfile', () => { + beforeEach(() => { + useAuthUser.mockReturnValue({ + username: 'testUser', + email: 'test@example.com', + createdAt: '2024-01-01T00:00:00Z', + }); + }); + + it('renders user details', async () => { + axios.get.mockResolvedValueOnce({ + data: { + questions: 10, + correct: 7, + wrong: 3, + }, + }); + + const { getByText } = render(); + + await waitFor(() => { + expect(getByText('Username: testUser')).toBeInTheDocument(); + expect(getByText('Email: test@example.com')).toBeInTheDocument(); + expect(getByText('Joined: 1/1/2024')).toBeInTheDocument(); + expect(getByText('Total Answered Questions: 10')).toBeInTheDocument(); + expect(getByText('Right Answers: 7')).toBeInTheDocument(); + expect(getByText('Wrong Answers: 3')).toBeInTheDocument(); + }); + }); + + it('changes category when category button is clicked', async () => { + axios.get.mockResolvedValueOnce({ + data: { + questions: 5, + correct: 3, + wrong: 2, + }, + }); + + const { getByText } = render(); + + fireEvent.click(getByText('Flags')); + + await waitFor(() => { + expect(getByText('Total Answered Questions: 5')).toBeInTheDocument(); + expect(getByText('Right Answers: 3')).toBeInTheDocument(); + expect(getByText('Wrong Answers: 2')).toBeInTheDocument(); + }); + }); + }); \ No newline at end of file From 3093b898ffe85da055b6172384f1b8bd601121bb Mon Sep 17 00:00:00 2001 From: uo287841 Date: Sun, 21 Apr 2024 12:27:09 +0200 Subject: [PATCH 5/7] Navbar Test and UserProfile test --- webapp/src/components/Navbar.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webapp/src/components/Navbar.test.js b/webapp/src/components/Navbar.test.js index 0c00b9b..f0d5e2c 100644 --- a/webapp/src/components/Navbar.test.js +++ b/webapp/src/components/Navbar.test.js @@ -14,7 +14,7 @@ describe('Navbar', () => { // Reset mock function calls before each test jest.clearAllMocks(); }); - + it('renders authenticated user links and logout button', () => { useIsAuthenticated.mockReturnValue(() => true); const { getByText } = render( @@ -43,4 +43,5 @@ describe('Navbar', () => { expect(getByText('Rankings')).toBeInTheDocument(); expect(getByText('Sign in')).toBeInTheDocument(); }); + }); From f36aae0fc6b9168cfb4b48acf1673f0253186091 Mon Sep 17 00:00:00 2001 From: uo287841 Date: Thu, 25 Apr 2024 00:27:03 +0200 Subject: [PATCH 6/7] Modifies NavBarTest --- webapp/src/components/Navbar.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/Navbar.test.js b/webapp/src/components/Navbar.test.js index f0d5e2c..0e80380 100644 --- a/webapp/src/components/Navbar.test.js +++ b/webapp/src/components/Navbar.test.js @@ -27,7 +27,7 @@ describe('Navbar', () => { expect(getByText('Play')).toBeInTheDocument(); expect(getByText('Rankings')).toBeInTheDocument(); expect(getByText('UserProfile')).toBeInTheDocument(); - expect(getByText('Logout')).toBeInTheDocument(); + expect(getByText('Log out')).toBeInTheDocument(); }); it('renders unauthenticated user links and sign-in link', () => { @@ -41,7 +41,7 @@ describe('Navbar', () => { expect(getByText('WIQ')).toBeInTheDocument(); expect(getByText('Play')).toBeInTheDocument(); expect(getByText('Rankings')).toBeInTheDocument(); - expect(getByText('Sign in')).toBeInTheDocument(); + expect(getByText('Log In')).toBeInTheDocument(); }); }); From 2eacb7e81db7db17a6b2f440418f2995e5a08d11 Mon Sep 17 00:00:00 2001 From: uo287841 Date: Thu, 25 Apr 2024 00:34:59 +0200 Subject: [PATCH 7/7] changed && by ? --- webapp/src/components/Navbar.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/Navbar.jsx b/webapp/src/components/Navbar.jsx index 8adba39..f6b49fa 100644 --- a/webapp/src/components/Navbar.jsx +++ b/webapp/src/components/Navbar.jsx @@ -39,9 +39,9 @@ function Navbar() {
  • Rankings
  • - {isAuthenticated() && ( + {isAuthenticated() ? (
  • UserProfile
  • - )} + ):"" }