Skip to content

Commit

Permalink
feat(POM-443): migrate to swift testing (#403)
Browse files Browse the repository at this point in the history
* Migrate test targets to use Swift Testing.
* Remove unused test target from example app.
  • Loading branch information
andrii-vysotskyi-cko authored Dec 19, 2024
1 parent 5445804 commit a28139b
Show file tree
Hide file tree
Showing 40 changed files with 1,047 additions and 1,072 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ concurrency:
cancel-in-progress: true
jobs:
run-tests:
strategy:
matrix:
os: [macos-14, macos-15]
runs-on: ${{ matrix.os }}
runs-on: macos-15
steps:
- uses: actions/checkout@v4
- name: Bootstrap Project
uses: ./.github/actions/bootstrap-project
with:
test-project-constants: ${{ secrets.TEST_PROJECT_CONSTANTS }}
- name: Run Unit Tests
run: source Scripts/Test.sh
run: source Scripts/Tests/Run.sh
run-tests-legacy:
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- name: Bootstrap Project
uses: ./.github/actions/bootstrap-project
with:
test-project-constants: ${{ secrets.TEST_PROJECT_CONSTANTS }}
- name: Run Unit Tests
run: source Scripts/Tests/[email protected]
78 changes: 0 additions & 78 deletions Example/ExampleUiTests/Sources/ExampleUiTests.swift

This file was deleted.

13 changes: 0 additions & 13 deletions Example/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,9 @@ targets:
dependencies:
- package: ProcessOutUI
- package: ProcessOutCheckout3DS
ExampleUiTests:
type: bundle.ui-testing
sources: ExampleUiTests
platform: iOS
settings:
GENERATE_INFOPLIST_FILE: 1
PRODUCT_BUNDLE_IDENTIFIER: com.processout.processout-example-ui-tests
dependencies:
- target: Example

schemes:
Example:
build:
targets:
Example: all
ExampleUiTests: [test]
test:
gatherCoverageData: true
targets: [ExampleUiTests]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Before going further please make sure that you have installed all dependencies s
### Running tests
To run tests locally use `./Scripts/Test.sh` script. It is also possible to run them directly in Xcode from the ProcessOut target in `ProcessOut.xcodeproj`.
To run tests locally use `./Scripts/Tests/Run.sh` script. It is also possible to run them directly in Xcode from the ProcessOut target in `ProcessOut.xcodeproj`.
## License
Expand Down
File renamed without changes.
4 changes: 1 addition & 3 deletions Scripts/Test.sh → Scripts/Tests/Run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail

PROJECT='ProcessOut.xcodeproj'
DESTINATION=$(./Scripts/TestDestination.swift)
DESTINATION=$(./Scripts/Tests/Destination.swift)

# Run Tests
for PRODUCT in "ProcessOut" "ProcessOutUI" "ProcessOutCheckout3DS"; do
Expand All @@ -14,5 +14,3 @@ for PRODUCT in "ProcessOut" "ProcessOutUI" "ProcessOutCheckout3DS"; do
-enableCodeCoverage NO |
xcpretty
done

# todo(andrii-vysotskyi): run example target tests when POM-144 is resolved
18 changes: 18 additions & 0 deletions Scripts/Tests/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Note: Test targets are not compatible with Xcode 15.
# This script ensures that the project can be built successfully as a minimal validation check.

set -euo pipefail

PROJECT='ProcessOut.xcodeproj'
DESTINATION=$(./Scripts/Tests/Destination.swift)

# Iterate over each product and build it using xcodebuild
for PRODUCT in "ProcessOut" "ProcessOutUI" "ProcessOutCheckout3DS"; do
xcodebuild clean build \
-destination "$DESTINATION" \
-project $PROJECT \
-scheme $PRODUCT |
xcpretty
done
3 changes: 1 addition & 2 deletions Sources/ProcessOut/Sources/Api/ProcessOut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ public final class ProcessOut: @unchecked Sendable {
// MARK: - Private Methods

@MainActor
// swiftlint:disable:next function_body_length
private init(configuration: ProcessOutConfiguration) {
init(configuration: ProcessOutConfiguration) { // swiftlint:disable:this function_body_length
self._configuration = .init(wrappedValue: configuration)
let deviceMetadataProvider = Self.createDeviceMetadataProvider()
// Telemetry connector logs are not submitted to backend to avoid recursion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// Created by Andrii Vysotskyi on 17.04.2023.
//

import XCTest
import Testing
import ProcessOutCheckout3DS

final class Checkout3DSServiceTests: XCTestCase {
struct Checkout3DSServiceTests {

// swiftlint:disable:next empty_xctest_method
func testExample() throws { }
@Test
func example() throws { }
}
31 changes: 0 additions & 31 deletions Tests/ProcessOutTests/Sources/Core/Utils.swift

This file was deleted.

68 changes: 33 additions & 35 deletions Tests/ProcessOutTests/Sources/Integration/CardsServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@
//

import Foundation
import XCTest
import Testing
@testable import ProcessOut

final class CardsServiceTests: XCTestCase {
struct CardsServiceTests {

override func setUp() {
super.setUp()
ProcessOut.configure(configuration: .init(projectId: Constants.projectId), force: true)
sut = ProcessOut.shared.cards
init() async {
let processOut = await ProcessOut(configuration: .init(projectId: Constants.projectId))
sut = processOut.cards
}

// MARK: - Tests

func test_issuerInformation() async throws {
@Test
func issuerInformation() async throws {
// When
let information = try await sut.issuerInformation(iin: "400012")

// Then
XCTAssertEqual(information.bankName, "UNITED CITIZENS BANK OF SOUTHERN KENTUCKY")
XCTAssertEqual(information.brand, "visa business")
XCTAssertEqual(information.category, "commercial")
XCTAssertEqual(information.$scheme.typed, .visa)
XCTAssertEqual(information.type, "debit")
#expect(information.bankName == "UNITED CITIZENS BANK OF SOUTHERN KENTUCKY")
#expect(information.brand == "visa business")
#expect(information.category == "commercial")
#expect(information.$scheme.typed == .visa)
#expect(information.type == "debit")
}

func test_tokenizeRequest_returnsCard() async throws {
@Test
func tokenizeRequest_returnsCard() async throws {
// Given
let request = POCardTokenizationRequest(
number: "4242424242424242", expMonth: 12, expYear: 40, cvc: "737"
Expand All @@ -41,38 +42,33 @@ final class CardsServiceTests: XCTestCase {
let card = try await sut.tokenize(request: request)

// Then
XCTAssertEqual(card.last4Digits, "4242")
XCTAssertEqual(card.expMonth, 12)
XCTAssertEqual(card.expYear, 2040)
#expect(card.last4Digits == "4242" && card.expMonth == 12 && card.expYear == 2040)
}

func test_issuerInformation_whenIinIsTooShort_throws() async {
@Test
func issuerInformation_whenIinIsTooShort_throws() async {
// Given
let iin = "4"

// When
let issuerInformation = {
try await self.sut.issuerInformation(iin: iin)
await withKnownIssue {
_ = try await self.sut.issuerInformation(iin: iin)
}

// Then
await assertThrowsError(try await issuerInformation(), "IIN with length less than 6 symbols should be invalid")
}

func test_tokenizeRequest_whenNumberIsInvalid_throwsError() async {
@Test
func tokenizeRequest_whenNumberIsInvalid_throwsError() async {
// Given
let request = POCardTokenizationRequest(number: "", expMonth: 12, expYear: 40, cvc: "737")

// When
let card = {
try await self.sut.tokenize(request: request)
await withKnownIssue {
_ = try await self.sut.tokenize(request: request)
}

// Then
await assertThrowsError(try await card(), "Unexpected success, card number is invalid")
}

func test_updateCard_whenCvcIsSet_updatesIt() async throws {
@Test
func updateCard_whenCvcIsSet_updatesIt() async throws {
// Given
let card = try await sut.tokenize(
request: .init(number: "4242424242424242", expMonth: 12, expYear: 40, cvc: "737")
Expand All @@ -84,10 +80,11 @@ final class CardsServiceTests: XCTestCase {
)

// Then
XCTAssertEqual(updatedCard.updateType, "new-cvc2")
#expect(updatedCard.updateType == "new-cvc2")
}

func test_updateCard_whenPreferredSchemeIsSet_updatesIt() async throws {
@Test
func updateCard_whenPreferredSchemeIsSet_updatesIt() async throws {
// Given
let card = try await sut.tokenize(
request: .init(number: "4242424242424242", expMonth: 12, expYear: 40, cvc: "737")
Expand All @@ -99,10 +96,11 @@ final class CardsServiceTests: XCTestCase {
)

// Then
XCTAssertEqual(updatedCard.$preferredScheme.typed, "test")
#expect(updatedCard.$preferredScheme.typed == "test")
}

func test_tokenize_whenPreferredSchemeIsSet() async throws {
@Test
func tokenize_whenPreferredSchemeIsSet() async throws {
// Given
let request = POCardTokenizationRequest(
number: "5341026607460971", expMonth: 12, expYear: 40, preferredScheme: "carte bancaire"
Expand All @@ -112,10 +110,10 @@ final class CardsServiceTests: XCTestCase {
let card = try await sut.tokenize(request: request)

// Then
XCTAssertEqual(card.preferredScheme, request.preferredScheme)
#expect(card.preferredScheme == request.preferredScheme)
}

// MARK: - Private Properties

private var sut: POCardsService!
private let sut: POCardsService
}
Loading

0 comments on commit a28139b

Please sign in to comment.