Skip to content

Commit

Permalink
Small fixes to apis-gateway tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosBarrilVillaverde committed Apr 30, 2024
1 parent ed5736a commit 110d0d1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 58 deletions.
38 changes: 1 addition & 37 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,40 +251,4 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: apisgatewayservice
platforms: linux/arm64
docker-push-apisgatewayservice:
name: Push apis gateway service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [e2e-tests]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es6c/apisgatewayservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: apisgatewayservice
platforms: linux/arm64
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-webapp, docker-push-questiongeneratorservice, docker-push-storequestionservice, docker-push-userstatsservice, docker-push-wikidataextractorservice, docker-push-gameservice]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
with:
host: ${{ secrets.DEPLOY_HOST }}
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/arquisoft/wiq_es6c/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_es6c/master/.env -O .env
docker compose --profile prod down
docker compose --profile prod up -d --pull always
platforms: linux/arm64
5 changes: 1 addition & 4 deletions apisgatewayservice/apis-gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ function catchAction(error, res) {
else if('response' in error && 'status' in error.response){
res.status(error.response.status).json({ error: 'Unknown error' });
} else {
console.log("Unknown error: " + error);
res.status(500).json({ error: 'Internal server error' });
}
// } else {
// res.status(500).json({ error: 'Internal server error' });
// }
}

app.use(metricsMiddleware);
Expand Down
43 changes: 26 additions & 17 deletions apisgatewayservice/apis-gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,20 @@ describe('User Service', () => {
describe('/users', () => {
it('should return user information', async () => {
const mockUsers = [
{ username: 'user1', createdAt: new Date() },
{ username: 'user2', createdAt: new Date() }
{ username: 'user1'},
{ username: 'user2'}
];
User.find = jest.fn().mockResolvedValue(mockUsers);


axios.get.mockResolvedValue({ data: mockUsers });

const res = await request(app).get('/users');

expect(res.statusCode).toEqual(200);

expect(res.body).toEqual(mockUsers);
});

it('should handle errors', async () => {

User.find = jest.fn().mockRejectedValue(new Error('Database error'));

const res = await request(app).get('/users');

expect(res.statusCode).toEqual(500);

expect(res.body).toEqual({ error: 'Database error' });
});
});
});

Expand All @@ -53,12 +45,29 @@ describe('Gateway Service', () => {
expect(res.body).toEqual(mockData);
});

it('should handle errors', async () => {
axios.get.mockRejectedValue(new Error('Error'));
});
});

describe('Error Handling', () => {
describe('Error getting users', () => {
it('should handle error when getting users', async () => {
axios.get.mockRejectedValue(new Error('Failed to fetch users'));

const res = await request(app).get('/users');

expect(res.statusCode).toEqual(500);
expect(res.body).toEqual({ error: 'Internal server error' });
});
});

describe('Error getting history of questions', () => {
it('should handle error when getting history of questions', async () => {
axios.get.mockRejectedValue(new Error('Failed to fetch questions history'));

const res = await request(app).get('/history/questions');

expect(res.statusCode).toEqual(500);
expect(res.body).toEqual({ error: 'Error' });
expect(res.body).toEqual({ error: 'Internal server error' });
});
});
});
});

0 comments on commit 110d0d1

Please sign in to comment.