-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
98 lines (79 loc) · 2.56 KB
/
index.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import {makeMongooseDriver} from '../lib'
import {run} from '@cycle/core'
import {of, merge} from 'rx-factory'
import test from 'tape'
import mongoose from 'mongoose'
const schema = mongoose.Schema({name: 'string'})
schema.statics.customFindById = function (id, cb) {
this.findById(id, cb)
}
mongoose.model('TestModel', schema)
var db = makeMongooseDriver('mongodb://localhost/mongoose-cycle-driver-test')
test('Request API', {timeout: 1000}, (t) => {
const main = ({db}) => {
t.plan(8)
let created$ = db.select({create: _ => _}).mergeAll()
created$.subscribe(x => t.ok(x, 'create method'))
db.select({findById: _ => _}).mergeAll()
.subscribe(x => t.ok(x, 'request contains findById method returning promise'))
db.select({customFindById: _ => _}).mergeAll()
.subscribe(x => t.ok(x, 'request contains custom method (with callback)'))
db.select('queryArray').mergeAll()
.subscribe(x => t.ok(x, 'query is array (chain) of method calls'))
db.select('queryObj').mergeAll()
.subscribe(x => t.ok(x, 'query is an object (single method call)'))
db.select('queryFuncToExec').mergeAll()
.subscribe(x => t.ok(x, 'query is a function for exec()'))
db.select('queryFuncPromise').mergeAll()
.subscribe(x => t.ok(x, 'query is a function returning promise'))
db.select({remove: _ => _}).mergeAll()
.subscribe(x => {
t.is(x.result.ok, 1, 'remove method')
t.end()
})
return {
db: merge([
of({
Model: 'TestModel',
create: {
name: 'John',
age: '10'
}
}),
created$.map(({id}) => ({
Model: 'TestModel',
findById: id
})),
created$.map(({id}) => ({
Model: 'TestModel',
customFindById: id
})),
created$.map(({id}) => ({
Model: 'TestModel',
category: 'queryArray',
query: [{findById: id}, {select: 'name'}]
})),
created$.map(({id}) => ({
Model: 'TestModel',
category: 'queryObj',
query: {findById: id}
})),
created$.map(({id}) => ({
Model: 'TestModel',
category: 'queryFuncToExec',
query: (m) => m.findById(id)
})),
created$.map(({id}) => ({
Model: 'TestModel',
category: 'queryFuncPromise',
query: (m) => m.findById(id).exec()
})),
created$.map(({_id}) => ({
Model: 'TestModel',
remove: {_id}
})).delay(200)
])
}
}
run(main, {db})
})