Skip to content

Commit

Permalink
feat: remove byExecutionCondition endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
justmoon committed Mar 1, 2017
1 parent 255d56a commit d4bab8f
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 203 deletions.
3 changes: 1 addition & 2 deletions apidoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
"PutTransfer",
"PutTransferFulfillment",
"GetTransfer",
"GetTransferByExecutionCondition",
"GetTransferState",
"GetTransferFulfillment",
"Account_Methods",
"Account_Methods",
"PutAccount",
"GetAccount",
"SubscribeAccountTransfers",
Expand Down
52 changes: 0 additions & 52 deletions src/controllers/transfers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -416,7 +365,6 @@ function * putRejection () {

module.exports = {
getResource,
getResourcesByExecutionCondition,
getStateResource,
putResource,
putFulfillment,
Expand Down
1 change: 0 additions & 1 deletion src/lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
22 changes: 0 additions & 22 deletions src/models/db/transfers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -185,7 +164,6 @@ module.exports = {
getTransfer,
getTransferId,
getTransferById,
getTransfersByExecutionCondition,
upsertTransfer,
updateTransfer,
insertTransfers,
Expand Down
12 changes: 0 additions & 12 deletions src/models/transfers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -577,7 +566,6 @@ function * insertTransfers (externalTransfers) {

module.exports = {
getTransfer,
getTransfersByExecutionCondition,
getTransferStateReceipt,
setTransfer,
fulfillTransfer,
Expand Down
114 changes: 0 additions & 114 deletions test/getTransferSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
})
})

0 comments on commit d4bab8f

Please sign in to comment.