fix(curriculum): fix wrong tests sections in the backend challenges (#30137)
This commit is contained in:
committed by
mrugesh mohapatra
parent
c013738c70
commit
5607651c5e
@ -21,16 +21,17 @@ Start this project on Glitch using <a href='https://glitch.com/#!/import/github/
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: I can create a user by posting form data username to /api/exercise/new-user and returned will be an object with username and <code>_id</code>.
|
||||
testString: ''
|
||||
- text: I can get an array of all users by getting api/exercise/users with the same info as when creating a user.
|
||||
testString: ''
|
||||
- text: 'I can add an exercise to any user by posting form data userId(_id), description, duration, and optionally date to /api/exercise/add. If no date supplied it will use current date. App will return the user object with the exercise fields added.'
|
||||
testString: ''
|
||||
- text: I can retrieve a full exercise log of any user by getting /api/exercise/log with a parameter of userId(_id). App will return the user object with added array log and count (total exercise count).
|
||||
testString: ''
|
||||
- text: 'I can retrieve part of the log of any user by also passing along optional parameters of from & to or limit. (Date format yyyy-mm-dd, limit = int)'
|
||||
testString: ''
|
||||
tests:
|
||||
- text: I can create a user by posting form data username to /api/exercise/new-user and returned will be an object with username and <code>_id</code>.
|
||||
testString: ''
|
||||
- text: I can get an array of all users by getting api/exercise/users with the same info as when creating a user.
|
||||
testString: ''
|
||||
- text: 'I can add an exercise to any user by posting form data userId(_id), description, duration, and optionally date to /api/exercise/add. If no date supplied it will use current date. App will return the user object with the exercise fields added.'
|
||||
testString: ''
|
||||
- text: I can retrieve a full exercise log of any user by getting /api/exercise/log with a parameter of userId(_id). App will return the user object with added array log and count (total exercise count).
|
||||
testString: ''
|
||||
- text: 'I can retrieve part of the log of any user by also passing along optional parameters of from & to or limit. (Date format yyyy-mm-dd, limit = int)'
|
||||
testString: ''
|
||||
|
||||
```
|
||||
|
||||
|
@ -21,10 +21,11 @@ Start this project on Glitch using <a href='https://glitch.com/#!/import/github/
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: I can submit a FormData object that includes a file upload.
|
||||
testString: ''
|
||||
- text: 'When I submit something, I will receive the file size in bytes within the JSON response.'
|
||||
testString: ''
|
||||
tests:
|
||||
- text: I can submit a FormData object that includes a file upload.
|
||||
testString: ''
|
||||
- text: 'When I submit something, I will receive the file size in bytes within the JSON response.'
|
||||
testString: ''
|
||||
|
||||
```
|
||||
|
||||
|
@ -21,8 +21,9 @@ Start this project on Glitch using <a href='https://glitch.com/#!/import/github/
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: 'I can get the IP address, language and operating system for my browser.'
|
||||
testString: ''
|
||||
tests:
|
||||
- text: 'I can get the IP address, language and operating system for my browser.'
|
||||
testString: ''
|
||||
|
||||
```
|
||||
|
||||
|
@ -21,18 +21,19 @@ Start this project on Glitch using <a href='https://glitch.com/#!/import/github/
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: 'It should handle a valid date, and return the correct unix timestamp'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp/2016-12-25'').then(data => { assert.equal(data.unix, 1482624000000, ''Should be a valid unix timestamp''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: 'It should handle a valid date, and return the correct UTC string'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'')+ ''/api/timestamp/2016-12-25'').then(data => { assert.equal(data.utc, ''Sun, 25 Dec 2016 00:00:00 GMT'', ''Should be a valid UTC date string''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: 'It should handle a valid unix date, and return the correct unix timestamp'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp/1482624000000'').then(data => { assert.equal(data.unix, 1482624000000) ; }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: It should return the expected error message for an invalid date
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp/this-is-not-a-date'').then(data => { assert.equal(data.error.toLowerCase(), ''invalid date'');}, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: 'It should handle an empty date parameter, and return the current time in unix format'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp'').then(data => { var now = Date.now(); assert.approximately(data.unix, now, 20000) ;}, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: 'It should handle an empty date parameter, and return the current time in UTC format'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp'').then(data => { var now = Date.now(); var serverTime = (new Date(data.utc)).getTime(); assert.approximately(serverTime, now, 20000) ;}, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: 'It should handle a valid date, and return the correct unix timestamp'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp/2016-12-25'').then(data => { assert.equal(data.unix, 1482624000000, ''Should be a valid unix timestamp''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: 'It should handle a valid date, and return the correct UTC string'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'')+ ''/api/timestamp/2016-12-25'').then(data => { assert.equal(data.utc, ''Sun, 25 Dec 2016 00:00:00 GMT'', ''Should be a valid UTC date string''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: 'It should handle a valid unix date, and return the correct unix timestamp'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp/1482624000000'').then(data => { assert.equal(data.unix, 1482624000000) ; }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: It should return the expected error message for an invalid date
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp/this-is-not-a-date'').then(data => { assert.equal(data.error.toLowerCase(), ''invalid date'');}, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: 'It should handle an empty date parameter, and return the current time in unix format'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp'').then(data => { var now = Date.now(); assert.approximately(data.unix, now, 20000) ;}, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: 'It should handle an empty date parameter, and return the current time in UTC format'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp'').then(data => { var now = Date.now(); var serverTime = (new Date(data.utc)).getTime(); assert.approximately(serverTime, now, 20000) ;}, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -21,12 +21,13 @@ Start this project on Glitch using <a href='https://glitch.com/#!/import/github/
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: I can pass a URL as a parameter and I will receive a shortened URL in the JSON response.
|
||||
testString: ''
|
||||
- text: 'If I pass an invalid URL that doesn''t follow the valid http://www.example.com format, the JSON response will contain an error instead.'
|
||||
testString: ''
|
||||
- text: 'When I visit that shortened URL, it will redirect me to my original link.'
|
||||
testString: ''
|
||||
tests:
|
||||
- text: I can pass a URL as a parameter and I will receive a shortened URL in the JSON response.
|
||||
testString: ''
|
||||
- text: 'If I pass an invalid URL that doesn''t follow the valid http://www.example.com format, the JSON response will contain an error instead.'
|
||||
testString: ''
|
||||
- text: 'When I visit that shortened URL, it will redirect me to my original link.'
|
||||
testString: ''
|
||||
|
||||
```
|
||||
|
||||
|
@ -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); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -24,8 +24,9 @@ Remember to use double-quotes for field-names (") and commas (,) to separate fie
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: package.json should have a valid "description" key
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.description, ''"description" is missing''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: package.json should have a valid "description" key
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.description, ''"description" is missing''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -24,8 +24,9 @@ Fill the license-field in the package.json of your Glitch project as you find su
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: package.json should have a valid "license" key
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.license, ''"license" is missing''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: package.json should have a valid "license" key
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.license, ''"license" is missing''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -22,8 +22,9 @@ Add a version to the package.json in your Glitch project.
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: package.json should have a valid "version" key
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.version, ''"version" is missing''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: package.json should have a valid "version" key
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.version, ''"version" is missing''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -24,12 +24,13 @@ One of the keywords should be freecodecamp.
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: package.json should have a valid "keywords" key
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.keywords, ''"keywords" is missing''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"keywords" field should be an Array'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.isArray(packJson.keywords, ''"keywords" is not an array''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"keywords" should include "freecodecamp"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.include(packJson.keywords, ''freecodecamp'', ''"keywords" does not include "freecodecamp"''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: package.json should have a valid "keywords" key
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.keywords, ''"keywords" is missing''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"keywords" field should be an Array'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.isArray(packJson.keywords, ''"keywords" is not an array''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"keywords" should include "freecodecamp"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.include(packJson.keywords, ''freecodecamp'', ''"keywords" does not include "freecodecamp"''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -26,10 +26,11 @@ Moment is a handy library for working with time and dates.
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: '"dependencies" should include "moment"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''moment'', ''"dependencies" does not include "moment"''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"moment" version should be "2.14.0"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.match(packJson.dependencies.moment, /^[\^\~]?2\.14\.0/, ''Wrong version of "moment" installed. It should be 2.14.0''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: '"dependencies" should include "moment"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''moment'', ''"dependencies" does not include "moment"''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"moment" version should be "2.14.0"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.match(packJson.dependencies.moment, /^[\^\~]?2\.14\.0/, ''Wrong version of "moment" installed. It should be 2.14.0''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -27,8 +27,9 @@ All fields must be separated with a comma (,)
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: package.json should have a valid "author" key
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.author, ''"author" is missing''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: package.json should have a valid "author" key
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.author, ''"author" is missing''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -31,10 +31,11 @@ In the dependencies-section of your package.json, change the version of moment t
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: '"dependencies" should include "moment"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''moment'', ''"dependencies" does not include "moment"''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"moment" version should be "2.10.2"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.match(packJson.dependencies.moment, /^[\^\~]?2\.10\.2/, ''Wrong version of "moment". It should be 2.10.2''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: '"dependencies" should include "moment"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''moment'', ''"dependencies" does not include "moment"''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"moment" version should be "2.10.2"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.match(packJson.dependencies.moment, /^[\^\~]?2\.10\.2/, ''Wrong version of "moment". It should be 2.10.2''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -23,8 +23,9 @@ Make sure you have the right amount of commas after removing it.
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: '"dependencies" should not include "moment"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.notProperty(packJson.dependencies, ''moment'', ''"dependencies" still includes "moment"''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: '"dependencies" should not include "moment"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.notProperty(packJson.dependencies, ''moment'', ''"dependencies" still includes "moment"''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -24,10 +24,11 @@ Note that the version numbers themselves not should be changed.
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: '"dependencies" should include "moment"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''moment'', ''"dependencies" does not include "moment"''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"moment" version should match "^2.x.x"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.match(packJson.dependencies.moment, /^\^2\./, ''Wrong version of "moment". It should be ^2.10.2''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: '"dependencies" should include "moment"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''moment'', ''"dependencies" does not include "moment"''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"moment" version should match "^2.x.x"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.match(packJson.dependencies.moment, /^\^2\./, ''Wrong version of "moment". It should be ^2.10.2''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -24,10 +24,11 @@ Note that the version numbers themselves not should be changed.
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: '"dependencies" should include "moment"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''moment'', ''"dependencies" does not include "moment"''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"moment" version should match "~2.10.2"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.match(packJson.dependencies.moment, /^\~2\.10\.2/, ''Wrong version of "moment". It should be ~2.10.2''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: '"dependencies" should include "moment"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''moment'', ''"dependencies" does not include "moment"''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"moment" version should match "~2.10.2"'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.match(packJson.dependencies.moment, /^\~2\.10\.2/, ''Wrong version of "moment". It should be ~2.10.2''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -19,8 +19,9 @@ Find people who like "burrito". Sort them by name, limit the results to two docu
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: Chaining query helpers should succeed
|
||||
testString: 'getUserInput => $.ajax({url: getUserInput(''url'') + ''/_api/query-tools'', type: ''POST'', contentType:''application/json'', data: JSON.stringify([{name: ''Pablo'', age: 26, favoriteFoods: [''burrito'', ''hot-dog'']}, {name: ''Bob'', age: 23, favoriteFoods: [''pizza'', ''nachos'']}, {name: ''Ashley'', age: 32, favoriteFoods: [''steak'', ''burrito'']}, {name: ''Mario'', age: 51, favoriteFoods: [''burrito'', ''prosciutto'']} ]) }).then(data => { assert.isArray(data, ''the response should be an Array''); assert.equal(data.length, 2, ''the data array length is not what expected''); assert.notProperty(data[0], ''age'', ''The returned first item has too many properties''); assert.equal(data[0].name, ''Ashley'', ''The returned first item name is not what expected''); assert.notProperty(data[1], ''age'', ''The returned second item has too many properties''); assert.equal(data[1].name, ''Mario'', ''The returned second item name is not what expected'');}, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: Chaining query helpers should succeed
|
||||
testString: 'getUserInput => $.ajax({url: getUserInput(''url'') + ''/_api/query-tools'', type: ''POST'', contentType:''application/json'', data: JSON.stringify([{name: ''Pablo'', age: 26, favoriteFoods: [''burrito'', ''hot-dog'']}, {name: ''Bob'', age: 23, favoriteFoods: [''pizza'', ''nachos'']}, {name: ''Ashley'', age: 32, favoriteFoods: [''steak'', ''burrito'']}, {name: ''Mario'', age: 51, favoriteFoods: [''burrito'', ''prosciutto'']} ]) }).then(data => { assert.isArray(data, ''the response should be an Array''); assert.equal(data.length, 2, ''the data array length is not what expected''); assert.notProperty(data[0], ''age'', ''The returned first item has too many properties''); assert.equal(data[0].name, ''Ashley'', ''The returned first item name is not what expected''); assert.notProperty(data[1], ''age'', ''The returned second item has too many properties''); assert.equal(data[1].name, ''Mario'', ''The returned second item name is not what expected'');}, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -38,8 +38,9 @@ Warning - When interacting with remote services, errors may occur !
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: Creating an instance from a mongoose schema should succeed
|
||||
testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/mongoose-model'', {name: ''Mike'', age: 28, favoriteFoods: [''pizza'', ''cheese'']}).then(data => { assert.equal(data.name, ''Mike'', ''"model.name" is not what expected''); assert.equal(data.age, ''28'', ''"model.age" is not what expected''); assert.isArray(data.favoriteFoods, ''"model.favoriteFoods" is not an Array''); assert.include(data.favoriteFoods, ''pizza'', ''"model.favoriteFoods" does not include the expected items''); assert.include(data.favoriteFoods, ''cheese'', ''"model.favoriteFoods" does not include the expected items''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: Creating an instance from a mongoose schema should succeed
|
||||
testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/mongoose-model'', {name: ''Mike'', age: 28, favoriteFoods: [''pizza'', ''cheese'']}).then(data => { assert.equal(data.name, ''Mike'', ''"model.name" is not what expected''); assert.equal(data.age, ''28'', ''"model.age" is not what expected''); assert.isArray(data.favoriteFoods, ''"model.favoriteFoods" is not an Array''); assert.include(data.favoriteFoods, ''pizza'', ''"model.favoriteFoods" does not include the expected items''); assert.include(data.favoriteFoods, ''cheese'', ''"model.favoriteFoods" does not include the expected items''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -23,8 +23,9 @@ Create a document instance using the Person constructor you build before. Pass t
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: Creating and saving a db item should succeed
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/create-and-save-person'').then(data => { assert.isString(data.name, ''"item.name" should be a String''); assert.isNumber(data.age, ''28'', ''"item.age" should be a Number''); assert.isArray(data.favoriteFoods, ''"item.favoriteFoods" should be an Array''); assert.equal(data.__v, 0, ''The db item should be not previously edited''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: Creating and saving a db item should succeed
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/create-and-save-person'').then(data => { assert.isString(data.name, ''"item.name" should be a String''); assert.isNumber(data.age, ''28'', ''"item.age" should be a Number''); assert.isArray(data.favoriteFoods, ''"item.favoriteFoods" should be an Array''); assert.equal(data.__v, 0, ''The db item should be not previously edited''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,8 +18,9 @@ Sometimes you need to create many instances of your models, e.g. when seeding a
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: Creating many db items at once should succeed
|
||||
testString: 'getUserInput => $.ajax({url: getUserInput(''url'') + ''/_api/create-many-people'', type: ''POST'', contentType:''application/json'', data: JSON.stringify([{name: ''John'', age: 24, favoriteFoods: [''pizza'', ''salad'']}, {name: ''Mary'', age: 21, favoriteFoods: [''onions'', ''chicken'']}])}).then(data => { assert.isArray(data, ''the response should be an array''); assert.equal(data.length, 2, ''the response does not contain the expected number of items''); assert.equal(data[0].name, ''John'', ''The first item is not correct''); assert.equal(data[0].__v, 0, ''The first item should be not previously edited''); assert.equal(data[1].name, ''Mary'', ''The second item is not correct''); assert.equal(data[1].__v, 0, ''The second item should be not previously edited''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: Creating many db items at once should succeed
|
||||
testString: 'getUserInput => $.ajax({url: getUserInput(''url'') + ''/_api/create-many-people'', type: ''POST'', contentType:''application/json'', data: JSON.stringify([{name: ''John'', age: 24, favoriteFoods: [''pizza'', ''salad'']}, {name: ''Mary'', age: 21, favoriteFoods: [''onions'', ''chicken'']}])}).then(data => { assert.isArray(data, ''the response should be an array''); assert.equal(data.length, 2, ''the response does not contain the expected number of items''); assert.equal(data[0].name, ''John'', ''The first item is not correct''); assert.equal(data[0].__v, 0, ''The first item should be not previously edited''); assert.equal(data[1].name, ''Mary'', ''The second item is not correct''); assert.equal(data[1].__v, 0, ''The second item should be not previously edited''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -19,8 +19,9 @@ Note: Model.remove() doesn’t return the deleted document, but a JSON object co
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: Deleting many items at once should succeed
|
||||
testString: 'getUserInput => $.ajax({url: getUserInput(''url'') + ''/_api/remove-many-people'', type: ''POST'', contentType:''application/json'', data: JSON.stringify([{name: ''Mary'', age: 16, favoriteFoods: [''lollipop'']}, {name: ''Mary'', age: 21, favoriteFoods: [''steak'']}])}).then(data => { assert.isTrue(!!data.ok, ''The mongo stats are not what expected''); assert.equal(data.n, 2, ''The number of items affected is not what expected''); assert.equal(data.count, 0, ''the db items count is not what expected''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: Deleting many items at once should succeed
|
||||
testString: 'getUserInput => $.ajax({url: getUserInput(''url'') + ''/_api/remove-many-people'', type: ''POST'', contentType:''application/json'', data: JSON.stringify([{name: ''Mary'', age: 16, favoriteFoods: [''lollipop'']}, {name: ''Mary'', age: 21, favoriteFoods: [''steak'']}])}).then(data => { assert.isTrue(!!data.ok, ''The mongo stats are not what expected''); assert.equal(data.n, 2, ''The number of items affected is not what expected''); assert.equal(data.count, 0, ''the db items count is not what expected''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,8 +18,9 @@ Delete one person by her _id. You should use one of the methods findByIdAndRemov
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: Deleting an item should succeed
|
||||
testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/remove-one-person'', {name:''Jason Bourne'', age: 36, favoriteFoods:[''apples'']}).then(data => { assert.equal(data.name, ''Jason Bourne'', ''item.name is not what expected''); assert.equal(data.age, 36, ''item.age is not what expected''); assert.deepEqual(data.favoriteFoods, [''apples''], ''item.favoriteFoods is not what expected''); assert.equal(data.__v, 0); assert.equal(data.count, 0, ''the db items count is not what expected''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: Deleting an item should succeed
|
||||
testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/remove-one-person'', {name:''Jason Bourne'', age: 36, favoriteFoods:[''apples'']}).then(data => { assert.equal(data.name, ''Jason Bourne'', ''item.name is not what expected''); assert.equal(data.age, 36, ''item.age is not what expected''); assert.deepEqual(data.favoriteFoods, [''apples''], ''item.favoriteFoods is not what expected''); assert.equal(data.__v, 0); assert.equal(data.count, 0, ''the db items count is not what expected''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,12 +18,13 @@ Add mongodb and mongoose to the project’s package.json. Then require mongoose.
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: '"mongodb" dependency should be in package.json'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/file/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''mongodb''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"mongoose" dependency should be in package.json'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/file/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''mongoose''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"mongoose" should be connected to a database'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/is-mongoose-ok'').then(data => {assert.isTrue(data.isMongooseOk, ''mongoose is not connected'')}, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: '"mongodb" dependency should be in package.json'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/file/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''mongodb''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"mongoose" dependency should be in package.json'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/file/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''mongoose''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
- text: '"mongoose" should be connected to a database'
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/is-mongoose-ok'').then(data => {assert.isTrue(data.isMongooseOk, ''mongoose is not connected'')}, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,8 +20,9 @@ Find a person by _id ( use any of the above methods ) with the parameter personI
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: Find-edit-update an item should succeed
|
||||
testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/find-edit-save'', {name:''Poldo'', age: 40, favoriteFoods:[''spaghetti'']}).then(data => { assert.equal(data.name, ''Poldo'', ''item.name is not what expected''); assert.equal(data.age, 40, ''item.age is not what expected''); assert.deepEqual(data.favoriteFoods, [''spaghetti'', ''hamburger''], ''item.favoriteFoods is not what expected''); assert.equal(data.__v, 1, ''The item should be previously edited''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: Find-edit-update an item should succeed
|
||||
testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/find-edit-save'', {name:''Poldo'', age: 40, favoriteFoods:[''spaghetti'']}).then(data => { assert.equal(data.name, ''Poldo'', ''item.name is not what expected''); assert.equal(data.age, 40, ''item.age is not what expected''); assert.deepEqual(data.favoriteFoods, [''spaghetti'', ''hamburger''], ''item.favoriteFoods is not what expected''); assert.equal(data.__v, 1, ''The item should be previously edited''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,8 +20,9 @@ Hint: We want you to return the updated document. To do that you need to pass th
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: findOneAndUpdate an item should succeed
|
||||
testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/find-one-update'', {name:''Dorian Gray'', age: 35, favoriteFoods:[''unknown'']}).then(data => { assert.equal(data.name, ''Dorian Gray'', ''item.name is not what expected''); assert.equal(data.age, 20, ''item.age is not what expected''); assert.deepEqual(data.favoriteFoods, [''unknown''], ''item.favoriteFoods is not what expected''); assert.equal(data.__v, 0, ''findOneAndUpdate does not increment version by design !!!''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: findOneAndUpdate an item should succeed
|
||||
testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/find-one-update'', {name:''Dorian Gray'', age: 35, favoriteFoods:[''unknown'']}).then(data => { assert.equal(data.name, ''Dorian Gray'', ''item.name is not what expected''); assert.equal(data.age, 20, ''item.age is not what expected''); assert.deepEqual(data.favoriteFoods, [''unknown''], ''item.favoriteFoods is not what expected''); assert.equal(data.__v, 0, ''findOneAndUpdate does not increment version by design !!!''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -19,8 +19,9 @@ In its simplest usage, Model.find() accepts a query document (a JSON object ) as
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: Find all items corresponding to a criteria should succeed
|
||||
testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/find-all-by-name'', {name: ''r@nd0mN4m3'', age: 24, favoriteFoods: [''pizza'']}).then(data => { assert.isArray(data, ''the response should be an Array''); assert.equal(data[0].name, ''r@nd0mN4m3'', ''item.name is not what expected''); assert.equal(data[0].__v, 0, ''The item should be not previously edited''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: Find all items corresponding to a criteria should succeed
|
||||
testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/find-all-by-name'', {name: ''r@nd0mN4m3'', age: 24, favoriteFoods: [''pizza'']}).then(data => { assert.isArray(data, ''the response should be an Array''); assert.equal(data[0].name, ''r@nd0mN4m3'', ''item.name is not what expected''); assert.equal(data[0].__v, 0, ''The item should be not previously edited''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,8 +18,9 @@ When saving a document, mongodb automatically adds the field _id, and set it to
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: Find an item by Id should succeed
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/find-by-id'').then(data => { assert.equal(data.name, ''test'', ''item.name is not what expected''); assert.equal(data.age, 0, ''item.age is not what expected''); assert.deepEqual(data.favoriteFoods, [''none''], ''item.favoriteFoods is not what expected''); assert.equal(data.__v, 0, ''The item should be not previously edited''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: Find an item by Id should succeed
|
||||
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/find-by-id'').then(data => { assert.equal(data.name, ''test'', ''item.name is not what expected''); assert.equal(data.age, 0, ''item.age is not what expected''); assert.deepEqual(data.favoriteFoods, [''none''], ''item.favoriteFoods is not what expected''); assert.equal(data.__v, 0, ''The item should be not previously edited''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,8 +18,9 @@ Model.findOne() behaves like .find(), but it returns only one document (not an a
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
- text: Find one item should succeed
|
||||
testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/find-one-by-food'', {name: ''Gary'', age: 46, favoriteFoods: [''chicken salad'']}).then(data => { assert.equal(data.name, ''Gary'', ''item.name is not what expected''); assert.deepEqual(data.favoriteFoods, [''chicken salad''], ''item.favoriteFoods is not what expected''); assert.equal(data.__v, 0, ''The item should be not previously edited''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
tests:
|
||||
- text: Find one item should succeed
|
||||
testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/find-one-by-food'', {name: ''Gary'', age: 46, favoriteFoods: [''chicken salad'']}).then(data => { assert.equal(data.name, ''Gary'', ''item.name is not what expected''); assert.deepEqual(data.favoriteFoods, [''chicken salad''], ''item.favoriteFoods is not what expected''); assert.equal(data.__v, 0, ''The item should be not previously edited''); }, xhr => { throw new Error(xhr.responseText); })'
|
||||
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user