-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsubscriptionTimebased.ts
83 lines (75 loc) · 1.62 KB
/
subscriptionTimebased.ts
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
import test from 'ava'
import { connect } from '../src/index'
import { SelvaServer, start } from '@saulx/selva-server'
import { wait } from './assertions'
import getPort from 'get-port'
let srv: SelvaServer
let port: number
test.before(async (t) => {
port = await getPort()
srv = await start({
port,
})
const client = connect({ port })
await client.updateSchema({
languages: ['en'],
types: {
aType: {
prefix: 'at',
fields: {
name: { type: 'string' },
value: { type: 'number' },
date: { type: 'timestamp' },
},
},
},
})
await client.destroy()
})
test.after(async (t) => {
const client = connect({ port })
await client.destroy()
await srv.destroy()
})
test.serial('simple find subscription time based', async (t) => {
t.timeout(3000)
const client = connect({ port })
const ts = Date.now()
await client.set({
type: 'aType',
name: 'name',
date: ts + 1000,
})
await wait(200)
let resultAmount = 0
client
.observe({
items: {
id: true,
$list: {
$find: {
$traverse: 'children',
$filter: [
{
$field: 'type',
$operator: '=',
$value: 'aType',
},
{
$field: 'date',
$operator: '>',
$value: 'now',
},
],
},
},
},
})
.subscribe((result) => {
resultAmount = result.items?.length
})
await wait(200)
t.is(resultAmount, 1)
await wait(1200)
t.is(resultAmount, 0)
})