@@ -31,8 +31,15 @@ describe('cli', function () {
3131 beforeEach ( function ( ) {
3232 rmrf . sync ( tmpDir )
3333 fs . mkdirSync ( tmpDir )
34- fs . writeFileSync ( dbFile , JSON . stringify ( { posts : [ { 'id' : 1 , '_id' : 2 } ] } ) )
35- fs . writeFileSync ( routesFile , JSON . stringify ( { '/blog/' : '/' } ) )
34+ fs . writeFileSync ( dbFile , JSON . stringify ( {
35+ posts : [
36+ { id : 1 } ,
37+ { _id : 2 }
38+ ]
39+ } ) )
40+ fs . writeFileSync ( routesFile , JSON . stringify ( {
41+ '/blog/' : '/'
42+ } ) )
3643 ++ PORT
3744 request = supertest ( 'http://localhost:' + PORT )
3845 } )
@@ -49,7 +56,7 @@ describe('cli', function () {
4956 serverReady ( PORT , done )
5057 } )
5158
52- it ( 'should support JSON dbFile ' , function ( done ) {
59+ it ( 'should support JSON file ' , function ( done ) {
5360 request . get ( '/posts' ) . expect ( 200 , done )
5461 } )
5562
@@ -62,6 +69,17 @@ describe('cli', function () {
6269 . expect ( 200 , done )
6370 } )
6471
72+ it ( 'should update JSON file' , function ( done ) {
73+ request . post ( '/posts' )
74+ . send ( { title : 'hello' } )
75+ . end ( function ( ) {
76+ var str = fs . readFileSync ( dbFile , 'utf8' )
77+ setTimeout ( function ( ) {
78+ assert ( str . indexOf ( 'hello' ) !== - 1 )
79+ done ( )
80+ } , 1000 )
81+ } )
82+ } )
6583 } )
6684
6785 describe ( 'seed.js' , function ( ) {
0 commit comments