forked from fga-eps-mds/2023.2-PrintGo-ApiGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from fga-eps-mds/dev
Release 2
- Loading branch information
Showing
4 changed files
with
51 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,11 @@ on: | |
pull_request: | ||
branches: | ||
- master | ||
- dev | ||
types: [closed] | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
release: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/') }); | ||
}); | ||
}); |