mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-12-28 15:47:50 +01:00
commit
62629df926
3
.babelrc
3
.babelrc
@ -5,7 +5,8 @@
|
||||
"plugins": [
|
||||
"transform-export-extensions",
|
||||
"transform-object-assign",
|
||||
"transform-object-rest-spread"
|
||||
"transform-object-rest-spread",
|
||||
["transform-runtime", { "polyfill": false, "regenerator": true }]
|
||||
],
|
||||
"sourceMaps": true
|
||||
}
|
@ -46,7 +46,7 @@
|
||||
"babel-plugin-transform-export-extensions": "^6.22.0",
|
||||
"babel-plugin-transform-object-assign": "^6.22.0",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
||||
"babel-plugin-transform-runtime": "^6.22.0",
|
||||
"babel-plugin-transform-runtime": "^6.23.0",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"babel-preset-es2015-no-commonjs": "0.0.2",
|
||||
"babel-runtime": "^6.26.0",
|
||||
@ -80,6 +80,7 @@
|
||||
"js-utility-belt": "^1.5.0",
|
||||
"json-stable-stringify": "^1.0.1",
|
||||
"query-string": "^6.0.0",
|
||||
"rewire": "^4.0.1",
|
||||
"sprintf-js": "^1.1.1",
|
||||
"tweetnacl": "^1.0.0",
|
||||
"uglifyjs-webpack-plugin": "^1.2.7",
|
||||
|
@ -10,14 +10,14 @@ import coreObjectEntries from 'core-js/library/fn/object/entries'
|
||||
*/
|
||||
function filterFromObject(obj, filter, { isInclusion = true } = {}) {
|
||||
if (filter && Array.isArray(filter)) {
|
||||
return applyFilterOnObject(obj, isInclusion ? ((_, key) => coreIncludes(filter, key))
|
||||
: ((_, key) => !coreIncludes(filter, key)))
|
||||
return applyFilterOnObject(obj, isInclusion ? (val => coreIncludes(filter, val))
|
||||
: (val => !coreIncludes(filter, val)))
|
||||
} else if (filter && typeof filter === 'function') {
|
||||
// Flip the filter fn's return if it's for inclusion
|
||||
return applyFilterOnObject(obj, isInclusion ? filter
|
||||
: (...args) => !filter(...args))
|
||||
} else {
|
||||
throw new Error('The given filter is not an array or function. Exclude aborted')
|
||||
throw new Error('The given filter is not an array or function. Filter aborted')
|
||||
}
|
||||
}
|
||||
|
||||
|
15
test/base-request/test_baseRequest.js
Normal file
15
test/base-request/test_baseRequest.js
Normal file
@ -0,0 +1,15 @@
|
||||
import test from 'ava'
|
||||
import baseRequest from '../../src/baseRequest'
|
||||
|
||||
test('baseRequest test query and vsprint', async t => {
|
||||
const target = {
|
||||
message: 'HTTP Error: Requested page not reachable',
|
||||
requestURI: 'https://www.google.com/teapot',
|
||||
status: '418 I\'m a Teapot',
|
||||
}
|
||||
const error = await t.throws(baseRequest('https://%s.com/', {
|
||||
urlTemplateSpec: ['google'],
|
||||
query: 'teapot'
|
||||
}))
|
||||
t.deepEqual(target, error)
|
||||
})
|
@ -7,7 +7,7 @@ import { API_PATH } from '../constants'
|
||||
|
||||
const conn = new Connection(API_PATH)
|
||||
|
||||
test('Payload thrown at incorrect API_PATH', t => {
|
||||
test('Payload thrown at incorrect API_PATH', async t => {
|
||||
const path = 'http://localhost:9984/api/wrong/'
|
||||
const connection = new Connection(path)
|
||||
const target = {
|
||||
@ -15,10 +15,8 @@ test('Payload thrown at incorrect API_PATH', t => {
|
||||
status: '404 NOT FOUND',
|
||||
requestURI: 'http://localhost:9984/api/wrong/transactions/transactionId'
|
||||
}
|
||||
connection.getTransaction('transactionId')
|
||||
.catch(error => {
|
||||
t.deepEqual(target, error)
|
||||
})
|
||||
const error = await t.throws(connection.getTransaction('transactionId'))
|
||||
t.deepEqual(target, error)
|
||||
})
|
||||
|
||||
test('Generate API URLS', t => {
|
||||
|
60
test/sanitize/test_sanitize.js
Normal file
60
test/sanitize/test_sanitize.js
Normal file
@ -0,0 +1,60 @@
|
||||
import test from 'ava'
|
||||
import rewire from 'rewire'
|
||||
|
||||
const sanitize = rewire('../../src/sanitize.js')
|
||||
const applyFilterOnObject = sanitize.__get__('applyFilterOnObject')
|
||||
const filterFromObject = sanitize.__get__('filterFromObject')
|
||||
|
||||
|
||||
test('Ensure that null filter returns same object', t => {
|
||||
const expected = { 'testObj': 'test' }
|
||||
const actual = applyFilterOnObject({ 'testObj': 'test' }, null)
|
||||
|
||||
t.deepEqual(actual, expected)
|
||||
})
|
||||
|
||||
|
||||
test('Ensure function filter with isInclusion true works properly', t => {
|
||||
const testObj = [true, false, undefined, '', 0, null]
|
||||
const expected = { 0: true }
|
||||
const actual = filterFromObject(testObj, (val) => !!val, { isInclusion: true })
|
||||
|
||||
t.deepEqual(actual, expected)
|
||||
})
|
||||
|
||||
|
||||
test('Ensure function filter with isInclusion false works properly', t => {
|
||||
const testObj = [false, true, 1, 10, 'this will be removed as it is truthy']
|
||||
const expected = { 0: false }
|
||||
const actual = filterFromObject(testObj, (val) => !!val, { isInclusion: false })
|
||||
|
||||
t.deepEqual(actual, expected)
|
||||
})
|
||||
|
||||
|
||||
test('Ensure array filter with isInclusion true works properly', t => {
|
||||
const testObj = [true, false, undefined, '', 0, null]
|
||||
const expected = { 0: true }
|
||||
const actual = filterFromObject(testObj, [true], { isInclusion: true })
|
||||
|
||||
t.deepEqual(actual, expected)
|
||||
})
|
||||
|
||||
|
||||
test('Ensure array filter with isInclusion false works properly', t => {
|
||||
const testObj = [false, true, 1, 10]
|
||||
const expected = { 0: false }
|
||||
const actual = filterFromObject(testObj, [true, 1, 10], { isInclusion: false })
|
||||
|
||||
t.deepEqual(actual, expected)
|
||||
})
|
||||
|
||||
|
||||
test('Ensure throws error when given invalid filter', t => {
|
||||
const error = t.throws(() => {
|
||||
filterFromObject({}, 'lol')
|
||||
}, Error)
|
||||
|
||||
t.is(error.message, 'The given filter is not an array or function. Filter aborted')
|
||||
})
|
||||
|
48
test/text-format/test_format_text.js
Normal file
48
test/text-format/test_format_text.js
Normal file
@ -0,0 +1,48 @@
|
||||
import test from 'ava'
|
||||
import formatText from '../../src/format_text'
|
||||
|
||||
test('formatText test type 1', t => {
|
||||
const expected = 'Hi there Dimi!'
|
||||
const actual = formatText('Hi there ${dimi}!', { dimi: 'Dimi' }) // eslint-disable-line no-template-curly-in-string
|
||||
|
||||
t.is(actual, expected)
|
||||
})
|
||||
|
||||
test('formatText test type 2', t => {
|
||||
const expected = 'BigchainDB is big'
|
||||
const actual = formatText('${database} is %(status)s', { // eslint-disable-line no-template-curly-in-string
|
||||
database: 'BigchainDB',
|
||||
status: 'big'
|
||||
})
|
||||
|
||||
t.is(actual, expected)
|
||||
})
|
||||
|
||||
test('formatText test type 3', t => {
|
||||
const expected = 'Berlin is best known for its Currywurst'
|
||||
const actual = formatText(
|
||||
'Berlin is best known for its ${berlin.topKnownFor[0].name}', // eslint-disable-line no-template-curly-in-string
|
||||
{
|
||||
berlin: {
|
||||
topKnownFor: [
|
||||
{
|
||||
name: 'Currywurst'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
t.is(actual, expected)
|
||||
})
|
||||
|
||||
test('formatText test throws', t => {
|
||||
const error = t.throws(() => {
|
||||
formatText(
|
||||
'This will give ${error.}', // eslint-disable-line no-template-curly-in-string
|
||||
{ error: [{}] }
|
||||
)
|
||||
}, SyntaxError)
|
||||
|
||||
t.is(error.message, '[formatText] failed to parse named argument key: error.')
|
||||
})
|
Loading…
Reference in New Issue
Block a user