mirror of
https://github.com/typicode/json-server.git
synced 2025-07-28 20:52:08 +08:00
53 lines
1.1 KiB
JavaScript
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)
|
|
})
|
|
})
|
|
})
|