Browse Source

test: first test, at last!

noffle 3 years ago
parent
commit
e1cd57b978
2 changed files with 39 additions and 2 deletions
  1. 3
    2
      package.json
  2. 36
    0
      test/basic.js

+ 3
- 2
package.json View File

@@ -21,8 +21,9 @@
21 21
     "multifeed-index": "^3.2.2"
22 22
   },
23 23
   "devDependencies": {
24
-    "tape": "~4.6.2",
25
-    "standard": "~12.0.1"
24
+    "random-access-memory": "^3.1.1",
25
+    "standard": "~12.0.1",
26
+    "tape": "~4.6.2"
26 27
   },
27 28
   "license": "ISC"
28 29
 }

+ 36
- 0
test/basic.js View File

@@ -0,0 +1,36 @@
1
+var test = require('tape')
2
+var ram = require('random-access-memory')
3
+var kappa = require('..')
4
+
5
+test('simple view', function (t) {
6
+  var core = kappa(ram, { valueEncoding: 'json' })
7
+
8
+  var sum = 0
9
+
10
+  var sumview = {
11
+    api: {
12
+      get: function (core, cb) {
13
+        this.ready(function () {
14
+          cb(null, sum)
15
+        })
16
+      }
17
+    },
18
+    map: function (msgs, next) {
19
+      msgs.forEach(function (msg) {
20
+        if (typeof msg.value === 'number') sum += msg.value
21
+      })
22
+      next()
23
+    }
24
+  }
25
+
26
+  core.use('sum', sumview)
27
+
28
+  core.writer('default', function (err, feed) {
29
+    feed.append(1, function (err) {
30
+      core.api.sum.get(function (err, value) {
31
+        t.equals(1, value)
32
+        t.end()
33
+      })
34
+    })
35
+  })
36
+})