From d6dcb3bdc2a458a3933731054e33320588acab7c Mon Sep 17 00:00:00 2001 From: Gleb Kulik Date: Fri, 6 Dec 2024 15:09:41 +0100 Subject: [PATCH 1/5] feat(GiniBankSDKExample): SkontoTransferSummaryIntegrationTest. Update BaseIntegrationTest. Refactor transfer summary integration test PP-615 --- .../project.pbxproj | 10 ++ .../Base/BaseIntegrationTest.swift | 31 +--- .../BaseIntegrationTest+TransferSummary.swift | 10 +- ...SkontoTransferSummaryIntegrationTest.swift | 151 +++++++++++++++++ .../TransferSummaryIntegrationTest.swift | 34 +++- ...example_skonto_after_transfer_summary.json | 159 ++++++++++++++++++ 6 files changed, 360 insertions(+), 35 deletions(-) create mode 100644 BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift create mode 100644 BankSDK/GiniBankSDKExample/Tests/Resources/Skonto/result_Gini_invoice_example_skonto_after_transfer_summary.json diff --git a/BankSDK/GiniBankSDKExample/GiniBankSDKExample.xcodeproj/project.pbxproj b/BankSDK/GiniBankSDKExample/GiniBankSDKExample.xcodeproj/project.pbxproj index ce1fb01c4..5709139e2 100644 --- a/BankSDK/GiniBankSDKExample/GiniBankSDKExample.xcodeproj/project.pbxproj +++ b/BankSDK/GiniBankSDKExample/GiniBankSDKExample.xcodeproj/project.pbxproj @@ -97,8 +97,11 @@ 847B68CA2C4009FA00544050 /* CustomSkontoBottomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847B68C92C4009FA00544050 /* CustomSkontoBottomNavigationBar.swift */; }; 847B68CC2C400A0600544050 /* CustomSkontoBottomNavigationBarAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847B68CB2C400A0600544050 /* CustomSkontoBottomNavigationBarAdapter.swift */; }; 84C53D5E2C87477D00A908BB /* AttachmentsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C53D5D2C87477D00A908BB /* AttachmentsTableViewCell.swift */; }; + 84C5D65C2D0240E7005711C5 /* result_Gini_invoice_example_skonto_after_transfer_summary.json in Resources */ = {isa = PBXBuildFile; fileRef = 84C5D65B2D0240E7005711C5 /* result_Gini_invoice_example_skonto_after_transfer_summary.json */; }; + 84C5D65D2D0240E7005711C5 /* result_Gini_invoice_example_skonto_after_transfer_summary.json in Resources */ = {isa = PBXBuildFile; fileRef = 84C5D65B2D0240E7005711C5 /* result_Gini_invoice_example_skonto_after_transfer_summary.json */; }; 84CD074D2C7DBB9A004DF1DE /* CustomDigitalInvoiceSkontoBottomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CD074C2C7DBB9A004DF1DE /* CustomDigitalInvoiceSkontoBottomNavigationBar.swift */; }; 84CD074F2C7DBBAD004DF1DE /* CustomDigitalInvoiceSkontoBottomNavigationBarAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CD074E2C7DBBAD004DF1DE /* CustomDigitalInvoiceSkontoBottomNavigationBarAdapter.swift */; }; + 84DB5EA22D03172E005EDC4C /* SkontoTransferSummaryIntegrationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DB5EA12D03172E005EDC4C /* SkontoTransferSummaryIntegrationTest.swift */; }; 84F2FD142CD0FABC00DAE5B4 /* SettingsHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F2FD132CD0FABC00DAE5B4 /* SettingsHeaderView.swift */; }; 84F2FD172CD0FAC600DAE5B4 /* SettingsSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F2FD152CD0FAC600DAE5B4 /* SettingsSection.swift */; }; 84F2FD182CD0FAC600DAE5B4 /* SettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F2FD162CD0FAC600DAE5B4 /* SettingsViewModel.swift */; }; @@ -273,8 +276,10 @@ 847B68C92C4009FA00544050 /* CustomSkontoBottomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSkontoBottomNavigationBar.swift; sourceTree = ""; }; 847B68CB2C400A0600544050 /* CustomSkontoBottomNavigationBarAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSkontoBottomNavigationBarAdapter.swift; sourceTree = ""; }; 84C53D5D2C87477D00A908BB /* AttachmentsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentsTableViewCell.swift; sourceTree = ""; }; + 84C5D65B2D0240E7005711C5 /* result_Gini_invoice_example_skonto_after_transfer_summary.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = result_Gini_invoice_example_skonto_after_transfer_summary.json; sourceTree = ""; }; 84CD074C2C7DBB9A004DF1DE /* CustomDigitalInvoiceSkontoBottomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomDigitalInvoiceSkontoBottomNavigationBar.swift; sourceTree = ""; }; 84CD074E2C7DBBAD004DF1DE /* CustomDigitalInvoiceSkontoBottomNavigationBarAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomDigitalInvoiceSkontoBottomNavigationBarAdapter.swift; sourceTree = ""; }; + 84DB5EA12D03172E005EDC4C /* SkontoTransferSummaryIntegrationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkontoTransferSummaryIntegrationTest.swift; sourceTree = ""; }; 84F2FD132CD0FABC00DAE5B4 /* SettingsHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsHeaderView.swift; sourceTree = ""; }; 84F2FD152CD0FAC600DAE5B4 /* SettingsSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSection.swift; sourceTree = ""; }; 84F2FD162CD0FAC600DAE5B4 /* SettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewModel.swift; sourceTree = ""; }; @@ -435,6 +440,7 @@ children = ( 28D77C3E2CBE99FC00F815DB /* Gini_invoice_example_skonto.pdf */, 28D77C3F2CBE99FC00F815DB /* result_Gini_invoice_example_skonto.json */, + 84C5D65B2D0240E7005711C5 /* result_Gini_invoice_example_skonto_after_transfer_summary.json */, ); path = Skonto; sourceTree = ""; @@ -500,6 +506,7 @@ children = ( 28D77C592CBEA8B100F815DB /* BaseIntegrationTest+TransferSummary.swift */, F45D7F002800566900C73C63 /* TransferSummaryIntegrationTest.swift */, + 84DB5EA12D03172E005EDC4C /* SkontoTransferSummaryIntegrationTest.swift */, ); path = TransferSummary; sourceTree = ""; @@ -999,6 +1006,7 @@ 28D77C542CBE99FC00F815DB /* result_Gini_invoice_example_line_items_with_discount.json in Resources */, 28B5874D2A374730008CB210 /* SegmentedOptionTableViewCell.xib in Resources */, 289D3DB42A4EC857002A6681 /* InfoTableViewCell.xib in Resources */, + 84C5D65C2D0240E7005711C5 /* result_Gini_invoice_example_skonto_after_transfer_summary.json in Resources */, 8303F4EF28F9AD7700285599 /* magicAnimation.json in Resources */, 83D02CD7290AC43E00DA97F7 /* CustomOnboardingBottomNavigationBar.xib in Resources */, F45D7F192800583800C73C63 /* Gini_invoice_example.pdf in Resources */, @@ -1035,6 +1043,7 @@ F45D7F132800566900C73C63 /* result_Gini_invoice_example_after_feedback.json in Resources */, F45D7F102800566900C73C63 /* result_Gini_invoice_example.json in Resources */, F45D7F112800566900C73C63 /* testPDF.pdf in Resources */, + 84C5D65D2D0240E7005711C5 /* result_Gini_invoice_example_skonto_after_transfer_summary.json in Resources */, 28D77C4F2CBE99FC00F815DB /* result_Gini_invoice_example_payment_reference_after_feedback.json in Resources */, 28D77C512CBE99FC00F815DB /* result_Gini_invoice_example_payment_reference.json in Resources */, 287068462CB9519000D5F2C9 /* result_Gini_invoice_example_RA_Skonto.json in Resources */, @@ -1168,6 +1177,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 84DB5EA22D03172E005EDC4C /* SkontoTransferSummaryIntegrationTest.swift in Sources */, 28B203FF2BB2E78B00C78740 /* FileLoader.swift in Sources */, F45D7F0E2800566900C73C63 /* ScreenAPICoordinator+UI_Only.swift in Sources */, 28D77C582CBEA85100F815DB /* BaseIntegrationTest+Skonto.swift in Sources */, diff --git a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/Base/BaseIntegrationTest.swift b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/Base/BaseIntegrationTest.swift index 98cf32f3e..68386b677 100644 --- a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/Base/BaseIntegrationTest.swift +++ b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/Base/BaseIntegrationTest.swift @@ -27,8 +27,7 @@ class BaseIntegrationTest: XCTestCase { */ func uploadAndAnalyzeDocument(fileName: String, delegate: GiniCaptureResultsDelegate, - documentType: String = "pdf", - sendTransferSummaryIfNeeded: Bool = false) { + documentType: String = "pdf") { guard let testDocumentData = FileLoader.loadFile(withName: fileName, ofType: documentType) else { XCTFail("Error loading file: `\(fileName).\(documentType)`") @@ -49,8 +48,7 @@ class BaseIntegrationTest: XCTestCase { switch result { case .success(_): self.handleUploadSuccess(captureDocument: captureDocument, - delegate: delegate, - sendTransferSummaryIfNeeded: sendTransferSummaryIfNeeded) + delegate: delegate) case let .failure(error): XCTFail(String(describing: error)) } @@ -66,14 +64,12 @@ class BaseIntegrationTest: XCTestCase { - sendTransferSummaryIfNeeded: A Boolean flag indicating whether to send a transfer summary after analysis. */ func handleUploadSuccess(captureDocument: GiniCaptureDocument, - delegate: GiniCaptureResultsDelegate, - sendTransferSummaryIfNeeded: Bool) { + delegate: GiniCaptureResultsDelegate) { giniHelper.giniCaptureSDKDocumentService?.startAnalysis { result in switch result { case let .success(extractionResult): self.handleAnalysisSuccess(extractionResult: extractionResult, - delegate: delegate, - sendTransferSummaryIfNeeded: sendTransferSummaryIfNeeded) + delegate: delegate) case let .failure(error): XCTFail(String(describing: error)) } @@ -89,8 +85,7 @@ class BaseIntegrationTest: XCTestCase { - sendTransferSummaryIfNeeded: A Boolean flag indicating whether to send a transfer summary after analysis. */ func handleAnalysisSuccess(extractionResult: ExtractionResult, - delegate: GiniCaptureResultsDelegate, - sendTransferSummaryIfNeeded: Bool) { + delegate: GiniCaptureResultsDelegate) { let extractions: [String: Extraction] = Dictionary(uniqueKeysWithValues: extractionResult.extractions.compactMap { guard let name = $0.name else { return nil } return (name, $0) @@ -98,25 +93,15 @@ class BaseIntegrationTest: XCTestCase { let analysisResult = AnalysisResult(extractions: extractions, lineItems: extractionResult.lineItems, + skontoDiscounts: extractionResult.skontoDiscounts, images: [], document: self.giniHelper.giniCaptureSDKDocumentService?.document, candidates: [:]) self.analysisExtractionResult = extractionResult - delegate.giniCaptureAnalysisDidFinishWith(result: analysisResult) GiniBankConfiguration.shared.lineItems = extractionResult.lineItems - - if sendTransferSummaryIfNeeded { - // Send transfer summary for the extractions the user confirmed - GiniBankConfiguration.shared.sendTransferSummary( - paymentRecipient: extractions["paymentRecipient"]?.value ?? "", - paymentReference: extractions["paymentReference"]?.value ?? "", - paymentPurpose: extractions["paymentPurpose"]?.value ?? "", - iban: extractions["iban"]?.value ?? "", - bic: extractions["bic"]?.value ?? "", - amountToPay: ExtractionAmount(value: 950.00, currency: .EUR) - ) - } + GiniBankConfiguration.shared.skontoDiscounts = extractionResult.skontoDiscounts + delegate.giniCaptureAnalysisDidFinishWith(result: analysisResult) } /** diff --git a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/BaseIntegrationTest+TransferSummary.swift b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/BaseIntegrationTest+TransferSummary.swift index e7a23d5f7..b28301a1f 100644 --- a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/BaseIntegrationTest+TransferSummary.swift +++ b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/BaseIntegrationTest+TransferSummary.swift @@ -13,7 +13,7 @@ import XCTest extension BaseIntegrationTest { // Method to handle updating and verifying feedback - func updateAndVerifyTransferSummary(result: AnalysisResult, expect: XCTestExpectation) { + func updateAndVerifyTransferSummary(result: AnalysisResult, mockedInvoiceUpdatedResultName: String, expect: XCTestExpectation) { // Assuming the user updated the amountToPay to "950.00:EUR" result.extractions["amountToPay"]?.value = "950.00:EUR" @@ -25,6 +25,7 @@ extension BaseIntegrationTest { switch updatedResult { case let .success(extractionResult): self.handleSuccessfulTransferSummaryUpdate(extractionResult: extractionResult, + mockedInvoiceUpdatedResultName: mockedInvoiceUpdatedResultName, expect: expect, result: result) case let .failure(error): @@ -44,13 +45,12 @@ extension BaseIntegrationTest { - result: The initial analysis result. */ private func handleSuccessfulTransferSummaryUpdate(extractionResult: ExtractionResult, + mockedInvoiceUpdatedResultName: String, expect: XCTestExpectation, result: AnalysisResult) { let extractionsAfterFeedback = extractionResult.extractions - - let mockedInvoice = "result_Gini_invoice_example_payment_reference_after_feedback" // Load the expected fixture after feedback - guard let fixtureExtractionsAfterFeedbackContainer = self.loadFixtureExtractionsContainer(from: mockedInvoice) else { + guard let fixtureExtractionsAfterFeedbackContainer = self.loadFixtureExtractionsContainer(from: mockedInvoiceUpdatedResultName) else { return } @@ -91,7 +91,7 @@ extension BaseIntegrationTest { * This method reproduces getting updated extractions for the already known document by the Bank SDK. * It is assumed that transfer summary was sent, and we retrieve the updated extractions for verification. */ - private func getUpdatedExtractionsFromGiniBankSDK(for document: Document, completion: @escaping AnalysisCompletion) { + func getUpdatedExtractionsFromGiniBankSDK(for document: Document, completion: @escaping AnalysisCompletion) { self.giniHelper.giniBankAPIDocumentService.extractions(for: document, cancellationToken: CancellationToken()) { result in switch result { diff --git a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift new file mode 100644 index 000000000..e2bc0eafe --- /dev/null +++ b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift @@ -0,0 +1,151 @@ +// +// SkontoTransferSummaryIntegrationTest.swift +// +// Copyright © 2024 Gini GmbH. All rights reserved. +// + + +import XCTest +@testable import GiniBankAPILibrary +@testable import GiniCaptureSDK +@testable import GiniBankSDK + +class SkontoTransferSummaryIntegrationTest: BaseIntegrationTest { + + func testSendSkontoTransferSummary() { + let mockedInvoiceName = "Gini_invoice_example_skonto" + let expect = expectation(description: "Transfer summary was correctly sent and extractions were updated") + let skontoTransferSummaryHandler = SkontoTransferSummaryHandler(testCase: self, + mockedInvoiceResultName: "result_Gini_invoice_example_skonto", + mockedInvoiceResultAfterFeedbackName: "result_Gini_invoice_example_skonto_after_transfer_summary", + expect: expect) + uploadAndAnalyzeDocument(fileName: mockedInvoiceName, + delegate: skontoTransferSummaryHandler) + wait(for: [expect], timeout: 60) + } + + class SkontoTransferSummaryHandler: GiniCaptureResultsDelegate { + let testCase: SkontoTransferSummaryIntegrationTest + let mockedInvoiceResultName: String + let mockedInvoiceResultAfterFeedbackName: String + let expect: XCTestExpectation + + init(testCase: SkontoTransferSummaryIntegrationTest, + mockedInvoiceResultName: String, + mockedInvoiceResultAfterFeedbackName: String, + expect: XCTestExpectation) { + self.testCase = testCase + self.mockedInvoiceResultName = mockedInvoiceResultName + self.mockedInvoiceResultAfterFeedbackName = mockedInvoiceResultAfterFeedbackName + self.expect = expect + } + + func giniCaptureAnalysisDidFinishWith(result: AnalysisResult) { + let mockedInvoice = mockedInvoiceResultName + // Use the helper method to load the fixture extractions container + guard let fixtureExtractionsContainer = testCase.loadFixtureExtractionsContainer(from: mockedInvoice) else { + return + } + + // Verify the extractions + testCase.verifyExtractions(result: result, fixtureContainer: fixtureExtractionsContainer) + + guard let skontoDiscountExtraction = result.skontoDiscounts?.first else { + return + } + let updatedAmountToPayString = "1000.00:EUR" + let updatedPercentage = "50.0" + result.extractions["amountToPay"]?.value = updatedAmountToPayString + let modifiedSkontoExtractions = skontoDiscountExtraction.map { extraction -> Extraction in + let modifiedExtraction = extraction + switch modifiedExtraction.name { + case "skontoAmountToPay", "skontoAmountToPayCalculated": + modifiedExtraction.value = updatedAmountToPayString + case "skontoPercentageDiscounted", "skontoPercentageDiscountedCalculated": + modifiedExtraction.value = updatedPercentage + default: + break + } + return modifiedExtraction + } + GiniBankConfiguration.shared.skontoDiscounts = [modifiedSkontoExtractions] + + let amountExtraction = self.createAmountExtraction(value: updatedAmountToPayString) + GiniBankConfiguration.shared.sendTransferSummaryWithSkonto(amountExtraction: amountExtraction, + amountToPayString: updatedAmountToPayString) + + // Call the updateAndVerifyTransferSummary method to handle the transfer summary update + self.updateAndVerifyTransferSummary(result: result, mockedInvoiceUpdatedResultName: mockedInvoiceResultAfterFeedbackName, expect: expect) + } + + func giniCaptureDidCancelAnalysis() { + // nothing to test here + } + + func giniCaptureDidEnterManually() { + // nothing to test heretestCase + } + + private func createAmountExtraction(value: String) -> Extraction { + return Extraction(box: nil, + candidates: nil, + entity: "amount", + value: value, + name: "amountToPay") + } + + func updateAndVerifyTransferSummary(result: AnalysisResult, + mockedInvoiceUpdatedResultName: String, + expect: XCTestExpectation) { + DispatchQueue.main.asyncAfter(deadline: .now() + 10) { [weak self] in + self?.testCase.getUpdatedExtractionsFromGiniBankSDK(for: result.document!) { updatedResult in + switch updatedResult { + case let .success(extractionResult): + self?.handleSuccessfulTransferSummary(extractionResult: extractionResult, + mockedInvoiceUpdatedResultName: mockedInvoiceUpdatedResultName, + expect: expect, + result: result) + case let .failure(error): + XCTFail("Error updating transfer summary: \(error)") + } + } + } + } + + private func handleSuccessfulTransferSummary(extractionResult: ExtractionResult, + mockedInvoiceUpdatedResultName: String, + expect: XCTestExpectation, + result: AnalysisResult) { + let extractionsAfterFeedback = extractionResult.extractions + // Load the expected fixture after feedback + guard let fixtureExtractionsAfterFeedbackContainer = testCase.loadFixtureExtractionsContainer(from: mockedInvoiceUpdatedResultName) else { + return + } + + // Validate the updated extractions against the fixture + XCTAssertEqual(fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "iban" })?.value, + extractionsAfterFeedback.first(where: { $0.name == "iban" })?.value) + + let paymentRecipientExtraction = extractionsAfterFeedback.first(where: { $0.name == "paymentRecipient" }) + testCase.verifyPaymentRecipient(paymentRecipientExtraction) + + XCTAssertEqual(fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "bic" })?.value, + extractionsAfterFeedback.first(where: { $0.name == "bic" })?.value) + XCTAssertEqual(fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "amountToPay" })?.value, + extractionsAfterFeedback.first(where: { $0.name == "amountToPay" })?.value) + + // Validate line items if applicable + let fixtureSkontoDiscounts = fixtureExtractionsAfterFeedbackContainer.compoundExtractions?.skontoDiscounts?.first + if let fixtureSkontoDiscountsAfterFeedback = extractionResult.skontoDiscounts?.first { + XCTAssertEqual(fixtureSkontoDiscounts?.first(where: { $0.name == "skontoAmountToPayCalculated" })?.value, + fixtureSkontoDiscountsAfterFeedback.first(where: { $0.name == "skontoAmountToPayCalculated" })?.value) + } + + // Free resources and cleanup + GiniBankConfiguration.shared.cleanup() + XCTAssertNil(GiniBankConfiguration.shared.documentService) + + expect.fulfill() + } + } +} diff --git a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/TransferSummaryIntegrationTest.swift b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/TransferSummaryIntegrationTest.swift index 95c4f4422..8b4265c8e 100644 --- a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/TransferSummaryIntegrationTest.swift +++ b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/TransferSummaryIntegrationTest.swift @@ -15,24 +15,42 @@ class TransferSummaryIntegrationTest: BaseIntegrationTest { func testSendTransferSummaryFeedback() { let mockedInvoiceName = "Gini_invoice_example_payment_reference" let expect = expectation(description: "Transfer summary was correctly sent and extractions were updated") + let delegate = CaptureResultsDelegateForTransferSummaryTest(testCase: self, + mockedInvoiceResultName: "result_Gini_invoice_example_payment_reference", + mockedInvoiceResultAfterFeedbackName: "result_Gini_invoice_example_payment_reference_after_feedback", + expect: expect) uploadAndAnalyzeDocument(fileName: mockedInvoiceName, - delegate: CaptureResultsDelegateForTransferSummaryTest(testCase: self, - expect: expect), - sendTransferSummaryIfNeeded: true) + delegate: delegate) wait(for: [expect], timeout: 60) } - + class CaptureResultsDelegateForTransferSummaryTest: GiniCaptureResultsDelegate { let testCase: TransferSummaryIntegrationTest + let mockedInvoiceResultName: String + let mockedInvoiceResultAfterFeedbackName: String let expect: XCTestExpectation - init(testCase: TransferSummaryIntegrationTest, expect: XCTestExpectation) { + init(testCase: TransferSummaryIntegrationTest, + mockedInvoiceResultName: String, + mockedInvoiceResultAfterFeedbackName: String, + expect: XCTestExpectation) { self.testCase = testCase + self.mockedInvoiceResultName = mockedInvoiceResultName + self.mockedInvoiceResultAfterFeedbackName = mockedInvoiceResultAfterFeedbackName self.expect = expect } func giniCaptureAnalysisDidFinishWith(result: AnalysisResult) { - let mockedInvoice = "result_Gini_invoice_example_payment_reference" + GiniBankConfiguration.shared.sendTransferSummary( + paymentRecipient: result.extractions["paymentRecipient"]?.value ?? "", + paymentReference: result.extractions["paymentReference"]?.value ?? "", + paymentPurpose: result.extractions["paymentPurpose"]?.value ?? "", + iban: result.extractions["iban"]?.value ?? "", + bic: result.extractions["bic"]?.value ?? "", + amountToPay: ExtractionAmount(value: 950.00, currency: .EUR) + ) + + let mockedInvoice = mockedInvoiceResultName // Use the helper method to load the fixture extractions container guard let fixtureExtractionsContainer = testCase.loadFixtureExtractionsContainer(from: mockedInvoice) else { return @@ -42,7 +60,9 @@ class TransferSummaryIntegrationTest: BaseIntegrationTest { testCase.verifyExtractions(result: result, fixtureContainer: fixtureExtractionsContainer) // Call the updateAndVerifyTransferSummary method to handle the transfer summary update - testCase.updateAndVerifyTransferSummary(result: result, expect: expect) + testCase.updateAndVerifyTransferSummary(result: result, + mockedInvoiceUpdatedResultName: mockedInvoiceResultAfterFeedbackName, + expect: expect) } func giniCaptureDidCancelAnalysis() { diff --git a/BankSDK/GiniBankSDKExample/Tests/Resources/Skonto/result_Gini_invoice_example_skonto_after_transfer_summary.json b/BankSDK/GiniBankSDKExample/Tests/Resources/Skonto/result_Gini_invoice_example_skonto_after_transfer_summary.json new file mode 100644 index 000000000..cf01d36fa --- /dev/null +++ b/BankSDK/GiniBankSDKExample/Tests/Resources/Skonto/result_Gini_invoice_example_skonto_after_transfer_summary.json @@ -0,0 +1,159 @@ +{ + "extractions": { + "paymentRecipient": { + "entity": "companyname", + "value": "Max Mustermann", + "box": { + "top": 1033.4, + "left": 96.4, + "width": 164.99999999999997, + "height": 11.0, + "page": 1 + }, + "candidates": "paymentRecipients" + }, + "paymentPurpose": { + "entity": "reference", + "value": "ReNr R2022-8" + }, + "bic": { + "entity": "bic", + "value": "COBADEFFXXX", + "candidates": "bics" + }, + "iban": { + "entity": "iban", + "value": "DE89370400440532013000", + "box": { + "top": 1050.4, + "left": 137.4, + "width": 190.99999999999997, + "height": 11.0, + "page": 1 + }, + "candidates": "ibans" + }, + "docType": { + "entity": "doctype", + "value": "Invoice" + }, + "amountToPay": { + "entity": "amount", + "value": "1000.00:EUR", + "box": { + "top": 860.55, + "left": 812.55, + "width": 54.89999999999998, + "height": 11.0, + "page": 1 + }, + "candidates": "amounts" + } + }, + "compoundExtractions": { + "skontoDiscounts": [ + { + "skontoRemainingDays": { + "entity": "numeric", + "value": "-63" + }, + "skontoPaymentMethod": { + "entity": "text", + "value": "Unspecified" + }, + "skontoAmountToPayCalculated": { + "entity": "amount", + "value": "1000.00:EUR" + }, + "skontoDuePeriod": { + "entity": "timeperiod", + "value": "7:day", + "box": { + "top": 938.0, + "left": 718.0, + "width": 48.0, + "height": 14.0, + "page": 1 + } + }, + "skontoAmountDiscountedCalculated": { + "entity": "amount", + "value": "119.00:EUR" + }, + "skontoPercentageDiscounted": { + "entity": "numeric", + "value": "50.0", + "box": { + "top": 938.0, + "left": 772.0, + "width": 68.0, + "height": 14.0, + "page": 1 + } + }, + "skontoDueDateCalculated": { + "entity": "date", + "value": "2024-08-08" + }, + "skontoPercentageDiscountedCalculated": { + "entity": "numeric", + "value": "5.0", + "box": { + "top": 938.0, + "left": 772.0, + "width": 68.0, + "height": 14.0, + "page": 1 + } + } + } + ] + }, + "candidates": { + "ibans": [ + { + "entity": "iban", + "value": "DE89370400440532013000", + "box": { + "top": 1050.4, + "left": 137.4, + "width": 190.99999999999997, + "height": 11.0, + "page": 1 + } + } + ], + "paymentRecipients": [ + { + "entity": "companyname", + "value": "Max Mustermann", + "box": { + "top": 1033.4, + "left": 96.4, + "width": 164.99999999999997, + "height": 11.0, + "page": 1 + } + } + ], + "amounts": [ + { + "entity": "amount", + "value": "2380.00:EUR", + "box": { + "top": 860.55, + "left": 812.55, + "width": 54.89999999999998, + "height": 11.0, + "page": 1 + } + } + ], + "bics": [ + { + "entity": "bic", + "value": "COBADEFFXXX" + } + ] + } +} From 2b86360e5b8cd928119535cc2373d4ce2ac2ba8b Mon Sep 17 00:00:00 2001 From: Gleb Kulik Date: Fri, 6 Dec 2024 19:18:01 +0100 Subject: [PATCH 2/5] feat(GiniBankSDKExample): SkontoTransferSummaryIntegrationTest optimisation. Handle Skonto not applied case PP-615 --- ...SkontoTransferSummaryIntegrationTest.swift | 307 +++++++++++------- 1 file changed, 198 insertions(+), 109 deletions(-) diff --git a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift index e2bc0eafe..5904bebaf 100644 --- a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift +++ b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift @@ -15,137 +15,226 @@ class SkontoTransferSummaryIntegrationTest: BaseIntegrationTest { func testSendSkontoTransferSummary() { let mockedInvoiceName = "Gini_invoice_example_skonto" let expect = expectation(description: "Transfer summary was correctly sent and extractions were updated") - let skontoTransferSummaryHandler = SkontoTransferSummaryHandler(testCase: self, - mockedInvoiceResultName: "result_Gini_invoice_example_skonto", - mockedInvoiceResultAfterFeedbackName: "result_Gini_invoice_example_skonto_after_transfer_summary", - expect: expect) - uploadAndAnalyzeDocument(fileName: mockedInvoiceName, - delegate: skontoTransferSummaryHandler) + + let handler = SkontoTransferSummaryHandler( + testCase: self, + mockedInvoiceResultName: "result_Gini_invoice_example_skonto", + mockedInvoiceResultAfterFeedbackName: "result_Gini_invoice_example_skonto_after_transfer_summary", + expect: expect + ) + + uploadAndAnalyzeDocument(fileName: mockedInvoiceName, delegate: handler) wait(for: [expect], timeout: 60) } +} + +class SkontoNotAppliedTransferSummaryIntegrationTest: BaseIntegrationTest { - class SkontoTransferSummaryHandler: GiniCaptureResultsDelegate { - let testCase: SkontoTransferSummaryIntegrationTest - let mockedInvoiceResultName: String - let mockedInvoiceResultAfterFeedbackName: String - let expect: XCTestExpectation - - init(testCase: SkontoTransferSummaryIntegrationTest, - mockedInvoiceResultName: String, - mockedInvoiceResultAfterFeedbackName: String, - expect: XCTestExpectation) { - self.testCase = testCase - self.mockedInvoiceResultName = mockedInvoiceResultName - self.mockedInvoiceResultAfterFeedbackName = mockedInvoiceResultAfterFeedbackName - self.expect = expect + func testSendSkontoTransferSummary() { + let mockedInvoiceName = "Gini_invoice_example_skonto" + let expect = expectation(description: "Transfer summary was correctly sent and extractions were updated") + + let handler = SkontoNotAppliedTransferSummaryHandler( + testCase: self, + mockedInvoiceResultName: "result_Gini_invoice_example_skonto", + mockedInvoiceResultAfterFeedbackName: "result_Gini_invoice_example_skonto", + expect: expect + ) + + uploadAndAnalyzeDocument(fileName: mockedInvoiceName, delegate: handler) + wait(for: [expect], timeout: 60) + } +} + +// MARK: - Base Handler + +class BaseSkontoTransferSummaryHandler: GiniCaptureResultsDelegate { + let testCase: TestCase + let mockedInvoiceResultName: String + let mockedInvoiceResultAfterFeedbackName: String + let expect: XCTestExpectation + + init(testCase: TestCase, + mockedInvoiceResultName: String, + mockedInvoiceResultAfterFeedbackName: String, + expect: XCTestExpectation) { + self.testCase = testCase + self.mockedInvoiceResultName = mockedInvoiceResultName + self.mockedInvoiceResultAfterFeedbackName = mockedInvoiceResultAfterFeedbackName + self.expect = expect + } + + func giniCaptureAnalysisDidFinishWith(result: AnalysisResult) { + guard let fixtureExtractionsContainer = testCase.loadFixtureExtractionsContainer(from: mockedInvoiceResultName) else { + return } - func giniCaptureAnalysisDidFinishWith(result: AnalysisResult) { - let mockedInvoice = mockedInvoiceResultName - // Use the helper method to load the fixture extractions container - guard let fixtureExtractionsContainer = testCase.loadFixtureExtractionsContainer(from: mockedInvoice) else { - return - } + testCase.verifyExtractions(result: result, fixtureContainer: fixtureExtractionsContainer) + applySkontoAdjustmentsIfNeeded(result: result) + sendTransferSummary(result: result) + updateAndVerifyTransferSummary(result: result, mockedInvoiceUpdatedResultName: mockedInvoiceResultAfterFeedbackName, expect: expect) + } - // Verify the extractions - testCase.verifyExtractions(result: result, fixtureContainer: fixtureExtractionsContainer) - - guard let skontoDiscountExtraction = result.skontoDiscounts?.first else { - return - } - let updatedAmountToPayString = "1000.00:EUR" - let updatedPercentage = "50.0" - result.extractions["amountToPay"]?.value = updatedAmountToPayString - let modifiedSkontoExtractions = skontoDiscountExtraction.map { extraction -> Extraction in - let modifiedExtraction = extraction - switch modifiedExtraction.name { - case "skontoAmountToPay", "skontoAmountToPayCalculated": - modifiedExtraction.value = updatedAmountToPayString - case "skontoPercentageDiscounted", "skontoPercentageDiscountedCalculated": - modifiedExtraction.value = updatedPercentage - default: - break + func giniCaptureDidCancelAnalysis() { + // not tested + } + + func giniCaptureDidEnterManually() { + // not tested + } + + // MARK: - Methods to override or customize in subclasses if needed + + /// Override this method in subclasses to apply any skonto-related modifications. + func applySkontoAdjustmentsIfNeeded(result: AnalysisResult) { + // Default: no adjustments + } + + /// Override this method in subclasses if the transfer summary should be sent differently. + func sendTransferSummary(result: AnalysisResult) { + guard let amountToPayString = result.extractions["amountToPay"]?.value else { return } + let amountExtraction = createAmountExtraction(value: amountToPayString) + GiniBankConfiguration.shared.sendTransferSummaryWithSkonto( + amountExtraction: amountExtraction, + amountToPayString: amountToPayString + ) + } + + // MARK: - Common logic + + func updateAndVerifyTransferSummary(result: AnalysisResult, + mockedInvoiceUpdatedResultName: String, + expect: XCTestExpectation) { + DispatchQueue.main.asyncAfter(deadline: .now() + 10) { [weak self] in + guard let self = self else { return } + self.testCase.getUpdatedExtractionsFromGiniBankSDK(for: result.document!) { updatedResult in + switch updatedResult { + case let .success(extractionResult): + self.handleSuccessfulTransferSummary( + extractionResult: extractionResult, + mockedInvoiceUpdatedResultName: mockedInvoiceUpdatedResultName, + expect: expect, + result: result + ) + case let .failure(error): + XCTFail("Error updating transfer summary: \(error)") } - return modifiedExtraction } - GiniBankConfiguration.shared.skontoDiscounts = [modifiedSkontoExtractions] - - let amountExtraction = self.createAmountExtraction(value: updatedAmountToPayString) - GiniBankConfiguration.shared.sendTransferSummaryWithSkonto(amountExtraction: amountExtraction, - amountToPayString: updatedAmountToPayString) - - // Call the updateAndVerifyTransferSummary method to handle the transfer summary update - self.updateAndVerifyTransferSummary(result: result, mockedInvoiceUpdatedResultName: mockedInvoiceResultAfterFeedbackName, expect: expect) } + } - func giniCaptureDidCancelAnalysis() { - // nothing to test here + func handleSuccessfulTransferSummary(extractionResult: ExtractionResult, + mockedInvoiceUpdatedResultName: String, + expect: XCTestExpectation, + result: AnalysisResult) { + let extractionsAfterFeedback = extractionResult.extractions + guard let fixtureExtractionsAfterFeedbackContainer = testCase.loadFixtureExtractionsContainer(from: mockedInvoiceUpdatedResultName) else { + return } - func giniCaptureDidEnterManually() { - // nothing to test heretestCase - } + // Validate basic extractions + XCTAssertEqual( + fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "iban" })?.value, + extractionsAfterFeedback.first(where: { $0.name == "iban" })?.value + ) - private func createAmountExtraction(value: String) -> Extraction { - return Extraction(box: nil, - candidates: nil, - entity: "amount", - value: value, - name: "amountToPay") - } + let paymentRecipientExtraction = extractionsAfterFeedback.first(where: { $0.name == "paymentRecipient" }) + testCase.verifyPaymentRecipient(paymentRecipientExtraction) - func updateAndVerifyTransferSummary(result: AnalysisResult, - mockedInvoiceUpdatedResultName: String, - expect: XCTestExpectation) { - DispatchQueue.main.asyncAfter(deadline: .now() + 10) { [weak self] in - self?.testCase.getUpdatedExtractionsFromGiniBankSDK(for: result.document!) { updatedResult in - switch updatedResult { - case let .success(extractionResult): - self?.handleSuccessfulTransferSummary(extractionResult: extractionResult, - mockedInvoiceUpdatedResultName: mockedInvoiceUpdatedResultName, - expect: expect, - result: result) - case let .failure(error): - XCTFail("Error updating transfer summary: \(error)") - } - } - } + XCTAssertEqual( + fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "bic" })?.value, + extractionsAfterFeedback.first(where: { $0.name == "bic" })?.value + ) + + XCTAssertEqual( + fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "amountToPay" })?.value, + extractionsAfterFeedback.first(where: { $0.name == "amountToPay" })?.value + ) + + // Validate skonto discounts if applicable + validateSkontoDiscounts( + fixtureContainer: fixtureExtractionsAfterFeedbackContainer, + extractionResult: extractionResult + ) + + // Cleanup + GiniBankConfiguration.shared.cleanup() + XCTAssertNil(GiniBankConfiguration.shared.documentService) + + expect.fulfill() + } + + func validateSkontoDiscounts(fixtureContainer: ExtractionsContainer, + extractionResult: ExtractionResult) { + let fixtureSkontoDiscounts = fixtureContainer.compoundExtractions?.skontoDiscounts?.first + if let fixtureSkontoDiscountsAfterFeedback = extractionResult.skontoDiscounts?.first { + XCTAssertEqual( + fixtureSkontoDiscounts?.first(where: { $0.name == "skontoAmountToPayCalculated" })?.value, + fixtureSkontoDiscountsAfterFeedback.first(where: { $0.name == "skontoAmountToPayCalculated" })?.value + ) } + } - private func handleSuccessfulTransferSummary(extractionResult: ExtractionResult, - mockedInvoiceUpdatedResultName: String, - expect: XCTestExpectation, - result: AnalysisResult) { - let extractionsAfterFeedback = extractionResult.extractions - // Load the expected fixture after feedback - guard let fixtureExtractionsAfterFeedbackContainer = testCase.loadFixtureExtractionsContainer(from: mockedInvoiceUpdatedResultName) else { - return - } + func createAmountExtraction(value: String) -> Extraction { + Extraction(box: nil, + candidates: nil, + entity: "amount", + value: value, + name: "amountToPay") + } +} + +// MARK: - Specific Handlers - // Validate the updated extractions against the fixture - XCTAssertEqual(fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "iban" })?.value, - extractionsAfterFeedback.first(where: { $0.name == "iban" })?.value) +class SkontoTransferSummaryHandler: BaseSkontoTransferSummaryHandler { - let paymentRecipientExtraction = extractionsAfterFeedback.first(where: { $0.name == "paymentRecipient" }) - testCase.verifyPaymentRecipient(paymentRecipientExtraction) + override func applySkontoAdjustmentsIfNeeded(result: AnalysisResult) { + guard let skontoDiscountExtraction = result.skontoDiscounts?.first else { return } - XCTAssertEqual(fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "bic" })?.value, - extractionsAfterFeedback.first(where: { $0.name == "bic" })?.value) - XCTAssertEqual(fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "amountToPay" })?.value, - extractionsAfterFeedback.first(where: { $0.name == "amountToPay" })?.value) + let updatedAmountToPayString = "1000.00:EUR" + let updatedPercentage = "50.0" - // Validate line items if applicable - let fixtureSkontoDiscounts = fixtureExtractionsAfterFeedbackContainer.compoundExtractions?.skontoDiscounts?.first - if let fixtureSkontoDiscountsAfterFeedback = extractionResult.skontoDiscounts?.first { - XCTAssertEqual(fixtureSkontoDiscounts?.first(where: { $0.name == "skontoAmountToPayCalculated" })?.value, - fixtureSkontoDiscountsAfterFeedback.first(where: { $0.name == "skontoAmountToPayCalculated" })?.value) + // Modify result extractions + result.extractions["amountToPay"]?.value = updatedAmountToPayString + let modifiedSkontoExtractions = skontoDiscountExtraction.map { extraction -> Extraction in + let modifiedExtraction = extraction + switch modifiedExtraction.name { + case "skontoAmountToPay", "skontoAmountToPayCalculated": + modifiedExtraction.value = updatedAmountToPayString + case "skontoPercentageDiscounted", "skontoPercentageDiscountedCalculated": + modifiedExtraction.value = updatedPercentage + default: + break } + return modifiedExtraction + } + + GiniBankConfiguration.shared.skontoDiscounts = [modifiedSkontoExtractions] + } - // Free resources and cleanup - GiniBankConfiguration.shared.cleanup() - XCTAssertNil(GiniBankConfiguration.shared.documentService) + override func sendTransferSummary(result: AnalysisResult) { + guard let updatedAmountToPayString = result.extractions["amountToPay"]?.value else { return } + let amountExtraction = createAmountExtraction(value: updatedAmountToPayString) + GiniBankConfiguration.shared.sendTransferSummaryWithSkonto( + amountExtraction: amountExtraction, + amountToPayString: updatedAmountToPayString + ) + } +} - expect.fulfill() - } +class SkontoNotAppliedTransferSummaryHandler: BaseSkontoTransferSummaryHandler { + + override func applySkontoAdjustmentsIfNeeded(result: AnalysisResult) { + guard let skontoDiscountExtraction = result.skontoDiscounts?.first else { return } + GiniBankConfiguration.shared.skontoDiscounts = [skontoDiscountExtraction] + } + + override func sendTransferSummary(result: AnalysisResult) { + let amountToPayString = result.extractions["amountToPay"]?.value ?? "" + let amountExtraction = createAmountExtraction(value: amountToPayString) + GiniBankConfiguration.shared.sendTransferSummaryWithSkonto( + amountExtraction: amountExtraction, + amountToPayString: amountToPayString + ) } } From d31640b92d425a6156d7f73ca9e785563d0c2f4b Mon Sep 17 00:00:00 2001 From: Gleb Kulik Date: Mon, 9 Dec 2024 16:24:22 +0100 Subject: [PATCH 3/5] feat(GiniBankSDKExample): Update integration tests after merge. Formatting PP-615 --- ...SkontoTransferSummaryIntegrationTest.swift | 61 +++++++------------ 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift index 5904bebaf..6efd42e1c 100644 --- a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift +++ b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift @@ -20,8 +20,7 @@ class SkontoTransferSummaryIntegrationTest: BaseIntegrationTest { testCase: self, mockedInvoiceResultName: "result_Gini_invoice_example_skonto", mockedInvoiceResultAfterFeedbackName: "result_Gini_invoice_example_skonto_after_transfer_summary", - expect: expect - ) + expect: expect) uploadAndAnalyzeDocument(fileName: mockedInvoiceName, delegate: handler) wait(for: [expect], timeout: 60) @@ -38,8 +37,7 @@ class SkontoNotAppliedTransferSummaryIntegrationTest: BaseIntegrationTest { testCase: self, mockedInvoiceResultName: "result_Gini_invoice_example_skonto", mockedInvoiceResultAfterFeedbackName: "result_Gini_invoice_example_skonto", - expect: expect - ) + expect: expect) uploadAndAnalyzeDocument(fileName: mockedInvoiceName, delegate: handler) wait(for: [expect], timeout: 60) @@ -72,7 +70,9 @@ class BaseSkontoTransferSummaryHandler: GiniCaptu testCase.verifyExtractions(result: result, fixtureContainer: fixtureExtractionsContainer) applySkontoAdjustmentsIfNeeded(result: result) sendTransferSummary(result: result) - updateAndVerifyTransferSummary(result: result, mockedInvoiceUpdatedResultName: mockedInvoiceResultAfterFeedbackName, expect: expect) + updateAndVerifyTransferSummary(result: result, + mockedInvoiceUpdatedResultName: mockedInvoiceResultAfterFeedbackName, + expect: expect) } func giniCaptureDidCancelAnalysis() { @@ -94,10 +94,8 @@ class BaseSkontoTransferSummaryHandler: GiniCaptu func sendTransferSummary(result: AnalysisResult) { guard let amountToPayString = result.extractions["amountToPay"]?.value else { return } let amountExtraction = createAmountExtraction(value: amountToPayString) - GiniBankConfiguration.shared.sendTransferSummaryWithSkonto( - amountExtraction: amountExtraction, - amountToPayString: amountToPayString - ) + GiniBankConfiguration.shared.sendTransferSummaryWithSkonto(amountToPayExtraction: amountExtraction, + amountToPayString: amountToPayString) } // MARK: - Common logic @@ -114,8 +112,7 @@ class BaseSkontoTransferSummaryHandler: GiniCaptu extractionResult: extractionResult, mockedInvoiceUpdatedResultName: mockedInvoiceUpdatedResultName, expect: expect, - result: result - ) + result: result) case let .failure(error): XCTFail("Error updating transfer summary: \(error)") } @@ -133,29 +130,21 @@ class BaseSkontoTransferSummaryHandler: GiniCaptu } // Validate basic extractions - XCTAssertEqual( - fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "iban" })?.value, - extractionsAfterFeedback.first(where: { $0.name == "iban" })?.value - ) + XCTAssertEqual(fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "iban" })?.value, + extractionsAfterFeedback.first(where: { $0.name == "iban" })?.value) let paymentRecipientExtraction = extractionsAfterFeedback.first(where: { $0.name == "paymentRecipient" }) testCase.verifyPaymentRecipient(paymentRecipientExtraction) - XCTAssertEqual( - fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "bic" })?.value, - extractionsAfterFeedback.first(where: { $0.name == "bic" })?.value - ) + XCTAssertEqual(fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "bic" })?.value, + extractionsAfterFeedback.first(where: { $0.name == "bic" })?.value) - XCTAssertEqual( - fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "amountToPay" })?.value, - extractionsAfterFeedback.first(where: { $0.name == "amountToPay" })?.value - ) + XCTAssertEqual(fixtureExtractionsAfterFeedbackContainer.extractions.first(where: { $0.name == "amountToPay" })?.value, + extractionsAfterFeedback.first(where: { $0.name == "amountToPay" })?.value) // Validate skonto discounts if applicable - validateSkontoDiscounts( - fixtureContainer: fixtureExtractionsAfterFeedbackContainer, - extractionResult: extractionResult - ) + validateSkontoDiscounts(fixtureContainer: fixtureExtractionsAfterFeedbackContainer, + extractionResult: extractionResult) // Cleanup GiniBankConfiguration.shared.cleanup() @@ -168,10 +157,8 @@ class BaseSkontoTransferSummaryHandler: GiniCaptu extractionResult: ExtractionResult) { let fixtureSkontoDiscounts = fixtureContainer.compoundExtractions?.skontoDiscounts?.first if let fixtureSkontoDiscountsAfterFeedback = extractionResult.skontoDiscounts?.first { - XCTAssertEqual( - fixtureSkontoDiscounts?.first(where: { $0.name == "skontoAmountToPayCalculated" })?.value, - fixtureSkontoDiscountsAfterFeedback.first(where: { $0.name == "skontoAmountToPayCalculated" })?.value - ) + XCTAssertEqual(fixtureSkontoDiscounts?.first(where: { $0.name == "skontoAmountToPayCalculated" })?.value, + fixtureSkontoDiscountsAfterFeedback.first(where: { $0.name == "skontoAmountToPayCalculated" })?.value) } } @@ -215,10 +202,8 @@ class SkontoTransferSummaryHandler: BaseSkontoTransferSummaryHandler Date: Mon, 9 Dec 2024 16:29:37 +0100 Subject: [PATCH 4/5] feat(GiniBankSDKExample): rename applySkontoAdjustmentsIfNeeded -> applySkontoChangesIfNeeded PP-615 --- ...SkontoTransferSummaryIntegrationTest.swift | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift index 6efd42e1c..f9b84eb7c 100644 --- a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift +++ b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift @@ -68,7 +68,7 @@ class BaseSkontoTransferSummaryHandler: GiniCaptu } testCase.verifyExtractions(result: result, fixtureContainer: fixtureExtractionsContainer) - applySkontoAdjustmentsIfNeeded(result: result) + applySkontoChangesIfNeeded(result: result) sendTransferSummary(result: result) updateAndVerifyTransferSummary(result: result, mockedInvoiceUpdatedResultName: mockedInvoiceResultAfterFeedbackName, @@ -86,8 +86,8 @@ class BaseSkontoTransferSummaryHandler: GiniCaptu // MARK: - Methods to override or customize in subclasses if needed /// Override this method in subclasses to apply any skonto-related modifications. - func applySkontoAdjustmentsIfNeeded(result: AnalysisResult) { - // Default: no adjustments + func applySkontoChangesIfNeeded(result: AnalysisResult) { + // Default: no changes } /// Override this method in subclasses if the transfer summary should be sent differently. @@ -108,11 +108,10 @@ class BaseSkontoTransferSummaryHandler: GiniCaptu self.testCase.getUpdatedExtractionsFromGiniBankSDK(for: result.document!) { updatedResult in switch updatedResult { case let .success(extractionResult): - self.handleSuccessfulTransferSummary( - extractionResult: extractionResult, - mockedInvoiceUpdatedResultName: mockedInvoiceUpdatedResultName, - expect: expect, - result: result) + self.handleSuccessfulTransferSummary(extractionResult: extractionResult, + mockedInvoiceUpdatedResultName: mockedInvoiceUpdatedResultName, + expect: expect, + result: result) case let .failure(error): XCTFail("Error updating transfer summary: \(error)") } @@ -175,7 +174,7 @@ class BaseSkontoTransferSummaryHandler: GiniCaptu class SkontoTransferSummaryHandler: BaseSkontoTransferSummaryHandler { - override func applySkontoAdjustmentsIfNeeded(result: AnalysisResult) { + override func applySkontoChangesIfNeeded(result: AnalysisResult) { guard let skontoDiscountExtraction = result.skontoDiscounts?.first else { return } let updatedAmountToPayString = "1000.00:EUR" @@ -209,7 +208,7 @@ class SkontoTransferSummaryHandler: BaseSkontoTransferSummaryHandler { - override func applySkontoAdjustmentsIfNeeded(result: AnalysisResult) { + override func applySkontoChangesIfNeeded(result: AnalysisResult) { guard let skontoDiscountExtraction = result.skontoDiscounts?.first else { return } GiniBankConfiguration.shared.skontoDiscounts = [skontoDiscountExtraction] } From 536c30048e80b81d03bc3edba9034b78537242b8 Mon Sep 17 00:00:00 2001 From: Gleb Kulik Date: Tue, 10 Dec 2024 11:28:40 +0100 Subject: [PATCH 5/5] feat(GiniBankSDKExample): SkontoTransferSummaryIntegrationTest: remove sendTransferSummary overrides for specific handlers in PP-615 --- .../SkontoTransferSummaryIntegrationTest.swift | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift index f9b84eb7c..9e6c8736c 100644 --- a/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift +++ b/BankSDK/GiniBankSDKExample/Tests/IntegrationTests/TransferSummary/SkontoTransferSummaryIntegrationTest.swift @@ -197,13 +197,6 @@ class SkontoTransferSummaryHandler: BaseSkontoTransferSummaryHandler { @@ -212,11 +205,4 @@ class SkontoNotAppliedTransferSummaryHandler: BaseSkontoTransferSummaryHandler