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

Creación de endpoint lista explorers por stack #156

Open
wants to merge 4 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
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 explorers = Reader.readJsonFile("explorers.json");
return ExplorerService.getExplorersbyStack(explorers, stack);
}
}

module.exports = ExplorerController;
6 changes: 6 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ app.get("/v1/explorers/usernames/:mission", (request, response) => {
response.json({mission: request.params.mission, explorers: explorersUsernames});
});

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

app.get("/v1/fizzbuzz/:score", (request, response) => {
const score = parseInt(request.params.score);
const fizzbuzzTrick = ExplorerController.applyFizzbuzz(score);
Expand Down
5 changes: 5 additions & 0 deletions lib/services/ExplorerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class ExplorerService {
return explorersUsernames;
}

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

}

module.exports = ExplorerService;
7 changes: 6 additions & 1 deletion test/services/ExplorerService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ describe("Tests para ExplorerService", () => {
const explorersInNode = ExplorerService.filterByMission(explorers, "node");
expect(explorersInNode.length).toBe(1);
});


test("Requerimiento 2: Obtener todos los explorers con cierto stack", () => {
const explorers = [{stacks: ["javascript","reasonML","elm"]}];
const explorersWithStack = ExplorerService.getExplorersbyStack(explorers, "reasonML");
expect(explorersWithStack.length).toBe(1);
});
});