Skip to content
Snippets Groups Projects
init-node.js 848 B
Newer Older
  • Learn to ignore specific revisions
  • import { dirname, basename } from 'path';
    
    import fetch from 'node-fetch';
    import 'source-map-support/register';
    
    
    // eslint-disable-next-line import/extensions
    import bundle from './lib-dist/bundle.desktop.js';
    
    
    global.fetch = fetch;
    
    James Long's avatar
    James Long committed
    
    async function init(budgetPath) {
    
      const dir = dirname(budgetPath);
      const budgetId = basename(budgetPath);
    
    James Long's avatar
    James Long committed
      await bundle.initEmbedded('0.0.147', true, dir);
      await bundle.lib.send('load-budget', { id: budgetId });
    
      return bundle.lib;
    }
    
    async function run() {
    
      const { send } = await init('/tmp/_test-budget');
      const accounts = await send('accounts-get');
    
    James Long's avatar
    James Long committed
    
      await send('transaction-add', {
        date: '2022-03-20',
        account: accounts[0].id,
    
        amount: 1000,
    
    James Long's avatar
    James Long committed
      });
    
      await new Promise(resolve => {
        setTimeout(() => {
          resolve();
        }, 5000);
      });
    
      await send('close-budget');
    }
    
    run();