Skip to content

Commit 71b6c95

Browse files
committed
test: should update json file
1 parent 2ce4590 commit 71b6c95

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

src/cli/utils/load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = function (source, cb) {
2828

2929
} else if (is.JSON(source)) {
3030

31-
data = low(source, { storage: fileAsync }).state()
31+
data = low(source, { storage: fileAsync }).getState()
3232
cb(null, data)
3333

3434
} else {

src/server/router/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function (source) {
2424
var db
2525
if (_.isObject(source)) {
2626
db = low()
27-
db.state(source)
27+
db.setState(source)
2828
} else {
2929
db = low(source, { storage: fileAsync })
3030
}
@@ -45,7 +45,7 @@ module.exports = function (source) {
4545

4646
// GET /db
4747
function showDatabase (req, res, next) {
48-
res.locals.data = db.state()
48+
res.locals.data = db.getState()
4949
next()
5050
}
5151

src/server/router/plural.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ module.exports = function (db, name) {
246246
var resource = db.get(name).removeById(utils.toNative(req.params.id)).value()
247247

248248
// Remove dependents documents
249-
var removable = db._.getRemovable(db.state())
249+
var removable = db._.getRemovable(db.getState())
250250

251251
_.each(removable, function (item) {
252252
db.get(item.name).removeById(item.id).value()

test/cli/index.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 () {

test/server/plural.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ describe('Server', function () {
556556

557557
describe('Database state', function () {
558558
it('should be accessible', function () {
559-
assert(router.db.state())
559+
assert(router.db.getState())
560560
})
561561
})
562562

@@ -614,7 +614,7 @@ describe('Server', function () {
614614
describe('router.db._.id', function (done) {
615615

616616
beforeEach(function () {
617-
router.db.state({
617+
router.db.getState({
618618
posts: [
619619
{ _id: 1 }
620620
]
@@ -627,7 +627,7 @@ describe('Server', function () {
627627
request(server)
628628
.get('/posts/1')
629629
.expect('Content-Type', /json/)
630-
.expect(router.db.state().posts[0])
630+
.expect(router.db.getState().posts[0])
631631
.expect(200, done)
632632
})
633633

0 commit comments

Comments
 (0)