Skip to content

Commit

Permalink
Merge branch 'master' into 150-increase-code-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Mario committed Apr 27, 2024
2 parents 5bc0d60 + 4dd8ba2 commit aedf575
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Arquisoft_wiq_en1b&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Arquisoft_wiq_en1b)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=Arquisoft_wiq_en1b&metric=coverage)](https://sonarcloud.io/summary/new_code?id=Arquisoft_wiq_en1b)

<b>To access the game simply follow the link [here](http://wiqen1b.serveminecraft.net:3000)</b><br>
<b>To access the game simply follow the link [here](http://wiqen1b.serveminecraft.net)</b><br>
The documentation of the system can be found [here](https://arquisoft.github.io/wiq_en1b/)<br>
And the API documentation can be seen [here](http://wiqen1b.serveminecraft.net:8000/api-doc/)<br>

Expand Down
53 changes: 52 additions & 1 deletion webapp/src/components/ForgetPassword/ForgetPassword.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import userEvent from '@testing-library/user-event';
import Cookies from 'js-cookie';

import ForgetPasswordFunctions from './ForgetPasswordFunctions';
i18en.use(initReactI18next).init({
resources: {},
lng: 'en',
Expand All @@ -23,6 +23,7 @@ const mockAxios = new MockAdapter(axios);
const code = 111111
const token = "mockedToken"

jest.mock('axios');
describe('ForgetPassword Component', () => {
test('renders Ask Email component', async () => {
act( () => {
Expand Down Expand Up @@ -75,8 +76,58 @@ describe('ForgetPassword Component', () => {
});


describe('ForgetPasswordFunctions', () => {
let forgetPasswordFunctions;

beforeEach(() => {
forgetPasswordFunctions = new ForgetPasswordFunctions();
});

describe('sendEmail', () => {
it('should send email and return true on success', async () => {
axios.post.mockResolvedValue({ data: true });
const result = await forgetPasswordFunctions.sendEmail('[email protected]', 'testuser');
expect(result).toBe(true);
});

it('should throw error on failure', async () => {
axios.post.mockRejectedValue(new Error('Failed to send email'));
await expect(forgetPasswordFunctions.sendEmail('[email protected]', 'testuser')).rejects.toThrow('Failed to send email');
});
});

describe('tokenFromCode', () => {
it('should get token from code and set it', async () => {
const token = 'testToken';
axios.get.mockResolvedValue({ data: { token } });
await forgetPasswordFunctions.tokenFromCode('testCode');
expect(forgetPasswordFunctions.token).toBe(token);
});

it('should throw error on failure', async () => {
axios.get.mockRejectedValue(new Error('Failed to get token'));
await expect(forgetPasswordFunctions.tokenFromCode('testCode')).rejects.toThrow('Failed to get token');
});
});

describe('changePassword', () => {
it('should change password', async () => {
const response = { data: 'Password changed successfully' };
axios.post.mockResolvedValue(response);
const result = await forgetPasswordFunctions.changePassword('[email protected]', 'testuser', 'newpassword', 'newpassword');
expect(result).toEqual(response);
});

it('should throw error on failure', async () => {
axios.post.mockRejectedValue(new Error('Failed to change password'));
await expect(forgetPasswordFunctions.changePassword('[email protected]', 'testuser', 'newpassword', 'newpassword')).rejects.toThrow('Failed to change password');
});
});
});
});



async function insertEmail(email, username) {
const emailInput = screen.getByPlaceholderText(/addUser.email_placeholder/i);
const usernameInput = screen.getByPlaceholderText(/addUser.username_placeholder/i);
Expand Down

0 comments on commit aedf575

Please sign in to comment.