Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Mar 24, 2016
1 parent 5439df6 commit 1c6fe60
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const app = require('./src/app')
const port = process.env.PORT || 3000

app.listen(port, () => {
console.log('JSONPlaceholder listening on http://localhost:' + port)
})
1 change: 1 addition & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ app.use((req, res, next) => {
app.use(jsonServer.defaults({
logger: process.env.NODE_ENV !== 'production'
}))

app.use(router)

module.exports = app
26 changes: 26 additions & 0 deletions test/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const test = require('tape')
const request = require('supertest')
const app = require('../src/app')

test('GET /', (t) => {
request(app)
.get('/')
.expect(200, (err) => t.end(err))
})

test('POST /', (t) => {
request(app)
.post('/posts')
.send({ body: 'foo' })
.expect(201, (err) => {
t.error(err)
// Check that GET /posts length still returns 100 items
request(app)
.get('/posts')
.expect(200, (err, res) => {
t.error(err)
t.equal(res.body.length, 100, 'more than 100 posts found')
t.end()
})
})
})

0 comments on commit 1c6fe60

Please sign in to comment.