Set up a test for the failing parsing
This commit is contained in:
parent
4e4760b55a
commit
f2112c360d
5 changed files with 4354 additions and 35 deletions
39
helpers.js
Normal file
39
helpers.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
function parse(data) {
|
||||
if (typeof data !== 'object' || data === null) {
|
||||
throw new Error(`Bad Data, expected an object, got: ${data === null ? null : typeof data}`);
|
||||
}
|
||||
|
||||
if ((typeof data.title) !== 'string') {
|
||||
throw new Error(`Bad Title: ${data.title}`);
|
||||
}
|
||||
|
||||
if (!['string', 'number'].includes(typeof data.amount)) {
|
||||
throw new Error(`Bad amount: ${data.amount}`);
|
||||
}
|
||||
|
||||
if (typeof data.amount === 'string') {
|
||||
const value = Number(data.amount.replaceAll(/[^\d]/g, ''));
|
||||
data.amount = Number.isNaN(value) ? 0 : value;
|
||||
}
|
||||
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function makeTransaction(data, account) {
|
||||
return {
|
||||
account,
|
||||
date: new Date().toLocaleDateString('sv-SE'), // "YYYY-MM-DD"
|
||||
payee_name: data.title,
|
||||
// Actual considers this an integer representing a decimal value so the last two digits of the integer
|
||||
// are placed after the decimal point (unclear why but okay...)
|
||||
// It has to be negative or actual will think it's a deposit
|
||||
amount: data.amount * -100,
|
||||
cleared: true,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
makeTransaction,
|
||||
parse
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue