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

Contribution Open Source to visual partnership - fizzbuzz #176

Open
wants to merge 5 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
11 changes: 11 additions & 0 deletions lib/controllers/ExplorerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 6 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
Expand Down
7 changes: 7 additions & 0 deletions lib/services/ExplorerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
13 changes: 13 additions & 0 deletions test/controllers/ExplorerController.test.js
Original file line number Diff line number Diff line change
@@ -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);

});
});
51 changes: 51 additions & 0 deletions test/services/ExplorerService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});



});