Files
json-server/test/server/mixins.js
typicode 2b26630ac6 v0.9.0 (#404)
* Remove automatic type conversion

* Remove body-parser from default middlewares

* Ignore lib

* ES2015

* Use shortid

* Add babel-register

* Update paths to ./lib

* Add .npmignore

* Update bin

* temp fix

* Fix bin

* Add message when creating default db

* Use fs.watch

* Fix operator existence test

* Fix 0.12 tests

* Update dependencies

* Update

* Increase timeout

* Fix 0.12 support

* 0.9.0-beta.1

* Fix missing example.json issue

* 0.9.0-beta.2

* Update message

* Update CHANGELOG.md

* Update lowdb dependency

* Add error message

* Update README.md

* Add database validation

* Update

* Update

* Fix tests

* Update
2016-11-12 01:59:43 +01:00

53 lines
1.1 KiB
JavaScript

const assert = require('assert')
const _ = require('lodash')
const _db = require('underscore-db')
const mixins = require('../../src/server/mixins')
describe('mixins', () => {
let db
before(() => {
_.mixin(_db)
_.mixin(mixins)
})
beforeEach(() => {
db = {
posts: [
{ id: 1, comment: 1 }
],
comments: [
{ id: 1, postId: 1 },
// Comments below references a post that doesn't exist
{ id: 2, postId: 2 },
{ id: 3, postId: 2 }
],
photos: [
{ id: '1' },
{ id: '2' }
]
}
})
describe('getRemovable', () => {
it('should return removable documents', () => {
const expected = [
{ name: 'comments', id: 2 },
{ name: 'comments', id: 3 }
]
assert.deepEqual(_.getRemovable(db), expected)
})
})
describe('createId', () => {
it('should return a new id', () => {
assert.equal(_.createId(db.comments), 4)
})
it('should return a new uuid', () => {
assert.notEqual(_.createId(db.photos), 3)
})
})
})