From 95f914ce3e9d89202a7b49a726f5ff20c186eb41 Mon Sep 17 00:00:00 2001 From: Philippe <83185129+phil3838@users.noreply.github.com> Date: Mon, 24 Mar 2025 16:42:41 -0400 Subject: [PATCH] share by email code and tests removed --- .../services/ShareQuizService.test.tsx | 40 ------------------- client/src/services/ApiService.tsx | 30 -------------- 2 files changed, 70 deletions(-) diff --git a/client/src/__tests__/services/ShareQuizService.test.tsx b/client/src/__tests__/services/ShareQuizService.test.tsx index c1e473e..1730ad4 100644 --- a/client/src/__tests__/services/ShareQuizService.test.tsx +++ b/client/src/__tests__/services/ShareQuizService.test.tsx @@ -5,46 +5,6 @@ import { ENV_VARIABLES } from '../../constants'; jest.mock('axios'); const mockedAxios = axios as jest.Mocked; -describe('ApiService', () => { - describe('shareQuiz', () => { - it('should call the API to share a quiz and return true on success', async () => { - const quizId = '123'; - const email = 'test@example.com'; - const response = { status: 200 }; - mockedAxios.put.mockResolvedValue(response); - - const result = await ApiService.ShareQuiz(quizId, email); - - expect(mockedAxios.put).toHaveBeenCalledWith( - `${ENV_VARIABLES.VITE_BACKEND_URL}/api/quiz/Share`, - { quizId, email }, - { headers: expect.any(Object) } - ); - expect(result).toBe(true); - }); - - it('should return an error message if the API call fails', async () => { - const quizId = '123'; - const email = 'test@example.com'; - const errorMessage = 'An unexpected error occurred.'; - mockedAxios.put.mockRejectedValue({ response: { data: { error: errorMessage } } }); - - const result = await ApiService.ShareQuiz(quizId, email); - - expect(result).toBe(errorMessage); - }); - - it('should return a generic error message if an unexpected error occurs', async () => { - const quizId = '123'; - const email = 'test@example.com'; - mockedAxios.put.mockRejectedValue(new Error('Unexpected error')); - - const result = await ApiService.ShareQuiz(quizId, email); - - expect(result).toBe('An unexpected error occurred.'); - }); - }); - describe('getSharedQuiz', () => { it('should call the API to get a shared quiz and return the quiz data on success', async () => { const quizId = '123'; diff --git a/client/src/services/ApiService.tsx b/client/src/services/ApiService.tsx index fa2b4e7..8f9cc67 100644 --- a/client/src/services/ApiService.tsx +++ b/client/src/services/ApiService.tsx @@ -836,36 +836,6 @@ public async login(email: string, password: string): Promise { } } - async ShareQuiz(quizId: string, email: string): Promise { - try { - if (!quizId || !email) { - throw new Error(`quizId and email are required.`); - } - - const url: string = this.constructRequestUrl(`/quiz/Share`); - const headers = this.constructRequestHeaders(); - const body = { quizId, email }; - - const result: AxiosResponse = await axios.put(url, body, { headers: headers }); - - if (result.status !== 200) { - throw new Error(`Update and share quiz failed. Status: ${result.status}`); - } - - return true; - } catch (error) { - console.log("Error details: ", error); - - if (axios.isAxiosError(error)) { - const err = error as AxiosError; - const data = err.response?.data as { error: string } | undefined; - return data?.error || 'Unknown server error during request.'; - } - - return `An unexpected error occurred.`; - } - } - async getSharedQuiz(quizId: string): Promise { try { if (!quizId) {