Skip to content

Commit

Permalink
Add some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
okhan-okbay-cko committed Oct 20, 2023
1 parent 5c5e9f4 commit 8562ac0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Source/UI/SecurityCodeComponent/SecurityCodeComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public final class SecurityCodeComponent: UIView {
}

extension SecurityCodeComponent {
public func configure(with configuration: SecurityCodeComponentConfiguration, isSecurityCodeValid: @escaping (Bool) -> Void) {
public func configure(with configuration: SecurityCodeComponentConfiguration,
isSecurityCodeValid: @escaping (Bool) -> Void) {
self.configuration = configuration
self.isSecurityCodeValid = isSecurityCodeValid

Expand Down
57 changes: 57 additions & 0 deletions Tests/UI/SecurityCodeComponent/SecurityCodeComponentTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// SecurityCodeComponentTests.swift
//
//
// Created by Okhan Okbay on 20/10/2023.
//

@testable import Frames
import XCTest

final class SecurityCodeComponentTests: XCTestCase {
let sut = SecurityCodeComponent()
var mockconfig = SecurityCodeComponentConfiguration(apiKey: "some_api_key", environment: .sandbox)

func test_whenConfigureIsCalled_thenRequiredPropertiesAreSet() {

}

func test_whenUpdateIsCalledWith_thenISSecurityCodeValidCalledWithCorrectResult() {
let testMatrix: [(scheme: Card.Scheme, securityCode: String, expectedResult: Bool)] = [
(.visa, "", false),
(.visa, "1", false),
(.visa, "12", false),
(.visa, "123", true),
(.visa, "1234", false),
(.americanExpress, "", false),
(.americanExpress, "1", false),
(.americanExpress, "12", false),
(.americanExpress, "123", false),
(.americanExpress, "1234", true),
(.unknown, "", false),
(.unknown, "1", false),
(.unknown, "12", false),
(.unknown, "123", true),
(.unknown, "1234", true),
]

testMatrix.forEach { testData in
mockconfig.cardScheme = testData.scheme
verify(securityCode: testData.securityCode, expectedResult: testData.expectedResult)
}
}

func verify(securityCode: String,
expectedResult: Bool,
file: StaticString = #file,
line: UInt = #line) {
sut.configure(with: mockconfig) { [weak self] isSecurityCodeValid in
XCTAssertEqual(expectedResult,
isSecurityCodeValid,
"Security code: \(securityCode) Card Scheme: \(self?.mockconfig.cardScheme?.rawValue ?? "nil") \n Expected: \(expectedResult) but found: \(isSecurityCodeValid)",
file: file,
line: line)
}
sut.update(securityCode: securityCode)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -25,10 +25,10 @@
0BD2ECBF28B65DA10041A942 /* FrameUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD2ECBE28B65DA10041A942 /* FrameUITests.swift */; };
0BD2ECC128B65EC20041A942 /* XCUIApplication+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD2ECC028B65EC20041A942 /* XCUIApplication+Extension.swift */; };
162CD88E2A6827E900027FEF /* XCUIElement+TestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 162CD88D2A6827E900027FEF /* XCUIElement+TestHelpers.swift */; };
166FE3AC2AC30F1800BF5775 /* Frames in Frameworks */ = {isa = PBXBuildFile; productRef = 166FE3AB2AC30F1800BF5775 /* Frames */; };
16857B742A65F15F005CAE39 /* CardTypeTokenCreationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16857B732A65F15F005CAE39 /* CardTypeTokenCreationTests.swift */; };
16857B7E2A65F3F3005CAE39 /* XCUIApplication+TestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16857B7D2A65F3F3005CAE39 /* XCUIApplication+TestHelpers.swift */; };
168CEC952AC5C71700BB52B0 /* SecurityCodeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 168CEC942AC5C71700BB52B0 /* SecurityCodeViewController.swift */; };
16900D412AE2FAB3009A7CE9 /* Frames in Frameworks */ = {isa = PBXBuildFile; productRef = 16900D402AE2FAB3009A7CE9 /* Frames */; };
169DF1482A7BFB1B00891DF0 /* CardSchemeFormatSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 169DF1472A7BFB1B00891DF0 /* CardSchemeFormatSnapshotTests.swift */; };
16C3F8402A7927ED00690639 /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 16C3F83F2A7927ED00690639 /* SnapshotTesting */; };
16C3F8422A7956EA00690639 /* CardValidationSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16C3F8412A7956EA00690639 /* CardValidationSnapshotTests.swift */; };
Expand Down Expand Up @@ -125,7 +125,6 @@
0BD2ECBE28B65DA10041A942 /* FrameUITests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FrameUITests.swift; sourceTree = "<group>"; };
0BD2ECC028B65EC20041A942 /* XCUIApplication+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCUIApplication+Extension.swift"; sourceTree = "<group>"; };
162CD88D2A6827E900027FEF /* XCUIElement+TestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCUIElement+TestHelpers.swift"; sourceTree = "<group>"; };
166FE3AA2AC30BB600BF5775 /* frames-ios */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "frames-ios"; path = ..; sourceTree = "<group>"; };
16857B712A65F15F005CAE39 /* iOS Example Frame Regression Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "iOS Example Frame Regression Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
16857B732A65F15F005CAE39 /* CardTypeTokenCreationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardTypeTokenCreationTests.swift; sourceTree = "<group>"; };
16857B7D2A65F3F3005CAE39 /* XCUIApplication+TestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCUIApplication+TestHelpers.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -220,7 +219,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
166FE3AC2AC30F1800BF5775 /* Frames in Frameworks */,
16900D412AE2FAB3009A7CE9 /* Frames in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -441,7 +440,6 @@
E6646F8120CE6C0900D8353A = {
isa = PBXGroup;
children = (
166FE3AA2AC30BB600BF5775 /* frames-ios */,
CBA81CAA27ABDF21000DF192 /* iOS Example Frame */,
CB9412D82825714C00C889E8 /* iOS Example FrameUITests */,
16857B722A65F15F005CAE39 /* iOS Example Frame Regression Tests */,
Expand Down Expand Up @@ -510,7 +508,7 @@
);
name = "iOS Example Frame";
packageProductDependencies = (
166FE3AB2AC30F1800BF5775 /* Frames */,
16900D402AE2FAB3009A7CE9 /* Frames */,
);
productName = "iOS Example Frame";
productReference = 16AE74C32A5C1EBB0031F794 /* iOS Example Frame.app */;
Expand Down Expand Up @@ -559,6 +557,7 @@
mainGroup = E6646F8120CE6C0900D8353A;
packageReferences = (
16C3F83E2A7927ED00690639 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */,
16900D3F2AE2FAB3009A7CE9 /* XCRemoteSwiftPackageReference "frames-ios" */,
);
productRefGroup = E6646F8120CE6C0900D8353A;
projectDirPath = "";
Expand Down Expand Up @@ -1210,6 +1209,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
16900D3F2AE2FAB3009A7CE9 /* XCRemoteSwiftPackageReference "frames-ios" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "file:///Users/okhanokbay/Documents/frames-ios";
requirement = {
branch = "feature/cvv-component";
kind = branch;
};
};
16C3F83E2A7927ED00690639 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pointfreeco/swift-snapshot-testing";
Expand All @@ -1221,8 +1228,9 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
166FE3AB2AC30F1800BF5775 /* Frames */ = {
16900D402AE2FAB3009A7CE9 /* Frames */ = {
isa = XCSwiftPackageProductDependency;
package = 16900D3F2AE2FAB3009A7CE9 /* XCRemoteSwiftPackageReference "frames-ios" */;
productName = Frames;
};
16C3F83F2A7927ED00690639 /* SnapshotTesting */ = {
Expand Down

0 comments on commit 8562ac0

Please sign in to comment.