diff --git a/src/components/Dashboards/Rating/LearningElementRatingDashboard/LearningElementRatingDashboard.test.tsx b/src/components/Dashboards/Rating/LearningElementRatingDashboard/LearningElementRatingDashboard.test.tsx index 50470a9a..8f6b2162 100644 --- a/src/components/Dashboards/Rating/LearningElementRatingDashboard/LearningElementRatingDashboard.test.tsx +++ b/src/components/Dashboards/Rating/LearningElementRatingDashboard/LearningElementRatingDashboard.test.tsx @@ -1,4 +1,4 @@ -import { fireEvent, render, renderHook, screen, waitFor } from '@testing-library/react' +import { fireEvent, render, renderHook, waitFor } from '@testing-library/react' import { mockServices } from 'jest.setup' import 'react-rating-charts' import { MemoryRouter } from 'react-router-dom' diff --git a/src/components/Dashboards/Rating/StudentRatingDashboard/StudentRatingDashboard.hooks.tsx b/src/components/Dashboards/Rating/StudentRatingDashboard/StudentRatingDashboard.hooks.tsx index 4e6a8e0a..c4d8398a 100644 --- a/src/components/Dashboards/Rating/StudentRatingDashboard/StudentRatingDashboard.hooks.tsx +++ b/src/components/Dashboards/Rating/StudentRatingDashboard/StudentRatingDashboard.hooks.tsx @@ -133,7 +133,7 @@ export const useStudentRatingDashboard = (): StudentRatingDashboardHookReturn => }) // Fetch all ratings of all students. - fetchStudentRatings() + fetchStudentRatings(user.settings.user_id, user.id) .then((ratings) => { // Get the maximum rating value. const maxRatingValue = Math.max(...ratings.map((rating) => rating.rating_value)) diff --git a/src/components/Dashboards/Rating/StudentRatingDashboard/StudentRatingDashboard.test.tsx b/src/components/Dashboards/Rating/StudentRatingDashboard/StudentRatingDashboard.test.tsx index c2074379..01c39e39 100644 --- a/src/components/Dashboards/Rating/StudentRatingDashboard/StudentRatingDashboard.test.tsx +++ b/src/components/Dashboards/Rating/StudentRatingDashboard/StudentRatingDashboard.test.tsx @@ -1,4 +1,4 @@ -import { fireEvent, render, renderHook, screen, waitFor } from '@testing-library/react' +import { fireEvent, render, renderHook, waitFor } from '@testing-library/react' import { mockServices } from 'jest.setup' import 'react-rating-charts' import { MemoryRouter } from 'react-router-dom' diff --git a/src/services/Rating/fetchStudentRatings.test.tsx b/src/services/Rating/fetchStudentRatings.test.tsx index a3946189..2e29c4ee 100644 --- a/src/services/Rating/fetchStudentRatings.test.tsx +++ b/src/services/Rating/fetchStudentRatings.test.tsx @@ -30,7 +30,7 @@ describe('fetchStudentRatings', () => { // @ts-ignore fetch.mockResolvedValue(mockResponse) - const result = await fetchStudentRatings() + const result = await fetchStudentRatings(1, 1) expect(fetch).toHaveBeenCalledWith(`${getConfig().BACKEND}/student/rating`, { method: 'GET', @@ -42,4 +42,8 @@ describe('fetchStudentRatings', () => { expect(result).toEqual(inputData) }) + + it('should throw error on missing variable', async () => { + expect(fetchStudentRatings(1)).rejects.toThrow('userId and studentId are required') + }) }) diff --git a/src/services/Rating/fetchStudentRatings.ts b/src/services/Rating/fetchStudentRatings.ts index f7684960..f62d3980 100644 --- a/src/services/Rating/fetchStudentRatings.ts +++ b/src/services/Rating/fetchStudentRatings.ts @@ -10,8 +10,12 @@ import { fetchData } from '../RequestResponse' * @remarks * Returns an empty array, if there are no ratings present. */ -export const fetchStudentRatings: StudentRatingReturn = async () => { - return fetchData(getConfig().BACKEND + `/student/rating`, { +export const fetchStudentRatings: StudentRatingReturn = async (userId?: number, studentId?: number) => { + if (!userId || !studentId) { + throw new Error('userId and studentId are required') + } + + return fetchData(getConfig().BACKEND + `/user/${userId}/student/${studentId}/rating`, { method: 'GET', credentials: 'include', headers: { diff --git a/src/shared/translation/translationGerman.json b/src/shared/translation/translationGerman.json index 1336e99a..e5482782 100644 --- a/src/shared/translation/translationGerman.json +++ b/src/shared/translation/translationGerman.json @@ -1743,7 +1743,7 @@ "tooltip.openGlobalSettings": "Globale Einstellungen", "tooltip.openQuestionnaireResults": "Lerncharakteristik", "tooltip.openSettings": "Einstellungen", - "tooltip.statisticsMenuSelection": "Verschiedene Informationen zu Ihren Lernfortschritten.", + "tooltip.statisticsMenuSelection": "Verschiedene Informationen zu Ihrem Lernfortschritten.", "warning": "Warnung", "warning.offline": "Sie sind offline. Bitte überprüfen Sie Ihre Internetverbindung.", "warning.online": "Sie sind wieder online."