Set up a test for the failing parsing

This commit is contained in:
Campbell Alden 2026-03-25 19:19:03 +09:00
parent 4e4760b55a
commit 470be2880c
5 changed files with 4354 additions and 35 deletions

View file

@ -11,41 +11,7 @@ import AsyncLock from 'async-lock';
import cors from 'cors'
import api from '@actual-app/api';
import fs from 'fs';
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 (typeof data.amount !== 'number' || typeof data.amount !== 'string') {
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,
};
}
import { makeTransaction, parse } from './helpers.js';
async function addTransaction(config, transaction) {
try {