diff --git a/lib/controllers/ExplorerController.js b/lib/controllers/ExplorerController.js index 85590a6d..53b748d6 100644 --- a/lib/controllers/ExplorerController.js +++ b/lib/controllers/ExplorerController.js @@ -21,6 +21,17 @@ class ExplorerController{ const explorers = Reader.readJsonFile("explorers.json"); return ExplorerService.getAmountOfExplorersByMission(explorers, mission); } + + + + static getInStack(language){ + const explorers = Reader.readJsonFile("explorers.json"); + //const namesContainLanguage = ExplorerService.inStack(explorers,language); + //return namesContainLanguage; + + return ExplorerService.inStack(explorers,language); + } + } module.exports = ExplorerController; diff --git a/lib/server.js b/lib/server.js index 9860b437..a3d83831 100644 --- a/lib/server.js +++ b/lib/server.js @@ -25,13 +25,17 @@ app.get("/v1/explorers/usernames/:mission", (request, response) => { const explorersUsernames = ExplorerController.getExplorersUsernamesByMission(mission); response.json({mission: request.params.mission, explorers: explorersUsernames}); }); - app.get("/v1/fizzbuzz/:score", (request, response) => { const score = parseInt(request.params.score); const fizzbuzzTrick = ExplorerController.applyFizzbuzz(score); response.json({score: score, trick: fizzbuzzTrick}); }); - +app.get("/v1/explorers/stack/:language", (request, response) => { + //const language = "javascript" + const language = parseInt(request.params.language); + const valor = ExplorerController.getInStack(request.params.language); + response.json({languageInStack: request.params.language, explorers: valor}); +}); app.listen(port, () => { console.log(`FizzBuzz API in localhost:${port}`); }); diff --git a/lib/services/ExplorerService.js b/lib/services/ExplorerService.js index 9fef9574..e9c50bba 100644 --- a/lib/services/ExplorerService.js +++ b/lib/services/ExplorerService.js @@ -16,6 +16,13 @@ class ExplorerService { return explorersUsernames; } + + static inStack(explorers, language){ + const explorersInNodeToGetUsernames = explorers.filter((explorer) => explorer.stacks.includes(language)); + const usernamesInNode = explorersInNodeToGetUsernames.map((explorer) => explorer.name); + return usernamesInNode; + } + } module.exports = ExplorerService; diff --git a/test/controllers/ExplorerController.test.js b/test/controllers/ExplorerController.test.js new file mode 100644 index 00000000..3f790f80 --- /dev/null +++ b/test/controllers/ExplorerController.test.js @@ -0,0 +1,13 @@ + +const ExplorerController = require("./../../lib/controllers/ExplorerController"); +//CODE TO CONTRIBUTION OPEN SOURCE - VISUALPARTNERSHIP +describe("Requerimiento para ExplorerController", () => { + test("Requerimiento OPEN SOURCE: Regrese toda la lista de explorers filtrados por un stack.", () => { + + + //const resultController = ExplorerService.inStack(explorers, "javascript"); + expect(ExplorerController.getInStack("javascript")).not.toBeUndefined(); + expect(ExplorerController.getInStack("javascript").length).toBe(11); + + }); +}); diff --git a/test/services/ExplorerService.test.js b/test/services/ExplorerService.test.js index 4313f192..b270c12f 100644 --- a/test/services/ExplorerService.test.js +++ b/test/services/ExplorerService.test.js @@ -7,4 +7,55 @@ describe("Tests para ExplorerService", () => { expect(explorersInNode.length).toBe(1); }); + //CODE TO CONTRIBUTION OPEN SOURCE - VISUALPARTNERSHIP + test("Requerimiento OPEN SOURCE: regrese toda la lista de explorers filtrados por un stack.", () => { + const explorers = +[ + { + "name": "Woopa1", + "githubUsername": "ajolonauta1", + "score": 1, + "mission": "node", + "stacks": [ + "javascript", + "reasonML", + "elm" + ] + }, + { + "name": "Woopa2", + "githubUsername": "ajolonauta2", + "score": 2, + "mission": "node", + "stacks": [ + "javascript", + "groovy", + "elm" + ] + }, + { + "name": "Woopa3", + "githubUsername": "ajolonauta3", + "score": 3, + "mission": "node", + "stacks": [ + "elixir", + "groovy", + "reasonML" + ] + } +]; + + + + + const explorersLanguage = ExplorerService.inStack(explorers, "javascript"); + expect(explorersLanguage).not.toBeUndefined(); + expect(explorersLanguage.length).toBe(2); + expect(explorersLanguage).toContain("Woopa1"); + expect(explorersLanguage).toContain("Woopa2"); + }); + + + });