diff --git a/jest.config.ts b/jest.config.ts index ca8d04d..462e1d1 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -3,7 +3,7 @@ import type { Config } from '@jest/types'; // Sync object const config: Config.InitialOptions = { verbose: true, - testTimeout: 30000, + testTimeout: 15000, transform: { '^.+\\.tsx?$': 'ts-jest' }, diff --git a/src/converters/degiroConverterV2.test.ts b/src/converters/degiroConverterV2.test.ts index 983a8b6..48bfc5b 100644 --- a/src/converters/degiroConverterV2.test.ts +++ b/src/converters/degiroConverterV2.test.ts @@ -5,7 +5,7 @@ import { GhostfolioExport } from "../models/ghostfolioExport"; describe("degiroConverterV2", () => { beforeEach(() => { - jest.spyOn(console, "log").mockImplementation(jest.fn()); + // jest.spyOn(console, "log").mockImplementation(jest.fn()); }); afterEach(() => { @@ -33,7 +33,7 @@ describe("degiroConverterV2", () => { // Assert expect(actualExport).toBeTruthy(); expect(actualExport.activities.length).toBeGreaterThan(0); - expect(actualExport.activities.length).toBe(16); + expect(actualExport.activities.length).toBe(15); done(); }, () => { done.fail("Should not have an error!"); }); diff --git a/src/converters/degiroConverterV2.ts b/src/converters/degiroConverterV2.ts index c94bf33..501aa55 100644 --- a/src/converters/degiroConverterV2.ts +++ b/src/converters/degiroConverterV2.ts @@ -130,7 +130,7 @@ export class DeGiroConverterV2 extends AbstractConverter { continue; } } - else if (this.isTransactionFeeRecord(record)) { + else if (this.isTransactionFeeRecord(record, false)) { // If it was a transaction record without any other transaction connected, skip it. bar1.increment(); @@ -236,12 +236,12 @@ export class DeGiroConverterV2 extends AbstractConverter { // Determine which of the two records is the action record (e.g. buy/sell) and which contains the transaction fees. // Firstly, check if the current record is the TxFee record. - if (this.isTransactionFeeRecord(currentRecord)) { + if (this.isTransactionFeeRecord(currentRecord, true)) { actionRecord = nextRecord; txFeeRecord = currentRecord; } // Next, check wether the next record is NOT a TxFee record. In this case, the transaction has no fees. - else if (!this.isTransactionFeeRecord(nextRecord)) { + else if (!this.isTransactionFeeRecord(nextRecord, true)) { txFeeRecord = null; } @@ -295,12 +295,12 @@ export class DeGiroConverterV2 extends AbstractConverter { // Determine which of the two records is the dividend record and which contains the transaction fees. // Firstly, check if the current record is the TxFee record. - if (this.isTransactionFeeRecord(currentRecord)) { + if (this.isTransactionFeeRecord(currentRecord, false)) { dividendRecord = nextRecord; txFeeRecord = currentRecord; } // Next, check wether the next record is NOT a TxFee record. In this case, the dividend has no fees. - else if (!this.isTransactionFeeRecord(nextRecord)) { + else if (!this.isTransactionFeeRecord(nextRecord, false)) { txFeeRecord = null; } @@ -338,9 +338,9 @@ export class DeGiroConverterV2 extends AbstractConverter { // - TxFee + Buy/Sell records, or // - Buy/Sell record without TxFee. return ( - (this.isBuyOrSellRecord(currentRecord) && this.isTransactionFeeRecord(nextRecord)) || - (this.isTransactionFeeRecord(currentRecord) && this.isBuyOrSellRecord(nextRecord) || - (this.isBuyOrSellRecord(currentRecord) && !this.isTransactionFeeRecord(nextRecord)))); + (this.isBuyOrSellRecord(currentRecord) && this.isTransactionFeeRecord(nextRecord, true)) || + (this.isTransactionFeeRecord(currentRecord, true) && this.isBuyOrSellRecord(nextRecord) || + (this.isBuyOrSellRecord(currentRecord) && !this.isTransactionFeeRecord(nextRecord, true)))); } private isDividendRecordSet(currentRecord: DeGiroRecord, nextRecord: DeGiroRecord): boolean { @@ -350,9 +350,9 @@ export class DeGiroConverterV2 extends AbstractConverter { // - TxFee + Dividend record, or // - Dividend record without TxFee. return ( - (this.isDividendRecord(currentRecord) && this.isTransactionFeeRecord(nextRecord)) || - (this.isTransactionFeeRecord(currentRecord) && this.isDividendRecord(nextRecord)) || - (this.isDividendRecord(currentRecord) && !this.isTransactionFeeRecord(nextRecord))); + (this.isDividendRecord(currentRecord) && this.isTransactionFeeRecord(nextRecord, false)) || + (this.isTransactionFeeRecord(currentRecord, false) && this.isDividendRecord(nextRecord)) || + (this.isDividendRecord(currentRecord) && !this.isTransactionFeeRecord(nextRecord, false))); } private isBuyOrSellRecord(record: DeGiroRecord): boolean { @@ -375,12 +375,17 @@ export class DeGiroConverterV2 extends AbstractConverter { return record.description.toLocaleLowerCase().indexOf("dividend") > -1 || record.description.toLocaleLowerCase().indexOf("capital return") > -1; } - private isTransactionFeeRecord(record: DeGiroRecord): boolean { + private isTransactionFeeRecord(record: DeGiroRecord, isBuyOrSellTransactionFeeRecord: boolean): boolean { if (!record) { return false; } + // When a dividend transaction must be found, there should not be an orderid. + if (!isBuyOrSellTransactionFeeRecord && record.orderId) { + return false; + } + const transactionFeeRecordType = ["en\/of", "and\/or", "und\/oder", "e\/o", "adr\/gdr", "ritenuta", "belasting", "daň z dividendy", "taxe sur les", "comissões de transação", "courtage et/ou"]; return transactionFeeRecordType.some((t) => record.description.toLocaleLowerCase().indexOf(t) > -1);