forked from osv/meteor-mongo-counter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
counter.tests.js
47 lines (39 loc) · 1.59 KB
/
counter.tests.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
export const Counters = new Mongo.Collection("counters");
Tinytest.add('mongo-counter delete counters',
(test) => {
deleteCounters(Counters)
})
Tinytest.add('mongo-counter inc counters', (test) => {
test.equal(incrementCounter(Counters, 'foo'), 1)
test.equal(incrementCounter(Counters, 'foo'), 2)
test.equal(incrementCounter(Counters, 'foo'), 3)
test.equal(incrementCounter(Counters, 'foo', 10), 13)
})
Tinytest.add('mongo-counter dec counters', (test) => {
test.equal(decrementCounter(Counters, 'foo'), 12)
})
Tinytest.add('mongo-counter get counter', (test) => {
setCounter(Counters, 'foo', 100)
test.equal(getCounter(Counters, 'foo'), 100)
test.equal(decrementCounter(Counters, 'foo'), 99)
test.equal(getCounter(Counters, 'foo'), 99)
test.equal(incrementCounter(Counters, 'foo'), 100)
test.equal(getCounter(Counters, 'foo'), 100)
test.equal(incrementCounter(Counters, 'foo'), 101)
test.equal(getCounter(Counters, 'foo'), 101)
})
Tinytest.add('mongo-counter set counter', (test) => {
setCounter(Counters, 'foo', 100)
test.equal(incrementCounter(Counters, 'foo'), 101)
test.equal(incrementCounter(Counters, 'bar'), 1)
})
Tinytest.add('mongo-counter set counter again', (test) => {
setCounter(Counters, 'bar', 100)
test.equal(decrementCounter(Counters, 'bar'), 99)
})
export const Counters2 = new Mongo.Collection("counters2");
Tinytest.add('mongo-counter run setCounter on fresh collection', (test) => {
deleteCounters(Counters2)
setCounter(Counters2, 'bar', 100)
test.equal(decrementCounter(Counters2, 'bar'), 99)
})