1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-12-28 15:47:50 +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) {
// TODO: Use camel case
return this.path + {
'blocks': 'blocks',
'blocks_detail': 'blocks/%(blockId)s',
'blocksDetail': 'blocks/%(blockId)s',
'outputs': 'outputs',
'statuses': 'statuses',
'transactions': 'transactions',
'transactions_detail': 'transactions/%(transactionId)s',
'search_assets': 'assets',
'transactionsDetail': 'transactions/%(transactionId)s',
'searchAssets': 'assets',
'votes': 'votes'
}[endpoints]
}
@ -32,7 +31,7 @@ export default class Connection {
* @param blockId
*/
getBlock(blockId) {
return this._req(this.getApiUrls('blocks_detail'), {
return this._req(this.getApiUrls('blocksDetail'), {
urlTemplateSpec: {
blockId
}
@ -56,9 +55,9 @@ export default class Connection {
* @param transactionId
*/
getTransaction(transactionId) {
return this._req(this.getApiUrls('transactions_detail'), {
return this._req(this.getApiUrls('transactionsDetail'), {
urlTemplateSpec: {
transaction_id: transactionId
transactionId
}
})
}
@ -164,10 +163,10 @@ export default class Connection {
/**
* @public
*
* @param transaction
* @param query
*/
searchAssets(query) {
return this.req(this.getApiUrls('search_assets'), {
return this._req(this.getApiUrls('searchAssets'), {
query: {
text_search: query
}

View File

@ -9,12 +9,12 @@ const conn = new Connection(API_PATH)
test('generate API URLS', t => {
const endpoints = {
'blocks': 'blocks',
'blocks_detail': 'blocks/%(blockId)s',
'blocksDetail': 'blocks/%(blockId)s',
'outputs': 'outputs',
'statuses': 'statuses',
'transactions': 'transactions',
'transactions_detail': 'transactions/%(transactionId)s',
'search_assets': 'assets',
'transactionsDetail': 'transactions/%(transactionId)s',
'searchAssets': 'assets',
}
Object.keys(endpoints).forEach((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 => {
const expectedPath = 'path'
const transactionId = 'abc'
@ -49,7 +64,7 @@ test('Get transaction for a transaction id', t => {
conn.getTransaction(transactionId)
t.truthy(conn._req.calledWith(
expectedPath,
{ urlTemplateSpec: { transaction_id: transactionId } }
{ urlTemplateSpec: { transactionId } }
))
})
@ -88,3 +103,18 @@ test('Get votes for a block id', t => {
{ 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))
})