Skip to content

Instantly share code, notes, and snippets.

@adamatti
Last active November 1, 2019 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamatti/365d87333f1ad49013df3d4618317c60 to your computer and use it in GitHub Desktop.
Save adamatti/365d87333f1ad49013df3d4618317c60 to your computer and use it in GitHub Desktop.
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!');
});
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')
});
{
"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