mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
share by email code and tests removed
This commit is contained in:
parent
46c17ba127
commit
95f914ce3e
2 changed files with 0 additions and 70 deletions
|
|
@ -5,46 +5,6 @@ import { ENV_VARIABLES } from '../../constants';
|
|||
jest.mock('axios');
|
||||
const mockedAxios = axios as jest.Mocked<typeof axios>;
|
||||
|
||||
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';
|
||||
|
|
|
|||
|
|
@ -836,36 +836,6 @@ public async login(email: string, password: string): Promise<any> {
|
|||
}
|
||||
}
|
||||
|
||||
async ShareQuiz(quizId: string, email: string): Promise<ApiResponse> {
|
||||
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<string> {
|
||||
try {
|
||||
if (!quizId) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue