Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for url construction #169

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions webapp/src/components/ForgetPassword/ForgetPassword.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ describe('ForgetPassword Component', () => {
await expect(forgetPasswordFunctions.changePassword('[email protected]', 'testuser', 'newpassword', 'newpassword')).rejects.toThrow('Failed to change password');
});
});

describe('checkUrl', () => {
it('should have base url', async () => {
expect(forgetPasswordFunctions.apiUrl).toEqual('http://localhost:8000');
});

it('should have env variable url', async () => {
process.env.REACT_APP_API_ENDPOINT = 'test';
forgetPasswordFunctions = new ForgetPasswordFunctions();
expect(forgetPasswordFunctions.apiUrl).toEqual('test');
});
});
});
});

Expand Down
10 changes: 10 additions & 0 deletions webapp/src/components/questionView/QuestionGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ describe('QuestionGenerator', () => {
expect(questions.length).toBe(1);
expect(questions[0].question).toBe("What is the population of Oviedo?");
});

it('should have the base url', () => {
expect(questionGenerator.apiUrl).toEqual('http://localhost:8000/questions')
})

it('should not have the base url', () => {
process.env.REACT_APP_API_ENDPOINT = 'test';
questionGenerator = new QuestionGenerator();
expect(questionGenerator.apiUrl).toEqual('test/questions')
})
});
44 changes: 44 additions & 0 deletions webapp/src/components/ranking/RankingRetriever.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import axios from 'axios';
import RankingRetriever from './RankingRetriever'; // Ruta a tu archivo RankingRetriever

jest.mock('axios'); // Simula las llamadas a Axios

describe('RankingRetriever Tests', () => {
let rankingRetriever;

beforeEach(() => {
rankingRetriever = new RankingRetriever();
});

test('Throws error if endpoint is not set for getTopTen', async () => {
axios.get.mockRejectedValue(new Error('Endpoint not found')); // Simula error

try {
await rankingRetriever.getTopTen('dummy-token');
} catch (error) {
expect(error).toBeInstanceOf(Error); // Verifica que se lanzó un error
expect(error.message).toContain('Endpoint not found'); // Verifica el mensaje del error
}
});

test('Throws error if endpoint is not set for getUser', async () => {
axios.get.mockRejectedValue(new Error('Endpoint not found')); // Simula error

try {
await rankingRetriever.getUser('dummy-user', 'dummy-token');
} catch (error) {
expect(error).toBeInstanceOf(Error); // Verifica que se lanzó un error
expect(error.message).toContain('Endpoint not found'); // Verifica el mensaje del error
}
});

test('should have the base url', () => {
expect(rankingRetriever.apiUrl).toEqual('http://localhost:8000/record/ranking')
})

test('should not have the base url', () => {
process.env.REACT_APP_API_ENDPOINT = 'test';
rankingRetriever = new RankingRetriever();
expect(rankingRetriever.apiUrl).toEqual('test/record/ranking')
})
});