From d4bab8f41e20d65d126a4ce718f0272beb637b54 Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Fri, 17 Feb 2017 21:32:45 +0100 Subject: [PATCH] feat: remove byExecutionCondition endpoint --- apidoc.json | 3 +- src/controllers/transfers.js | 52 ---------------- src/lib/app.js | 1 - src/models/db/transfers.js | 22 ------- src/models/transfers.js | 12 ---- test/getTransferSpec.js | 114 ----------------------------------- 6 files changed, 1 insertion(+), 203 deletions(-) diff --git a/apidoc.json b/apidoc.json index 8ab8e07..6ebdbde 100644 --- a/apidoc.json +++ b/apidoc.json @@ -6,10 +6,9 @@ "PutTransfer", "PutTransferFulfillment", "GetTransfer", - "GetTransferByExecutionCondition", "GetTransferState", "GetTransferFulfillment", - "Account_Methods", + "Account_Methods", "PutAccount", "GetAccount", "SubscribeAccountTransfers", diff --git a/src/controllers/transfers.js b/src/controllers/transfers.js index d4c1f6c..f83444a 100644 --- a/src/controllers/transfers.js +++ b/src/controllers/transfers.js @@ -61,57 +61,6 @@ function * getResource () { this.body = yield model.getTransfer(id.toLowerCase()) } -/** - * @api {get} /transfers/byExecutionCondition/:execution_condition Get Transfers by Condition - * @apiName GetTransferByExecutionCondition - * @apiGroup Transfer Methods - * @apiVersion 15.0.0 - * - * @apiDescription Use this to query about the details or status of a local - * transfer that is using atomic mode. - * - * @apiParam {String} execution_condition - * - * @apiExample {shell} Get a transfer - * curl -X GET http://usd-ledger.example/transfers/ByExecutionCondition/cc:0:3:8ZdpKBDUV-KX_OnFZTsCWB_5mlCFI3DynX5f5H2dN-Y:2 - * - * @apiSuccess (Success) {Transfer[]} Array Array of [Transfer objects](#transfer_object) matching the condition. - * - * @apiSuccessExample {Array} Array of Transfer responses: - * HTTP/1.1 200 OK - * [{ - * "id": "http://usd-ledger.example/transfers/3a2a1d9e-8640-4d2d-b06c-84f2cd613204", - * "ledger": "http://usd-ledger.example", - * "debits": [{ - * "account": "http://usd-ledger.example/accounts/alice", - * "amount": "50" - * }], - * "credits": [{ - * "account": "http://usd-ledger.example/accounts/bob", - * "amount": "50" - * }], - * "execution_condition": "cc:0:3:8ZdpKBDUV-KX_OnFZTsCWB_5mlCFI3DynX5f5H2dN-Y:2", - * "expires_at": "2015-06-16T00:00:01.000Z", - * "state": "executed", - * "timeline": { - * "proposed_at": "2015-06-16T00:00:00.000Z", - * "prepared_at": "2015-06-16T00:00:00.500Z", - * "executed_at": "2015-06-16T00:00:00.999Z" - * } - * }] - * - * @apiUse NotFoundError - * @apiUse InvalidUriParameterError - */ -/** - * @returns {void} - */ -function * getResourcesByExecutionCondition () { - const executionConditon = this.params.execution_condition - requestUtil.validateUriParameter('execution_condition', executionConditon, 'Condition') - this.body = yield model.getTransfersByExecutionCondition(executionConditon) -} - /** * @api {get} /transfers/:id/state Get Signed Transfer State * @apiName GetTransferState @@ -416,7 +365,6 @@ function * putRejection () { module.exports = { getResource, - getResourcesByExecutionCondition, getStateResource, putResource, putFulfillment, diff --git a/src/lib/app.js b/src/lib/app.js index 74983f0..cb61051 100644 --- a/src/lib/app.js +++ b/src/lib/app.js @@ -139,7 +139,6 @@ class App { transfers.putRejection) router.get('/transfers/:id', transfers.getResource) - router.get('/transfers/byExecutionCondition/:execution_condition', transfers.getResourcesByExecutionCondition) router.get('/transfers/:id/state', transfers.getStateResource) router.get('/accounts', diff --git a/src/models/db/transfers.js b/src/models/db/transfers.js index 96b0531..f0fa0da 100644 --- a/src/models/db/transfers.js +++ b/src/models/db/transfers.js @@ -105,23 +105,6 @@ function * getTransferWhere (where, options) { }) } -function * getTransfersWhere (where, options) { - return db.select(where, options && options.transaction) - .then((transfers) => { - if (_.isEmpty(transfers)) { - return [] - } - - return Promise.all(transfers.map((transfer) => { - return adjustments.getAdjustments(transfer._id, options) - .then((adjustments) => { - const result = _.assign({}, transfer, adjustments) - return _.isEmpty(result) ? null : _.omit(result, '_id') - }) - })) - }) -} - function * getTransfer (uuid, options) { return yield getTransferWhere({TRANSFER_UUID: uuid}, options) } @@ -136,10 +119,6 @@ function * getTransferById (id, options) { return yield getTransferWhere({TRANSFER_ID: id}, options) } -function * getTransfersByExecutionCondition (executionCondition, options) { - return yield getTransfersWhere({EXECUTION_CONDITION: executionCondition}, options) -} - function * updateTransfer (transfer, options) { const transaction = options && options.transaction return db.update(transfer, {TRANSFER_UUID: transfer.id}, transaction) @@ -185,7 +164,6 @@ module.exports = { getTransfer, getTransferId, getTransferById, - getTransfersByExecutionCondition, upsertTransfer, updateTransfer, insertTransfers, diff --git a/src/models/transfers.js b/src/models/transfers.js index e0212fe..12f021f 100644 --- a/src/models/transfers.js +++ b/src/models/transfers.js @@ -60,17 +60,6 @@ function * getTransfer (id) { return converters.convertToExternalTransfer(transfer) } -function * getTransfersByExecutionCondition (executionCondition) { - log.debug('fetching transfers by execution condition ' + executionCondition) - - const transfers = yield db.getTransfersByExecutionCondition(executionCondition) - if (_.isEmpty(transfers)) { - throw new NotFoundError('Unknown execution condition') - } - - return Promise.all(transfers.map(converters.convertToExternalTransfer)) -} - function * getTransferStateReceipt (id, receiptType, conditionState) { log.debug('fetching state receipt for transfer ID ' + id) const transfer = yield db.getTransfer(id) @@ -577,7 +566,6 @@ function * insertTransfers (externalTransfers) { module.exports = { getTransfer, - getTransfersByExecutionCondition, getTransferStateReceipt, setTransfer, fulfillTransfer, diff --git a/test/getTransferSpec.js b/test/getTransferSpec.js index db13b20..8d7904a 100644 --- a/test/getTransferSpec.js +++ b/test/getTransferSpec.js @@ -3,7 +3,6 @@ const _ = require('lodash') const nock = require('nock') nock.enableNetConnect(['localhost', '127.0.0.1']) -const expect = require('chai').expect const app = require('../src/services/app') const logger = require('../src/services/log') const dbHelper = require('./helpers/db') @@ -99,116 +98,3 @@ describe('GET /transfers/:uuid', function () { .end() }) }) - -describe('GET /transfers/byExecutionCondition/:execution_condition', function () { - logHelper(logger) - - before(function * () { - yield dbHelper.init() - }) - - beforeEach(function * () { - appHelper.create(this, app) - yield dbHelper.clean() - this.clock = sinon.useFakeTimers(START_DATE, 'Date') - - // Define example data - this.executedTransfer = _.cloneDeep(require('./data/transfers/executed')) - this.transferWithExpiry = _.cloneDeep(require('./data/transfers/withExpiry')) - this.transferWithAndCondition = _.cloneDeep(require('./data/transfers/withAndCondition')) - this.preparedTransfer = _.cloneDeep(require('./data/transfers/prepared')) - - // Store some example data - yield dbHelper.addAccounts(_.values(require('./data/accounts'))) - yield dbHelper.addTransfers([this.executedTransfer]) - }) - - afterEach(function * () { - nock.cleanAll() - this.clock.restore() - }) - - it('should return 200 for an existing transfer', function * () { - const transfer = this.executedTransfer - yield this.request() - .get(`/transfers/byExecutionCondition/${transfer.execution_condition}`) - .expect(200) - .expect([transfer]) - .expect(validator.validateTransfers) - .end() - }) - - it('should return 200 for multiple existing transfers', function * () { - yield dbHelper.addTransfers([this.preparedTransfer]) - - const transfer = this.executedTransfer - yield this.request() - .get(`/transfers/byExecutionCondition/${transfer.execution_condition}`) - .expect(200) - .expect((res) => { - const sortedResponse = _.sortBy(res.body, (transfer) => { - return transfer.id - }) - const sortedTransfers = _.sortBy([transfer, this.preparedTransfer], (transfer) => { - return transfer.id - }) - expect(sortedResponse).to.deep.equal(sortedTransfers) - }) - .expect(validator.validateTransfers) - .end() - }) - - it('should return 404 when the transfer does not exist', function * () { - yield this.request() - .get(`/transfers/byExecutionCondition/${this.transferWithAndCondition.execution_condition}`) - .expect(404) - .expect(function (res) { - expect(res.body.id).to.equal('NotFoundError') - expect(res.body.message).to.equal('Unknown execution condition') - }) - .end() - }) - - it('should return 400 when the provided parameter is not an execution condition', function * () { - yield this.request() - .get('/transfers/byExecutionCondition/notanexecutioncondition') - .expect(400) - .expect(function (res) { - expect(res.body.id).to.equal('InvalidUriParameterError') - expect(res.body.message).to.equal('execution_condition is not a valid Condition') - }) - .end() - }) - - it('should return a rejected transfer if the expiry date has passed', function * () { - const transfer = this.transferWithExpiry - delete transfer.debits[0].authorized - delete transfer.debits[1].authorized - - yield this.request() - .put(transfer.id) - .auth('alice', 'alice') - .send(transfer) - .expect(201) - .expect(validator.validateTransfer) - .end() - - this.clock.tick(1000) - - // In production this function should be triggered by the worker started in app.js - yield transferExpiryMonitor.processExpiredTransfers() - - yield this.request() - .get(`/transfers/byExecutionCondition/${transfer.execution_condition}`) - .expect(200, [_.assign({}, transfer, { - state: transferStates.TRANSFER_STATE_REJECTED, - rejection_reason: 'expired', - timeline: { - proposed_at: '2015-06-16T00:00:00.000Z', - rejected_at: transfer.expires_at - } - })]) - .expect(validator.validateTransfers) - .end() - }) -})