Skip to content

Commit

Permalink
feat(POM-222): add integration tests infra (#129)
Browse files Browse the repository at this point in the history
Add infrastructure for integration tests as well as cards service tests
  • Loading branch information
andrii-vysotskyi-cko authored Jul 5, 2023
1 parent 8438f24 commit 167c026
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 51 deletions.
24 changes: 12 additions & 12 deletions .github/actions/bootstrap-project/action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Bootstrap Project
description: Pulls needed dependencies and bootstraps project
inputs:
example-constants:
description: 'Content of example project constants file'
test-project-constants:
description: 'Content of test project constants file'
type: string
required: false
runs:
Expand All @@ -12,23 +12,23 @@ runs:
with:
ruby-version: '3.1.2'
bundler-cache: true
- name: Install Mint
run: brew update && brew install mint
shell: bash
- name: Cache Mint Packages
uses: actions/cache@v3
with:
path: ~/.mint/packages
key: ${{ runner.os }}-mint-${{ hashFiles('**/Mintfile') }}
restore-keys: |
${{ runner.os }}-mint-
- name: Write Constants
run: |
CONSTANTS=$'${{ inputs.test-project-constants }}'
echo "$CONSTANTS" > Tests/ProcessOutTests/Resources/Constants.yml
echo "$CONSTANTS" > Example/Example/Resources/Constants.yml
shell: bash
- name: Bootstrap Project
run: ./Scripts/BootstrapProject.sh --skip-bundle-instal
shell: bash
- name: Bootstrap Example Project
if: ${{ inputs.example-constants != '' }}
run: |
cd Example
echo "${{ inputs.example-constants }}" > Example/Resources/Constants.yml
source Scripts/BootstrapProject.sh --skip-mint-bootstrap
shell: bash
# - name: Bootstrap Example Project
# if: ${{ inputs.test-project-constants != '' }}
# run: cd Example && ./Scripts/BootstrapProject.sh --skip-mint-bootstrap
# shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
- name: Bootstrap Project
uses: ./.github/actions/bootstrap-project
with:
example-constants: ${{ secrets.EXAMPLE_PROJECT_CONSTANTS }}
test-project-constants: ${{ secrets.TEST_PROJECT_CONSTANTS }}
- name: Run Unit Tests
run: source Scripts/Test.sh
14 changes: 6 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
### fastlane ###
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/screenshots/screenshots.html
fastlane/test_output

### macOS ###
## macOS
.DS_Store
.AppleDouble
.LSOverride
Expand All @@ -16,3 +9,8 @@ fastlane/test_output
Packages
*.xcodeproj
xcuserdata/
Tests/ProcessOutTests/Sources/Generated/*.swift
Tests/ProcessOutTests/Resources/Constants.yml

## Brew
Brewfile.lock.json
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ included:
excluded:
- Sources/ProcessOut/Sources/Legacy
- Sources/ProcessOut/Sources/Generated
- Tests/ProcessOutTests/Sources/Generated

function_parameter_count:
warning: 5
Expand Down
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
brew "mint"
1 change: 1 addition & 0 deletions Example/Brewfile
2 changes: 1 addition & 1 deletion Example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Project demonstrates multiple flows that ProcessOut framework is capable of.

- A recent version of macOS (tested with 13.3.1)
- A recent version of Xcode (tested with 14.3.1)
- [Mint](https://github.com/yonaskolb/Mint) package manager
- [Homebrew](https://https://brew.sh/) package manager

### Installation

Expand Down
3 changes: 3 additions & 0 deletions Example/Scripts/BootstrapProject.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

set -e

# Installs brew dependencies
brew bundle

# Installs mint dependencies if needed
if ! [[ "$@" =~ '--skip-mint-bootstrap' ]]; then
mint bootstrap
Expand Down
4 changes: 1 addition & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ let package = Package(
dependencies: [
.target(name: "cmark")
],
// Having DocC in sources may cause build failures so excluded until issue is resolved by Apple. See
// https://forums.swift.org/t/xcode-and-swift-package-manager/44704 for details.
exclude: ["ProcessOut.docc"],
exclude: ["ProcessOut.docc", "swiftgen.yml"],
resources: [
.process("Resources")
]
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,24 @@ We welcome contributions of any kind including new features, bug fixes, and gene

- A recent version of macOS (tested with 13.3.1)
- A recent version of Xcode (tested with 14.3.1)
- [Mint](https://github.com/yonaskolb/Mint) package manager
- [Homebrew](https://https://brew.sh/) package manager
- [Ruby](https://www.ruby-lang.org) (tested with 3.1.2) with [bundler](https://bundler.io) installed

### Installation

Before going further please make sure that you have installed all dependencies specified in [requirements](#development-requirements) section. Then in order to install remaining dependencies and prepare a project run `./Scripts/BootstrapProject.sh` script from repository's root directory. It will create `ProcessOut.xcodeproj` project that should be used for development.

> **Note**
>
> If you plan to run tests ensure that `Tests/ProcessOutTests/Resources/Constants.yml` file with test project credentials exists before generating project. E.g.
>
> ```yml
> projectId: test-proj_K3Ur9LQzcKtm4zttWJ7oAKHgqdiwboAw
> projectPrivateKey: key_test_RE14RLcNikkP5ZXMn84BFYApwotD05Kc
> apiBaseUrl: https://api.processout.com
> checkoutBaseUrl: https://checkout.processout.com
> ```
### 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`.
Expand Down
3 changes: 3 additions & 0 deletions Scripts/BootstrapProject.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ set -e
# Exports version as environment variable
export CURRENT_VERSION="$(cat Version.resolved)"

# Installs brew dependencies
brew bundle

# Installs mint dependencies
mint bootstrap

Expand Down
3 changes: 3 additions & 0 deletions Scripts/SwiftGen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

mint run swiftgen config run --config "${TARGET_ROOT}/swiftgen.yml"
6 changes: 0 additions & 6 deletions Scripts/SwiftGen/Input.xcfilelist

This file was deleted.

3 changes: 0 additions & 3 deletions Scripts/SwiftGen/Output.xcfilelist

This file was deleted.

3 changes: 0 additions & 3 deletions Scripts/SwiftGen/SwiftGen.sh

This file was deleted.

4 changes: 2 additions & 2 deletions Scripts/Test.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash

set -e
set -euo pipefail

SDK='iphonesimulator'
DESTINATION='platform=iOS Simulator,name=iPhone 14 Pro,OS=16.2'
DESTINATION='platform=iOS Simulator,name=iPhone 14 Pro,OS=latest'

xcodebuild clean test \
-project ProcessOut.xcodeproj \
Expand Down
7 changes: 3 additions & 4 deletions swiftgen.yml → Sources/ProcessOut/swiftgen.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## Every input/output paths in the rest of the config will then be expressed relative to these.
input_dir: ${PROJECT_DIR}/Sources/${TARGET_NAME}/Resources/
output_dir: ${PROJECT_DIR}/Sources/${TARGET_NAME}/Sources/Generated/
input_dir: ${TARGET_ROOT}/Resources/
output_dir: ${TARGET_ROOT}/Sources/Generated/

## Constants for Assets Catalogs.
xcassets:
Expand All @@ -14,7 +13,7 @@ xcassets:
forceProvidesNamespaces: true
bundle: BundleLocator.bundle
output: Assets+Generated.swift

## Constants for Localized Strings.
strings:
inputs:
Expand Down
Empty file.
66 changes: 66 additions & 0 deletions Tests/ProcessOutTests/Sources/Integration/CardsServiceTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// CardsServiceTests.swift
// ProcessOutTests
//
// Created by Andrii Vysotskyi on 27.06.2023.
//

import Foundation
import XCTest
@_spi(PO) import ProcessOut

final class CardsServiceTests: XCTestCase {

override func setUp() {
super.setUp()
let configuration = ProcessOutConfiguration.test(
projectId: Constants.projectId,
privateKey: Constants.projectPrivateKey,
apiBaseUrl: URL(string: Constants.apiBaseUrl)!,
checkoutBaseUrl: URL(string: Constants.checkoutBaseUrl)!
)
ProcessOut.configure(configuration: configuration)
sut = ProcessOut.shared.cards
}

func test_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, "business")
XCTAssertEqual(information.scheme, "visa")
XCTAssertEqual(information.type, "debit")
}

func test_issuerInformation_whenIinIsTooShort_throws() async {
do {
// When
_ = try await sut.issuerInformation(iin: "4")
} catch {
return
}

// Then
XCTFail("IIN with length less than 6 symbols should be invalid")
}

func test_tokenizeRequest_returnsCard() async throws {
// Given
let request = POCardTokenizationRequest(number: "4242424242424242", expMonth: 12, expYear: 40, cvc: "737")

// When
let card = try await sut.tokenize(request: request)

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

// MARK: - Tests

private var sut: POCardsService!
}
12 changes: 12 additions & 0 deletions Tests/ProcessOutTests/swiftgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
input_dir: ${TARGET_ROOT}/Resources/
output_dir: ${TARGET_ROOT}/Sources/Generated/

## Application Constants
yaml:
inputs:
- Constants.yml
outputs:
- templateName: inline-swift5
params:
enumName: Constants
output: Constants+Generated.swift
27 changes: 20 additions & 7 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,41 @@ targets:
SKIP_INSTALL: NO
BUILD_LIBRARY_FOR_DISTRIBUTION: YES
OTHER_SWIFT_FLAGS: "-Xfrontend -module-interface-preserve-types-as-written"
TARGET_ROOT: $(PROJECT_DIR)/Sources/ProcessOut
preBuildScripts:
- path: Scripts/Lint.sh
name: Swiftlint
basedOnDependencyAnalysis: false
- path: Scripts/SwiftGen/SwiftGen.sh
- path: Scripts/SwiftGen.sh
name: SwiftGen
inputFileLists:
- $(PROJECT_DIR)/Scripts/SwiftGen/Input.xcfilelist
outputFileLists:
- $(PROJECT_DIR)/Scripts/SwiftGen/Output.xcfilelist
basedOnDependencyAnalysis: false
- path: Scripts/Sourcery.sh
name: Sourcery
basedOnDependencyAnalysis: false
sources: Sources/ProcessOut
sources:
- path: Sources/ProcessOut
excludes:
- swiftgen.yml
dependencies:
- framework: Vendor/cmark.xcframework
ProcessOutTests:
type: bundle.unit-test
platform: iOS
deploymentTarget: "16.0"
settings:
TARGET_ROOT: $(PROJECT_DIR)/Tests/ProcessOutTests
preBuildScripts:
- path: Scripts/SwiftGen.sh
name: SwiftGen
outputFiles:
- $(TARGET_ROOT)/Sources/Generated/Constants+Generated.swift
basedOnDependencyAnalysis: false
dependencies:
- target: ProcessOut
sources: Tests/ProcessOutTests
sources:
- path: Tests/ProcessOutTests
- path: Tests/ProcessOutTests/Sources/Generated/Constants+Generated.swift
optional: true
ProcessOutCheckout3DS:
type: framework
platform: iOS
Expand All @@ -53,6 +65,7 @@ targets:
PRODUCT_BUNDLE_IDENTIFIER: com.processout.checkout-3ds-ios
SKIP_INSTALL: NO
BUILD_LIBRARY_FOR_DISTRIBUTION: YES
TARGET_ROOT: $(PROJECT_DIR)/Sources/ProcessOutCheckout3DS
preBuildScripts:
- path: Scripts/Lint.sh
name: Swiftlint
Expand Down

0 comments on commit 167c026

Please sign in to comment.