fix(curriculum): fix wrong tests sections in the backend challenges (#30137)
This commit is contained in:
committed by
mrugesh mohapatra
parent
c013738c70
commit
5607651c5e
@ -23,10 +23,11 @@ Hint: The test will not pass if you don’t chain the middleware. If you mount t
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- 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); })'
|
||||
- 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); })'
|
||||
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); })'
|
||||
- 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); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -26,10 +26,11 @@ There are also a couple of other methods which are used to negotiate a connectio
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- 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); })'
|
||||
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 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); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -21,10 +21,11 @@ TIP: In the following exercise we are going to receive data from a POST request,
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- 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); })'
|
||||
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 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); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,10 +20,11 @@ Build an echo server, mounted at the route <code>GET /:word/echo</code>. Respond
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- 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); })'
|
||||
- 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); })'
|
||||
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); })'
|
||||
- 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); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -24,8 +24,9 @@ Hint: Express evaluates functions in the order they appear in the code. This is
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- 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); })'
|
||||
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); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -19,8 +19,9 @@ To get started, just print the classic "Hello World" in the console. We recommen
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: <code>"Hello World"</code> 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); })'
|
||||
tests:
|
||||
- text: <code>"Hello World"</code> 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); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -22,8 +22,9 @@ Note: You can edit the solution of the previous challenge, or create a new one.
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: Your app should serve the file views/index.html
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'')).then(data => { assert.match(data, /<h1>.*<\/h1>/, ''Your app does not serve the expected HTML''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: Your app should serve the file views/index.html
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'')).then(data => { assert.match(data, /<h1>.*<\/h1>/, ''Your app does not serve the expected HTML''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,8 +20,9 @@ Serve the object <code>{"message": "Hello json"}</code> as a response in JSON fo
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: 'The endpoint <code>/json</code> should serve the json object <code>{"message": "Hello json"}</code>'
|
||||
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); })'
|
||||
tests:
|
||||
- text: 'The endpoint <code>/json</code> should serve the json object <code>{"message": "Hello json"}</code>'
|
||||
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); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,8 +20,9 @@ Now your app should be able to serve a CSS stylesheet. From outside the public f
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: Your app should serve asset files from the <code>/public</code> 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); })'
|
||||
tests:
|
||||
- text: Your app should serve asset files from the <code>/public</code> 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); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -23,8 +23,9 @@ Use the <code>app.get()</code> method to serve the string Hello Express, to GET
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- 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); })'
|
||||
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); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -25,8 +25,9 @@ The middleware to handle url encoded data is returned by <code>bodyParser.urlenc
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- 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); })'
|
||||
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); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,8 +20,9 @@ Let's add an environment variable as a configuration option. Store the variable
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: The response of the endpoint <code>/json</code> should change according to the environment variable <code>MESSAGE_STYLE</code>
|
||||
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); })'
|
||||
tests:
|
||||
- text: The response of the endpoint <code>/json</code> should change according to the environment variable <code>MESSAGE_STYLE</code>
|
||||
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); })'
|
||||
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user