Comparing version 0.25.3 to 0.25.4
@@ -8,2 +8,4 @@ # Changelog | ||
## [Unreleased] | ||
### Changed | ||
- Transaction search (`models.transaction.search`) will no longer consider numbers > 20M for the amount filter. | ||
@@ -10,0 +12,0 @@ ## [0.25.2] - 2020-02-28 |
@@ -64,2 +64,3 @@ "use strict"; | ||
var MAX_SEARCH_QUERY_LENGTH = 200; | ||
var MAX_SEARCH_AMOUNT_IN_CENTS = 2000000000; | ||
var TRANSACTION_FIELDS = "\n id\n amount\n name\n iban\n type\n bookingDate\n valutaDate\n originalAmount\n foreignCurrency\n e2eId\n mandateNumber\n paymentMethod\n category\n userSelectedBookingDate\n purpose\n documentNumber\n documentPreviewUrl\n documentDownloadUrl\n documentType\n"; | ||
@@ -150,3 +151,6 @@ var FETCH_TRANSACTIONS = "\n query fetchTransactions ($first: Int, $last: Int, $after: String, $before: String, $filter: TransactionFilter) {\n viewer {\n mainAccount {\n transactions(first: $first, last: $last, after: $after, before: $before, filter: $filter) {\n edges {\n node {\n " + TRANSACTION_FIELDS + "\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n }\n"; | ||
Transaction.prototype.parseSearchQuery = function (searchQuery) { | ||
var searchTerms = searchQuery.slice(0, MAX_SEARCH_QUERY_LENGTH).split(" "); | ||
var searchTerms = searchQuery | ||
.slice(0, MAX_SEARCH_QUERY_LENGTH) | ||
.split(" ") | ||
.filter(function (term) { return term.length > 0; }); | ||
var filter = { | ||
@@ -162,3 +166,5 @@ name_likeAny: searchTerms, | ||
var amountInCents = Math.round(parseFloat(term.replace(",", ".")) * 100); | ||
return __spreadArrays(terms, [amountInCents, amountInCents * -1]); | ||
return amountInCents > MAX_SEARCH_AMOUNT_IN_CENTS | ||
? terms | ||
: __spreadArrays(terms, [amountInCents, amountInCents * -1]); | ||
}, []); | ||
@@ -165,0 +171,0 @@ if (amountTerms.length > 0) { |
{ | ||
"name": "kontist", | ||
"version": "0.25.3", | ||
"version": "0.25.4", | ||
"description": "Kontist client SDK", | ||
@@ -5,0 +5,0 @@ "main": "dist/lib/index.js", |
@@ -328,3 +328,44 @@ import { expect } from "chai"; | ||
}); | ||
describe("when user provides number above 20 millions", () => { | ||
it("should not include it as amount filter", async () => { | ||
// arrange | ||
const userQuery = "19999999 20000001 345678912"; | ||
// act | ||
await client.models.transaction.search(userQuery); | ||
// assert | ||
expect(fetchStub.callCount).to.eq(1); | ||
expect(fetchStub.getCall(0).args[0]).to.deep.eq({ | ||
filter: { | ||
amount_in: [1999999900, -1999999900], | ||
name_likeAny: ["19999999", "20000001", "345678912"], | ||
operator: BaseOperator.Or, | ||
purpose_likeAny: ["19999999", "20000001", "345678912"] | ||
} | ||
}); | ||
}); | ||
}); | ||
describe("when user provides several spaces back to back", () => { | ||
it("should not include empty strings as filters", async () => { | ||
// arrange | ||
const userQuery = " hello world "; | ||
// act | ||
await client.models.transaction.search(userQuery); | ||
// assert | ||
expect(fetchStub.callCount).to.eq(1); | ||
expect(fetchStub.getCall(0).args[0]).to.deep.eq({ | ||
filter: { | ||
name_likeAny: ["hello", "world"], | ||
operator: BaseOperator.Or, | ||
purpose_likeAny: ["hello", "world"] | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
492294
7431