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-11-14 15:03:01 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/integration/integration_record.dart';
       5              : import 'package:app_finance/_classes/integration/simplefin/simplefin_client.dart';
       6              : import 'package:app_finance/_classes/structure/interface_app_data.dart';
       7              : import 'package:uuid/uuid.dart';
       8              : 
       9              : class SimpleFinImporter {
      10              :   final bool Function(String uuid) exists;
      11              :   final void Function(InterfaceAppData item, String uuid) add;
      12              : 
      13            1 :   const SimpleFinImporter({required this.exists, required this.add});
      14              : 
      15            1 :   IntegrationImportResult run({
      16              :     required SimpleFinAccount source,
      17              :     required String account,
      18              :     required String category,
      19              :   }) {
      20              :     var added = 0;
      21              :     var skipped = 0;
      22              :     var pending = 0;
      23            2 :     for (final transaction in source.transactions) {
      24            1 :       final date = transaction.date;
      25            1 :       if (transaction.pending || date == null) {
      26            1 :         pending++;
      27              :         continue;
      28              :       }
      29            5 :       final uuid = const Uuid().v5(Namespace.url.value, 'simplefin:${source.id}:${transaction.id}');
      30            2 :       if (exists(uuid)) {
      31            1 :         skipped++;
      32              :         continue;
      33              :       }
      34            2 :       add(
      35            1 :         IntegrationRecord.toAppData(
      36            1 :           amount: transaction.amount,
      37            1 :           currency: source.currency,
      38              :           date: date,
      39            1 :           title: transaction.description,
      40              :           account: account,
      41              :           category: category,
      42              :         ),
      43              :         uuid,
      44              :       );
      45            1 :       added++;
      46              :     }
      47              :     return (added: added, skipped: skipped, pending: pending);
      48              :   }
      49              : }
        

Generated by: LCOV version 2.0-1