-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganise tests + reinstate debug app tests
- Loading branch information
Showing
101 changed files
with
219 additions
and
803 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
741 changes: 75 additions & 666 deletions
741
Debug App/Primer.io Debug App.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
87
Debug App/Tests/Unit Tests/Utils/AppetizeConfigTests.swift
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
Debug App/Tests/Unit Tests/Utils/MetadataParserTests.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.