LCOV - code coverage report
Current view: top level - lib/_classes/integration/monzo - monzo_importer.dart Coverage Total Hit
Test: lcov.info Lines: 100.0 % 18 18
Test Date: 2026-12-05 10:50:38 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/monzo/monzo_client.dart';
       6              : import 'package:app_finance/_classes/math/budget_prediction.dart';
       7              : import 'package:app_finance/_classes/structure/interface_app_data.dart';
       8              : import 'package:uuid/uuid.dart';
       9              : 
      10              : class MonzoImporter {
      11              :   final bool Function(String uuid) exists;
      12              :   final void Function(InterfaceAppData item, String uuid) add;
      13              : 
      14            1 :   const MonzoImporter({required this.exists, required this.add});
      15              : 
      16            1 :   static String uuidOf(String accountId, String transactionId) =>
      17            3 :       const Uuid().v5(Namespace.url.value, 'monzo:$accountId:$transactionId');
      18              : 
      19            1 :   IntegrationImportResult run({
      20              :     required String accountId,
      21              :     required List<MonzoTransaction> transactions,
      22              :     required String account,
      23              :     required String category,
      24              :     BudgetPrediction? prediction,
      25              :   }) {
      26              :     var added = 0;
      27              :     var skipped = 0;
      28              :     var pending = 0;
      29            2 :     for (final transaction in transactions) {
      30              :       // Declined transactions moved no money
      31            1 :       if (transaction.declined) {
      32              :         continue;
      33              :       }
      34            1 :       if (transaction.pending) {
      35            1 :         pending++;
      36              :         continue;
      37              :       }
      38            2 :       final uuid = uuidOf(accountId, transaction.id);
      39            2 :       if (exists(uuid)) {
      40            1 :         skipped++;
      41              :         continue;
      42              :       }
      43            2 :       add(
      44            1 :         IntegrationRecord.toAppData(
      45            1 :           amount: transaction.amount,
      46            1 :           currency: transaction.currency,
      47            1 :           date: transaction.created,
      48            1 :           title: transaction.description,
      49              :           account: account,
      50              :           category: category,
      51              :           prediction: prediction,
      52              :         ),
      53              :         uuid,
      54              :       );
      55            1 :       added++;
      56              :     }
      57              :     return (added: added, skipped: skipped, pending: pending);
      58              :   }
      59              : }
        

Generated by: LCOV version 2.0-1