Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
Add method and tests for getAccountTransactions with date range support
Browse files Browse the repository at this point in the history
  • Loading branch information
todoubled committed Jul 29, 2015
1 parent 9fdadab commit 8e58479
Show file tree
Hide file tree
Showing 7 changed files with 547 additions and 4 deletions.
31 changes: 29 additions & 2 deletions lib/client.coffee
Expand Up @@ -3,6 +3,16 @@ Request = require "./request"

BASE_URL = "https://financialdatafeed.platform.intuit.com/v1"

zeroBased = (number) ->
("0" + number).slice(-2)

# 2015-07-29
formatDate = (date) ->
year = date.getFullYear()
month = zeroBased date.getMonth() + 1
day = zeroBased date.getDate()
"#{year}-#{month}-#{day}"

module.exports = class IntuitClient
constructor: (@options) ->

Expand Down Expand Up @@ -36,9 +46,26 @@ module.exports = class IntuitClient
return done err if err
done err, _.first response.accounts

getAccountTransactions: (userId, accountId, startDate, endDate) ->
# Download last week of transactions unless a date range is specified
# If no endDate is specified, startDate to current is downloaded
getAccountTransactions: (userId, accountId, startDate, endDate, done) ->
oneWeekAgo = -10080
defaultStartDate = formatDate new Date(new Date().getTime() + oneWeekAgo * 60000)

if typeof(startDate) is "function"
[startDate, endDate, done] = [defaultStartDate, null, startDate]
else if typeof(endDate) is "function"
[startDate, endDate, done] = [formatDate(startDate), null, endDate]
else
[startDate, endDate, done] = [formatDate(startDate), formatDate(endDate), done]

url = "/accounts/#{accountId}/transactions?txnStartDate=#{startDate}"
url += "&txnEndDate=#{endDate}" if endDate

@options.userId = userId
@request "get", "/accounts/#{accountId}/transactions", done
@request "get", url, (err, response) ->
return done err if err
done err, response.bankingTransactions

updateInstitutionLogin: (userId, institutionId, loginId, credentials, done) ->
@options.userId = userId
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -18,7 +18,8 @@
"devDependencies": {
"bondjs": "^1.2.3",
"mocha": "^2.2.5",
"nock": "^2.9.1"
"nock": "^2.9.1",
"timekeeper": "0.0.5"
},
"engines": {
"node": "0.12.5",
Expand Down
28 changes: 27 additions & 1 deletion test/api.coffee
@@ -1,4 +1,5 @@
assert = require "assert"
timekeeper = require "timekeeper"
request = require "request"
bond = require "bondjs"
request = require "request"
Expand Down Expand Up @@ -44,7 +45,32 @@ describe "Intuit Client", ->
done err

describe "getAccountTransactions", ->
it "should return transactions"
describe "default parameters", ->
before -> timekeeper.freeze new Date "2015-07-30"
before -> fixture.load "getAccountTransactions"
after -> timekeeper.reset()
it "should return transactions", (done) ->
intuit.getAccountTransactions "userId", 400107846787, (err, transactions) ->
assert.equal transactions.length, 8
done err

describe "Specific start date", ->
before -> timekeeper.freeze new Date "2015-07-30"
before -> fixture.load "getAccountTransactions_startDate"
after -> timekeeper.reset()
it "should return transactions", (done) ->
intuit.getAccountTransactions "userId", 400107846787, new Date("2015-05-15"), (err, transactions) ->
assert.equal transactions.length, 8
done err

describe "Specific date range", ->
before -> timekeeper.freeze new Date "2015-07-30"
before -> fixture.load "getAccountTransactions_dateRange"
after -> timekeeper.reset()
it "should return transactions", (done) ->
intuit.getAccountTransactions "userId", 400107846787, new Date("2015-05-15"), new Date("2015-05-22"), (err, transactions) ->
assert.equal transactions.length, 8
done err

describe "updateInstitutionLogin", ->
it "should update bank credentials"
Expand Down
159 changes: 159 additions & 0 deletions test/fixtures/getAccountTransactions.json
@@ -0,0 +1,159 @@
[
{
"scope": "https://financialdatafeed.platform.intuit.com:443",
"method": "GET",
"path": "/v1/accounts/400107846787/transactions?txnStartDate=2015-07-22",
"body": "",
"status": 200,
"response": {
"bankingTransactions": [
{
"id": 403657885582,
"currencyType": "USD",
"postedDate": 1437634800000,
"payeeName": "CHECKINGD debit 204",
"amount": -7.23,
"pending": false,
"institutionTransactionId": "INTUIT-403657885582",
"userDate": 1437634800000,
"categorization": {
"context": [

],
"common": {

}
}
},
{
"id": 403657885585,
"currencyType": "USD",
"postedDate": 1437894000000,
"payeeName": "CHECKINGD credit 207",
"amount": 7.26,
"pending": false,
"institutionTransactionId": "INTUIT-403657885585",
"userDate": 1437894000000,
"categorization": {
"context": [

],
"common": {

}
}
},
{
"id": 403657885595,
"currencyType": "USD",
"postedDate": 1437548400000,
"payeeName": "CHECKINGD credit 203",
"amount": 7.22,
"pending": false,
"institutionTransactionId": "INTUIT-403657885595",
"userDate": 1437548400000,
"categorization": {
"context": [

],
"common": {

}
}
},
{
"id": 403657885902,
"currencyType": "USD",
"postedDate": 1437807600000,
"payeeName": "CHECKINGD debit 206",
"amount": -7.25,
"pending": false,
"institutionTransactionId": "INTUIT-403657885902",
"userDate": 1437807600000,
"categorization": {
"context": [

],
"common": {

}
}
},
{
"id": 403657885905,
"currencyType": "USD",
"postedDate": 1437721200000,
"payeeName": "CHECKINGD credit 205",
"amount": 7.24,
"pending": false,
"institutionTransactionId": "INTUIT-403657885905",
"userDate": 1437721200000,
"categorization": {
"context": [

],
"common": {

}
}
},
{
"id": 403663363252,
"currencyType": "USD",
"postedDate": 1437980400000,
"payeeName": "CHECKINGD debit 208",
"amount": -7.27,
"pending": false,
"institutionTransactionId": "INTUIT-403663363252",
"userDate": 1437980400000,
"categorization": {
"context": [

],
"common": {

}
}
},
{
"id": 403664091017,
"currencyType": "USD",
"payeeName": "CHECKINGD credit 209",
"amount": 7.28,
"pending": true,
"userDate": 1438153200000,
"categorization": {
"context": [

],
"common": {

}
}
},
{
"id": 403664091018,
"currencyType": "USD",
"payeeName": "CHECKINGD debit 210",
"amount": -7.29,
"pending": true,
"userDate": 1438153200000,
"categorization": {
"context": [

],
"common": {

}
}
}
]},
"headers": {
"date": "Tue, 28 Jul 2015 18:32:49 GMT",
"content-type": "text/plain",
"content-length": "0",
"intuit_tid": "gw-1e6def67-b82b-4317-981c-d2e7bed343c8",
"connection": "close"
}
}
]

0 comments on commit 8e58479

Please sign in to comment.