这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"env": {
"mocha": true
},
"extends": "standard"
}
5 changes: 5 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recursive": true,
"timeout": 1000,
"exit": true
}
18 changes: 16 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const path = require('path')
const async = require('async')
const Lokue = require('lokue')
const Base = require('bfx-facs-base')
Expand All @@ -18,9 +19,22 @@ class LokueFacility extends Base {

const cal = this.caller

const {
dbPathAbsolute,
label,
persist
} = this.opts
const baseName = `${this.name}_${this.opts.name}_${label}.db.json`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue here, for undefined options.

also, tests are missing.

const name = (
typeof dbPathAbsolute === 'string' &&
path.isAbsolute(dbPathAbsolute)
)
? path.join(dbPathAbsolute, baseName)
: path.join(cal.ctx.root, 'db', baseName)

this.q = new Lokue({
name: `${cal.ctx.root}/db/${this.name}_${this.opts.name}_${this.opts.label}.db.json`,
persist: this.opts.persist
name,
persist
})
}

Expand Down
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bfx-facs-lokue",
"version": "0.0.1",
"version": "0.0.2",
"private": false,
"description": "Bitfinex Lokue Facility",
"author": {
Expand All @@ -11,6 +11,11 @@
"keywords": [
"bitfinex"
],
"scripts": {
"test": "npm run lint && npm run unit",
"unit": "mocha ./test/**/*.spec.js --config .mocharc.json",
"lint": "standard"
},
"dependencies": {
"async": "^2.6.1",
"bfx-facs-base": "git+https://github.com/bitfinexcom/bfx-facs-base.git",
Expand All @@ -30,5 +35,11 @@
"name": "prdn",
"email": "paolo@bitfinex.com"
}
]
],
"devDependencies": {
"mkdirp": "^0.5.1",
"mocha": "^7.0.0",
"rimraf": "^3.0.0",
"standard": "^14.3.1"
}
}
96 changes: 96 additions & 0 deletions test/general.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* eslint-env mocha */

'use strict'

const assert = require('assert')
const path = require('path')

const mkdirp = require('mkdirp')
const rimraf = require('rimraf')

const Fac = require('../')

const relativePathToDb = './db'
const absolutePathToDb = path.join(__dirname, 'db')
const fakeDbDir = path.join(__dirname, 'fake_db_dir')

beforeEach(() => {
rimraf.sync(absolutePathToDb)
mkdirp.sync(absolutePathToDb)

Fac.ctx = { root: '' }
})

afterEach(() => {
rimraf.sync(absolutePathToDb)
})

describe('General', () => {
it('Uses absolute path to db', (done) => {
const fac = new Fac(
Fac,
{
name: 'name',
label: 'label',
persist: true,
dbPathAbsolute: absolutePathToDb
}
)

fac._start((err) => {
assert.ifError(err)

fac._stop((err) => {
assert.ifError(err)

done()
})
})
})

it('Uses relative path to db', (done) => {
Fac.ctx = { root: './test' }

const fac = new Fac(
Fac,
{
name: 'name',
label: 'label',
persist: true,
dbPathAbsolute: relativePathToDb
}
)

fac._start((err) => {
assert.ifError(err)

fac._stop((err) => {
assert.ifError(err)

done()
})
})
})

it('Returns an error if db directory does not exist', (done) => {
const fac = new Fac(
Fac,
{
name: 'name',
label: 'label',
persist: true,
dbPathAbsolute: fakeDbDir
}
)

fac._start((err) => {
assert.ifError(err)

fac._stop((err) => {
assert.ok(err instanceof Error)

done()
})
})
})
})