Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where is the id '42' coming from? #4

Closed
webmaven opened this issue Oct 28, 2014 · 13 comments
Closed

Where is the id '42' coming from? #4

webmaven opened this issue Oct 28, 2014 · 13 comments

Comments

@webmaven
Copy link
Contributor

I don't understand how any implementation can be compliant if the first expected ID the system generates must be 42.

@stephenplusplus
Copy link
Member

@proppy is the blueprint guy, but I believe 42 is simply a placeholder for a value type. In other words, an id is an integer.

@proppy
Copy link
Collaborator

proppy commented Oct 28, 2014

Yes, the spec doesn't enforce IDs it's just use them as placeholder and double-check that the payload types and structures (schema) match.

See https://github.com/apiaryio/api-blueprint/blob/master/API%20Blueprint%20Specification.md

@proppy proppy closed this as completed Oct 28, 2014
@webmaven
Copy link
Contributor Author

webmaven commented Nov 2, 2014

@proppy, the spec may not enforce it, but the tests are.

The Todo tests do a GET for /todos/42, so my implementation can't pass the 4th test:

request: 
body: 

headers: 
    User-Agent: Dredd/0.3.14 (Linux 3.11.0-26-generic; x64)

uri: /todos/42
method: GET


expected: 
headers: 
    Content-Type: application/json; charset=UTF-8

body: 
    {
        "id": 42,
        "title": "dredd",
        "completed": false
    }

statusCode: 200


actual: 
statusCode: 404
headers: 
    content-type: text/plain; charset=UTF-8
    cache-control: no-cache
    expires: Fri, 01 Jan 1990 00:00:00 GMT
    content-length: 27
    server: Development/2.0
    date: Sun, 02 Nov 2014 13:05:38 GMT

body: 
Sorry, Nothing at this URL.

Whereas I know that doing the query for localhost:8080/todos/4980856393302016 through Postman works:

{
id: 4980856393302016,
completed: false,
title: "dredd"
}

@webmaven
Copy link
Contributor Author

webmaven commented Nov 2, 2014

@proppy, same issue with PUT and DELETE for Todos.

@proppy
Copy link
Collaborator

proppy commented Nov 2, 2014

@webmaven make sure you run the hooks with --hookfiles

@proppy
Copy link
Collaborator

proppy commented Nov 2, 2014

Also see #3

@webmaven
Copy link
Contributor Author

webmaven commented Nov 2, 2014

@proppy, this is how I have been running the tests: dredd todos.apib http://localhost:8080 --hookfiles=hooks.js

but it looks like I was missing an npm module. So now the GET passes, but PUT and DELETE still don't.

Here is an entire run:

webmaven@workshop:~/projects/appengine-todos-morepath$ dredd todos.apib http://localhost:8080 --hookfiles=hooks.js
info: Found Hookfiles: hooks.js
info: Beginning Dredd testing...
pass: POST /todos duration: 930ms
pass: GET /todos duration: 112ms
pass: DELETE /todos duration: 56ms
pass: GET /todos/42 duration: 85ms
fail: PUT /todos/42 duration: 68ms
fail: DELETE /todos/42 duration: 99ms
info: Displaying failed tests...
fail: PUT /todos/42 duration: 68ms
fail: headers: Value of the ‘content-type’ must be application/json; charset=UTF-8.
body: No validator found for real data media type 'text/plain' and expected data media type 'application/json; charset=UTF-8'.
statusCode: Real and expected data does not match.

request: 
body: 
{
  "title": "dredd",
  "completed": true
}
headers: 
    Content-Type: application/json
    User-Agent: Dredd/0.3.14 (Linux 3.11.0-26-generic; x64)
    Content-Length: 64

uri: /todos/42
method: PUT


expected: 
headers: 
    Content-Type: application/json; charset=UTF-8

body: 
    {
        "id": 42,
        "title": "dredd",
        "completed": true
    }

statusCode: 200


actual: 
statusCode: 404
headers: 
    content-type: text/plain; charset=UTF-8
    cache-control: no-cache
    expires: Fri, 01 Jan 1990 00:00:00 GMT
    content-length: 27
    server: Development/2.0
    date: Sun, 02 Nov 2014 15:21:18 GMT

body: 
Sorry, Nothing at this URL.



fail: DELETE /todos/42 duration: 99ms
fail: body: Unknown real body media type. Content-type header is "application/json; charset=UTF-8" but body is not a parseble JSON.
Parse error on line 1:

^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'EOF'
body: No validator found for real data media type 'null' and expected data media type 'text/plain'.

request: 
body: 

headers: 
    User-Agent: Dredd/0.3.14 (Linux 3.11.0-26-generic; x64)

uri: /todos/42
method: DELETE


expected: 
headers: 

body: 

statusCode: 204


actual: 
statusCode: 204
headers: 
    content-type: application/json; charset=UTF-8
    server: Development/2.0
    date: Sun, 02 Nov 2014 15:21:18 GMT

body: 




complete: 4 passing, 2 failing, 0 errors, 0 skipped
complete: Tests took 3484ms
webmaven@workshop:~/projects/appengine-todos-morepath$ 

@proppy
Copy link
Collaborator

proppy commented Nov 2, 2014

Which npm install? Was the dep missing in package.json? Can you run again with --level silly

@webmaven
Copy link
Contributor Author

webmaven commented Nov 2, 2014

The package I was missing was 'async'. Since I installed dredd manually, I didn't get all the requirements for the hooks file. Here is the run with --level silly

webmaven@workshop:~/projects/appengine-todos-morepath$ dredd todos.apib http://localhost:8080 --hookfiles=hooks.js --level silly
info: Found Hookfiles: hooks.js
info: Beginning Dredd testing...
pass: POST /todos duration: 185ms
pass: GET /todos duration: 45149ms
pass: DELETE /todos duration: 59ms
debug: Running hooks...
debug: Running hooks...
pass: GET /todos/42 duration: 73ms
fail: PUT /todos/42 duration: 66ms
debug: Running hooks...
fail: DELETE /todos/42 duration: 94ms
debug: Running hooks...
info: Displaying failed tests...
fail: PUT /todos/42 duration: 66ms
fail: headers: Value of the ‘content-type’ must be application/json; charset=UTF-8.
body: No validator found for real data media type 'text/plain' and expected data media type 'application/json; charset=UTF-8'.
statusCode: Real and expected data does not match.

request: 
body: 
{
  "title": "dredd",
  "completed": true
}
headers: 
    Content-Type: application/json
    User-Agent: Dredd/0.3.14 (Linux 3.11.0-26-generic; x64)
    Content-Length: 64

uri: /todos/42
method: PUT


expected: 
headers: 
    Content-Type: application/json; charset=UTF-8

body: 
    {
        "id": 42,
        "title": "dredd",
        "completed": true
    }

statusCode: 200


actual: 
statusCode: 404
headers: 
    content-type: text/plain; charset=UTF-8
    cache-control: no-cache
    expires: Fri, 01 Jan 1990 00:00:00 GMT
    content-length: 27
    server: Development/2.0
    date: Sun, 02 Nov 2014 16:13:13 GMT

body: 
Sorry, Nothing at this URL.



fail: DELETE /todos/42 duration: 94ms
fail: body: Unknown real body media type. Content-type header is "application/json; charset=UTF-8" but body is not a parseble JSON.
Parse error on line 1:

^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'EOF'
body: No validator found for real data media type 'null' and expected data media type 'text/plain'.

request: 
body: 

headers: 
    User-Agent: Dredd/0.3.14 (Linux 3.11.0-26-generic; x64)

uri: /todos/42
method: DELETE


expected: 
headers: 

body: 

statusCode: 204


actual: 
statusCode: 204
headers: 
    content-type: application/json; charset=UTF-8
    server: Development/2.0
    date: Sun, 02 Nov 2014 16:13:13 GMT

body: 




complete: 4 passing, 2 failing, 0 errors, 0 skipped
complete: Tests took 46070ms
webmaven@workshop:~/projects/appengine-todos-morepath$ 

@webmaven
Copy link
Contributor Author

webmaven commented Nov 2, 2014

OK, after this I got the Todo DELETEs working by forcing the returned content-type to text/plain. PUTs still not passing, though.

@webmaven
Copy link
Contributor Author

webmaven commented Nov 2, 2014

Turns out the test couldn't pass. I extended the hooks.js file (PR #8 ) and now all is (finally) well:

webmaven@workshop:~/projects/appengine-todos-morepath$ dredd todos.apib http://localhost:8080 --hookfiles=hooks.js
info: Found Hookfiles: hooks.js
info: Beginning Dredd testing...
pass: POST /todos duration: 629ms
pass: GET /todos duration: 101ms
pass: DELETE /todos duration: 52ms
pass: GET /todos/42 duration: 74ms
pass: PUT /todos/42 duration: 106ms
pass: DELETE /todos/42 duration: 72ms
complete: 6 passing, 0 failing, 0 errors, 0 skipped
complete: Tests took 1694ms
webmaven@workshop:~/projects/appengine-todos-morepath$

@stephenplusplus
Copy link
Member

Just a note for @proppy -- we were getting a false positive from our implementation because of our magic .save method, that inserts if an entity doesn't exist.

@webmaven
Copy link
Contributor Author

webmaven commented Nov 2, 2014

Ah, you were using get_or_insert() for Todo as well as the TodoList? Let me know if either of you have any suggestions for improving my implementation that is based on @proppy's early code: https://github.com/webmaven/appengine-todos-morepath

stephenplusplus added a commit that referenced this issue Nov 3, 2014
Include a hook for the PUT test so it passes too. Closes Issue #4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants