diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ce61f454..b26d387b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 \ No newline at end of file diff --git a/apisgatewayservice/apis-gateway-service.js b/apisgatewayservice/apis-gateway-service.js index 167cc246..04501a1c 100644 --- a/apisgatewayservice/apis-gateway-service.js +++ b/apisgatewayservice/apis-gateway-service.js @@ -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); diff --git a/apisgatewayservice/apis-gateway-service.test.js b/apisgatewayservice/apis-gateway-service.test.js index 789f7ac9..b8779246 100644 --- a/apisgatewayservice/apis-gateway-service.test.js +++ b/apisgatewayservice/apis-gateway-service.test.js @@ -12,11 +12,12 @@ 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); @@ -24,16 +25,7 @@ describe('User Service', () => { 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' }); - }); }); }); @@ -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' }); }); }); -}); +}); \ No newline at end of file