Skip to content

Commit

Permalink
Merge pull request #151 from Arquisoft/150-increase-code-coverage
Browse files Browse the repository at this point in the history
150 increase code coverage
  • Loading branch information
uo289267 authored Apr 28, 2024
2 parents 4dd8ba2 + 7036926 commit 5a4318c
Show file tree
Hide file tree
Showing 18 changed files with 653 additions and 298 deletions.
154 changes: 154 additions & 0 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,158 @@ describe('Gateway Service without mocked micro services', () => {
expect(error.response.data.error).toBe('Internal server error');
}
});

it('should not forward login request and give 400', async () => {
axios.post.mockImplementation((url, data) => {
if (url.endsWith('/login')) {
return Promise.reject({
response: {
status: 400,
data: { message: 'Invalid username or password' },
},
});
}
});

try{
await request(app)
.post('/login')
.send({ username: 'testuser', password: 'testpassword' });

} catch(error){
expect(error.response.status).toBe(400);
expect(error.response.data.error).toBe('Invalid username or password');
}
});

it('should not forward adduser request and give 500', async () => {
try{
await request(app)
.post('/adduser')
.send({ username: 'testuser', password: 'testpassword' });

} catch(error){
expect(error.response.status).toBe(500);
expect(error.response.data.error).toBe('Internal server error');
}
});

it('should not forward forgetPassword request and give 500', async () => {
try{
await request(app)
.post('/forgetPassword');

} catch(error){
expect(error.response.status).toBe(500);
expect(error.response.data.error).toBe('Internal server error');
}
});

it('should not forward changePassword request and give 500', async () => {
try{
await request(app)
.post('/changePassword')
.set('token', 'valorDelToken');;

} catch(error){
expect(error.response.status).toBe(500);
expect(error.response.data.error).toBe('Internal server error');
}
});

it('should not forward questions request and give 500', async () => {
try{
await request(app)
.get('/questions')
.set('token', 'valorDelToken');;

} catch(error){
expect(error.response.status).toBe(500);
expect(error.response.data.error).toBe('Internal server error');
}
});

it('should not forward questions request and give 500', async () => {
try{
await request(app)
.get('/questions/es/1/CAPITAL')
.set('token', 'valorDelToken');;

} catch(error){
expect(error.response.status).toBe(500);
expect(error.response.data.error).toBe('Internal server error');
}
});

it('should not forward questions request and give 500', async () => {
try{
await request(app)
.get('/questions/es/1')
.set('token', 'valorDelToken');;

} catch(error){
expect(error.response.status).toBe(500);
expect(error.response.data.error).toBe('Internal server error');
}
});

it('should not forward questions request and give 500', async () => {
try{
await request(app)
.get('/questions/es')
.set('token', 'valorDelToken');;

} catch(error){
expect(error.response.status).toBe(500);
expect(error.response.data.error).toBe('Internal server error');
}
});

it('should not forward record request and give 500', async () => {
try{
await request(app)
.post('/record')
.set('token', 'valorDelToken');;

} catch(error){
expect(error.response.status).toBe(500);
expect(error.response.data.error).toBe('Internal server error');
}
});

it('should not forward record request and give 500', async () => {
try{
await request(app)
.get('/record/ranking/top10')
.set('token', 'valorDelToken');;

} catch(error){
expect(error.response.status).toBe(500);
expect(error.response.data.error).toBe('Internal server error');
}
});

it('should not forward record request and give 500', async () => {
try{
await request(app)
.get('/record/ranking/user')
.set('token', 'valorDelToken');;

} catch(error){
expect(error.response.status).toBe(500);
expect(error.response.data.error).toBe('Internal server error');
}
});

it('should not forward record request and give 500', async () => {
try{
await request(app)
.get('/record/user')
.set('token', 'valorDelToken');;

} catch(error){
expect(error.response.status).toBe(500);
expect(error.response.data.error).toBe('Internal server error');
}
});
});
8 changes: 5 additions & 3 deletions questionGenerator/src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class Main {

private static QuestionGenerator qg = QuestionGenerator.getInstance();

private static final long TIME_SKIP = 18000000; //5 hours
// private static final long TIME_SKIP = 18000000; //5 hours
// private static final long TIME_SKIP = 43200000; //12 hours
//private static final long TIME_SKIP = 1000; //1 minute
private static final long TIME_SKIP = 10000; //10 minutes


private static String[] languages = {"en", "es", "tr"};
Expand All @@ -32,10 +32,12 @@ public class Main {
public static void main(String[] args) {
List<String> questions = generate().stream().map(q -> q.getJSON().toString()).toList();
while(true) {
long timeStart = System.currentTimeMillis();
QuestionRepository.getInstance().populate(questions);
questions = generate().stream().map(q -> q.getJSON().toString()).toList();
long timeFinish = System.currentTimeMillis();
try {
Thread.sleep(TIME_SKIP);
Thread.sleep(TIME_SKIP - (timeFinish - timeStart));
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down
123 changes: 13 additions & 110 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5a4318c

Please sign in to comment.