Skip to content

Commit

Permalink
Locate test specific helper code with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlocke committed Dec 14, 2023
1 parent bacab8a commit 21c6e4a
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,37 +144,3 @@ public class SecureStorageAccessDefaultImpl: SecureStorageAccess {
}
}
}

public class SecureStorageAccessTestImpl: SecureStorageAccess {
private var accessTokenData: Data?

public init() {}

public func checkAccessibilityMigrationOneTime() {}

public func setAccessTokenData(for userId: String, data: Data) -> Bool {
accessTokenData = data
return true
}

public func getAllUserIds() -> [String] {
[]
}

public func getDropboxAccessToken(for key: String) -> DropboxAccessToken? {
guard let accessTokenData = accessTokenData else {
return nil
}

let jsonDecoder = JSONDecoder()
return try? jsonDecoder.decode(DropboxAccessToken.self, from: accessTokenData)
}

public func deleteInfo(for key: String) -> Bool {
return true
}

public func deleteInfoForAllKeys() -> Bool {
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,4 @@ public class DBXDropboxOAuthManager: NSObject {
public func accessTokenProviderForToken(_ token: DBXDropboxAccessToken) -> DBXAccessTokenProvider {
swift.accessTokenProviderForToken(token.swift).objc
}

/// Only for use in tests. Resets DropboxOAuthManager so a new one for Team client use can be set up.
@objc
public static func __test_only_resetForTeamSetup() {
DropboxOAuthManager.sharedOAuthManager = nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,11 @@ extension SecureStorageAccessDefaultImpl {
}
}

extension SecureStorageAccessTestImpl {
var objc: DBXSecureStorageAccessTestImpl {
DBXSecureStorageAccessTestImpl(swift: self)
}
}

@objc
public class DBXSecureStorageAccessImpl: NSObject, DBXSecureStorageAccess {
open class DBXSecureStorageAccessImpl: NSObject, DBXSecureStorageAccess {
let swift: SecureStorageAccess

fileprivate init(swift: SecureStorageAccess) {
public init(swift: SecureStorageAccess) {
self.swift = swift
}

Expand Down Expand Up @@ -72,18 +66,6 @@ public class DBXSecureStorageAccessDefaultImpl: DBXSecureStorageAccessImpl {
}
}

@objc
public class DBXSecureStorageAccessTestImpl: DBXSecureStorageAccessImpl {
@objc
public convenience init() {
self.init(swift: SecureStorageAccessTestImpl())
}

fileprivate init(swift: SecureStorageAccessTestImpl) {
super.init(swift: swift)
}
}

extension DBXSecureStorageAccess {
var swift: SecureStorageAccess {
SecureStorageAccessBridge(objc: self)
Expand Down
32 changes: 32 additions & 0 deletions TestSwiftyDropbox/TestSwiftyDropbox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
F907ED4729F32CCF0049A603 /* DebugBackgroundSessionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F907ED4629F32CCF0049A603 /* DebugBackgroundSessionView.swift */; };
F907ED4929F3345B0049A603 /* FileTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F907ED4829F3345B0049A603 /* FileTextView.swift */; };
F907ED4B29F584550049A603 /* FileBrowserView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F907ED4A29F584550049A603 /* FileBrowserView.swift */; };
F91CEDE92B2A95F5009EED11 /* SwiftyDropboxTestExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F95F4B822B2A7F1800C237FB /* SwiftyDropboxTestExtensions.swift */; };
F91CEDEA2B2A95F5009EED11 /* SwiftyDropboxTestExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F95F4B822B2A7F1800C237FB /* SwiftyDropboxTestExtensions.swift */; };
F937A6A828E355DE00A98E99 /* BackgroundSessionTestClasses.swift in Sources */ = {isa = PBXBuildFile; fileRef = F937A6A728E355DE00A98E99 /* BackgroundSessionTestClasses.swift */; };
F937A6A928E355DE00A98E99 /* BackgroundSessionTestClasses.swift in Sources */ = {isa = PBXBuildFile; fileRef = F937A6A728E355DE00A98E99 /* BackgroundSessionTestClasses.swift */; };
F937A6AC28E355DE00A98E99 /* BackgroundSessionTestClasses.swift in Sources */ = {isa = PBXBuildFile; fileRef = F937A6A728E355DE00A98E99 /* BackgroundSessionTestClasses.swift */; };
Expand Down Expand Up @@ -209,6 +211,7 @@
F937A6A728E355DE00A98E99 /* BackgroundSessionTestClasses.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundSessionTestClasses.swift; sourceTree = "<group>"; };
F948416429F6BCF400D0EE7B /* DebugBackgroundSessionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugBackgroundSessionViewModel.swift; sourceTree = "<group>"; };
F949339E265D7ABA005DCA3C /* TeamRoutesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeamRoutesTests.swift; sourceTree = "<group>"; };
F95F4B822B2A7F1800C237FB /* SwiftyDropboxTestExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftyDropboxTestExtensions.swift; sourceTree = "<group>"; };
F975E5ED265702F400A17965 /* TestSwiftyDropbox_iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TestSwiftyDropbox_iOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
F975E5EF265702F400A17965 /* FilesRoutesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilesRoutesTests.swift; sourceTree = "<group>"; };
F975E5F1265702F400A17965 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -465,6 +468,7 @@
F975E5EF265702F400A17965 /* FilesRoutesTests.swift */,
F949339E265D7ABA005DCA3C /* TeamRoutesTests.swift */,
1A2038B128E74BAC00FFF227 /* CustomRoutesTests.swift */,
F95F4B822B2A7F1800C237FB /* SwiftyDropboxTestExtensions.swift */,
1A5E38ED28F62667000DDA19 /* ObjCFilesRoutesTests.h */,
1A5E38EE28F62667000DDA19 /* ObjCFilesRoutesTests.m */,
1AC07D67294D2ADE00ACB584 /* ObjCTeamRoutesTests.h */,
Expand Down Expand Up @@ -1132,6 +1136,7 @@
1AC07D69294D2ADE00ACB584 /* ObjCTeamRoutesTests.m in Sources */,
F975E5F0265702F400A17965 /* FilesRoutesTests.swift in Sources */,
1A2038B228E74BAC00FFF227 /* CustomRoutesTests.swift in Sources */,
F91CEDE92B2A95F5009EED11 /* SwiftyDropboxTestExtensions.swift in Sources */,
1A5E38EF28F62667000DDA19 /* ObjCFilesRoutesTests.m in Sources */,
F949339F265D7ABA005DCA3C /* TeamRoutesTests.swift in Sources */,
F9C66FDE266A5EE50042C899 /* TestTokenAuthGenerator.swift in Sources */,
Expand All @@ -1145,6 +1150,7 @@
1AC07D6A294D2ADE00ACB584 /* ObjCTeamRoutesTests.m in Sources */,
F9B7C82E2672DBD40099E24D /* TeamRoutesTests.swift in Sources */,
1A2038B328E74BAC00FFF227 /* CustomRoutesTests.swift in Sources */,
F91CEDEA2B2A95F5009EED11 /* SwiftyDropboxTestExtensions.swift in Sources */,
1A5E38F028F62667000DDA19 /* ObjCFilesRoutesTests.m in Sources */,
F9B7C82A2672DBD00099E24D /* FilesRoutesTests.swift in Sources */,
F9C67018266A64D40042C899 /* TestTokenAuthGenerator.swift in Sources */,
Expand Down Expand Up @@ -1439,6 +1445,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down Expand Up @@ -1497,6 +1504,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down Expand Up @@ -1527,6 +1535,7 @@
CODE_SIGN_ENTITLEMENTS = TestSwiftyDropbox_iOS/TestSwiftyDropbox.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = NO;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "$(SRCROOT)/TestSwiftyDropbox_iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
Expand All @@ -1549,6 +1558,7 @@
CODE_SIGN_ENTITLEMENTS = TestSwiftyDropbox_iOS/TestSwiftyDropbox.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = NO;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "$(SRCROOT)/TestSwiftyDropbox_iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
Expand All @@ -1570,6 +1580,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = NO;
INFOPLIST_FILE = TestSwiftyDropbox_macOS/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
Expand All @@ -1592,6 +1603,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = NO;
INFOPLIST_FILE = TestSwiftyDropbox_macOS/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
Expand All @@ -1617,6 +1629,11 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
GCC_C_LANGUAGE_STANDARD = gnu11;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"\"${PODS_CONFIGURATION_BUILD_DIR}/SwiftyDropbox-iOS/SwiftyDropbox.framework/Headers\"",
"\"${PODS_CONFIGURATION_BUILD_DIR}/SwiftyDropboxObjC-iOS/SwiftyDropboxObjC.framework/Headers\"",
);
INFOPLIST_FILE = TestSwiftyDropbox_iOSTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.4;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
Expand Down Expand Up @@ -1647,6 +1664,11 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
GCC_C_LANGUAGE_STANDARD = gnu11;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"\"${PODS_CONFIGURATION_BUILD_DIR}/SwiftyDropbox-iOS/SwiftyDropbox.framework/Headers\"",
"\"${PODS_CONFIGURATION_BUILD_DIR}/SwiftyDropboxObjC-iOS/SwiftyDropboxObjC.framework/Headers\"",
);
INFOPLIST_FILE = TestSwiftyDropbox_iOSTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.4;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
Expand Down Expand Up @@ -1675,6 +1697,11 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"\"${PODS_CONFIGURATION_BUILD_DIR}/SwiftyDropbox-macOS/SwiftyDropbox.framework/Headers\"",
"\"${PODS_CONFIGURATION_BUILD_DIR}/SwiftyDropboxObjC-macOS/SwiftyDropboxObjC.framework/Headers\"",
);
INFOPLIST_FILE = TestSwiftyDropbox_macOSTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
Expand Down Expand Up @@ -1706,6 +1733,11 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"\"${PODS_CONFIGURATION_BUILD_DIR}/SwiftyDropbox-macOS/SwiftyDropbox.framework/Headers\"",
"\"${PODS_CONFIGURATION_BUILD_DIR}/SwiftyDropboxObjC-macOS/SwiftyDropboxObjC.framework/Headers\"",
);
INFOPLIST_FILE = TestSwiftyDropbox_macOSTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#import "ObjCFilesRoutesTests.h"
#import "ObjCTestClasses.h"

#if TARGET_OS_IPHONE
#import "TestSwiftyDropbox_iOSTests-Swift.h"
#elif TARGET_OS_MAC
#import "TestSwiftyDropbox_macOSTests-Swift.h"
#endif


@implementation ObjCFilesRoutesTests {
NSOperationQueue *_delegateQueue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#import "ObjCTeamRoutesTests.h"
#import "ObjCTestClasses.h"

#if TARGET_OS_IPHONE
#import "TestSwiftyDropbox_iOSTests-Swift.h"
#elif TARGET_OS_MAC
#import "TestSwiftyDropbox_macOSTests-Swift.h"
#endif

@implementation ObjCTeamRoutesTests {
NSOperationQueue *_delegateQueue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// TestSecureStorageAccess.swift
// TestSwiftyDropbox
//
// Created by jlocke on 12/13/23.
// Copyright © 2023 Dropbox. All rights reserved.
//

import Foundation
import SwiftyDropbox
import SwiftyDropboxObjC

public extension DBXDropboxOAuthManager {
@objc
static func __test_only_resetForTeamSetup() {
DropboxOAuthManager.sharedOAuthManager = nil
}
}

@objc
public class DBXSecureStorageAccessTestImpl: DBXSecureStorageAccessImpl {
@objc
public convenience init() {
self.init(swift: SecureStorageAccessTestImpl())
}

fileprivate init(swift: SecureStorageAccessTestImpl) {
super.init(swift: swift)
}
}

public class SecureStorageAccessTestImpl: SecureStorageAccess {
private var accessTokenData: Data?

public init() {}

public func checkAccessibilityMigrationOneTime() {}

public func setAccessTokenData(for userId: String, data: Data) -> Bool {
accessTokenData = data
return true
}

public func getAllUserIds() -> [String] {
[]
}

public func getDropboxAccessToken(for key: String) -> DropboxAccessToken? {
guard let accessTokenData = accessTokenData else {
return nil
}

let jsonDecoder = JSONDecoder()
return try? jsonDecoder.decode(DropboxAccessToken.self, from: accessTokenData)
}

public func deleteInfo(for key: String) -> Bool {
return true
}

public func deleteInfoForAllKeys() -> Bool {
return true
}
}

0 comments on commit 21c6e4a

Please sign in to comment.