UNPKG

3.84 kBtext/coffeescriptView Raw
1esm_tests = (ESM) ->
2 ns = "default"
3
4 describe 'ESM compacting database', ->
5 describe '#compact_people', ->
6 it 'should truncate the events of peoples history', ->
7 init_esm(ESM,ns)
8 .then (esm) ->
9 bb.all([
10 esm.add_event(ns, 'p1','view','t1')
11 esm.add_event(ns, 'p1','view','t2')
12 esm.add_event(ns, 'p1','view','t3')
13 ])
14 .then( ->
15 esm.pre_compact(ns)
16 )
17 .then( ->
18 esm.count_events(ns)
19 )
20 .then( (count) ->
21 count.should.equal 3
22 esm.compact_people(ns, 2, ['view'])
23 )
24 .then( ->
25 esm.count_events(ns)
26 )
27 .then( (count) ->
28 count.should.equal 2
29 )
30
31
32 it 'should truncate people by action', ->
33 init_esm(ESM)
34 .then (esm) ->
35 bb.all([
36
37 esm.add_event(ns, 'p1','view','t2', created_at: new Date(4000))
38 esm.add_event(ns, 'p1','view','t3', created_at: new Date(3000))
39 esm.add_event(ns, 'p1','buy','t3', created_at: new Date(1000))
40
41 esm.add_event(ns, 'p1','view','t1', created_at: new Date(5000))
42 esm.add_event(ns, 'p1','buy','t1', created_at: new Date(6000))
43 ])
44 .then( ->
45 esm.pre_compact(ns)
46 )
47 .then( ->
48 esm.compact_people(ns, 1, ['view', 'buy'])
49 )
50 .then( ->
51 esm.post_compact(ns)
52 )
53 .then( ->
54 bb.all([esm.count_events(ns), esm.find_events(ns, person: 'p1', action: 'view', thing: 't1'), esm.find_events(ns, person: 'p1', action: 'buy', thing: 't1')])
55 )
56 .spread( (count, es1, es2) ->
57 count.should.equal 2
58 es1.length.should.equal 1
59 es2.length.should.equal 1
60 )
61
62
63 describe '#compact_things', ->
64 it 'should truncate the events of things history', ->
65 init_esm(ESM)
66 .then (esm) ->
67 bb.all([
68 esm.add_event(ns, 'p1','view','t1')
69 esm.add_event(ns, 'p2','view','t1')
70 esm.add_event(ns, 'p3','view','t1')
71 ])
72 .then( ->
73 esm.pre_compact(ns)
74 )
75 .then( ->
76 esm.count_events(ns)
77 )
78 .then( (count) ->
79 count.should.equal 3
80 esm.compact_things(ns, 2, ['view'])
81 )
82 .then( ->
83 esm.count_events(ns)
84 )
85 .then( (count) ->
86 count.should.equal 2
87 )
88
89 it 'should truncate things by action', ->
90 init_esm(ESM)
91 .then (esm) ->
92 bb.all([
93
94 esm.add_event(ns, 'p1','view','t1', created_at: new Date(4000))
95 esm.add_event(ns, 'p1','view','t1', created_at: new Date(3000))
96 esm.add_event(ns, 'p1','buy','t1', created_at: new Date(1000))
97
98 esm.add_event(ns, 'p1','view','t1', created_at: new Date(5000))
99 esm.add_event(ns, 'p1','buy','t1', created_at: new Date(6000))
100 ])
101 .then( ->
102 esm.pre_compact(ns)
103 )
104 .then( ->
105 esm.compact_things(ns, 1, ['view', 'buy'])
106 )
107 .then( ->
108 esm.post_compact(ns)
109 )
110 .then( ->
111 bb.all([esm.count_events(ns), esm.find_events(ns, action: 'view', thing: 't1'), esm.find_events(ns, action: 'buy', thing: 't1')])
112 )
113 .spread( (count, es1, es2) ->
114 count.should.equal 2
115 es1.length.should.equal 1
116 es2.length.should.equal 1
117 )
118
119
120 describe '#pre_compact', ->
121 it 'should prepare the ESM for compaction'
122
123 describe '#post_compact', ->
124 it 'should perform tasks after compaction'
125
126
127module.exports = esm_tests;
128
129