Skip to content

Commit 1c6fe60

Browse files
committed
Refactor
1 parent 5439df6 commit 1c6fe60

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const app = require('./src/app')
2+
const port = process.env.PORT || 3000
3+
4+
app.listen(port, () => {
5+
console.log('JSONPlaceholder listening on http://localhost:' + port)
6+
})

src/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ app.use((req, res, next) => {
1414
app.use(jsonServer.defaults({
1515
logger: process.env.NODE_ENV !== 'production'
1616
}))
17+
1718
app.use(router)
1819

1920
module.exports = app

test/app.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const test = require('tape')
2+
const request = require('supertest')
3+
const app = require('../src/app')
4+
5+
test('GET /', (t) => {
6+
request(app)
7+
.get('/')
8+
.expect(200, (err) => t.end(err))
9+
})
10+
11+
test('POST /', (t) => {
12+
request(app)
13+
.post('/posts')
14+
.send({ body: 'foo' })
15+
.expect(201, (err) => {
16+
t.error(err)
17+
// Check that GET /posts length still returns 100 items
18+
request(app)
19+
.get('/posts')
20+
.expect(200, (err, res) => {
21+
t.error(err)
22+
t.equal(res.body.length, 100, 'more than 100 posts found')
23+
t.end()
24+
})
25+
})
26+
})

0 commit comments

Comments
 (0)