-
Notifications
You must be signed in to change notification settings - Fork 1
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 #1 from AYD1-G9/release/v-3.0.0
Fase 2 del proyecto
- Loading branch information
Showing
33 changed files
with
2,707 additions
and
583 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
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 |
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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"] |
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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'); | ||
}); | ||
|
||
}); |
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,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'); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.