-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from checkout/feature/new-error-codes
Add new error codes to handle HTTP 422 with data
- Loading branch information
Showing
13 changed files
with
229 additions
and
20 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
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,55 @@ | ||
included: | ||
- Source | ||
|
||
excluded: | ||
- Tests | ||
|
||
opt_in_rules: | ||
- array_init | ||
- closure_end_indentation | ||
- closure_spacing | ||
- collection_alignment | ||
- colon # promote to error | ||
- convenience_type | ||
- discouraged_object_literal | ||
- empty_collection_literal | ||
- empty_count | ||
- empty_string | ||
- enum_case_associated_values_count | ||
- fatal_error_message | ||
- first_where | ||
- force_unwrapping | ||
- implicitly_unwrapped_optional | ||
- last_where | ||
- legacy_random | ||
- literal_expression_end_indentation | ||
- multiline_arguments | ||
- multiline_function_chains | ||
- multiline_literal_brackets | ||
- multiline_parameters | ||
- multiline_parameters_brackets | ||
- operator_usage_whitespace | ||
- overridden_super_call | ||
- pattern_matching_keywords | ||
- prefer_self_type_over_type_of_self | ||
- redundant_nil_coalescing | ||
- redundant_type_annotation | ||
- strict_fileprivate | ||
- toggle_bool | ||
- trailing_closure | ||
- unneeded_parentheses_in_closure_argument | ||
- yoda_condition | ||
|
||
disabled_rules: | ||
- multiline_parameters_brackets | ||
|
||
analyzer_rules: | ||
- unused_import | ||
|
||
line_length: | ||
warning: 160 | ||
ignores_urls: true | ||
|
||
identifier_name: | ||
excluded: | ||
- id |
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
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
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,20 @@ | ||
// | ||
// ErrorReason.swift | ||
// | ||
// | ||
// Created by Okhan Okbay on 18/01/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct ErrorReason: Decodable, Equatable { | ||
public let requestID: String | ||
public let errorType: String | ||
public let errorCodes: [String] | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case requestID = "request_id" | ||
case errorType = "error_type" | ||
case errorCodes = "error_codes" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// AsyncWrapperTests.swift | ||
// | ||
// | ||
// Created by Okhan Okbay on 18/01/2024. | ||
// | ||
|
||
@testable import CheckoutNetwork | ||
import XCTest | ||
|
||
final class AsyncWrapperTests: XCTestCase { | ||
|
||
func test_whenRunRequestReturnsData_ThenAsyncRunRequestPropagatesIt() async throws { | ||
let fakeSession = FakeSession() | ||
let fakeDataTask = FakeDataTask() | ||
fakeSession.calledDataTasksReturn = fakeDataTask | ||
let client = CheckoutNetworkClientSpy(session: fakeSession) | ||
let testConfig = try! RequestConfiguration(path: FakePath.testServices) | ||
|
||
let expectedResult = FakeObject(id: "some response") | ||
client.expectedResult = expectedResult | ||
client.expectedError = nil | ||
let result: FakeObject = try await client.runRequest(with: testConfig) | ||
XCTAssertEqual(client.configuration.request, testConfig.request) | ||
XCTAssertEqual(client.runRequestCallCount, 1) | ||
XCTAssertEqual(result, expectedResult) | ||
} | ||
|
||
func test_whenRunRequestReturnsError_ThenAsyncRunRequestPropagatesIt() async throws { | ||
let fakeSession = FakeSession() | ||
let fakeDataTask = FakeDataTask() | ||
fakeSession.calledDataTasksReturn = fakeDataTask | ||
let client = CheckoutNetworkClientSpy(session: fakeSession) | ||
let testConfig = try! RequestConfiguration(path: FakePath.testServices) | ||
|
||
let expectedError = FakeError.someError | ||
client.expectedResult = nil | ||
client.expectedError = expectedError | ||
|
||
do { | ||
let _: FakeObject = try await client.runRequest(with: testConfig) | ||
XCTFail("An error was expected to be thrown") | ||
} catch let error as FakeError { | ||
XCTAssertEqual(client.configuration.request, testConfig.request) | ||
XCTAssertEqual(client.runRequestCallCount, 1) | ||
XCTAssertEqual(error, expectedError) | ||
} | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
Tests/CheckoutNetworkTests/Helpers/CheckoutNetworkClientSpy.swift
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,27 @@ | ||
// | ||
// CheckoutNetworkClientSpy.swift | ||
// | ||
// | ||
// Created by Okhan Okbay on 19/01/2024. | ||
// | ||
|
||
@testable import CheckoutNetwork | ||
|
||
class CheckoutNetworkClientSpy: CheckoutNetworkClient { | ||
private(set) var runRequestCallCount: Int = 0 | ||
private(set) var configuration: RequestConfiguration! | ||
|
||
var expectedResult: FakeObject? | ||
var expectedError: Error? | ||
|
||
override func runRequest<T>(with configuration: RequestConfiguration, completionHandler: @escaping CheckoutNetworkClient.CompletionHandler<T>) where T : Decodable { | ||
runRequestCallCount += 1 | ||
self.configuration = configuration | ||
|
||
if let result = expectedResult { | ||
completionHandler(.success(result as! T)) | ||
} else if let error = expectedError { | ||
completionHandler(.failure(error)) | ||
} | ||
} | ||
} |
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,12 @@ | ||
// | ||
// FakeError.swift | ||
// | ||
// | ||
// Created by Okhan Okbay on 19/01/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
enum FakeError: Error { | ||
case someError | ||
} |