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

150 increase code coverage #151

Merged
merged 13 commits into from
Apr 28, 2024
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