8000 [BWA-155] refactor: Move ConfigAPIService to BitwardenKit by KatherineInCode · Pull Request #1499 · bitwarden/ios · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[BWA-155] refactor: Move ConfigAPIService to BitwardenKit #1499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// A protocol for an API service used to make config requests.
///
public protocol ConfigAPIService {
/// Performs an API request to get the configuration from the backend.
///
func getConfig() async throws -> ConfigResponseModel
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Foundation
import TestHelpers

public extension APITestData {
/// A valid server configuration to produce a `ConfigResponseModel`.
static let validServerConfig = loadFromJsonBundle(
resource: "ValidServerConfig",
bundle: BitwardenKitMocksBundleFinder.bundle
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ public extension APITestData {
bundle: BitwardenKitMocksBundleFinder.bundle
)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import BitwardenKit
import Foundation
import Networking
import TestHelpers

public class MockConfigAPIService: ConfigAPIService {
public var getConfigResult: Result<ConfigResponseModel, Error> =
Result<HTTPResponse, Error>
.httpSuccess(testData: .validServerConfig)
.map { try! ConfigResponseModel(response: $0) } // swiftlint:disable:this force_try

public func getConfig() async throws -> ConfigResponseModel {
try getConfigResult.get()
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
// swiftlint:disable:this file_name

import BitwardenKit
import Networking

/// A protocol for an API service used to make config requests.
///
protocol ConfigAPIService {
/// Performs an API request to get the configuration from the backend.
///
func getConfig() async throws -> ConfigResponseModel
}

extension APIService: ConfigAPIService {
func getConfig() async throws -> ConfigResponseModel {
let isAuthenticated = try? await stateService.isAuthenticated()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BitwardenKit
import XCTest

@testable import BitwardenShared
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import Foundation
import Networking
import TestHelpers

extension Result where Success == HTTPResponse, Error: Error {
public extension Result where Success == HTTPResponse, Error: Error {
/// Convenience method to get a successful HTTPResponse result with APITestData.
static func httpSuccess(testData: APITestData) -> Result<HTTPResponse, Error> {
let response = HTTPResponse.success(
body: testData.data
)
return .success(response)
}

/// Convenience method to get a successful result with a failed HTTPResponse.
static func httpFailure(
statusCode: Int = 500,
headers: [String: String] = [:],
Expand All @@ -23,6 +24,7 @@ extension Result where Success == HTTPResponse, Error: Error {
return .success(response)
}

/// Convenience method to get a failed HTTPResponse result.
static func httpFailure(_ error: Error) -> Result<HTTPResponse, Error> {
.failure(error)
}
Expand Down
0