Comparing version 0.24.4 to 0.25.0
@@ -73,10 +73,11 @@ "use strict"; | ||
Account.prototype.get = function () { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, this.client.rawQuery(GET_ACCOUNT)]; | ||
case 1: | ||
result = _a.sent(); | ||
return [2 /*return*/, result.viewer.mainAccount || null]; | ||
result = _b.sent(); | ||
return [2 /*return*/, ((_a = result.viewer) === null || _a === void 0 ? void 0 : _a.mainAccount) || null]; | ||
} | ||
@@ -83,0 +84,0 @@ }); |
@@ -78,11 +78,11 @@ "use strict"; | ||
Card.prototype.fetch = function () { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, cards, pageInfo; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: return [4 /*yield*/, this.client.rawQuery(GET_CARDS)]; | ||
case 1: | ||
result = _c.sent(); | ||
cards = (_b = (_a = result.viewer.mainAccount) === null || _a === void 0 ? void 0 : _a.cards, (_b !== null && _b !== void 0 ? _b : [])); | ||
result = _d.sent(); | ||
cards = (_c = (_b = (_a = result.viewer) === null || _a === void 0 ? void 0 : _a.mainAccount) === null || _b === void 0 ? void 0 : _b.cards, (_c !== null && _c !== void 0 ? _c : [])); | ||
pageInfo = { | ||
@@ -104,11 +104,11 @@ hasNextPage: false, | ||
Card.prototype.get = function (args) { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: return [4 /*yield*/, this.client.rawQuery(GET_CARD, args)]; | ||
case 1: | ||
result = _c.sent(); | ||
return [2 /*return*/, (_b = (_a = result.viewer.mainAccount) === null || _a === void 0 ? void 0 : _a.card, (_b !== null && _b !== void 0 ? _b : null))]; | ||
result = _d.sent(); | ||
return [2 /*return*/, (_c = (_b = (_a = result.viewer) === null || _a === void 0 ? void 0 : _a.mainAccount) === null || _b === void 0 ? void 0 : _b.card, (_c !== null && _c !== void 0 ? _c : null))]; | ||
} | ||
@@ -125,11 +125,11 @@ }); | ||
Card.prototype.getLimits = function (args) { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
return __generator(this, function (_e) { | ||
switch (_e.label) { | ||
case 0: return [4 /*yield*/, this.client.rawQuery(GET_CARD_LIMITS, args)]; | ||
case 1: | ||
result = _d.sent(); | ||
return [2 /*return*/, (_c = (_b = (_a = result.viewer.mainAccount) === null || _a === void 0 ? void 0 : _a.card) === null || _b === void 0 ? void 0 : _b.settings, (_c !== null && _c !== void 0 ? _c : null))]; | ||
result = _e.sent(); | ||
return [2 /*return*/, (_d = (_c = (_b = (_a = result.viewer) === null || _a === void 0 ? void 0 : _a.mainAccount) === null || _b === void 0 ? void 0 : _b.card) === null || _c === void 0 ? void 0 : _c.settings, (_d !== null && _d !== void 0 ? _d : null))]; | ||
} | ||
@@ -136,0 +136,0 @@ }); |
@@ -46,2 +46,3 @@ export declare type Maybe<T> = T | null; | ||
export declare type AccountTransactionsArgs = { | ||
filter?: Maybe<TransactionFilter>; | ||
first?: Maybe<Scalars['Int']>; | ||
@@ -61,2 +62,6 @@ last?: Maybe<Scalars['Int']>; | ||
}; | ||
export declare enum BaseOperator { | ||
Or = "OR", | ||
And = "AND" | ||
} | ||
export declare type BatchTransfer = { | ||
@@ -209,36 +214,2 @@ __typename?: 'BatchTransfer'; | ||
}; | ||
/** The available fields to create a Standing Order */ | ||
export declare type CreateStandingOrderInput = { | ||
/** The name of the Standing Order payments recipient */ | ||
recipient: Scalars['String']; | ||
/** The IBAN of the Standing Order payments recipient */ | ||
iban: Scalars['String']; | ||
/** The amount of each Standing Order payment in cents */ | ||
amount: Scalars['Int']; | ||
/** The date at which the first payment will be executed */ | ||
executeAt: Scalars['DateTime']; | ||
/** The date at which the last payment will be executed */ | ||
lastExecutionDate?: Maybe<Scalars['DateTime']>; | ||
/** The purpose of the Standing Order - 140 max characters */ | ||
purpose?: Maybe<Scalars['String']>; | ||
/** The end to end ID of the Standing Order */ | ||
e2eId?: Maybe<Scalars['String']>; | ||
/** The reoccurrence type of the Standing Order payments */ | ||
reoccurrence: StandingOrderReoccurenceType; | ||
}; | ||
/** The available fields to create a Timed Order */ | ||
export declare type CreateTimedOrderInput = { | ||
/** The name of the Timed Order recipient */ | ||
recipient: Scalars['String']; | ||
/** The IBAN of the Timed Order recipient */ | ||
iban: Scalars['String']; | ||
/** The amount of the Timed Order in cents */ | ||
amount: Scalars['Int']; | ||
/** The date at which the payment will be executed */ | ||
executeAt: Scalars['DateTime']; | ||
/** The purpose of the Timed Order - 140 max characters */ | ||
purpose?: Maybe<Scalars['String']>; | ||
/** The end to end ID of the Timed Order */ | ||
e2eId?: Maybe<Scalars['String']>; | ||
}; | ||
/** The available fields to create a transfer */ | ||
@@ -325,9 +296,17 @@ export declare type CreateTransferInput = { | ||
confirmFraud: ConfirmFraudResponse; | ||
/** Create a new card */ | ||
createCard: Card; | ||
/** Activate a card */ | ||
activateCard: Card; | ||
/** Update settings (e.g. limits) */ | ||
updateCardSettings: CardSettings; | ||
/** Block or unblock or close a card */ | ||
changeCardStatus: Card; | ||
/** Set a new PIN, needs to be confirmed */ | ||
changeCardPIN: ConfirmationRequest; | ||
/** Confirm a PIN change request */ | ||
confirmChangeCardPIN: ConfirmationStatus; | ||
/** Call when customer's card is lost or stolen */ | ||
replaceCard: Card; | ||
/** Close and order new card. Call when customer's card is damaged */ | ||
reorderCard: Card; | ||
@@ -682,3 +661,4 @@ /** Categorize a transaction with an optional custom booking date for VAT or Tax categories */ | ||
/** The current user information */ | ||
viewer: User; | ||
viewer?: Maybe<User>; | ||
status: SystemStatus; | ||
}; | ||
@@ -718,26 +698,2 @@ export declare enum ScopeType { | ||
} | ||
export declare type StandingOrder = { | ||
__typename?: 'StandingOrder'; | ||
id: Scalars['String']; | ||
/** The status of the Standing Order */ | ||
status: StandingOrderStatus; | ||
/** The IBAN of the Standing Order payments recipient */ | ||
iban: Scalars['String']; | ||
/** The name of the Standing Order payments recipient */ | ||
recipient: Scalars['String']; | ||
/** The purpose of the Standing Order - 140 max characters */ | ||
purpose?: Maybe<Scalars['String']>; | ||
/** The amount of each Standing Order payment in cents */ | ||
amount: Scalars['Int']; | ||
/** The date at which the first payment will be executed */ | ||
executeAt: Scalars['DateTime']; | ||
/** The date at which the last payment will be executed */ | ||
lastExecutionDate?: Maybe<Scalars['DateTime']>; | ||
/** The end to end ID of the Standing Order */ | ||
e2eId?: Maybe<Scalars['String']>; | ||
/** The reoccurrence type of the Standing Order payments */ | ||
reoccurrence: StandingOrderReoccurenceType; | ||
/** The date at which the next payment will be executed */ | ||
nextOccurrence?: Maybe<Scalars['DateTime']>; | ||
}; | ||
export declare enum StandingOrderReoccurenceType { | ||
@@ -749,7 +705,4 @@ Monthly = "MONTHLY", | ||
} | ||
export declare enum StandingOrderStatus { | ||
Created = "CREATED", | ||
Active = "ACTIVE", | ||
Inactive = "INACTIVE", | ||
Canceled = "CANCELED" | ||
export declare enum Status { | ||
Error = "ERROR" | ||
} | ||
@@ -760,29 +713,7 @@ export declare type Subscription = { | ||
}; | ||
export declare type TimedOrder = { | ||
__typename?: 'TimedOrder'; | ||
id: Scalars['ID']; | ||
/** The date at which the payment will be executed */ | ||
executeAt: Scalars['String']; | ||
/** The status of the Timed Order */ | ||
status: TimedOrderStatus; | ||
/** The purpose of the Timed Order - 140 max characters */ | ||
purpose?: Maybe<Scalars['String']>; | ||
/** The IBAN of the Timed Order recipient */ | ||
iban: Scalars['String']; | ||
/** The name of the Timed Order recipient */ | ||
recipient: Scalars['String']; | ||
/** The end to end ID of the Timed Order */ | ||
e2eId?: Maybe<Scalars['String']>; | ||
/** The amount of the Timed Order in cents */ | ||
amount: Scalars['Int']; | ||
export declare type SystemStatus = { | ||
__typename?: 'SystemStatus'; | ||
type?: Maybe<Status>; | ||
message?: Maybe<Scalars['String']>; | ||
}; | ||
export declare enum TimedOrderStatus { | ||
Created = "CREATED", | ||
AuthorizationRequired = "AUTHORIZATION_REQUIRED", | ||
ConfirmationRequired = "CONFIRMATION_REQUIRED", | ||
Scheduled = "SCHEDULED", | ||
Executed = "EXECUTED", | ||
Canceled = "CANCELED", | ||
Failed = "FAILED" | ||
} | ||
export declare type Transaction = { | ||
@@ -827,2 +758,32 @@ __typename?: 'Transaction'; | ||
} | ||
export declare type TransactionCondition = { | ||
operator?: Maybe<BaseOperator>; | ||
amount_lt?: Maybe<Scalars['Int']>; | ||
amount_gt?: Maybe<Scalars['Int']>; | ||
amount_gte?: Maybe<Scalars['Int']>; | ||
amount_lte?: Maybe<Scalars['Int']>; | ||
amount_eq?: Maybe<Scalars['Int']>; | ||
amount_ne?: Maybe<Scalars['Int']>; | ||
amount_in?: Maybe<Array<Scalars['Int']>>; | ||
iban_eq?: Maybe<Scalars['String']>; | ||
iban_ne?: Maybe<Scalars['String']>; | ||
iban_like?: Maybe<Scalars['String']>; | ||
iban_likeAny?: Maybe<Array<Scalars['String']>>; | ||
iban_in?: Maybe<Array<Scalars['String']>>; | ||
bookingDate_eq?: Maybe<Scalars['String']>; | ||
bookingDate_ne?: Maybe<Scalars['String']>; | ||
bookingDate_gt?: Maybe<Scalars['String']>; | ||
bookingDate_lt?: Maybe<Scalars['String']>; | ||
bookingDate_gte?: Maybe<Scalars['String']>; | ||
bookingDate_lte?: Maybe<Scalars['String']>; | ||
name_eq?: Maybe<Scalars['String']>; | ||
name_ne?: Maybe<Scalars['String']>; | ||
name_like?: Maybe<Scalars['String']>; | ||
name_likeAny?: Maybe<Array<Scalars['String']>>; | ||
name_in?: Maybe<Array<Scalars['String']>>; | ||
purpose_eq?: Maybe<Scalars['String']>; | ||
purpose_ne?: Maybe<Scalars['String']>; | ||
purpose_like?: Maybe<Scalars['String']>; | ||
purpose_likeAny?: Maybe<Array<Scalars['String']>>; | ||
}; | ||
export declare type TransactionFee = { | ||
@@ -849,2 +810,33 @@ __typename?: 'TransactionFee'; | ||
} | ||
export declare type TransactionFilter = { | ||
operator?: Maybe<BaseOperator>; | ||
amount_lt?: Maybe<Scalars['Int']>; | ||
amount_gt?: Maybe<Scalars['Int']>; | ||
amount_gte?: Maybe<Scalars['Int']>; | ||
amount_lte?: Maybe<Scalars['Int']>; | ||
amount_eq?: Maybe<Scalars['Int']>; | ||
amount_ne?: Maybe<Scalars['Int']>; | ||
amount_in?: Maybe<Array<Scalars['Int']>>; | ||
iban_eq?: Maybe<Scalars['String']>; | ||
iban_ne?: Maybe<Scalars['String']>; | ||
iban_like?: Maybe<Scalars['String']>; | ||
iban_likeAny?: Maybe<Array<Scalars['String']>>; | ||
iban_in?: Maybe<Array<Scalars['String']>>; | ||
bookingDate_eq?: Maybe<Scalars['String']>; | ||
bookingDate_ne?: Maybe<Scalars['String']>; | ||
bookingDate_gt?: Maybe<Scalars['String']>; | ||
bookingDate_lt?: Maybe<Scalars['String']>; | ||
bookingDate_gte?: Maybe<Scalars['String']>; | ||
bookingDate_lte?: Maybe<Scalars['String']>; | ||
name_eq?: Maybe<Scalars['String']>; | ||
name_ne?: Maybe<Scalars['String']>; | ||
name_like?: Maybe<Scalars['String']>; | ||
name_likeAny?: Maybe<Array<Scalars['String']>>; | ||
name_in?: Maybe<Array<Scalars['String']>>; | ||
purpose_eq?: Maybe<Scalars['String']>; | ||
purpose_ne?: Maybe<Scalars['String']>; | ||
purpose_like?: Maybe<Scalars['String']>; | ||
purpose_likeAny?: Maybe<Array<Scalars['String']>>; | ||
conditions?: Maybe<Array<TransactionCondition>>; | ||
}; | ||
export declare enum TransactionProjectionType { | ||
@@ -996,3 +988,3 @@ CreditPresentment = "CREDIT_PRESENTMENT", | ||
identificationStatus?: Maybe<IdentificationStatus>; | ||
/** The user's IDNow identification status */ | ||
/** The link to use for IDNow identification */ | ||
identificationLink?: Maybe<Scalars['String']>; | ||
@@ -999,0 +991,0 @@ gender?: Maybe<Gender>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var BaseOperator; | ||
(function (BaseOperator) { | ||
BaseOperator["Or"] = "OR"; | ||
BaseOperator["And"] = "AND"; | ||
})(BaseOperator = exports.BaseOperator || (exports.BaseOperator = {})); | ||
var BatchTransferStatus; | ||
@@ -373,19 +378,6 @@ (function (BatchTransferStatus) { | ||
})(StandingOrderReoccurenceType = exports.StandingOrderReoccurenceType || (exports.StandingOrderReoccurenceType = {})); | ||
var StandingOrderStatus; | ||
(function (StandingOrderStatus) { | ||
StandingOrderStatus["Created"] = "CREATED"; | ||
StandingOrderStatus["Active"] = "ACTIVE"; | ||
StandingOrderStatus["Inactive"] = "INACTIVE"; | ||
StandingOrderStatus["Canceled"] = "CANCELED"; | ||
})(StandingOrderStatus = exports.StandingOrderStatus || (exports.StandingOrderStatus = {})); | ||
var TimedOrderStatus; | ||
(function (TimedOrderStatus) { | ||
TimedOrderStatus["Created"] = "CREATED"; | ||
TimedOrderStatus["AuthorizationRequired"] = "AUTHORIZATION_REQUIRED"; | ||
TimedOrderStatus["ConfirmationRequired"] = "CONFIRMATION_REQUIRED"; | ||
TimedOrderStatus["Scheduled"] = "SCHEDULED"; | ||
TimedOrderStatus["Executed"] = "EXECUTED"; | ||
TimedOrderStatus["Canceled"] = "CANCELED"; | ||
TimedOrderStatus["Failed"] = "FAILED"; | ||
})(TimedOrderStatus = exports.TimedOrderStatus || (exports.TimedOrderStatus = {})); | ||
var Status; | ||
(function (Status) { | ||
Status["Error"] = "ERROR"; | ||
})(Status = exports.Status || (exports.Status = {})); | ||
var TransactionCategory; | ||
@@ -392,0 +384,0 @@ (function (TransactionCategory) { |
import { IterableModel } from "./iterableModel"; | ||
import { ResultPage } from "./resultPage"; | ||
import { MutationCategorizeTransactionArgs, Transaction as TransactionModel } from "./schema"; | ||
import { AccountTransactionsArgs, MutationCategorizeTransactionArgs, Transaction as TransactionModel } from "./schema"; | ||
import { FetchOptions, Subscription } from "./types"; | ||
@@ -14,4 +14,13 @@ export declare const NEW_TRANSACTION_SUBSCRIPTION: string; | ||
*/ | ||
fetch(args?: FetchOptions): Promise<ResultPage<TransactionModel>>; | ||
fetch(args?: AccountTransactionsArgs): Promise<ResultPage<TransactionModel>>; | ||
/** | ||
* Fetches up to first 50 matching transactions for a given user input | ||
* It will consider case insensitive like matches for amount, | ||
* iban, description, and name | ||
* | ||
* @param searchQuery input query from user | ||
* @returns | ||
*/ | ||
search(searchQuery: string): Promise<ResultPage<TransactionModel>>; | ||
/** | ||
* @inheritdoc | ||
@@ -35,2 +44,3 @@ */ | ||
categorize(args: MutationCategorizeTransactionArgs): Promise<TransactionModel>; | ||
private parseSearchQuery; | ||
} |
@@ -51,8 +51,17 @@ "use strict"; | ||
}; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var iterableModel_1 = require("./iterableModel"); | ||
var resultPage_1 = require("./resultPage"); | ||
var schema_1 = require("./schema"); | ||
var types_1 = require("./types"); | ||
var MAX_SEARCH_QUERY_LENGTH = 200; | ||
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"; | ||
var FETCH_TRANSACTIONS = "query fetchTransactions ($first: Int, $last: Int, $after: String, $before: String) {\n viewer {\n mainAccount {\n transactions(first: $first, last: $last, after: $after, before: $before) {\n edges {\n node {\n " + TRANSACTION_FIELDS + "\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n}"; | ||
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"; | ||
exports.NEW_TRANSACTION_SUBSCRIPTION = "subscription {\n newTransaction {\n " + TRANSACTION_FIELDS + "\n }\n}"; | ||
@@ -91,2 +100,19 @@ exports.CATEGORIZE_TRANSACTION = "mutation categorizeTransaction(\n $id: String!\n $category: TransactionCategory,\n $userSelectedBookingDate: DateTime\n) {\n categorizeTransaction(\n id: $id\n category: $category\n userSelectedBookingDate: $userSelectedBookingDate\n ) {\n " + TRANSACTION_FIELDS + "\n }\n}"; | ||
/** | ||
* Fetches up to first 50 matching transactions for a given user input | ||
* It will consider case insensitive like matches for amount, | ||
* iban, description, and name | ||
* | ||
* @param searchQuery input query from user | ||
* @returns | ||
*/ | ||
Transaction.prototype.search = function (searchQuery) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var filter; | ||
return __generator(this, function (_a) { | ||
filter = this.parseSearchQuery(searchQuery); | ||
return [2 /*return*/, this.fetch({ filter: filter })]; | ||
}); | ||
}); | ||
}; | ||
/** | ||
* @inheritdoc | ||
@@ -124,2 +150,22 @@ */ | ||
}; | ||
Transaction.prototype.parseSearchQuery = function (searchQuery) { | ||
var searchTerms = searchQuery.slice(0, MAX_SEARCH_QUERY_LENGTH).split(" "); | ||
var filter = { | ||
iban_likeAny: searchTerms, | ||
name_likeAny: searchTerms, | ||
operator: schema_1.BaseOperator.Or, | ||
purpose_likeAny: searchTerms, | ||
}; | ||
var amountRegex = /^-?\d+([,.]\d{1,2})?$/; | ||
var amountTerms = searchTerms | ||
.filter(function (term) { return amountRegex.test(term); }) | ||
.reduce(function (terms, term) { | ||
var amountInCents = Math.round(parseFloat(term.replace(",", ".")) * 100); | ||
return __spreadArrays(terms, [amountInCents, amountInCents * -1]); | ||
}, []); | ||
if (amountTerms.length > 0) { | ||
filter.amount_in = amountTerms; | ||
} | ||
return filter; | ||
}; | ||
return Transaction; | ||
@@ -126,0 +172,0 @@ }(iterableModel_1.IterableModel)); |
import { IterableModel } from "./iterableModel"; | ||
import { ResultPage } from "./resultPage"; | ||
import { BatchTransfer, ConfirmationRequestOrTransfer, CreateTransferInput, Transfer as TransferModel, TransferSuggestion, TransferType, UpdateTransferInput } from "./schema"; | ||
import { TransferFetchOptions } from "./types"; | ||
export declare class Transfer extends IterableModel<TransferModel, TransferFetchOptions> { | ||
import { AccountTransfersArgs, BatchTransfer, ConfirmationRequestOrTransfer, CreateTransferInput, Transfer as TransferModel, TransferSuggestion, TransferType, UpdateTransferInput } from "./schema"; | ||
export declare class Transfer extends IterableModel<TransferModel, AccountTransfersArgs> { | ||
/** | ||
@@ -66,3 +65,3 @@ * Creates single wire transfer / timed order / standing order | ||
*/ | ||
fetch(args: TransferFetchOptions): Promise<ResultPage<TransferModel, TransferFetchOptions>>; | ||
fetch(args: AccountTransfersArgs): Promise<ResultPage<TransferModel, AccountTransfersArgs>>; | ||
/** | ||
@@ -69,0 +68,0 @@ * Fetches a list of suggestions for wire transfer |
@@ -1,2 +0,2 @@ | ||
import { CardType, Mutation, Query, TransfersConnectionFilter, TransferType } from "./schema"; | ||
import { CardType, Mutation, Query } from "./schema"; | ||
export declare type FetchOptions = { | ||
@@ -8,6 +8,2 @@ first?: number; | ||
}; | ||
export declare type TransferFetchOptions = { | ||
type: TransferType; | ||
where?: TransfersConnectionFilter; | ||
} & FetchOptions; | ||
export declare type GetCardOptions = { | ||
@@ -14,0 +10,0 @@ id: string; |
@@ -11,3 +11,3 @@ import { Model } from "./model"; | ||
*/ | ||
get(): Promise<UserModel>; | ||
get(): Promise<UserModel | undefined | null>; | ||
} |
{ | ||
"name": "kontist", | ||
"version": "0.24.4", | ||
"version": "0.25.0", | ||
"description": "Kontist client SDK", | ||
@@ -5,0 +5,0 @@ "main": "dist/lib/index.js", |
import { expect } from "chai"; | ||
import * as sinon from "sinon"; | ||
import { Client } from "../../lib"; | ||
import { Transaction, TransactionCategory } from "../../lib/graphql/schema"; | ||
import { Transaction, TransactionCategory, BaseOperator } from "../../lib/graphql/schema"; | ||
import { NEW_TRANSACTION_SUBSCRIPTION } from "../../lib/graphql/transaction"; | ||
@@ -25,5 +25,11 @@ import { SubscriptionType } from "../../lib/graphql/types"; | ||
firstTransaction = createTransaction(); | ||
firstTransaction = createTransaction({ | ||
name: "Santa Claus", | ||
amount: 900 | ||
}); | ||
secondTransaction = createTransaction(); | ||
thirdTransaction = createTransaction(); | ||
thirdTransaction = createTransaction({ | ||
name: "Willy Wonka", | ||
ammount: 1200 | ||
}); | ||
@@ -79,2 +85,35 @@ stub.onFirstCall().resolves( | ||
it("can fetch filtered transactions", async () => { | ||
stub.onFirstCall().resolves( | ||
generatePaginatedResponse({ | ||
key: "transactions", | ||
items: [firstTransaction, thirdTransaction], | ||
pageInfo: { hasPreviousPage: false, hasNextPage: false }, | ||
}), | ||
); | ||
const results = await client.models.transaction.fetch({ | ||
filter: { | ||
operator: BaseOperator.And, | ||
amount_gt: 1000, | ||
name_like:"SaNtA" | ||
} | ||
}); | ||
expect(stub.callCount).to.equal(1); | ||
expect(stub.getCall(0).args[1]).to.deep.equal( | ||
{ | ||
filter: { | ||
operator: BaseOperator.And, | ||
amount_gt: 1000, | ||
name_like: "SaNtA" | ||
} | ||
} | ||
); | ||
expect(results.items).to.deep.equal([ | ||
firstTransaction, | ||
thirdTransaction, | ||
]); | ||
}) | ||
describe("when iterating backwards", () => { | ||
@@ -169,2 +208,106 @@ it("can fetch the previous page using the previousPage method", async () => { | ||
}); | ||
describe("#search", () => { | ||
let client: Client; | ||
let fetchStub: any; | ||
before(() => { | ||
client = createClient(); | ||
fetchStub = sinon.stub(client.models.transaction, "fetch").resolves(); | ||
}); | ||
after(() => { | ||
fetchStub.restore(); | ||
}); | ||
afterEach(() => { | ||
fetchStub.resetHistory(); | ||
}) | ||
describe("when user provides only text", () => { | ||
it("should call fetch with properly formatted filter", 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: { | ||
iban_likeAny: ["hello", "world"], | ||
name_likeAny: ["hello", "world"], | ||
operator: BaseOperator.Or, | ||
purpose_likeAny: ["hello", "world"], | ||
} | ||
}); | ||
}); | ||
}); | ||
describe("when user provides only numbers", () => { | ||
it("should call fetch with properly formatted filter", async () => { | ||
// arrange | ||
const userQuery = "1234 -567 86.12 90,1"; | ||
// 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: [123400, -123400, -56700, 56700, 8612, -8612, 9010, -9010], | ||
iban_likeAny: ["1234", "-567", "86.12", "90,1"], | ||
name_likeAny: ["1234", "-567", "86.12", "90,1"], | ||
operator: BaseOperator.Or, | ||
purpose_likeAny: ["1234", "-567", "86.12", "90,1"], | ||
} | ||
}); | ||
}); | ||
}); | ||
describe("when user provides a mix of numbers and text", () => { | ||
it("should call fetch with properly formatted filter", async () => { | ||
// arrange | ||
const userQuery = "DE12345 -90,87 hello 33.91"; | ||
// 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: [-9087, 9087, 3391, -3391], | ||
iban_likeAny: ["DE12345", "-90,87", "hello", "33.91"], | ||
name_likeAny: ["DE12345", "-90,87", "hello", "33.91"], | ||
operator: BaseOperator.Or, | ||
purpose_likeAny: ["DE12345", "-90,87", "hello", "33.91"], | ||
} | ||
}); | ||
}); | ||
}); | ||
describe("when user provides terms which are not valid amount", () => { | ||
it("should call fetch without including amount filter", async () => { | ||
// arrange | ||
const userQuery = "1.123 -234, .10"; | ||
// act | ||
await client.models.transaction.search(userQuery); | ||
// assert | ||
expect(fetchStub.callCount).to.eq(1); | ||
expect(fetchStub.getCall(0).args[0]).to.deep.eq({ | ||
filter: { | ||
iban_likeAny: ["1.123", "-234,", ".10"], | ||
name_likeAny: ["1.123", "-234,", ".10"], | ||
operator: BaseOperator.Or, | ||
purpose_likeAny: ["1.123", "-234,", ".10"], | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
484826
7293