From dd2a52bf1f7456548561ebe849f4b3b3863495e2 Mon Sep 17 00:00:00 2001 From: manolodewiner Date: Tue, 21 Nov 2017 16:51:31 +0100 Subject: [PATCH] search metadata field --- src/connection.js | 14 +++++++++++++- test/connection/test_connection.js | 15 +++++++++++++++ test/integration/test_integration.js | 23 +++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/connection.js b/src/connection.js index 48f387a..6e00495 100644 --- a/src/connection.js +++ b/src/connection.js @@ -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 + } + }) + } } diff --git a/test/connection/test_connection.js b/test/connection/test_connection.js index 435e38b..5877563 100644 --- a/test/connection/test_connection.js +++ b/test/connection/test_connection.js @@ -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 } } + )) +}) diff --git a/test/integration/test_integration.js b/test/integration/test_integration.js index b5e53fe..09e261f 100644 --- a/test/integration/test_integration.js +++ b/test/integration/test_integration.js @@ -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)