mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-07-02 18:42:31 +00:00
Add a couple tests for determineAddress
This commit is contained in:
parent
2435560c95
commit
2378b654a5
@ -186,6 +186,48 @@ Object.keys(testAPIs).forEach(API => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('determineAddress', function() {
|
||||
describe('Errors', function() {
|
||||
it('throws an error if given an invalid database type', async () => {
|
||||
let err
|
||||
try {
|
||||
await orbitdb.determineAddress('first', 'invalid-type')
|
||||
} catch (e) {
|
||||
err = e.toString()
|
||||
}
|
||||
assert.equal(err, 'Error: Invalid database type \'invalid-type\'')
|
||||
})
|
||||
|
||||
it('throws an error if given an address instead of name', async () => {
|
||||
let err
|
||||
try {
|
||||
await orbitdb.determineAddress('/orbitdb/Qmc9PMho3LwTXSaUXJ8WjeBZyXesAwUofdkGeadFXsqMzW/first', 'feed')
|
||||
} catch (e) {
|
||||
err = e.toString()
|
||||
}
|
||||
assert.equal(err, 'Error: Given database name is an address. Please give only the name of the database!')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Success', function() {
|
||||
before(async () => {
|
||||
address = await orbitdb.determineAddress('third', 'feed', { replicate: false })
|
||||
localDataPath = path.join(dbPath, address.root, address.path)
|
||||
})
|
||||
|
||||
it('does not save the address locally', async () => {
|
||||
assert.equal(fs.existsSync(localDataPath), false)
|
||||
})
|
||||
|
||||
it('returns the address that would have been created', async () => {
|
||||
db = await orbitdb.create('third', 'feed', { replicate: false })
|
||||
assert.equal(address.toString().indexOf('/orbitdb'), 0)
|
||||
assert.equal(address.toString().indexOf('Qm'), 9)
|
||||
assert.equal(address.toString(), db.address.toString())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Open', function() {
|
||||
before(async () => {
|
||||
db = await orbitdb.open('abc', { create: true, type: 'feed' })
|
||||
|
Loading…
x
Reference in New Issue
Block a user