Skip to content

Commit

Permalink
Reorganise tests + reinstate debug app tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewc committed Apr 20, 2024
1 parent 18cfc80 commit d56d29c
Show file tree
Hide file tree
Showing 101 changed files with 219 additions and 803 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build_test_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
unit-test:
runs-on: macos-13-large
timeout-minutes: 30
name: "Unit Tests"
name: "Debug App - Unit Tests"
steps:
- name: Git - Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
spm-test:
runs-on: macos-13-large
timeout-minutes: 20
name: "Run unit tests (SPM)"
name: "SDK - Unit Tests"
steps:
- name: Cancel previous jobs
uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1
Expand Down Expand Up @@ -103,7 +103,9 @@ jobs:
MATCH_KEYCHAIN_PASSWORD: ${{ secrets.MATCH_KEYCHAIN_PASSWORD }}
SOURCE_BRANCH: ${{ github.head_ref }}
build-and-upload-to-appetize:
needs: unit-test
needs:
- unit-test
- spm-test
runs-on: macos-13
timeout-minutes: 45
name: "Build and upload app to Appetize"
Expand Down
5 changes: 5 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/PrimerSDKTests.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
BlueprintName = "PrimerSDKTests"
ReferencedContainer = "container:">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "HUC_TokenizationViewModelTests">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
</TestAction>
Expand Down
741 changes: 75 additions & 666 deletions Debug App/Primer.io Debug App.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions Debug App/Tests/AppetizeConfigTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// AppetizeConfigTests.swift
// Debug App Tests
//
// Created by Niall Quinn on 12/03/24.
// Copyright © 2024 Primer API Ltd. All rights reserved.
//

import XCTest
@testable import Debug_App

final class AppetizeConfigTests: XCTestCase {

func test_fetchConfig() throws {
let mockConfig = SessionConfiguration.mockConfig

let mockPayloadProvider = MockPayloadProvider(config: mockConfig)

let configProvider = AppetizeConfigProvider(payloadProvider: mockPayloadProvider)

let fetchedConfig = configProvider.fetchConfig()

XCTAssertEqual(fetchedConfig, mockConfig)
}

func test_fetchNoConfig() throws {

let mockPayloadProvider = MockPayloadProvider(config: nil)

let configProvider = AppetizeConfigProvider(payloadProvider: mockPayloadProvider)

let fetchedConfig = configProvider.fetchConfig()

XCTAssertNil(fetchedConfig)
}
}

private struct MockPayloadProvider: AppetizePayloadProviding {
var isAppetize: Bool?
var configJwt: String?

init(config: SessionConfiguration?) {
guard let config else {
self.isAppetize = false
self.configJwt = nil
return
}
self.isAppetize = true
self.configJwt = config.base64Encoded
}
}

private extension SessionConfiguration {
var base64Encoded: String? {
let encoder = JSONEncoder()
if let jsonData = try? encoder.encode(self) {
let base64String = jsonData.base64EncodedString()
return base64String
} else {
return nil
}
}

static var mockConfig: SessionConfiguration {
.init(customerId: "mock-customerId",
locale: "mock-locale",
paymentFlow: "mock-paymentFlow",
currency: "mock-currency",
countryCode: "mock-countryCode",
value: "mock-value",
surchargeEnabled: false,
applePaySurcharge: 0,
firstName: "mock-firstName",
lastName: "mock-lastName",
email: "mock-email",
mobileNumber: "mock-mobileNumber",
addressLine1: "mock-addressLine1",
state: "mock-state",
city: "mock-city",
postalCode: "mock-postalCode",
vault: false,
newWorkflows: false,
environment: "mock-environment",
customApiKey: "mock-customApiKey",
metadata: "mock-metadata")
}
}
46 changes: 46 additions & 0 deletions Debug App/Tests/MetadataParserTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// MetadataParserTests.swift
// Debug App Tests
//
// Created by Niall Quinn on 11/03/24.
// Copyright © 2024 Primer API Ltd. All rights reserved.
//

import XCTest
@testable import Debug_App

final class MetadataParserTests: XCTestCase {

private let metadataParser = MetadataParser()

func testParseMetadataWithJSON() throws {
let jsonMetadata = #"{"key1": "value1", "key2": 123}"#

let result = metadataParser.parse(jsonMetadata)

XCTAssertEqual(result["key1"] as? String, "value1")
XCTAssertEqual(result["key2"] as? Int, 123)
}

func testParseMetadataWithKeyValuePairs() throws {
let keyValueMetadata = """
key1=value1
doubleKey=123.0
intKey=123
"""

let result = metadataParser.parse(keyValueMetadata)

XCTAssertEqual(result["key1"] as? String, "value1")
XCTAssertEqual(result["doubleKey"] as? Double, 123)
XCTAssertEqual(result["intKey"] as? Int, 123)
}

func testParseMetadataWithInvalidMetadata() throws {
let invalidMetadata = "invalid json"

let result = metadataParser.parse(invalidMetadata)

XCTAssertEqual(result.count, 0)
}
}
87 changes: 0 additions & 87 deletions Debug App/Tests/Unit Tests/Utils/AppetizeConfigTests.swift

This file was deleted.

46 changes: 0 additions & 46 deletions Debug App/Tests/Unit Tests/Utils/MetadataParserTests.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let package = Package(
dependencies: [
.byName(name: "PrimerSDK")
],
path: "Debug App/Tests/Unit Tests"
path: "Tests/Unit Tests"
)
],
swiftLanguageVersions: [.v5]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit d56d29c

Please sign in to comment.