Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enviando mi contribución al proyecto Fizzbuzz #159

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = {
"ecmaVersion": "latest"
},
"rules": {
"no-unused-vars": "off",
indent: ["error", 4],
"linebreak-style": ["error", "unix"],
quotes: ["error", "double"],
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ jobs:
- uses: actions/checkout@v1
- name: Run Jest
uses: stefanoeb/[email protected]

Binary file added images/Imagen10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Imagen11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Imagen2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Imagen3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Imagen5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Imagen6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Imagen8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Imagen9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions lib/controllers/ExplorerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class ExplorerController{
const explorers = Reader.readJsonFile("explorers.json");
return ExplorerService.getAmountOfExplorersByMission(explorers, mission);
}

static getExplorersWithStack(stack){
const explorers = Reader.readJsonFile("explorers.json");
return ExplorerService.filterByStack(explorers, stack);
}
}

module.exports = ExplorerController;
7 changes: 7 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ExplorerController = require("./controllers/ExplorerController");
const express = require("express");
const { request, response } = require("express");
const app = express();
app.use(express.json());
const port = 3000;
Expand Down Expand Up @@ -32,6 +33,12 @@ app.get("/v1/fizzbuzz/:score", (request, response) => {
response.json({score: score, trick: fizzbuzzTrick});
});

app.get("/v1/explorers/stack/:stack", (request, response) =>{
const stack = request.params.stack;
const explorersWithStack = ExplorerController.getExplorersWithStack(stack);
response.json(explorersWithStack);
});

app.listen(port, () => {
console.log(`FizzBuzz API in localhost:${port}`);
});
Expand Down
4 changes: 4 additions & 0 deletions lib/services/ExplorerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class ExplorerService {
return explorersUsernames;
}

static filterByStack(explorers, stack){
const explorersWithStack = explorers.filter((explorer) => explorer.stacks.includes(stack));
return explorersWithStack;
}
}

module.exports = ExplorerService;
90 changes: 45 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
{
"name": "fizzbuzz",
"version": "1.0.0",
"description": "",
"description": "Crear un endpoint que regrese la lista de explorers filtrados por un stack",
"main": "index.js",
"scripts": {
"test": "node ./node_modules/.bin/jest",
"test": "node ./node_modules/jest/bin/jest.js",
"linter": "node ./node_modules/eslint/bin/eslint.js",
"linter-fix": "node ./node_modules/eslint/bin/eslint.js . --fix",
"server": "node ./lib/server.js"
},
"keywords": [],
"author": "",
"author": "Cecilia Muñoz",
"license": "ISC",
"devDependencies": {
"eslint": "^8.14.0",
"eslint": "^8.15.0",
"jest": "^27.5.1"
},
"dependencies": {
"express": "^4.17.3"
}
},
"directories": {
"lib": "lib",
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/CeViMu/fizzbuzz-1.git"
},
"bugs": {
"url": "https://github.com/CeViMu/fizzbuzz-1/issues"
},
"homepage": "https://github.com/CeViMu/fizzbuzz-1#readme"
}
58 changes: 51 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,60 @@
# Linter
# Requerimiento:

1. Instalar dependencia:
Crear un endpoint que regrese la lista de explorers filtrados por un stack

> npm install eslint --save-dev
# Procedimiento

2. Modificar package.json, agregar debajo de test
1. Instalamos la dependencia jest.

> "linter": "node ./node_modules/eslint/bin/eslint.js"
> npm init
> npm install --save -dev jest

3. Crear configuración en archivo .eslintrc (si se versiona)
2. Modificamos el archivo package.json en la linea de "test" pues en windows 10 hay que cambiar la dirección para que pueda funcionar jest.
![image](https://github.com/CeViMu/fizzbuzz-1/blob/master/images/Imagen2.png)

3. Agregamos prueba para el nuevo requerimiento, esta se crea en el archivo ExplorerService.test.js y tiene que filtrar los explorers que tengan el stack que se indique.
![image](https://github.com/CeViMu/fizzbuzz-1/blob/master/images/Imagen3.png)

4. Vemos que la prueba falla porque la función ExplorerService.filterByStack no se ha definido.

5. Agregamos la función filterByStacj en el archivo ExplorerService.js
![image](https://github.com/CeViMu/fizzbuzz-1/blob/master/images/Imagen5.png)

6. Agregamos una prueba para el requerimiento desde el ExplorerControler
![image](https://github.com/CeViMu/fizzbuzz-1/blob/master/images/Imagen6.png)

7. Verificamos que la prueba falla porque la función getExplorerWithStack no se ha definido

8. Definimos la función faltante en el archivo ExplorerController.js
![image](https://github.com/CeViMu/fizzbuzz-1/blob/master/images/Imagen8.png)

9. Agregamos al server.js un nuevo endPoint con una nueva URL y un nuevo método getExplorersWithStack tomado del archivo ExplorerController.
![image](https://github.com/CeViMu/fizzbuzz-1/blob/master/images/Imagen9.png)

10. Verificamos que la url funcione
Consumimos nuestro servidor
> node lib/server.js
Abrimos la dirección localhost:3000/v1/explorers/stack/javascript.
![image](https://github.com/CeViMu/fizzbuzz-1/blob/master/images/Imagen10.png)

11. Verificamos que las pruebas automatizadas de GitHub funcionen y pasen.
![image](https://github.com/CeViMu/fizzbuzz-1/blob/master/images/Imagen11.png)

12. Instalamos linter
>npm install eslint --save-dev

Modificamos package.json, agregar debajo de test
> "linter": "node ./node_modules/eslint/bin/eslint.js"

Crear configuración en archivo .eslintrc
> npm init @eslint/config

Corremos linter
> npm run linter

Arreglamos el estilo de nuestro proyecto
> npm run linter -fix

> npm init @eslint/config

Rules: https://eslint.org/docs/rules/
Airbnb Code Style: https://github.com/airbnb/javascript
8 changes: 8 additions & 0 deletions test/controllers/ExplorerController.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const ExplorerController = require("./../../lib/controllers/ExplorerController");

describe("Unit test", () =>{
test("Tes para filtar a los explorers por stacks", ()=>{
const explorersWithJavaScript = ExplorerController.getExplorersWithStack("javascript");
expect(explorersWithJavaScript.length).toBe(11);
});
});
Loading