Skip to content

Commit

Permalink
Fixed spelling mistake, added parameters to fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
juli-txt committed Sep 12, 2024
1 parent 31337a6 commit 4ca755a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
6 changes: 5 additions & 1 deletion src/services/Rating/fetchStudentRatings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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')
})
})
8 changes: 6 additions & 2 deletions src/services/Rating/fetchStudentRatings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StudentRating[]>(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<StudentRating[]>(getConfig().BACKEND + `/user/${userId}/student/${studentId}/rating`, {
method: 'GET',
credentials: 'include',
headers: {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/translation/translationGerman.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 4ca755a

Please sign in to comment.