From 8051fbf0cffc45b3b0d68506bdec0755e9a76149 Mon Sep 17 00:00:00 2001 From: Andrei Solovev Date: Tue, 5 Dec 2023 22:54:10 +0700 Subject: [PATCH] Add unittests --- OmiseSDK.xcodeproj/project.pbxproj | 4 + .../PaymentChooserViewControllerTests.swift | 90 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 OmiseSDKTests/Views/PaymentChooserViewControllerTests.swift diff --git a/OmiseSDK.xcodeproj/project.pbxproj b/OmiseSDK.xcodeproj/project.pbxproj index 39cbf751..2c906239 100644 --- a/OmiseSDK.xcodeproj/project.pbxproj +++ b/OmiseSDK.xcodeproj/project.pbxproj @@ -98,6 +98,7 @@ 75F2A0BB2A1A60630038FA54 /* AtomeFormViewContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75F2A0B52A1A5F020038FA54 /* AtomeFormViewContext.swift */; }; 75F2A0C12A1A84900038FA54 /* UIColor+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75F2A0C02A1A84900038FA54 /* UIColor+Helpers.swift */; }; 75F2A0C22A1A87AE0038FA54 /* UIColor+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75F2A0C02A1A84900038FA54 /* UIColor+Helpers.swift */; }; + 75F8C0B72B1F78E300AE78D9 /* PaymentChooserViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75F8C0B62B1F78E300AE78D9 /* PaymentChooserViewControllerTests.swift */; }; 8A01E48D21059EFF00D73FE6 /* PaymentInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A01E48C21059EFF00D73FE6 /* PaymentInformation.swift */; }; 8A01F78B20D90EC5003FC11E /* Client+ObjC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A01F78A20D90EC5003FC11E /* Client+ObjC.swift */; }; 8A01F78E20D91091003FC11E /* OMSTokenRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A01F78D20D91091003FC11E /* OMSTokenRequest.swift */; }; @@ -316,6 +317,7 @@ 75F2A0B32A1A5EAD0038FA54 /* AtomeFormViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AtomeFormViewModelProtocol.swift; sourceTree = ""; }; 75F2A0B52A1A5F020038FA54 /* AtomeFormViewContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AtomeFormViewContext.swift; sourceTree = ""; }; 75F2A0C02A1A84900038FA54 /* UIColor+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Helpers.swift"; sourceTree = ""; }; + 75F8C0B62B1F78E300AE78D9 /* PaymentChooserViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentChooserViewControllerTests.swift; sourceTree = ""; }; 8A00FEC21F1DE88600246078 /* README.md */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; tabWidth = 2; }; 8A01E48C21059EFF00D73FE6 /* PaymentInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentInformation.swift; sourceTree = ""; }; 8A01F78A20D90EC5003FC11E /* Client+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Client+ObjC.swift"; sourceTree = ""; }; @@ -882,6 +884,7 @@ isa = PBXGroup; children = ( F615CBF7261565D600E1A2D9 /* CardExpiryDatePickerTests.swift */, + 75F8C0B62B1F78E300AE78D9 /* PaymentChooserViewControllerTests.swift */, ); path = Views; sourceTree = ""; @@ -1349,6 +1352,7 @@ 7509D4E72A1C8E3D0050AB38 /* AtomeFormViewModelTests.swift in Sources */, 7509D4E22A1C876B0050AB38 /* AtomeFormViewContextMockup.swift in Sources */, 8A3C10562159F7FC00BEFD8A /* InvalidCardAPIErrorParsingTestCase.swift in Sources */, + 75F8C0B72B1F78E300AE78D9 /* PaymentChooserViewControllerTests.swift in Sources */, 758244092ACE988700781B3B /* PaymentInformationTestCase.swift in Sources */, 8A37E43620B584D300E2DA18 /* ModelTestCase.swift in Sources */, ); diff --git a/OmiseSDKTests/Views/PaymentChooserViewControllerTests.swift b/OmiseSDKTests/Views/PaymentChooserViewControllerTests.swift new file mode 100644 index 00000000..96c09646 --- /dev/null +++ b/OmiseSDKTests/Views/PaymentChooserViewControllerTests.swift @@ -0,0 +1,90 @@ +// +// PaymentChooserViewControllerTests.swift +// OmiseSDKTests +// +// Created by Andrei Solovev on 5/12/23. +// Copyright © 2023 Omise. All rights reserved. +// + +import XCTest +@testable import OmiseSDK + +class PaymentChooserViewControllerTests: XCTestCase { + let allSourceTypes: [OMSSourceTypeValue] = [ + .internetBankingBAY, + .internetBankingBBL, + .mobileBankingSCB, + .mobileBankingOCBCPAO, + .mobileBankingOCBC, + .mobileBankingBAY, + .mobileBankingBBL, + .mobileBankingKTB, + .alipay, + .alipayCN, + .alipayHK, + .billPaymentTescoLotus, + .barcodeAlipay, + .dana, + .gcash, + .installmentBAY, + .installmentFirstChoice, + .installmentBBL, + .installmentMBB, + .installmentKTC, + .installmentKBank, + .installmentSCB, + .installmentCiti, + .installmentTTB, + .installmentUOB, + .kakaoPay, + .eContext, + .promptPay, + .payNow, + .touchNGo, + .touchNGoAlipayPlus, + .trueMoney, + .trueMoneyJumpApp, + .pointsCiti, + .fpx, + .mobileBankingKBank, + .rabbitLinepay, + .grabPay, + .grabPayRms, + .boost, + .shopeePay, + .shopeePayJumpApp, + .maybankQRPay, + .duitNowQR, + .duitNowOBW, + .atome, + .payPay + ] + + func testTruemoveFiltering() { + let trueMoneyWalletOnly = allSourceTypes.filter { $0 != .trueMoneyJumpApp } + let trueMoneyJumpAppOnly = allSourceTypes.filter { $0 != .trueMoney } + let trueMoneyAndJumpApp = allSourceTypes + let noTrueMoneyAndJumpApp = allSourceTypes.filter { + ($0 != .trueMoney) && ($0 != .trueMoneyJumpApp) + } + + let vc = PaymentChooserViewController() + vc.loadView() + + vc.allowedPaymentMethods = trueMoneyWalletOnly + XCTAssertTrue(vc.showingValues.contains(.truemoney)) + XCTAssertFalse(vc.showingValues.contains(.truemoneyJumpApp)) + + vc.allowedPaymentMethods = trueMoneyJumpAppOnly + XCTAssertTrue(vc.showingValues.contains(.truemoneyJumpApp)) + XCTAssertFalse(vc.showingValues.contains(.truemoney)) + + vc.allowedPaymentMethods = trueMoneyAndJumpApp + XCTAssertTrue(vc.showingValues.contains(.truemoneyJumpApp)) + XCTAssertFalse(vc.showingValues.contains(.truemoney)) + + vc.allowedPaymentMethods = noTrueMoneyAndJumpApp + XCTAssertFalse(vc.showingValues.contains(.truemoneyJumpApp)) + XCTAssertFalse(vc.showingValues.contains(.truemoney)) + } +}