Created
August 27, 2012 10:31
-
-
Save phpnode/3487301 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set up our requirements | |
request = require "request" | |
chai = require "chai" | |
chai.should() | |
# The API provides several methods for interacting with users. | |
describe "API user", -> | |
# Get a list of records. The set of returned attributes for list may be different from view. | |
describe "list", -> | |
it "should return a list of users", (done) -> | |
# Make an API request | |
request {uri: "http://pph.local/api/v1/user"}, (err, response, body) -> | |
response.statusCode.should.equal 200 | |
res = JSON.parse body | |
# API responses come wrapped in an object that provides | |
# information about the request itself | |
res.should.have.property "success" | |
res.should.have.property("data").that.is.a "array" | |
res.should.have.property "count" | |
res.should.have.property "page" | |
res.should.have.property "pageCount" | |
res.should.have.property "nextUrl" | |
res.should.have.property "previousUrl" | |
# Make sure we have at least one user returned | |
res.data.length.should.be.above 0 | |
user = res.data[0] | |
# The following properties should always be available | |
user.should.have.property "id" | |
user.should.have.property "fname" | |
user.should.have.property "lname" | |
user.should.have.property "city" | |
user.should.have.property "country" | |
user.should.have.property "job_title" | |
user.should.have.property "photo" | |
user.should.have.property "industry" | |
user.should.have.property "about" | |
user.should.have.property "cv" | |
done err | |
# By default, the following attributes available for users | |
# id - the user's id | |
# fname - the user's first name | |
# lname - the user's last name | |
it "should let me choose which attributes to return", (done) -> | |
request {uri: "http://pph.local/api/v1/user?a=id"}, (err, response, body) -> | |
response.statusCode.should.equal 200 | |
res = JSON.parse body | |
# make sure we got at least one user | |
res.data.length.should.be.above 0 | |
# make sure we only returned the user's id | |
Object.keys(res.data[0]).should.eql ["id"] | |
done err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var chai, request; | |
request = require("request"); | |
chai = require("chai"); | |
chai.should(); | |
describe("API user", function() { | |
return describe("list", function() { | |
it("should return a list of users", function(done) { | |
return request({ | |
uri: "http://pph.local/api/v1/user" | |
}, function(err, response, body) { | |
var res, user; | |
response.statusCode.should.equal(200); | |
res = JSON.parse(body); | |
res.should.have.property("success"); | |
res.should.have.property("data").that.is.a("array"); | |
res.should.have.property("count"); | |
res.should.have.property("page"); | |
res.should.have.property("pageCount"); | |
res.should.have.property("nextUrl"); | |
res.should.have.property("previousUrl"); | |
res.data.length.should.be.above(0); | |
user = res.data[0]; | |
user.should.have.property("id"); | |
user.should.have.property("fname"); | |
user.should.have.property("lname"); | |
user.should.have.property("city"); | |
user.should.have.property("country"); | |
user.should.have.property("job_title"); | |
user.should.have.property("photo"); | |
user.should.have.property("industry"); | |
user.should.have.property("about"); | |
user.should.have.property("cv"); | |
return done(err); | |
}); | |
}); | |
return it("should let me choose which attributes to return", function(done) { | |
return request({ | |
uri: "http://pph.local/api/v1/user?a=id" | |
}, function(err, response, body) { | |
var res; | |
response.statusCode.should.equal(200); | |
res = JSON.parse(body); | |
res.data.length.should.be.above(0); | |
Object.keys(res.data[0]).should.eql(["id"]); | |
return done(err); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment