Skip to content

Commit

Permalink
Merge pull request #1 from AYD1-G9/release/v-3.0.0
Browse files Browse the repository at this point in the history
Fase 2 del proyecto
  • Loading branch information
Tiwue authored Oct 26, 2024
2 parents 8e19f27 + 879bfa8 commit a6a54c6
Show file tree
Hide file tree
Showing 33 changed files with 2,707 additions and 583 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/cicd-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: CI/CD Pipeline backend

on:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Set environment variables
run: |
cd ./backend
echo "HOST=${{ secrets.HOST }}" >> .env
echo "PORT=${{ secrets.PORT }}" >> .env
echo "DB_HOST=${{ secrets.DB_HOST }}" >> .env
echo "DB_PORT=${{ secrets.DB_PORT }}" >> .env
echo "DB_NAME=${{ secrets.DB_NAME }}" >> .env
echo "DB_USER=${{ secrets.DB_USER }}" >> .env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
echo "ACCESS_KEY_ID=${{ secrets.ACCESS_KEY_ID }}" >> .env
echo "SECRET_ACCESS_KEY=${{ secrets.SECRET_ACCESS_KEY }}" >> .env
echo "REGION=${{ secrets.REGION }}" >> .env
echo "BUCKET=${{ secrets.BUCKET }}" >> .env
echo "FRONT_URL=${{ secrets.FRONT_URL }}" >> .env
echo "EMAIL_ORIGIN=${{ secrets.EMAIL_ORIGIN }}" >> .env
echo "APP_KEY=${{ secrets.APP_KEY }}" >> .env
echo "EMAIL_HOST=${{ secrets.EMAIL_HOST }}" >> .env
echo "REACT_APP_API_HOST=${{ secrets.REACT_APP_API_HOST }}" >> .env
- name: Install dependencies
run: |
cd ./backend
npm install
- name: Run tests
run: |
cd ./backend
npm test
- name: Log in to DockerHub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

- name: Build and push Docker image
run: |
cd ./backend
docker build -t ${{ secrets.DOCKER_USERNAME }}/backend-ayd-image:latest .
docker push ${{ secrets.DOCKER_USERNAME }}/backend-ayd-image:latest
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Run deployment script via SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_KEY }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/backend-ayd-image:latest
docker stop backend-ayd-container || true
docker rm backend-ayd-container || true
docker run -d --name backend-ayd-container --env-file /home/ubuntu/ayd/AyD1S2-Proyecto_F1_9/backend/.env -p ${{ secrets.PORT }}:4000 ${{ secrets.DOCKER_USERNAME }}/backend-ayd-image:latest
13 changes: 13 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Ignorar dependencias instaladas
node_modules

# Ignorar archivos de pruebas
**/*.test.mjs
**/*.spec.mjs
__tests__/

# Ignorar archivos de configuración y caché
.env
npm-debug.log
yarn-debug.log
yarn-error.log
20 changes: 20 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Usa una imagen base de Node.js
FROM node:18

# Establece el directorio de trabajo en el contenedor
WORKDIR /app

# Copia el archivo package.json y package-lock.json
COPY package*.json ./

# Instala las dependencias de la aplicación
RUN npm install

# Copia el resto del código de la aplicación
COPY . .

# Expone el puerto en el que la aplicación escucha
EXPOSE 4000

# Comando para ejecutar la aplicación
CMD ["npm", "start"]
10 changes: 0 additions & 10 deletions backend/__tests__/changeStorageRequest.test.js

This file was deleted.

10 changes: 5 additions & 5 deletions backend/__tests__/files.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import request from 'supertest';
import app from '../server.mjs'; // Puedes seguir usando import para tus módulos
import app from '../index.test.mjs'; // Puedes seguir usando import para tus módulos

test('POST /uploadFile, debe retornar un atributo status=200, file', async () => {
const res = await request(app).post('/uploadFile').send({
idUser: 2,
username: 'tiky',
username: 'test',
folder: 1,
file: {
name: 'test.txt',
Expand All @@ -22,11 +22,11 @@ import app from '../server.mjs'; // Puedes seguir usando import para tus módulo
test('POST /createFolder, debe retornar un atributo status=200, y el id del folder', async () => {
const res = await request(app).post('/createFolder').send({
idUser: 2,
username: 'tiky',
username: 'test',
parentFolder: 1,
name: 'test'
name: 'test folder'
});
expect(res.status).toBe(200);
expect(res.body).toHaveProperty('status', 200);
expect(res.body).toHaveProperty('file');
expect(res.body).toHaveProperty('folder');
}, 30000); // 30 segundos de timeout
4 changes: 2 additions & 2 deletions backend/__tests__/profile.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import request from 'supertest'
import app from '../server.mjs'
import app from '../index.test.mjs'

test('POST /uploadProfile, debe retornar un atributo status=200, icon, message', async () => {
const res = await request(app).post('/uploadProfile').send({ ID_USUARIO: 2, changes: {NOMBRE: 'John', APELLIDO: 'Connor'}})
const res = await request(app).post('/uploadProfile').send({ ID_USUARIO: 2, changes: {NOMBRE: 'Steven', APELLIDO: 'Gonzalez'}})
expect(res.status).toBe(200);
expect(res.body).toHaveProperty('status', 200);
expect(res.body).toHaveProperty('icon');
Expand Down
10 changes: 0 additions & 10 deletions backend/__tests__/registerDeleteAccountRquest.test.js

This file was deleted.

68 changes: 68 additions & 0 deletions backend/__tests__/share.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import request from 'supertest';
import app from '../index.test.mjs';

describe('Share items tests', () => {

test('POST /shareItem should share a file successfully', async () => {
const res = await request(app).post('/shareItem').send({
currentUserId: 2, // Propietario
userIdentifier: '[email protected]', // Destinatario
idFile: 1, // Suponemos un archivo con ID 1
type: 'file'
});
expect(res.status).toBe(200);
expect(res.body).toHaveProperty('status', 200);
expect(res.body).toHaveProperty('message', 'File shared successfully');
});

test('POST /shareItem should return 400 when trying to share with oneself', async () => {
const res = await request(app).post('/shareItem').send({
currentUserId: 2, // Propietario
userIdentifier: '[email protected]', // Mismo usuario que el propietario
idFile: 1,
type: 'file'
});
expect(res.status).toBe(400);
expect(res.body).toHaveProperty('message', 'You cannot share the file with yourself');
});

test('POST /getSharedWithMeItems should return shared items for user', async () => {
const res = await request(app).post('/getSharedWithMeItems').send({
idUsuario: 3, // Destinatario
});
expect(res.status).toBe(200);
expect(res.body).toHaveProperty('status', 200);
expect(res.body).toHaveProperty('children');
});

test('POST /showSharedIconInSideBar should return icon visibility for shared items', async () => {
const res = await request(app).post('/showSharedIconInSideBar').send({
idUsuario: 3, // Destinatario
});
expect(res.status).toBe(200);
expect(res.body).toHaveProperty('status', 200);
expect(res.body).toHaveProperty('icon');
});

test('POST /getUsersWithItemShared should return users with whom the file is shared', async () => {
const res = await request(app).post('/getUsersWithItemShared').send({
idItem: 1, // Suponemos un archivo con ID 1
type: 'file'
});
expect(res.status).toBe(200);
expect(res.body).toHaveProperty('status', 200);
expect(res.body).toHaveProperty('users');
});

test('POST /stopSharing should unshare the file', async () => {
const res = await request(app).post('/stopSharing').send({
idItem: 1, // Archivo con ID 1
type: 'file',
idUser: 3, // Destinatario
});
expect(res.status).toBe(200);
expect(res.body).toHaveProperty('status', 200);
expect(res.body).toHaveProperty('message', 'File unshared successfully');
});

});
9 changes: 2 additions & 7 deletions backend/__tests__/storage.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import request from 'supertest';
import app from '../server.mjs'; // Puedes seguir usando import para tus módulos
import app from '../index.test.mjs'; // Puedes seguir usando import para tus módulos

test('POST /getStorage debería devolver un json con los tributos status:200, used, total', async () => {
const res = await request(app).post('/getStorage').send({ username: 'tiky' });
const res = await request(app).post('/getStorage').send({ username: 'test' });
expect(res.status).toBe(200);
expect(res.body).toHaveProperty('status', 200);
expect(res.body).toHaveProperty('used');
expect(res.body).toHaveProperty('total');
});

test('POST /getStorage debería retornar status 400 ya que los parametros estan nulos', async () => {
const res = await request(app).post('/getStorage').send({ username: undefined });
expect(res.status).toBe(400);
expect(res.body).toHaveProperty('message', 'User ID is required to get storage used');
});
10 changes: 0 additions & 10 deletions backend/__tests__/user.test.js

This file was deleted.

Loading

0 comments on commit a6a54c6

Please sign in to comment.