Skip to content

Commit

Permalink
fix(exercise 12): test GET request for fail #446
Browse files Browse the repository at this point in the history
This is still missing most of the translations for the doc change.
  • Loading branch information
hoijui committed Feb 19, 2018
1 parent 6a676d9 commit 756bc29
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 30 deletions.
63 changes: 36 additions & 27 deletions exercises/http_uppercaserer/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,43 @@ function query (mode) {

function connect (port, stream) {
var input = through2()
var count = 0
var iv
var url = 'http://localhost:' + port
var req

// TODO: test GET requests for #fail
req = input.pipe(hyperquest.post(url)
.on('error', function (err) {
exercise.emit(
'fail'
, exercise.__('fail.connection', {address: url, message: err.message})
)
}))

req.pipe(stream)
setTimeout(function () {
stream.unpipe(req)
stream.end()
}, 5000)

iv = setInterval(function () {
input.write(words[count].trim() + '\n')

if (++count === words.length) {
clearInterval(iv)
input.end()
}
}, 50)
var methods = ['post', 'get']

var mi = 0
var miv = setInterval(function () {
var count = 0
// test POST request for #success
// or GET request for #fail
var req = input.pipe(hyperquest[methods[mi]](url)
.on('error', function (err) {
exercise.emit(
'fail'
, exercise.__('fail.connection', {address: url, message: err.message})
)
}))

req.pipe(stream)
setTimeout(function () {
stream.unpipe(req)
if (++mi === methods.length) {
stream.end()
}
}, 5000)

var iv = setInterval(function () {
input.write(words[count].trim() + '\n')

if (++count === words.length) {
clearInterval(iv)

if (++mi === methods.length) {
clearInterval(miv)
input.end()
}
}
}, 50)
}, 600)
}

connect(this.submissionPort, this.submissionStdout)
Expand Down
2 changes: 2 additions & 0 deletions exercises/http_uppercaserer/problem.es.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Escribe un **servidor** HTTP que reciba sólo peticiones POST y convierta los caracteres del cuerpo de la petición a mayúsculas y lo devuelva al cliente.

Peticiones GET hay que dar les una respuesta vacia.

El servidor deberá escuchar en un puerto cuyo número será el primer argumento del programa.

----------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions exercises/http_uppercaserer/problem.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Write an HTTP **server** that receives only POST requests and converts incoming POST body characters to upper-case and returns it to the client.

GET requests have to be answered with an empty response.

Your server should listen on the port provided by the first argument to your program.

----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion exercises/http_uppercaserer/solution/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const map = require('through2-map')

const server = http.createServer(function (req, res) {
if (req.method !== 'POST') {
return res.end('send me a POST\n')
return res.end()
}

req.pipe(map(function (chunk) {
Expand Down
2 changes: 1 addition & 1 deletion exercises/juggling_async/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var comparestdout = require('workshopper-exercise/comparestdout')
var bogan = require('boganipsum')
var after = require('after')

// three separate chunks of words to spit out
// three separate chunks of words to spit out
var words = [
bogan({ paragraphs: 1, sentenceMax: 1 }).split(' '),
bogan({ paragraphs: 1, sentenceMax: 1 }).split(' '),
Expand Down
2 changes: 1 addition & 1 deletion test/http_uppercaserer/valid_01.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require('http').createServer(function (req, res) {
if (req.method !== 'POST') {
return res.end('POST only!\n')
return res.end()
}

req.pipe(require('through2-map')(function (chunk) {
Expand Down

0 comments on commit 756bc29

Please sign in to comment.