diff --git a/challenges/05-apis-and-microservices/basic-node-and-express.json b/challenges/05-apis-and-microservices/basic-node-and-express.json index 7ad5e88ad8d..ad3e9d59384 100644 --- a/challenges/05-apis-and-microservices/basic-node-and-express.json +++ b/challenges/05-apis-and-microservices/basic-node-and-express.json @@ -14,7 +14,8 @@ "tests": [ { "text": "\"Hello World\" should be in the console", - "testString": "getUserInput => $.get(getUserInput('url') + '/_api/hello-console').then(data => { assert.isTrue(data.passed, '\"Hello World\" is not in the server console'); }, xhr => { throw new Error(xhr.responseText); })" + "testString": + "getUserInput => $.get(getUserInput('url') + '/_api/hello-console').then(data => { assert.isTrue(data.passed, '\"Hello World\" is not in the server console'); }, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [], @@ -26,7 +27,7 @@ "id": "587d7fb0367417b2b2512bee", "title": "Start a Working Express Server", "description": [ - "In the first two lines of the file myApp.js you can see how it’s easy to create an Express app object. This object has several methods, and we will learn many of them in these challenges. One fundamental method is app.listen(port). It tells your server to listen on a given port, putting it in running state. You can see it at the bottom of the file. It is inside comments because for testing reasons we need the app to be running in background. All the code that you may want to add goes between these two fundamental parts. Glitch stores the port number in the environemet variable process.env.PORT. Its value is 3000.", + "In the first two lines of the file myApp.js you can see how it’s easy to create an Express app object. This object has several methods, and we will learn many of them in these challenges. One fundamental method is app.listen(port). It tells your server to listen on a given port, putting it in running state. You can see it at the bottom of the file. It is inside comments because for testing reasons we need the app to be running in background. All the code that you may want to add goes between these two fundamental parts. Glitch stores the port number in the environment variable process.env.PORT. Its value is 3000.", "Let’s serve our first string! In Express, routes takes the following structure: app.METHOD(PATH, HANDLER). METHOD is an http method in lowercase. PATH is a relative path on the server (it can be a string, or even a regular expression). HANDLER is a function that Express calls when the route is matched.", "Handlers take the form function(req, res) {...}, where req is the request object, and res is the response object. For example, the handler", "
function(req, res) {
res.send('Response String');
}
", @@ -36,7 +37,8 @@ "tests": [ { "text": "Your app should serve the string 'Hello Express'", - "testString": "getUserInput => $.get(getUserInput('url')).then(data => { assert.equal(data, 'Hello Express', 'Your app does not serve the text \"Hello Express\"'); }, xhr => { throw new Error(xhr.responseText); })" + "testString": + "getUserInput => $.get(getUserInput('url')).then(data => { assert.equal(data, 'Hello Express', 'Your app does not serve the text \"Hello Express\"'); }, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [], @@ -57,7 +59,8 @@ "tests": [ { "text": "Your app should serve the file views/index.html", - "testString": "getUserInput => $.get(getUserInput('url')).then(data => { assert.match(data, /

.*<\\/h1>/, 'Your app does not serve the expected HTML'); }, xhr => { throw new Error(xhr.responseText); })" + "testString": + "getUserInput => $.get(getUserInput('url')).then(data => { assert.match(data, /

.*<\\/h1>/, 'Your app does not serve the expected HTML'); }, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [], @@ -75,8 +78,10 @@ ], "tests": [ { - "text": "Your app should serve asset files from the /public directory", - "testString": "getUserInput => $.get(getUserInput('url') + '/style.css').then(data => { assert.match(data, /body\\s*\\{[^\\}]*\\}/, 'Your app does not serve static assets'); }, xhr => { throw new Error(xhr.responseText); })" + "text": + "Your app should serve asset files from the /public directory", + "testString": + "getUserInput => $.get(getUserInput('url') + '/style.css').then(data => { assert.match(data, /body\\s*\\{[^\\}]*\\}/, 'Your app does not serve static assets'); }, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [], @@ -94,8 +99,10 @@ ], "tests": [ { - "text": "The endpoint /json should serve the json object {\"message\": \"Hello json\"}", - "testString": "getUserInput => $.get(getUserInput('url') + '/json').then(data => { assert.equal(data.message, 'Hello json', 'The \\'/json\\' endpoint does not serve the right data'); }, xhr => { throw new Error(xhr.responseText); })" + "text": + "The endpoint /json should serve the json object {\"message\": \"Hello json\"}", + "testString": + "getUserInput => $.get(getUserInput('url') + '/json').then(data => { assert.equal(data.message, 'Hello json', 'The \\'/json\\' endpoint does not serve the right data'); }, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [], @@ -113,8 +120,10 @@ ], "tests": [ { - "text": "The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE", - "testString": "getUserInput => $.get(getUserInput('url') + '/_api/use-env-vars').then(data => { assert.isTrue(data.passed, 'The response of \"/json\" does not change according to MESSAGE_STYLE'); }, xhr => { throw new Error(xhr.responseText); })" + "text": + "The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE", + "testString": + "getUserInput => $.get(getUserInput('url') + '/_api/use-env-vars').then(data => { assert.isTrue(data.passed, 'The response of \"/json\" does not change according to MESSAGE_STYLE'); }, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [], @@ -137,7 +146,8 @@ "tests": [ { "text": "Root level logger middleware should be active", - "testString": "getUserInput => $.get(getUserInput('url') + '/_api/root-middleware-logger').then(data => { assert.isTrue(data.passed, 'root-level logger is not working as expected'); }, xhr => { throw new Error(xhr.responseText); })" + "testString": + "getUserInput => $.get(getUserInput('url') + '/_api/root-middleware-logger').then(data => { assert.isTrue(data.passed, 'root-level logger is not working as expected'); }, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [], @@ -159,11 +169,14 @@ "tests": [ { "text": "The /now endpoint should have mounted middleware", - "testString": "getUserInput => $.get(getUserInput('url') + '/_api/chain-middleware-time').then(data => { assert.equal(data.stackLength, 2, '\"/now\" route has no mounted middleware'); }, xhr => { throw new Error(xhr.responseText); })" + "testString": + "getUserInput => $.get(getUserInput('url') + '/_api/chain-middleware-time').then(data => { assert.equal(data.stackLength, 2, '\"/now\" route has no mounted middleware'); }, xhr => { throw new Error(xhr.responseText); })" }, { - "text": "The /now endpoint should return a time that is +/- 20 secs from now", - "testString": "getUserInput => $.get(getUserInput('url') + '/_api/chain-middleware-time').then(data => { var now = new Date(); assert.isAtMost(Math.abs(new Date(data.time) - now), 20000, 'the returned time is not between +- 20 secs from now'); }, xhr => { throw new Error(xhr.responseText); })" + "text": + "The /now endpoint should return a time that is +/- 20 secs from now", + "testString": + "getUserInput => $.get(getUserInput('url') + '/_api/chain-middleware-time').then(data => { var now = new Date(); assert.isAtMost(Math.abs(new Date(data.time) - now), 20000, 'the returned time is not between +- 20 secs from now'); }, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [], @@ -182,11 +195,13 @@ "tests": [ { "text": "Test 1 : Your echo server should repeat words correctly", - "testString": "getUserInput => $.get(getUserInput('url') + '/eChOtEsT/echo').then(data => { assert.equal(data.echo, 'eChOtEsT', 'Test 1: the echo server is not working as expected') }, xhr => { throw new Error(xhr.responseText); })" + "testString": + "getUserInput => $.get(getUserInput('url') + '/eChOtEsT/echo').then(data => { assert.equal(data.echo, 'eChOtEsT', 'Test 1: the echo server is not working as expected') }, xhr => { throw new Error(xhr.responseText); })" }, { "text": "Test 2 : Your echo server should repeat words correctly", - "testString": "getUserInput => $.get(getUserInput('url') + '/ech0-t3st/echo').then(data => { assert.equal(data.echo, 'ech0-t3st', 'Test 2: the echo server is not working as expected') }, xhr => { throw new Error(xhr.responseText); })" + "testString": + "getUserInput => $.get(getUserInput('url') + '/ech0-t3st/echo').then(data => { assert.equal(data.echo, 'ech0-t3st', 'Test 2: the echo server is not working as expected') }, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [], @@ -205,12 +220,16 @@ ], "tests": [ { - "text": "Test 1 : Your API endpoint should respond with the correct name", - "testString": "getUserInput => $.get(getUserInput('url') + '/name?first=Mick&last=Jagger').then(data => { assert.equal(data.name, 'Mick Jagger', 'Test 1: \"GET /name\" route does not behave as expected') }, xhr => { throw new Error(xhr.responseText); })" + "text": + "Test 1 : Your API endpoint should respond with the correct name", + "testString": + "getUserInput => $.get(getUserInput('url') + '/name?first=Mick&last=Jagger').then(data => { assert.equal(data.name, 'Mick Jagger', 'Test 1: \"GET /name\" route does not behave as expected') }, xhr => { throw new Error(xhr.responseText); })" }, { - "text": "Test 2 : Your APi endpoint should respond with the correct name", - "testString": "getUserInput => $.get(getUserInput('url') + '/name?last=Richards&first=Keith').then(data => { assert.equal(data.name, 'Keith Richards', 'Test 2: \"GET /name\" route does not behave as expected') }, xhr => { throw new Error(xhr.responseText); })" + "text": + "Test 2 : Your APi endpoint should respond with the correct name", + "testString": + "getUserInput => $.get(getUserInput('url') + '/name?last=Richards&first=Keith').then(data => { assert.equal(data.name, 'Keith Richards', 'Test 2: \"GET /name\" route does not behave as expected') }, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [], @@ -234,7 +253,8 @@ "tests": [ { "text": "The 'body-parser' middleware should be mounted", - "testString": "getUserInput => $.get(getUserInput('url') + '/_api/add-body-parser').then(data => { assert.isAbove(data.mountedAt, 0, '\"body-parser\" is not mounted correctly') }, xhr => { throw new Error(xhr.responseText); })" + "testString": + "getUserInput => $.get(getUserInput('url') + '/_api/add-body-parser').then(data => { assert.isAbove(data.mountedAt, 0, '\"body-parser\" is not mounted correctly') }, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [], @@ -258,12 +278,16 @@ ], "tests": [ { - "text": "Test 1 : Your API endpoint should respond with the correct name", - "testString": "getUserInput => $.post(getUserInput('url') + '/name', {first: 'Mick', last: 'Jagger'}).then(data => { assert.equal(data.name, 'Mick Jagger', 'Test 1: \"POST /name\" route does not behave as expected') }, xhr => { throw new Error(xhr.responseText); })" + "text": + "Test 1 : Your API endpoint should respond with the correct name", + "testString": + "getUserInput => $.post(getUserInput('url') + '/name', {first: 'Mick', last: 'Jagger'}).then(data => { assert.equal(data.name, 'Mick Jagger', 'Test 1: \"POST /name\" route does not behave as expected') }, xhr => { throw new Error(xhr.responseText); })" }, { - "text": "Test 2 : Your API endpoint should respond with the correct name", - "testString": "getUserInput => $.post(getUserInput('url') + '/name', {first: 'Keith', last: 'Richards'}).then(data => { assert.equal(data.name, 'Keith Richards', 'Test 2: \"POST /name\" route does not behave as expected') }, xhr => { throw new Error(xhr.responseText); })" + "text": + "Test 2 : Your API endpoint should respond with the correct name", + "testString": + "getUserInput => $.post(getUserInput('url') + '/name', {first: 'Keith', last: 'Richards'}).then(data => { assert.equal(data.name, 'Keith Richards', 'Test 2: \"POST /name\" route does not behave as expected') }, xhr => { throw new Error(xhr.responseText); })" } ], "solutions": [], @@ -272,4 +296,4 @@ "translations": {} } ] -} \ No newline at end of file +}