Skip to content

Commit

Permalink
Merge pull request #9 from fga-eps-mds/dev
Browse files Browse the repository at this point in the history
Release 2
  • Loading branch information
eliseukadesh67 authored Aug 22, 2024
2 parents 7b643a6 + e31e05b commit c6b2f16
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 44 deletions.
19 changes: 6 additions & 13 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ on:
push:
branches:
- master
- dev
pull_request:
# types: [opened, synchronize, reopened]
branches:
- master
- dev

jobs:
sonarcloud:
Expand All @@ -19,7 +20,7 @@ jobs:
fetch-depth: 0

- name: Instala dependências
run: yarn
run: yarn install

- name: Executa linter
run: yarn lint
Expand All @@ -28,7 +29,8 @@ jobs:
run: yarn test:all
env:
URL_USER_SERVICE: ${{secrets.URL_USER_SERVICE}}
URL_PRNTER_SERVICE: ${{secrets.URL_PRINTER_SERVICE}}
URL_PRINTER_SERVICE: ${{secrets.URL_PRINTER_SERVICE}}
URL_CONTRACT_SERVICE: ${{secrets.URL_CONTRACT_SERVICE}}
URL_SCHEDULER_SERVICE: ${{secrets.URL_SCHEDULER_SERVICE}}

- name: Executa SonarCloud Scan
Expand All @@ -38,14 +40,5 @@ jobs:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
SONAR_TOKEN: ${{secrets.SONAR_TOKEN}}
URL_USER_SERVICE: ${{secrets.URL_USER_SERVICE}}
URL_PRNTER_SERVICE: ${{secrets.URL_PRINTER_SERVICE}}
URL_PRINTER_SERVICE: ${{secrets.URL_PRINTER_SERVICE}}
URL_SCHEDULER_SERVICE: ${{secrets.URL_SCHEDULER_SERVICE}}

- name: Envia cobertura para o Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
flags: jest
name: 2023.2-PrintGo-ApiGateway
verbose: true
4 changes: 4 additions & 0 deletions .github/workflows/metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ on:
pull_request:
branches:
- master
- dev
types: [closed]
push:
branches:
- master

jobs:
release:
Expand Down
6 changes: 3 additions & 3 deletions src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ app.get('/', (req, res) => {
});

app.use('/schedular', httProxy(process.env.URL_SCHEDULAR_SERVICE ? process.env.URL_SCHEDULAR_SERVICE : 'https://2023-1-schedula-gerenciador-de-localidades.vercel.app', { timeout: 10000 }));
app.use('/user', httProxy(process.env.URL_USER_SERVICE ? process.env.URL_USER_SERVICE : 'https://2023-2-print-go-user-service-seven.vercel.app', { timeout: 10000 }));
app.use('/printer', httProxy(process.env.URL_PRINTER_SERVICE ? process.env.URL_PRINTER_SERVICE : 'https://2023-2-print-go-printer-service.vercel.app', { timeout: 10000 }));
app.use('/contract', httProxy(process.env.URL_CONTRACT_SERVICE, { timeout: 10000 }));
// app.use('/user', httProxy(process.env.URL_USER_SERVICE, { timeout: 10000 }));
app.use('/printer', httProxy(process.env.URL_PRINTER_SERVICE ? process.env.URL_PRINTER_SERVICE : 'https://two024-1-printgo-printerservice-1.onrender.com/', { timeout: 10000 }));
app.use('/contract', httProxy(process.env.URL_CONTRACT_SERVICE ? process.env.URL_CONTRACT_SERVICE: 'https://two024-1-printgo-contractservice-0x4g.onrender.com/', { timeout: 10000 }));

const PORT = process.env.PORT || 4000;
const gateway = app.listen(PORT, () => {
Expand Down
66 changes: 38 additions & 28 deletions tests/gateway.spec.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
import request from 'supertest';
import { app, gateway } from '../src/gateway';
import 'dotenv/config';

describe('GET /', () => {
beforeAll(() => {
process.env.URL_USER_SERVICE = "https://2023-2-print-go-user-service-seven.vercel.app"
process.env.URL_PRINTER_SERVICE = "https://2023-2-print-go-printer-service.vercel.app"
process.env.URL_SCHEDULAR_SERVICE = "https://2023-1-schedula-gerenciador-de-localidades.vercel.app"

})
afterAll((done) => {
gateway.close(done);
jest.mock('express-http-proxy', () => jest.fn((url, options) => {
return (req, res, next) => {
res.status(200).json({ message: `Proxied to ${url}` });
};
}));

describe('API Gateway', () => {
afterAll(() => {
gateway.close();
});

test('should proxy requests to /schedular', async () => {
const res = await request(app).get('/schedular');
expect(res.statusCode).toEqual(200);
expect(res.body).toEqual({ message: 'Proxied to ' + (process.env.URL_SCHEDULER_SERVICE || 'https://2023-1-schedula-gerenciador-de-localidades.vercel.app') });
});

it('should return a message "Running Gateway"', async () => {
const response = await request(app).get('/');
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('message', 'Running Gateway');
});

it('should return a 200 status and the correct message', async () => {
const response = await request(app).get('/');
expect(response.status).toBe(200);
expect(response.body.message).toBe('Running Gateway');
});
// test('should proxy requests to /user', async () => {
// const res = await request(app).get('/user');
// expect(res.statusCode).toEqual(200);
// expect(res.body).toEqual({ message: 'Proxied to ' + process.env.URL_USER_SERVICE });
// });

it('should return a 200 status and the correct message', async () => {
const response = await request(app).get('/printer/impressora');
expect(response.status).toBe(200);
});
it('should return a 200 status and the correct message', async () => {
const response = await request(app).get('/user');
expect(response.status).toBe(200);
});
it('should return a 200 status and the correct message', async () => {
const response = await request(app).get('/schedular');
expect(response.status).toBe(200);
});
});
test('should proxy requests to /printer', async () => {
const res = await request(app).get('/printer');
expect(res.statusCode).toEqual(200);
expect(res.body).toEqual({ message: 'Proxied to ' + (process.env.URL_PRINTER_SERVICE || 'https://two024-1-printgo-printerservice-1.onrender.com/') });
});

test('should proxy requests to /contract', async () => {
const res = await request(app).get('/contract');
expect(res.statusCode).toEqual(200);
expect(res.body).toEqual({ message: 'Proxied to ' + (process.env.URL_CONTRACT_SERVICE || 'https://two024-1-printgo-contractservice-0x4g.onrender.com/') });
});
});

0 comments on commit c6b2f16

Please sign in to comment.