Browse Source

fix test after changes to store

Kieran Gibb 2 years ago
parent
commit
beb459ad40
No known key found for this signature in database
4 changed files with 46 additions and 11 deletions
  1. 0
    1
      main.js
  2. 1
    1
      package.json
  3. 23
    9
      test/controllers/groups/drive/all.test.js
  4. 22
    0
      test/controllers/groups/find.test.js

+ 0
- 1
main.js View File

@@ -6,7 +6,6 @@ const yargs = require('yargs')
6 6
 
7 7
 const argv = yargs.argv
8 8
 const storage = argv.storage || constants.storage
9
-console.log(storage)
10 9
 const config = Config(storage, { mount: argv.location })
11 10
 const location = config.options.get('mount')
12 11
 

+ 1
- 1
package.json View File

@@ -26,7 +26,7 @@
26 26
     "cobox-constants": "^1.0.0",
27 27
     "cobox-crypto": "git+https://ledger-git.dyne.org/cobox/cobox-crypto#development",
28 28
     "cobox-group": "git+https://ledger-git.dyne.org/cobox/cobox-group#development",
29
-    "cobox-group-store": "git+https://ledger-git.dyne.org/cobox/cobox-group-store#seed-collection",
29
+    "cobox-group-store": "git+https://ledger-git.dyne.org/cobox/cobox-group-store#development",
30 30
     "debug": "^4.1.1",
31 31
     "express": "^4.17.1",
32 32
     "express-validator": "^6.2.0",

+ 23
- 9
test/controllers/groups/drive/all.test.js View File

@@ -21,14 +21,8 @@ describe('GET /groups/:id/drive', (context) => {
21 21
     seedGroups(config, count)
22 22
     seed = config.groups.list()[0]
23 23
 
24
-    groups = {
25
-      store: Store(
26
-        path.join(config.root, 'groups'),
27
-        Group,
28
-        config.groups.list(),
29
-        { config }
30
-      )
31
-    }
24
+    groups = { store: Store(path.join(config.root, 'groups'), Group, { config }) }
25
+    groups.store.seed(config.groups.list())
32 26
 
33 27
     response = https.createResponse({
34 28
       eventEmitter: require('events').EventEmitter
@@ -49,9 +43,29 @@ describe('GET /groups/:id/drive', (context) => {
49 43
 
50 44
     response.on('end', () => {
51 45
       const messages = response._getJSONData()
52
-      console.log(messages)
53 46
       assert.equal(messages[0].value.filename, 'hello.txt', 'Expected response')
54 47
       cleanup(storage, next)
55 48
     })
56 49
   })
50
+
51
+  context('invalid with address', (assert, next) => {
52
+    var address = crypto.randomBytes(32).toString('hex')
53
+    request = https.createRequest({
54
+      method: 'GET',
55
+      url: `/groups/${address}`,
56
+      body: { address },
57
+      groups,
58
+      config
59
+    })
60
+
61
+    routeHandler(request, response)
62
+
63
+    response.on('end', () => {
64
+      var data = response._getJSONData()
65
+      let errors = data.errors
66
+      assert.ok(Array.isArray(errors), 'returns an error')
67
+      assert.same(errors[0].msg, 'group does not exist', 'returns an error message')
68
+      cleanup(storage, next)
69
+    })
70
+  })
57 71
 })

+ 22
- 0
test/controllers/groups/find.test.js View File

@@ -4,6 +4,7 @@ const Config = require('cobox-config')
4 4
 const Group = require('cobox-group/test/mock')
5 5
 const Store = require('cobox-group-store')
6 6
 const path = require('path')
7
+const crypto = require('cobox-crypto')
7 8
 
8 9
 const routeHandler = require('../../../app/controllers')
9 10
 const { tmp, cleanup } = require('../../util')
@@ -48,4 +49,25 @@ describe('GET /groups/:id', (context) => {
48 49
       cleanup(storage, next)
49 50
     })
50 51
   })
52
+
53
+  context('invalid if doesnt exist', (assert, next) => {
54
+    var address = crypto.randomBytes(32).toString('hex')
55
+    request = https.createRequest({
56
+      method: 'GET',
57
+      url: `/groups/${address}`,
58
+      body: { address },
59
+      groups,
60
+      config
61
+    })
62
+
63
+    routeHandler(request, response)
64
+
65
+    response.on('end', () => {
66
+      var data = response._getJSONData()
67
+      let errors = data.errors
68
+      assert.ok(Array.isArray(errors), 'returns an error')
69
+      assert.same(errors[0].msg, 'group does not exist', 'returns an error message')
70
+      cleanup(storage, next)
71
+    })
72
+  })
51 73
 })