Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion converters/cityConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ function shouldBeFilteredOut(payer, transactionType) {
return payer.startsWith('SPŁATA') || transactionType === 'SPŁATA KARTY KREDYTOWEJ' || transactionType === 'CREDIT CARD REPAYMENT' || transactionType === 'CITIBANK MASTERCARD PAYMENT'
}

function findCurrencyInDescription(description) {
if (description.includes('EUR')) {
return 'EUR'
}
return 'PLN'
}

const getExpenseManagerRecord = recordCategoryResolver => record => {
const transactionType = record[columns[5]]
const description = record[columns[1]]
const currency = findCurrencyInDescription(description)
const payer = getPayerByTransaction(transactionType) || parsePayer(description);
if (shouldBeFilteredOut(payer, transactionType)) {
return null;
Expand All @@ -33,7 +41,7 @@ const getExpenseManagerRecord = recordCategoryResolver => record => {
return moment(record[columns[0]], 'DD/MM/YYYY').format('DD.MM.YYYY') + ','
+ amount + ',' + category + ',' + subCategory
+ ',Credit Card,,,' + sanitize(payer)
+ ',,,CitiBank\n'
+ ',,,Citi ' + currency + '\n'
}

exports.convertCvsFileData = (input, categoriesMapping) => {
Expand Down
42 changes: 34 additions & 8 deletions converters/cityConverter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,37 @@ const categoriesMapping = {
'Deposit': { category: 'Income', subCategory: 'Deposit' }
};

test('should be able to convert Citi CSV files format', (done) => {
test('should be able to convert Citi CSV files format for PLN', (done) => {
const currency = 'PLN'
const input = `"30/10/2019","Employer","9.839,29","9.997,16","'1234567890'","PRZELEW ZEWNETRZNY WPLATA"
"28/10/2019","Play SA 76920 Gdansk PL 5575054750123136 10.00 PLN 08:52 210414","-10,00","123,45","'1234567890'","PRZELEW DOŁADOWANIE KOMÓRKI"`
const expected = `30.10.2019,9839.29,Income,Salary,Credit Card,,,Employer,,,CitiBank
28.10.2019,-10,Utilities,Telephone,Credit Card,,,Play SA,,,CitiBank
"28/10/2019","Play SA 76920 Gdansk PL 5575054750123136 10.00 ${currency} 08:52 210414","-10,00","123,45","'1234567890'","PRZELEW DOŁADOWANIE KOMÓRKI"`
const expected = `30.10.2019,9839.29,Income,Salary,Credit Card,,,Employer,,,Citi ${currency}
28.10.2019,-10,Utilities,Telephone,Credit Card,,,Play SA,,,Citi ${currency}
`
let transformedData = '';

const converter = citiConverter.convertCvsFileData(input, categoriesMapping)
.on('readable', () => {
let row = converter.read()
while (row) {
transformedData += row
row = converter.read()
}
})
.on('finish', () => {
setTimeout(() => {
expect(transformedData).toEqual(expected)
done()
})
})
})

test('should be able to convert Citi CSV files format for EUR', (done) => {
const currency = 'EUR'
const input = `"30/10/2019","Employer ${currency}","9.839,29","9.997,16","'1234567890'","PRZELEW ZEWNETRZNY WPLATA"
"28/10/2019","Play SA 76920 Gdansk PL 5575054750123136 10.00 ${currency} 08:52 210414","-10,00","123,45","'1234567890'","PRZELEW DOŁADOWANIE KOMÓRKI"`
const expected = `30.10.2019,9839.29,Income,Salary,Credit Card,,,Employer ${currency},,,Citi ${currency}
28.10.2019,-10,Utilities,Telephone,Credit Card,,,Play SA,,,Citi ${currency}
`
let transformedData = '';

Expand All @@ -35,7 +61,7 @@ test('should ignore paying credit type transactions', (done) => {
"31/10/2019","1234567890","-4.592,54","5.404,62","'1234567890'","CREDIT CARD REPAYMENT"
"31/10/2019","1234567890","-4.592,54","5.404,62","'1234567890'","CITIBANK MASTERCARD PAYMENT"
"28/10/2019","Play","-10,00","123,45","'1234567890'","PRZELEW DOŁADOWANIE KOMÓRKI"`
const expected = `28.10.2019,-10,Utilities,Telephone,Credit Card,,,Play,,,CitiBank
const expected = `28.10.2019,-10,Utilities,Telephone,Credit Card,,,Play,,,Citi PLN
`
let transformedData = '';

Expand All @@ -59,7 +85,7 @@ test('should ignore paying credit type transactions', (done) => {
test('should ignore records payer of which starts with "SPŁATA"', (done) => {
const input = `"31/10/2019","SPŁATA-1234567890","4.592,54","''","SPŁATA-1234567890"
"28/10/2019","Play","-10,00","123,45","'1234567890'","PRZELEW DOŁADOWANIE KOMÓRKI"`
const expected = `28.10.2019,-10,Utilities,Telephone,Credit Card,,,Play,,,CitiBank
const expected = `28.10.2019,-10,Utilities,Telephone,Credit Card,,,Play,,,Citi PLN
`
let transformedData = '';

Expand All @@ -83,8 +109,8 @@ test('should ignore records payer of which starts with "SPŁATA"', (done) => {
test('should set payer as Deposit for transaction type "ODSETKI - LOKATA TERMINOWA"', (done) => {
const input = `"12/09/2019","12345678901234567890","0,68","","'1234567890'","ODSETKI - LOKATA TERMINOWA"
"28/10/2019","Play","-10,00","123,45","'1234567890'","PRZELEW DOŁADOWANIE KOMÓRKI"`
const expected = `12.09.2019,0.68,Income,Deposit,Credit Card,,,Deposit,,,CitiBank
28.10.2019,-10,Utilities,Telephone,Credit Card,,,Play,,,CitiBank
const expected = `12.09.2019,0.68,Income,Deposit,Credit Card,,,Deposit,,,Citi PLN
28.10.2019,-10,Utilities,Telephone,Credit Card,,,Play,,,Citi PLN
`
let transformedData = '';

Expand Down
2 changes: 1 addition & 1 deletion e2e/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('should download converted csv without mapping for City by default', async
await waitForFile(expectedFile)
const file = readFileSync(expectedFile, 'utf-8')

await t.expect(file).eql('30.10.2019,9839.29,Income,,Credit Card,,,Employer,,,CitiBank\n28.10.2019,-10,,,Credit Card,,,Play,,,CitiBank\n')
await t.expect(file).eql('30.10.2019,9839.29,Income,,Credit Card,,,Employer,,,Citi PLN\n28.10.2019,-10,,,Credit Card,,,Play,,,Citi PLN\n')
})
.after(() => unlinkSync(expectedFile))

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "citi_to_expense_manager_csv_converter",
"name": "to_expense_manager_csv_converter",
"version": "1.0.0",
"description": "Convert CSV files from Citi to Expense Manager format",
"description": "Convert CSV files from different bank CSVs to Expense Manager format",
"repository": {
"type": "git",
"url": "https://github.com/Valdermeyder/CityToExpenseManager.git"
Expand Down