Browse Source

write a test for either regular Group or BlindReplicator

Kieran Gibb 2 years ago
parent
commit
e8f35d0013
No known key found for this signature in database
2 changed files with 60 additions and 13 deletions
  1. 1
    0
      package.json
  2. 59
    13
      test/index.test.js

+ 1
- 0
package.json View File

@@ -20,6 +20,7 @@
20 20
     "thunky": "^1.1.0"
21 21
   },
22 22
   "devDependencies": {
23
+    "cobox-blind-replicator": "git+https://ledger-git.dyne.org/cobox/cobox-blind-replicator",
23 24
     "mkdirp": "^0.5.1",
24 25
     "rimraf": "^3.0.0",
25 26
     "tap-spec": "^5.0.0",

+ 59
- 13
test/index.test.js View File

@@ -4,7 +4,8 @@ const crypto = require('cobox-crypto')
4 4
 const Store = require('../')
5 5
 
6 6
 const { tmp, cleanup } = require('./util')
7
-const createGroup = require('cobox-group/test/mock')
7
+const Group = require('cobox-group/test/mock')
8
+const BlindReplicator = require('cobox-blind-replicator/test/mock')
8 9
 
9 10
 describe('group store: basic', (context) => {
10 11
   context('ready()', async function (assert, next) {
@@ -15,7 +16,7 @@ describe('group store: basic', (context) => {
15 16
     config.groups.set(params.address, params)
16 17
 
17 18
     const collection = config.groups.list()
18
-    const store = Store(storage, createGroup, collection, { config })
19
+    const store = Store(storage, Group, collection, { config })
19 20
 
20 21
     try {
21 22
       await store.ready()
@@ -36,7 +37,7 @@ describe('group store: basic', (context) => {
36 37
     config.groups.set(params.address, params)
37 38
 
38 39
     const collection = config.groups.list()
39
-    const store = Store(storage, createGroup, collection, { config })
40
+    const store = Store(storage, Group, collection, { config })
40 41
 
41 42
     try {
42 43
       await store.ready()
@@ -59,7 +60,7 @@ describe('group store: basic', (context) => {
59 60
     config.groups.set(params.address, params)
60 61
 
61 62
     const collection = config.groups.list()
62
-    const store = Store(storage, createGroup, collection, { config })
63
+    const store = Store(storage, Group, collection, { config })
63 64
 
64 65
     try {
65 66
       await store.ready()
@@ -97,7 +98,7 @@ describe('group store: basic', (context) => {
97 98
     config.groups.set(params.address, params)
98 99
 
99 100
     const collection = config.groups.list()
100
-    const store = Store(storage, createGroup, collection, { config })
101
+    const store = Store(storage, Group, collection, { config })
101 102
 
102 103
     try {
103 104
       await store.ready()
@@ -123,7 +124,7 @@ describe('group store: basic', (context) => {
123 124
     config.groups.set(params.address, params)
124 125
 
125 126
     const collection = config.groups.list()
126
-    const store = Store(storage, createGroup, collection, { config })
127
+    const store = Store(storage, Group, collection, { config })
127 128
 
128 129
     try {
129 130
       await store.ready()
@@ -149,7 +150,7 @@ describe('group store: basic', (context) => {
149 150
     config.groups.set(params.address, params)
150 151
 
151 152
     const collection = config.groups.list()
152
-    const store = Store(storage, createGroup, collection, { config })
153
+    const store = Store(storage, Group, collection, { config })
153 154
 
154 155
     try {
155 156
       await store.ready()
@@ -175,7 +176,7 @@ describe('group store: basic', (context) => {
175 176
     config.groups.set(params.address, params)
176 177
 
177 178
     const collection = config.groups.list()
178
-    const store = Store(storage, createGroup, collection, { config })
179
+    const store = Store(storage, Group, collection, { config })
179 180
 
180 181
     try {
181 182
       await store.ready()
@@ -201,7 +202,7 @@ describe('group store: basic', (context) => {
201 202
     config.groups.set(params.address, params)
202 203
 
203 204
     const collection = config.groups.list()
204
-    const store = Store(storage, createGroup, collection, { config })
205
+    const store = Store(storage, Group, collection, { config })
205 206
 
206 207
     try {
207 208
       await store.ready()
@@ -226,7 +227,7 @@ describe('group store: basic', (context) => {
226 227
     config.groups.set(params.address, params)
227 228
 
228 229
     const collection = config.groups.list()
229
-    const store = Store(storage, createGroup, collection, { config })
230
+    const store = Store(storage, Group, collection, { config })
230 231
 
231 232
     try {
232 233
       await store.ready()
@@ -251,7 +252,7 @@ describe('group store: basic', (context) => {
251 252
     config.groups.set(params.address, params)
252 253
 
253 254
     const collection = config.groups.list()
254
-    const store = Store(storage, createGroup, collection, { config })
255
+    const store = Store(storage, Group, collection, { config })
255 256
 
256 257
     try {
257 258
       await store.ready()
@@ -272,7 +273,7 @@ describe('group store: basic', (context) => {
272 273
       params = Object.assign(crypto.keySet(), { name: 'magma' })
273 274
 
274 275
     const collection = config.groups.list()
275
-    const store = Store(storage, createGroup, collection, { config })
276
+    const store = Store(storage, Group, collection, { config })
276 277
 
277 278
     try {
278 279
       var group = await store.create(params)
@@ -289,7 +290,7 @@ describe('group store: basic', (context) => {
289 290
   //     params = crypto.keySet()
290 291
 
291 292
   //   config.groups.set(params.address, params)
292
-  //   const store = Store(createGroup, storage, { config })
293
+  //   const store = Store(Group, storage, { config })
293 294
 
294 295
   //   var groups = await store.all()
295 296
   //   console.log(groups.map((group) => group.address.toString('hex')))
@@ -299,3 +300,48 @@ describe('group store: basic', (context) => {
299 300
   //   cleanup(storage, next)
300 301
   // })
301 302
 })
303
+
304
+describe('multiple', (context) => {
305
+  context('factory', async (assert, next) => {
306
+    let storage = tmp(),
307
+      config = Config(storage),
308
+      group = crypto.keySet(),
309
+      replicator = { address: crypto.address() }
310
+
311
+    config.groups.set(group.address, group)
312
+    config.replicators.set(replicator.address, replicator)
313
+
314
+    const groups = config.groups.list()
315
+    const replicators = config.replicators.list()
316
+
317
+    const api = {
318
+      groups: {
319
+        store: Store(
320
+          storage,
321
+          Group,
322
+          groups,
323
+          { config }
324
+        )
325
+      },
326
+      replicators: {
327
+        store: Store(
328
+          storage,
329
+          BlindReplicator,
330
+          replicators,
331
+          { config }
332
+        )
333
+      }
334
+    }
335
+
336
+    await api.groups.store.ready()
337
+    await api.replicators.store.ready()
338
+
339
+    assert.same(Object.values(api.groups.store.collection).length, 1, 'builds then caches groups')
340
+    assert.same(Object.values(api.replicators.store.collection).length, 1, 'builds then caches replicators')
341
+
342
+    assert.ok(api.groups.store.collection[group.address.toString('hex')], 'accessible using address hex string')
343
+    assert.ok(api.replicators.store.collection[replicator.address.toString('hex')], 'accessible using address hex string')
344
+
345
+    cleanup(storage, next)
346
+  })
347
+})