LCOV - code coverage report
Current view: top level - _classes/integration/simplefin - simplefin_importer.dart Coverage Total Hit
Test: lcov.info Lines: 100.0 % 15 15
Test Date: 2026-12-05 10:48:47 Functions: - 0 0

            Line data    Source code
       1              : // Copyright 2026 The terCAD team. All rights reserved.
       2              : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
       3              : 
       4              : import 'package:app_finance/_classes/math/budget_prediction.dart';
       5              : import 'package:app_finance/_classes/integration/integration_record.dart';
       6              : import 'package:app_finance/_classes/integration/simplefin/simplefin_client.dart';
       7              : import 'package:app_finance/_classes/structure/interface_app_data.dart';
       8              : import 'package:uuid/uuid.dart';
       9              : 
      10              : class SimpleFinImporter {
      11              :   final bool Function(String uuid) exists;
      12              :   final void Function(InterfaceAppData item, String uuid) add;
      13              : 
      14            1 :   const SimpleFinImporter({required this.exists, required this.add});
      15              : 
      16            1 :   IntegrationImportResult run({
      17              :     required SimpleFinAccount source,
      18              :     required String account,
      19              :     required String category,
      20              :     BudgetPrediction? prediction,
      21              :   }) {
      22              :     var added = 0;
      23              :     var skipped = 0;
      24              :     var pending = 0;
      25            2 :     for (final transaction in source.transactions) {
      26            1 :       final date = transaction.date;
      27            1 :       if (transaction.pending || date == null) {
      28            1 :         pending++;
      29              :         continue;
      30              :       }
      31            5 :       final uuid = const Uuid().v5(Namespace.url.value, 'simplefin:${source.id}:${transaction.id}');
      32            2 :       if (exists(uuid)) {
      33            1 :         skipped++;
      34              :         continue;
      35              :       }
      36            2 :       add(
      37            1 :         IntegrationRecord.toAppData(
      38            1 :           amount: transaction.amount,
      39            1 :           currency: source.currency,
      40              :           date: date,
      41            1 :           title: transaction.description,
      42              :           account: account,
      43              :           category: category,
      44              :           prediction: prediction,
      45              :         ),
      46              :         uuid,
      47              :       );
      48            1 :       added++;
      49              :     }
      50              :     return (added: added, skipped: skipped, pending: pending);
      51              :   }
      52              : }
        

Generated by: LCOV version 2.0-1