Skip to content

Commit

Permalink
Added tests for url construction
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Mario committed Apr 28, 2024
1 parent d4307c6 commit e692266
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
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')
})
});

0 comments on commit e692266

Please sign in to comment.