Skip to content
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
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ module.exports = {
"browser": true,
"commonjs": true,
"es2021": true,
"jest": true
"jest":true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
"no-unused-vars": "off",
indent: ["error", 4],
"linebreak-style": ["error", "unix"],
quotes: ["error", "double"],
Expand Down
38 changes: 30 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
name: Run Tests in my project every push on GitHub

on: [push, pull_request]

name: Jest
on: push
jobs:
build:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run Jest
uses: stefanoeb/jest-action@1.0.3
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: "12"

# Speed up subsequent runs with caching
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

# Install required deps for action
- name: Install Dependencies
run: npm install

# Finally, run our tests
- name: Run the tests
run: npm test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
*.json
!package.json
4 changes: 4 additions & 0 deletions lib/controllers/ExplorerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class ExplorerController{
const explorers = Reader.readJsonFile("explorers.json");
return ExplorerService.getAmountOfExplorersByMission(explorers, mission);
}
static getExplorersByStack(stack){
const explorers = Reader.readJsonFile("explorers.json");
return ExplorerService.filterByStack(explorers,stack);
}
}

module.exports = ExplorerController;
6 changes: 5 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ app.get("/v1/fizzbuzz/:score", (request, response) => {
const fizzbuzzTrick = ExplorerController.applyFizzbuzz(score);
response.json({score: score, trick: fizzbuzzTrick});
});

app.get("/v1/explorers/stack/:mission", (request, response) => {
const mission = request.params.mission;
const usersTrick = ExplorerController.getExplorersByStack(mission);
response.json(usersTrick);
});
app.listen(port, () => {
console.log(`FizzBuzz API in localhost:${port}`);
});
Expand Down
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 filterByStack(explorers,stacks){
const explorersByStack = explorers.filter((explorer)=>explorer.stacks.includes(stacks));
return explorersByStack;
}

}

Expand Down
90 changes: 45 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "fizzbuzz",
"version": "1.0.0",
"description": "",
"description": "1. Instalar dependencia:",
"main": "index.js",
"scripts": {
"test": "node ./node_modules/.bin/jest",
"test": "node --experimental-vm-modules ./node_modules/jest/bin/jest",
"linter": "node ./node_modules/eslint/bin/eslint.js",
"linter-fix": "node ./node_modules/eslint/bin/eslint.js . --fix",
"server": "node ./lib/server.js"
Expand All @@ -13,10 +13,22 @@
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": "^8.14.0",
"eslint": "^8.15.0",
"jest": "^27.5.1"
},
"dependencies": {
"express": "^4.17.3"
}
},
"directories": {
"lib": "lib",
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/MoisesMendozaS01/fizzbuzz.git"
},
"bugs": {
"url": "https://github.com/MoisesMendozaS01/fizzbuzz/issues"
},
"homepage": "https://github.com/MoisesMendozaS01/fizzbuzz#readme"
}
9 changes: 9 additions & 0 deletions test/controllers/ExplorerController.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const ExplorerController = require("./../../../fizzbuzz/lib/controllers/ExplorerController");

describe("Unit Test for ExplorerController",()=>{
test("Parte 1:Prueba de unidad para llamar la funcion filtrar por stack",()=>{
const ExplorersInNodeJavascript = ExplorerController.getExplorersByStack("javascript");

expect(ExplorersInNodeJavascript).not.toBeUndefined();
});
});
5 changes: 5 additions & 0 deletions 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: Mostrar todos los explorers por stack",()=>{
const explorers = [{name:"ajolote1",stacks:["node","java"]},{name:"ajolote2",stacks:["node","java"]},{name:"ajolote3",stacks:"node"},{name:"ajolote4",stacks:"java"}];
const explorerInNode = ExplorerService.filterByStack(explorers,"node");
expect(explorerInNode).not.toBeUndefined();
});

});