Last active
November 1, 2019 16:51
-
-
Save adamatti/365d87333f1ad49013df3d4618317c60 to your computer and use it in GitHub Desktop.
Dojo Node jokenpo - http://dojopuzzles.com/problemas/exibe/jokenpo/ #dojo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
app.get('/health', function (req, res) { | |
res.send('Hello World!'); | |
}); | |
app.get('/jokenpo', function (req, res) { | |
let jogadaJogador1 = req.query.jogador1; | |
let jogadaJogador2 = req.query.jogador2; | |
const resultados = { | |
pedra: "tesoura", | |
tesoura: "papel", | |
papel: "pedra" | |
} | |
if(resultados[jogadaJogador1] == jogadaJogador2) { | |
res.send({jogadaVencedora: jogadaJogador1}); | |
return | |
} | |
if(resultados[jogadaJogador2] == jogadaJogador1) { | |
res.send({jogadaVencedora: jogadaJogador2}); | |
return | |
} | |
res.send('empate') | |
}); | |
app.listen(3000, function () { | |
console.log('Example app listening on port 3000!'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const frisby = require('frisby'); | |
it('should be a teapot', function () { | |
return frisby.get('http://localhost:3000/health') | |
.expect('status', 200) | |
}); | |
it('pedra ganha de tesoura', function () { | |
return frisby.get('http://localhost:3000/jokenpo?jogador1=pedra&jogador2=tesoura') | |
.expect('status', 200) | |
.expect('json', 'jogadaVencedora', 'pedra') | |
}); | |
it('tesoura ganha de papel', function () { | |
return frisby.get('http://localhost:3000/jokenpo?jogador1=tesoura&jogador2=papel') | |
.expect('status', 200) | |
.expect('json', 'jogadaVencedora', 'tesoura') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"express": "^4.16.3", | |
"frisby": "^2.1.0" | |
}, | |
"scripts": { | |
"test": "jest" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment