Skip to content

Commit 756bc29

Browse files
committed
fix(exercise 12): test GET request for fail #446
This is still missing most of the translations for the doc change.
1 parent 6a676d9 commit 756bc29

6 files changed

Lines changed: 43 additions & 30 deletions

File tree

exercises/http_uppercaserer/exercise.js

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,43 @@ function query (mode) {
5454

5555
function connect (port, stream) {
5656
var input = through2()
57-
var count = 0
58-
var iv
5957
var url = 'http://localhost:' + port
60-
var req
61-
62-
// TODO: test GET requests for #fail
63-
req = input.pipe(hyperquest.post(url)
64-
.on('error', function (err) {
65-
exercise.emit(
66-
'fail'
67-
, exercise.__('fail.connection', {address: url, message: err.message})
68-
)
69-
}))
70-
71-
req.pipe(stream)
72-
setTimeout(function () {
73-
stream.unpipe(req)
74-
stream.end()
75-
}, 5000)
76-
77-
iv = setInterval(function () {
78-
input.write(words[count].trim() + '\n')
79-
80-
if (++count === words.length) {
81-
clearInterval(iv)
82-
input.end()
83-
}
84-
}, 50)
58+
var methods = ['post', 'get']
59+
60+
var mi = 0
61+
var miv = setInterval(function () {
62+
var count = 0
63+
// test POST request for #success
64+
// or GET request for #fail
65+
var req = input.pipe(hyperquest[methods[mi]](url)
66+
.on('error', function (err) {
67+
exercise.emit(
68+
'fail'
69+
, exercise.__('fail.connection', {address: url, message: err.message})
70+
)
71+
}))
72+
73+
req.pipe(stream)
74+
setTimeout(function () {
75+
stream.unpipe(req)
76+
if (++mi === methods.length) {
77+
stream.end()
78+
}
79+
}, 5000)
80+
81+
var iv = setInterval(function () {
82+
input.write(words[count].trim() + '\n')
83+
84+
if (++count === words.length) {
85+
clearInterval(iv)
86+
87+
if (++mi === methods.length) {
88+
clearInterval(miv)
89+
input.end()
90+
}
91+
}
92+
}, 50)
93+
}, 600)
8594
}
8695

8796
connect(this.submissionPort, this.submissionStdout)

exercises/http_uppercaserer/problem.es.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
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.
22

3+
Peticiones GET hay que dar les una respuesta vacia.
4+
35
El servidor deberá escuchar en un puerto cuyo número será el primer argumento del programa.
46

57
----------------------------------------------------------------------

exercises/http_uppercaserer/problem.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Write an HTTP **server** that receives only POST requests and converts incoming POST body characters to upper-case and returns it to the client.
22

3+
GET requests have to be answered with an empty response.
4+
35
Your server should listen on the port provided by the first argument to your program.
46

57
----------------------------------------------------------------------

exercises/http_uppercaserer/solution/solution.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const map = require('through2-map')
33

44
const server = http.createServer(function (req, res) {
55
if (req.method !== 'POST') {
6-
return res.end('send me a POST\n')
6+
return res.end()
77
}
88

99
req.pipe(map(function (chunk) {

exercises/juggling_async/exercise.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var comparestdout = require('workshopper-exercise/comparestdout')
66
var bogan = require('boganipsum')
77
var after = require('after')
88

9-
// three separate chunks of words to spit out
9+
// three separate chunks of words to spit out
1010
var words = [
1111
bogan({ paragraphs: 1, sentenceMax: 1 }).split(' '),
1212
bogan({ paragraphs: 1, sentenceMax: 1 }).split(' '),

test/http_uppercaserer/valid_01.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require('http').createServer(function (req, res) {
22
if (req.method !== 'POST') {
3-
return res.end('POST only!\n')
3+
return res.end()
44
}
55

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

0 commit comments

Comments
 (0)