Skip to content

Commit

Permalink
Enable mock api clients too (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlocke authored Dec 16, 2023
1 parent 4b66501 commit 49533dd
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Source/SwiftyDropbox/Shared/Generated/Base.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import Foundation

public class DropboxBase {
public class DropboxBase: DropboxTransportClientOwning {
public var client: DropboxTransportClient

/// Routes within the account namespace. See AccountRoutes for details.
Expand Down Expand Up @@ -34,7 +34,7 @@ public class DropboxBase {
/// Routes within the users namespace. See UsersRoutes for details.
public var users: UsersRoutes!

public init(client: DropboxTransportClient) {
public required init(client: DropboxTransportClient) {
self.client = client

self.account = AccountRoutes(client: client)
Expand Down
4 changes: 2 additions & 2 deletions Source/SwiftyDropbox/Shared/Generated/BaseApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

import Foundation

public class DropboxAppBase {
public class DropboxAppBase: DropboxTransportClientOwning {
public var client: DropboxTransportClient

/// Routes within the auth namespace. See AuthAppAuthRoutes for details.
public var auth: AuthAppAuthRoutes!
/// Routes within the check namespace. See CheckAppAuthRoutes for details.
public var check: CheckAppAuthRoutes!

public init(client: DropboxTransportClient) {
public required init(client: DropboxTransportClient) {
self.client = client

self.auth = AuthAppAuthRoutes(client: client)
Expand Down
4 changes: 2 additions & 2 deletions Source/SwiftyDropbox/Shared/Generated/BaseTeam.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import Foundation

public class DropboxTeamBase {
public class DropboxTeamBase: DropboxTransportClientOwning {
public var client: DropboxTransportClient

/// Routes within the team namespace. See TeamRoutes for details.
public var team: TeamRoutes!

public init(client: DropboxTransportClient) {
public required init(client: DropboxTransportClient) {
self.client = client

self.team = TeamRoutes(client: client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ public class DropboxAppClient: DropboxAppBase {
self.transportClient = transportClient
super.init(client: transportClient)
}

/// Initializer used by DropboxTransportClientOwning in tests.
///
/// - Parameter client: The underlying DropboxTransportClient to make API calls.
required convenience init(client: DropboxTransportClient) {
self.init(transportClient: client)
}

}
7 changes: 7 additions & 0 deletions Source/SwiftyDropbox/Shared/Handwritten/DropboxClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ public class DropboxClient: DropboxBase {
super.init(client: transportClient)
}

/// Initializer used by DropboxTransportClientOwning in tests.
///
/// - Parameter client: The underlying DropboxTransportClient to make API calls.
required convenience init(client: DropboxTransportClient) {
self.init(transportClient: client)
}

/// Creates a new DropboxClient instance with the given path root.
///
/// - Parameter pathRoot: User's path root.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public class DropboxTeamClient: DropboxTeamBase {
super.init(client: transportClient)
}

/// Initializer used by DropboxTransportClientOwning in tests.
///
/// - Parameter client: The underlying DropboxTransportClient to make API calls.
required convenience init(client: DropboxTransportClient) {
self.init(transportClient: client)
}

/// Creates a new DropboxClient instance for the team member id.
///
/// - Parameter memberId: Team member id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protocol JSONRepresentable {
}

enum MockingUtilities {
static func makeRoutesObject<T: DropboxTransportClientOwning>(forType: T.Type) -> (T, MockDropboxTransportClient) {
static func makeMock<T: DropboxTransportClientOwning>(forType: T.Type) -> (T, MockDropboxTransportClient) {
let mockTransportClient = MockDropboxTransportClient()
let namespaceObject = T(client: mockTransportClient)
return (namespaceObject, mockTransportClient)
Expand Down
6 changes: 3 additions & 3 deletions Source/SwiftyDropboxUnitTests/TestMockingUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class TestMockingUtilities: XCTestCase {
func testExampleModel() throws {
let e = expectation(description: "webservice closure called")

let (filesRoutes, mockTransportClient) = MockingUtilities.makeRoutesObject(forType: FilesRoutes.self)
let (filesRoutes, mockTransportClient) = MockingUtilities.makeMock(forType: FilesRoutes.self)
let webService = ExampleWebService(routes: filesRoutes)

webService.getMetadata { result, _ in
Expand All @@ -30,7 +30,7 @@ final class TestMockingUtilities: XCTestCase {
func testExampleJsonFixture() throws {
let e = expectation(description: "webservice closure called")

let (filesRoutes, mockTransportClient) = MockingUtilities.makeRoutesObject(forType: FilesRoutes.self)
let (filesRoutes, mockTransportClient) = MockingUtilities.makeMock(forType: FilesRoutes.self)
let webService = ExampleWebService(routes: filesRoutes)

webService.getMetadata { result, _ in
Expand Down Expand Up @@ -59,7 +59,7 @@ final class TestMockingUtilities: XCTestCase {
func testExampleError() throws {
let e = expectation(description: "webservice closure called")

let (filesRoutes, mockTransportClient) = MockingUtilities.makeRoutesObject(forType: FilesRoutes.self)
let (filesRoutes, mockTransportClient) = MockingUtilities.makeMock(forType: FilesRoutes.self)
let webService = ExampleWebService(routes: filesRoutes)

webService.getMetadata { _, error in
Expand Down
2 changes: 1 addition & 1 deletion stone

0 comments on commit 49533dd

Please sign in to comment.