mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-11-22 09:46:58 +01:00
Add integration test for asset endpoint :diamond:
This commit is contained in:
parent
3fdaf40602
commit
db10937f9e
@ -15,7 +15,7 @@ export default class Connection {
|
||||
'statuses': 'statuses',
|
||||
'transactions': 'transactions',
|
||||
'transactionsDetail': 'transactions/%(transactionId)s',
|
||||
'searchAssets': 'assets',
|
||||
'assets': 'assets',
|
||||
'votes': 'votes'
|
||||
}[endpoints]
|
||||
}
|
||||
@ -161,12 +161,12 @@ export default class Connection {
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* @param query
|
||||
* @param search
|
||||
*/
|
||||
searchAssets(query) {
|
||||
return this._req(this.getApiUrls('searchAssets'), {
|
||||
searchAssets(search) {
|
||||
return this._req(this.getApiUrls('assets'), {
|
||||
query: {
|
||||
text_search: query
|
||||
search
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ test('generate API URLS', t => {
|
||||
'statuses': 'statuses',
|
||||
'transactions': 'transactions',
|
||||
'transactionsDetail': 'transactions/%(transactionId)s',
|
||||
'searchAssets': 'assets',
|
||||
'assets': 'assets',
|
||||
}
|
||||
Object.keys(endpoints).forEach((endpointName) => {
|
||||
const url = conn.getApiUrls(endpointName)
|
||||
@ -125,16 +125,16 @@ test('Get votes for a block id', t => {
|
||||
})
|
||||
|
||||
|
||||
test('Get asset for a text', t => {
|
||||
test('Get asset for text', t => {
|
||||
const expectedPath = 'path'
|
||||
const query = 'abc'
|
||||
const search = 'abc'
|
||||
|
||||
conn._req = sinon.spy()
|
||||
conn.getApiUrls = sinon.stub().returns(expectedPath)
|
||||
|
||||
conn.searchAssets(query)
|
||||
conn.searchAssets(search)
|
||||
t.truthy(conn._req.calledWith(
|
||||
expectedPath,
|
||||
{ query: { text_search: query } }
|
||||
{ query: { search } }
|
||||
))
|
||||
})
|
||||
|
@ -2,23 +2,23 @@ import test from 'ava'
|
||||
import { Transaction, Ed25519Keypair } from '../src'
|
||||
// TODO: Find out if ava has something like conftest, if so put this there.
|
||||
|
||||
// TODO: We're adding `Math.random()` here to never create the same transaction
|
||||
// twice.
|
||||
export const assetMessage = { assetMessage: Math.random() }
|
||||
export const metaDataMessage = { metaDataMessage: 'metaDataMessage' }
|
||||
// NOTE: We cast `Math.random()` to a string, as sometimes Javascript simply
|
||||
// yields a slightly different float during runtime, lol
|
||||
export function asset() { return { message: `${Math.random()}` } }
|
||||
export const metaData = { message: 'metaDataMessage' }
|
||||
|
||||
export const alice = new Ed25519Keypair()
|
||||
export const aliceCondition = Transaction.makeEd25519Condition(alice.publicKey)
|
||||
export const aliceOutput = Transaction.makeOutput(aliceCondition)
|
||||
export const createTx = Transaction.makeCreateTransaction(
|
||||
assetMessage,
|
||||
metaDataMessage,
|
||||
asset,
|
||||
metaData,
|
||||
[aliceOutput],
|
||||
alice.publicKey
|
||||
)
|
||||
export const transferTx = Transaction.makeTransferTransaction(
|
||||
createTx,
|
||||
metaDataMessage,
|
||||
metaData,
|
||||
[aliceOutput],
|
||||
0
|
||||
)
|
||||
|
@ -7,8 +7,8 @@ import {
|
||||
aliceOutput,
|
||||
bob,
|
||||
bobOutput,
|
||||
assetMessage,
|
||||
metaDataMessage
|
||||
asset,
|
||||
metaData
|
||||
} from '../constants'
|
||||
|
||||
const API_PATH = 'http://localhost:9984/api/v1/'
|
||||
@ -29,15 +29,15 @@ test('Valid CREATE transaction', t => {
|
||||
const conn = new Connection(API_PATH)
|
||||
|
||||
const tx = Transaction.makeCreateTransaction(
|
||||
assetMessage,
|
||||
metaDataMessage,
|
||||
asset(),
|
||||
metaData,
|
||||
[aliceOutput],
|
||||
alice.publicKey
|
||||
)
|
||||
|
||||
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
|
||||
|
||||
return conn.postTransaction(txSigned)
|
||||
.then(({ 'id': txId }) => conn.pollStatusAndFetchTransaction(txId))
|
||||
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
||||
.then(resTx => t.truthy(resTx))
|
||||
})
|
||||
|
||||
@ -45,8 +45,8 @@ test('Valid CREATE transaction', t => {
|
||||
test('Valid TRANSFER transaction with single Ed25519 input', t => {
|
||||
const conn = new Connection(API_PATH)
|
||||
const createTx = Transaction.makeCreateTransaction(
|
||||
assetMessage,
|
||||
metaDataMessage,
|
||||
asset(),
|
||||
metaData,
|
||||
[aliceOutput],
|
||||
alice.publicKey
|
||||
)
|
||||
@ -56,11 +56,11 @@ test('Valid TRANSFER transaction with single Ed25519 input', t => {
|
||||
)
|
||||
|
||||
return conn.postTransaction(createTxSigned)
|
||||
.then(({ 'id': txId }) => conn.pollStatusAndFetchTransaction(txId))
|
||||
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
||||
.then(() => {
|
||||
const transferTx = Transaction.makeTransferTransaction(
|
||||
createTxSigned,
|
||||
metaDataMessage,
|
||||
metaData,
|
||||
[aliceOutput],
|
||||
0
|
||||
)
|
||||
@ -78,8 +78,8 @@ test('Valid TRANSFER transaction with single Ed25519 input', t => {
|
||||
test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
|
||||
const conn = new Connection(API_PATH)
|
||||
const createTx = Transaction.makeCreateTransaction(
|
||||
assetMessage,
|
||||
metaDataMessage,
|
||||
asset(),
|
||||
metaData,
|
||||
[aliceOutput, bobOutput],
|
||||
alice.publicKey
|
||||
)
|
||||
@ -93,7 +93,7 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
|
||||
.then(() => {
|
||||
const transferTx = Transaction.makeTransferTransaction(
|
||||
createTxSigned,
|
||||
metaDataMessage,
|
||||
metaData,
|
||||
[Transaction.makeOutput(aliceCondition, '2')],
|
||||
0,
|
||||
1
|
||||
@ -108,3 +108,27 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
|
||||
.then(resTx => t.truthy(resTx))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
test('Search for an asset', t => {
|
||||
const conn = new Connection(API_PATH)
|
||||
|
||||
const createTx = Transaction.makeCreateTransaction(
|
||||
asset(),
|
||||
metaData,
|
||||
[aliceOutput],
|
||||
alice.publicKey
|
||||
)
|
||||
const createTxSigned = Transaction.signTransaction(
|
||||
createTx,
|
||||
alice.privateKey
|
||||
)
|
||||
|
||||
return conn.postTransaction(createTxSigned)
|
||||
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
||||
.then(() => conn.searchAssets(createTxSigned.asset.data.message))
|
||||
.then(assets => t.truthy(
|
||||
assets.pop(),
|
||||
createTxSigned.asset.data.message
|
||||
))
|
||||
})
|
||||
|
@ -1,14 +1,14 @@
|
||||
import test from 'ava'
|
||||
import sinon from 'sinon'
|
||||
|
||||
import { Transaction, Ed25519Keypair } from '../../src'
|
||||
import { Transaction } from '../../src'
|
||||
import * as makeTransaction from '../../src/transaction/makeTransaction' // eslint-disable-line
|
||||
import makeInputTemplate from '../../src/transaction/makeInputTemplate'
|
||||
|
||||
import {
|
||||
alice,
|
||||
aliceOutput,
|
||||
metaDataMessage,
|
||||
metaData,
|
||||
createTx,
|
||||
transferTx
|
||||
} from '../constants'
|
||||
@ -72,14 +72,14 @@ test('Create TRANSFER transaction based on CREATE transaction', t => {
|
||||
|
||||
Transaction.makeTransferTransaction(
|
||||
createTx,
|
||||
metaDataMessage,
|
||||
metaData,
|
||||
[aliceOutput],
|
||||
0
|
||||
)
|
||||
const expected = [
|
||||
'TRANSFER',
|
||||
{ id: createTx.id },
|
||||
metaDataMessage,
|
||||
metaData,
|
||||
[aliceOutput],
|
||||
[makeInputTemplate(
|
||||
[alice.publicKey],
|
||||
@ -100,14 +100,14 @@ test('Create TRANSFER transaction based on TRANSFER transaction', t => {
|
||||
|
||||
Transaction.makeTransferTransaction(
|
||||
transferTx,
|
||||
metaDataMessage,
|
||||
metaData,
|
||||
[aliceOutput],
|
||||
0
|
||||
)
|
||||
const expected = [
|
||||
'TRANSFER',
|
||||
{ id: transferTx.asset.id },
|
||||
metaDataMessage,
|
||||
metaData,
|
||||
[aliceOutput],
|
||||
[makeInputTemplate(
|
||||
[alice.publicKey],
|
||||
|
Loading…
Reference in New Issue
Block a user