search metadata field

This commit is contained in:
manolodewiner 2017-11-21 16:51:31 +01:00
parent 5f2ee8c0d8
commit dd2a52bf1f
3 changed files with 51 additions and 1 deletions

View File

@ -25,6 +25,7 @@ export default class Connection {
'transactions': 'transactions',
'transactionsDetail': 'transactions/%(transactionId)s',
'assets': 'assets',
'metadata': 'metadata',
'votes': 'votes'
}[endpoint]
}
@ -167,7 +168,6 @@ export default class Connection {
})
}
/**
* @public
* @param search
@ -179,4 +179,16 @@ export default class Connection {
}
})
}
/**
* @public
* @param search
*/
searchMetadata(search) {
return this._req(this.getApiUrls('metadata'), {
query: {
search
}
})
}
}

View File

@ -219,3 +219,18 @@ test('Get asset for text', t => {
{ query: { search } }
))
})
test('Get metadata for text', t => {
const expectedPath = 'path'
const search = 'abc'
conn._req = sinon.spy()
conn.getApiUrls = sinon.stub().returns(expectedPath)
conn.searchMetadata(search)
t.truthy(conn._req.calledWith(
expectedPath,
{ query: { search } }
))
})

View File

@ -264,6 +264,29 @@ test('Search for an asset', t => {
})
test('Search for metadata', 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.searchMetadata(createTxSigned.metadata.message))
.then(assets => t.truthy(
assets.pop(),
createTxSigned.metadata.message
))
})
test('Search blocks containing a transaction', t => {
const conn = new Connection(API_PATH)