Skip to content

Commit

Permalink
a test
Browse files Browse the repository at this point in the history
  • Loading branch information
tlevine committed Jan 15, 2013
1 parent d49b78a commit c1d1dcd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
13 changes: 5 additions & 8 deletions server/app.coffee
Expand Up @@ -34,27 +34,24 @@ server.put '/applications/:permitApplicationNumber', (req, res, next) ->
console.log req.query[key[0]]
sql = "UPDATE application SET #{key[0]} = ? WHERE permitApplicationNumber = ?;"
db.run sql, req.query[key[0]], req.params.permitApplicationNumber

res.send 200
res.status(204)
return next()

server.get '/applications/:permitApplicationNumber', (req, res, next) ->
db = new sqlite3.Database '/tmp/wetlands.db'
sql = "SELECT * FROM application WHERE permitApplicationNumber = ? LIMIT 1;"
db.get sql, req.params.permitApplicationNumber, (err, row) ->
if row
console.log row
res.send row
return next()
else
console.log 'no permit with this number'
res.send 200
return next()
return next(new restify.ResourceNotFoundError 'There is no permit with this number.')

server.get '/applications', (req, res, next) ->
db = new sqlite3.Database '/tmp/wetlands.db'
sql = "SELECT * FROM application;"
db.all sql, (err, rows) ->
console.log rows
res.send 200
res.send rows
return next()

server.listen 8080
4 changes: 3 additions & 1 deletion server/package.json
Expand Up @@ -15,6 +15,8 @@
"restify": "~2.0.4",
"sqlite3": "~2.1.5"
},
"devDependencies": {},
"devDependencies": {
"api-easy": "~0.3.7"
},
"optionalDependencies": {}
}
13 changes: 13 additions & 0 deletions server/test.coffee
@@ -0,0 +1,13 @@
APIeasy = require 'api-easy'
assert = require 'assert'

suite = APIeasy.describe '/applications'
suite.discuss('When I request the applications list,')
.use('localhost', 8080)
.setHeader('Content-Type', 'application/json')
.get('/applications', { test: 'data' })
.expect(200, { ok: true })
.expect('should respond with a 226-record JSON list', (err, res, body) ->
assert.equal (JSON.parse body).length, 226
)
.export module

0 comments on commit c1d1dcd

Please sign in to comment.