1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2025-02-14 21:10:32 +01:00

CamelCase for path keys

This commit is contained in:
tim 2017-06-19 14:56:00 +02:00
parent af49ec1c7a
commit d4ea4d6ccd
3 changed files with 42 additions and 43 deletions

View File

@ -8,15 +8,14 @@ export default class Connection {
} }
getApiUrls(endpoints) { getApiUrls(endpoints) {
// TODO: Use camel case
return this.path + { return this.path + {
'blocks': 'blocks', 'blocks': 'blocks',
'blocks_detail': 'blocks/%(blockId)s', 'blocksDetail': 'blocks/%(blockId)s',
'outputs': 'outputs', 'outputs': 'outputs',
'statuses': 'statuses', 'statuses': 'statuses',
'transactions': 'transactions', 'transactions': 'transactions',
'transactions_detail': 'transactions/%(transactionId)s', 'transactionsDetail': 'transactions/%(transactionId)s',
'search_assets': 'assets', 'searchAssets': 'assets',
'votes': 'votes' 'votes': 'votes'
}[endpoints] }[endpoints]
} }
@ -32,7 +31,7 @@ export default class Connection {
* @param blockId * @param blockId
*/ */
getBlock(blockId) { getBlock(blockId) {
return this._req(this.getApiUrls('blocks_detail'), { return this._req(this.getApiUrls('blocksDetail'), {
urlTemplateSpec: { urlTemplateSpec: {
blockId blockId
} }
@ -56,9 +55,9 @@ export default class Connection {
* @param transactionId * @param transactionId
*/ */
getTransaction(transactionId) { getTransaction(transactionId) {
return this._req(this.getApiUrls('transactions_detail'), { return this._req(this.getApiUrls('transactionsDetail'), {
urlTemplateSpec: { urlTemplateSpec: {
transaction_id: transactionId transactionId
} }
}) })
} }
@ -164,10 +163,10 @@ export default class Connection {
/** /**
* @public * @public
* *
* @param transaction * @param query
*/ */
searchAssets(query) { searchAssets(query) {
return this.req(this.getApiUrls('search_assets'), { return this._req(this.getApiUrls('searchAssets'), {
query: { query: {
text_search: query text_search: query
} }

View File

@ -9,12 +9,12 @@ const conn = new Connection(API_PATH)
test('generate API URLS', t => { test('generate API URLS', t => {
const endpoints = { const endpoints = {
'blocks': 'blocks', 'blocks': 'blocks',
'blocks_detail': 'blocks/%(blockId)s', 'blocksDetail': 'blocks/%(blockId)s',
'outputs': 'outputs', 'outputs': 'outputs',
'statuses': 'statuses', 'statuses': 'statuses',
'transactions': 'transactions', 'transactions': 'transactions',
'transactions_detail': 'transactions/%(transactionId)s', 'transactionsDetail': 'transactions/%(transactionId)s',
'search_assets': 'assets', 'searchAssets': 'assets',
} }
Object.keys(endpoints).forEach((endpointName) => { Object.keys(endpoints).forEach((endpointName) => {
const url = conn.getApiUrls(endpointName) const url = conn.getApiUrls(endpointName)
@ -24,6 +24,21 @@ test('generate API URLS', t => {
}) })
test('Get block for a block id', t => {
const expectedPath = 'path'
const blockId = 'abc'
conn._req = sinon.spy()
conn.getApiUrls = sinon.stub().returns(expectedPath)
conn.getBlock(blockId)
t.truthy(conn._req.calledWith(
expectedPath,
{ urlTemplateSpec: { blockId } }
))
})
test('Get status for a transaction', t => { test('Get status for a transaction', t => {
const expectedPath = 'path' const expectedPath = 'path'
const transactionId = 'abc' const transactionId = 'abc'
@ -49,7 +64,7 @@ test('Get transaction for a transaction id', t => {
conn.getTransaction(transactionId) conn.getTransaction(transactionId)
t.truthy(conn._req.calledWith( t.truthy(conn._req.calledWith(
expectedPath, expectedPath,
{ urlTemplateSpec: { transaction_id: transactionId } } { urlTemplateSpec: { transactionId } }
)) ))
}) })
@ -88,3 +103,18 @@ test('Get votes for a block id', t => {
{ query: { block_id: blockId } } { query: { block_id: blockId } }
)) ))
}) })
test('Get asset for a text', t => {
const expectedPath = 'path'
const query = 'abc'
conn._req = sinon.spy()
conn.getApiUrls = sinon.stub().returns(expectedPath)
conn.searchAssets(query)
t.truthy(conn._req.calledWith(
expectedPath,
{ query: { text_search: query } }
))
})

View File

@ -1,30 +0,0 @@
import test from 'ava'
import { Ed25519Keypair, Transaction, Connection } from '../src'
const API_PATH = 'http://localhost:9984/api/v1/'
test('Keypair is created', t => {
const keyPair = new Ed25519Keypair()
t.truthy(keyPair.publicKey)
t.truthy(keyPair.privateKey)
})
test('Valid CREATE transaction is evaluated by BigchainDB', t => {
const alice = new Ed25519Keypair()
const asset = { name: 'Shmui', type: 'cat' }
const metadata = { dayOfTheWeek: 'Caturday' }
const tx = Transaction.makeCreateTransaction(
asset,
metadata,
[Transaction.makeOutput(Transaction.makeEd25519Condition(alice.publicKey))],
alice.publicKey
)
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
const conn = new Connection(API_PATH)
return conn.postTransaction(txSigned)
.then(resTx => t.truthy(resTx))
})