forked from typicode/json-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmixins.js
More file actions
61 lines (52 loc) · 1.34 KB
/
Copy pathmixins.js
File metadata and controls
61 lines (52 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const assert = require('assert')
const _ = require('lodash')
const lodashId = require('lodash-id')
const mixins = require('../../src/server/mixins')
describe('mixins', () => {
let db
before(() => {
_.mixin(lodashId)
_.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, { foreignKeySuffix: 'Id' }), expected)
})
it('should support custom foreignKeySuffix', () => {
const expected = [
{ name: 'comments', id: 2 },
{ name: 'comments', id: 3 }
]
assert.deepEqual(_.getRemovable(db, { foreignKeySuffix: 'Id' }), 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)
})
})
})