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

Agregando requerimiento: Endpoint-stack #172

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

axlgoze
Copy link

@axlgoze axlgoze commented Jun 10, 2022

Práctica 4 -- Microsoft Launch X

Contribución Open Source

  1. Hacer un Fork del repositorio de Carlo fizzbuzz.
  2. Clonar el repositorio en maquina personal.
  3. Es de buenas prácitcas Crear una Rama nueva al hacer contribuciones.
  4. Realizar cambios de configuración
    4.1 Agregamos dependencias eslint con el comando npm install eslint --save -dev
    4.1.1 Modificamos el archivo package.json:
    Agregando correctamente la ruta para "test"
    4.1.2 Configurar eslint con el comando npm init @eslint/config
    4.1.3 Agregar reglas que se ocuparan en el proyecto dentro del archivo ".eslint.js":
  5. Agregar nuevo requerimiento
    5.1 Agregamos las pruebas necesarias y las hacemos fallar:
  • Prueba de filtrado por Stack
test("Requerimiento 4: Filter explorers by Stack", () => {
        const explorers=Reader.readJsonFile("explorers.json");
        const explorersInStackE = ExplorerService.getExplorersByStack(explorers,"elixir");
        const explorersAmountInStackE = explorersInStackE.length;
        expect(explorersAmountInStackE).toBe(9);
    });
  • Prueba para el controlador
test("1) Regresar lista de explorers por Stack", () =>{
        const ListExplorersByStack = ExplorerService.getExplorersByStack(explorers,"reasonML");
        expect(ListExplorersByStack.length).toBeDefined();
    });

5.2 Agregamos el código funcional para hacer pasar nuestras pruebas

  • Método estático para filtrar por Stack agregado al archivo ExplorerService.js
static getExplorersByStack(explorers,stack){
           const explorersInStack = explorers.filter((explorer) => explorer.stacks.includes(stack));
           return explorersInStack;
    }
  • Método estático para hacer pasar la prueba del controlador agregado al archivo ExplorerController.js
static getExplorersByStack(stack){
        const explorers = Reader.readJsonFile("explorers.json");
        const getListExplorersByStack = ExplorerService.getExplorersByStack(explorers,stack);
        return getListExplorersByStack;
    }
  1. Agregamos el Endpoint en el archivo server.js
  • Ejemplo: localhost:3000/v1/explorers/stack/:elixir
app.get("/v1/explorers/stack/:stack", (request, response) => {
    const stack = request.params.stack;
    const explorerListByStack = ExplorerController.getExplorersByStack(stack);
    response.json(explorerListByStack);
});
  1. Levantamos el servidor y probamos en el browser localhost:3000/v1/explorers/stack/:elm
Endpoint Request Response
localhost:3000/v1/explorers/stack/:stack localhost:3000/v1/explorers/stack/elm [{"name":"Woopa3","githubUsername":"ajolonauta3","score":3,"mission":"node","stacks":["elixir","groovy","reasonML"]},{"name":"Woopa5","githubUsername":"ajolonauta5","score":5,"mission":"node","stacks":["javascript","elixir","elm"]},{"name":"Woopa9","githubUsername":"ajolonauta9","score":9,"mission":"java","stacks":["javascript","elixir","groovy","reasonML","elm"]},{"name":"Woopa10","githubUsername":"ajolonauta10","score":10,"mission":"java","stacks":["javascript","elixir","groovy","reasonML","elm"]},{"name":"Woopa11","githubUsername":"ajolonauta11","score":11,"mission":"node","stacks":["javascript","elixir","groovy","reasonML","elm"]},{"name":"Woopa12","githubUsername":"ajolonauta12","score":12,"mission":"node","stacks":["javascript","elixir","groovy","reasonML","elm"]},{"name":"Woopa13","githubUsername":"ajolonauta13","score":13,"mission":"node","stacks":["javascript","elixir","groovy","reasonML","elm"]},{"name":"Woopa14","githubUsername":"ajolonauta14","score":14,"mission":"node","stacks":["javascript","elixir","groovy","reasonML","elm"]},{"name":"Woopa15","githubUsername":"ajolonauta15","score":15,"mission":"node","stacks":["javascript","elixir","groovy","reasonML","elm"]}]

Open Source Contribution Finished !!! ⚡
Saludos MC, Estoy aprendiendo mucho. Gracias.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant