mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-26 07:52:30 +00:00
test: Move store tests to subdir.
This commit is contained in:
parent
421bd5c694
commit
d8145edcc3
@ -1,201 +0,0 @@
|
|||||||
// import assert from 'assert'
|
|
||||||
// import rmrf from 'rimraf'
|
|
||||||
// import path from 'path'
|
|
||||||
// import OrbitDB from '../src/OrbitDB.js'
|
|
||||||
|
|
||||||
// // Include test utilities
|
|
||||||
// import {
|
|
||||||
// config,
|
|
||||||
// startIpfs,
|
|
||||||
// stopIpfs,
|
|
||||||
// testAPIs,
|
|
||||||
// } from 'orbit-db-test-utils'
|
|
||||||
|
|
||||||
// const dbPath = './orbitdb/tests/docstore'
|
|
||||||
|
|
||||||
// Object.keys(testAPIs).forEach(API => {
|
|
||||||
// describe(`orbit-db - Document Store (${API})`, function() {
|
|
||||||
// this.timeout(config.timeout)
|
|
||||||
|
|
||||||
// let ipfsd, ipfs, orbitdb1, db
|
|
||||||
|
|
||||||
// before(async () => {
|
|
||||||
// ipfsd = await startIpfs(API, config.daemon1)
|
|
||||||
// ipfs = ipfsd.api
|
|
||||||
// orbitdb1 = await OrbitDB.createInstance(ipfs, { directory: path.join(dbPath, '1') })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// after(async () => {
|
|
||||||
// if(orbitdb1)
|
|
||||||
// await orbitdb1.stop()
|
|
||||||
|
|
||||||
// if (ipfsd)
|
|
||||||
// await stopIpfs(ipfsd)
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('creates and opens a database', async () => {
|
|
||||||
// db = await orbitdb1.docstore('first doc database')
|
|
||||||
// assert.notEqual(db, null)
|
|
||||||
// assert.equal(db.type, 'docstore')
|
|
||||||
// assert.equal(db.dbname, 'first doc database')
|
|
||||||
// })
|
|
||||||
|
|
||||||
// describe('Default index \'_id\'', function() {
|
|
||||||
// beforeEach(async () => {
|
|
||||||
// const options = {
|
|
||||||
// replicate: false,
|
|
||||||
// maxHistory: 0,
|
|
||||||
// path: dbPath,
|
|
||||||
// }
|
|
||||||
// db = await orbitdb1.docstore('orbit-db-tests', options)
|
|
||||||
// })
|
|
||||||
|
|
||||||
// afterEach(async () => {
|
|
||||||
// await db.drop()
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('put', async () => {
|
|
||||||
// const doc = { _id: 'hello world', doc: 'all the things'}
|
|
||||||
// await db.put(doc)
|
|
||||||
// const value = db.get('hello world')
|
|
||||||
// assert.deepEqual(value, [doc])
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('get - partial term match', async () => {
|
|
||||||
// const doc1 = { _id: 'hello world', doc: 'some things'}
|
|
||||||
// const doc2 = { _id: 'hello universe', doc: 'all the things'}
|
|
||||||
// const doc3 = { _id: 'sup world', doc: 'other things'}
|
|
||||||
// await db.put(doc1)
|
|
||||||
// await db.put(doc2)
|
|
||||||
// await db.put(doc3)
|
|
||||||
// const value = db.get('hello')
|
|
||||||
// assert.deepEqual(value, [doc1, doc2])
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('get after delete', async () => {
|
|
||||||
// const doc1 = { _id: 'hello world', doc: 'some things'}
|
|
||||||
// const doc2 = { _id: 'hello universe', doc: 'all the things'}
|
|
||||||
// const doc3 = { _id: 'sup world', doc: 'other things'}
|
|
||||||
// await db.put(doc1)
|
|
||||||
// await db.put(doc2)
|
|
||||||
// await db.put(doc3)
|
|
||||||
// await db.del('hello universe')
|
|
||||||
// const value1 = db.get('hello')
|
|
||||||
// const value2 = db.get('sup')
|
|
||||||
// assert.deepEqual(value1, [doc1])
|
|
||||||
// assert.deepEqual(value2, [doc3])
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('put updates a value', async () => {
|
|
||||||
// const doc1 = { _id: 'hello world', doc: 'all the things'}
|
|
||||||
// const doc2 = { _id: 'hello world', doc: 'some of the things'}
|
|
||||||
// await db.put(doc1)
|
|
||||||
// await db.put(doc2)
|
|
||||||
// const value = db.get('hello')
|
|
||||||
// assert.deepEqual(value, [doc2])
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('query', async () => {
|
|
||||||
// const doc1 = { _id: 'hello world', doc: 'all the things', views: 17}
|
|
||||||
// const doc2 = { _id: 'sup world', doc: 'some of the things', views: 10}
|
|
||||||
// const doc3 = { _id: 'hello other world', doc: 'none of the things', views: 5}
|
|
||||||
// const doc4 = { _id: 'hey universe', doc: ''}
|
|
||||||
|
|
||||||
// await db.put(doc1)
|
|
||||||
// await db.put(doc2)
|
|
||||||
// await db.put(doc3)
|
|
||||||
// await db.put(doc4)
|
|
||||||
|
|
||||||
// const value1 = db.query((e) => e.views > 5)
|
|
||||||
// const value2 = db.query((e) => e.views > 10)
|
|
||||||
// const value3 = db.query((e) => e.views > 17)
|
|
||||||
|
|
||||||
// assert.deepEqual(value1, [doc1, doc2])
|
|
||||||
// assert.deepEqual(value2, [doc1])
|
|
||||||
// assert.deepEqual(value3, [])
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('query after delete', async () => {
|
|
||||||
// const doc1 = { _id: 'hello world', doc: 'all the things', views: 17}
|
|
||||||
// const doc2 = { _id: 'sup world', doc: 'some of the things', views: 10}
|
|
||||||
// const doc3 = { _id: 'hello other world', doc: 'none of the things', views: 5}
|
|
||||||
// const doc4 = { _id: 'hey universe', doc: ''}
|
|
||||||
|
|
||||||
// await db.put(doc1)
|
|
||||||
// await db.put(doc2)
|
|
||||||
// await db.put(doc3)
|
|
||||||
// await db.del('hello world')
|
|
||||||
// await db.put(doc4)
|
|
||||||
// const value1 = db.query((e) => e.views >= 5)
|
|
||||||
// const value2 = db.query((e) => e.views >= 10)
|
|
||||||
// assert.deepEqual(value1, [doc2, doc3])
|
|
||||||
// assert.deepEqual(value2, [doc2])
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('query returns full op', async () => {
|
|
||||||
// const doc1 = { _id: 'hello world', doc: 'all the things', views: 17}
|
|
||||||
// const doc2 = { _id: 'sup world', doc: 'some of the things', views: 10}
|
|
||||||
|
|
||||||
// const expectedOperation = {
|
|
||||||
// op: 'PUT',
|
|
||||||
// key: 'sup world',
|
|
||||||
// value: {
|
|
||||||
// _id: 'sup world',
|
|
||||||
// doc: 'some of the things',
|
|
||||||
// views: 10
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
|
|
||||||
// await db.put(doc1)
|
|
||||||
// await db.put(doc2)
|
|
||||||
|
|
||||||
// const res = db.query(e => e.payload.value.views < 17, { fullOp: true })[0]
|
|
||||||
// assert.notEqual(res, undefined)
|
|
||||||
// assert.notEqual(res.hash, undefined)
|
|
||||||
// assert.notEqual(res.id, undefined)
|
|
||||||
// assert.deepEqual(res.payload, expectedOperation)
|
|
||||||
// assert.notEqual(res.next, undefined)
|
|
||||||
// assert.equal(res.next.length, 1)
|
|
||||||
// assert.equal(res.refs.length, 0)
|
|
||||||
// assert.equal(res.v, 2)
|
|
||||||
// assert.notEqual(res.clock, undefined)
|
|
||||||
// assert.equal(res.clock.time, 2)
|
|
||||||
// assert.notEqual(res.key, undefined)
|
|
||||||
// assert.notEqual(res.sig, undefined)
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// describe('Specified index', function() {
|
|
||||||
// beforeEach(async () => {
|
|
||||||
// const options = {
|
|
||||||
// indexBy: 'doc',
|
|
||||||
// replicate: false,
|
|
||||||
// maxHistory: 0
|
|
||||||
// }
|
|
||||||
// db = await orbitdb1.docstore('orbit-db-tests', options)
|
|
||||||
// })
|
|
||||||
|
|
||||||
// afterEach(async () => {
|
|
||||||
// await db.drop()
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('put', async () => {
|
|
||||||
// const doc = { _id: 'hello world', doc: 'all the things'}
|
|
||||||
// await db.put(doc)
|
|
||||||
// const value = db.get('all')
|
|
||||||
// assert.deepEqual(value, [doc])
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('get - matches specified index', async () => {
|
|
||||||
// const doc1 = { _id: 'hello world', doc: 'all the things'}
|
|
||||||
// const doc2 = { _id: 'hello world', doc: 'some things'}
|
|
||||||
// await db.put(doc1)
|
|
||||||
// await db.put(doc2)
|
|
||||||
// const value1 = db.get('all')
|
|
||||||
// const value2 = db.get('some')
|
|
||||||
// assert.deepEqual(value1, [doc1])
|
|
||||||
// assert.deepEqual(value2, [doc2])
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// })
|
|
Loading…
x
Reference in New Issue
Block a user