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

4 Contribución Open Source #155

Open
wants to merge 1 commit 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
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 getExplorersByStack(stack){
const result = ExplorerService.getExplorersByStack(explorers,stack);
return result;
}
}

module.exports = ExplorerController;
6 changes: 6 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ app.listen(port, () => {
console.log(`FizzBuzz API in localhost:${port}`);
});

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

4 changes: 4 additions & 0 deletions lib/services/ExplorerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class ExplorerService {
const explorersUsernames = explorersByMission.map((explorer) => explorer.githubUsername);
return explorersUsernames;
}
static getExplorersByStack(explorers,stack){
const explorersInNode = explorers.filter((explorer) => explorer.stacks.find((tec)=>tec==stack));
return explorersInNode;
}

}

Expand Down
18 changes: 18 additions & 0 deletions test/services/ExplorerService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,23 @@ describe("Tests para ExplorerService", () => {
const explorersInNode = ExplorerService.filterByMission(explorers, "node");
expect(explorersInNode.length).toBe(1);
});
test ("For getExplorersByStack function que filtra explorers dependieno de la stack",()=>{
const explorers = [{stacks: [
"javascript",
"elixir",
"groovy",
"reasonML",
"elm"]
},
{stacks: [
"elixir",
"groovy",
"reasonML",
"elm"]
}
];
const explorersInNode = ExplorerService.getExplorersByStack(explorers, "javascript");
expect(explorersInNode.length).toBe(1);
});

});