From a10559db460697bda899c22bf5b2b22b48f7c33e Mon Sep 17 00:00:00 2001 From: Serhii Londar Date: Sun, 15 Oct 2023 17:21:17 +0300 Subject: [PATCH] Fix tests. Add organizationName to all initialisers where needed. --- .../LoginFeature/CrowdinLoginConfig.swift | 9 --------- .../CrowdinSDKConfig+CrowdinProvider.swift | 8 ++++++-- Sources/Tests/Core/CrowdinSDKConfigTests.swift | 8 ++++++-- Sources/Tests/CrowdinAPI/CrowdinAPITests.swift | 2 +- .../CrowdinAPI/CrowdinLoginAPITests.swift | 3 ++- .../CrowdinAPI/DistributionsAPITests.swift | 2 +- .../Tests/CrowdinAPI/LanguagesAPITests.swift | 2 +- .../Tests/CrowdinAPI/ProjectsAPITests.swift | 2 +- .../CrowdinProvider/ManifestManagerTests.swift | 2 +- Tests/Tests.xcodeproj/project.pbxproj | 18 +++++++++--------- Tests/UnitTests/AddErrorHandlersTests.swift | 1 - .../InitializationCompletionHandlerTests.swift | 1 - .../Login/CrowdinLoginConfigTests.swift | 16 +++++++--------- .../Login/CrowdinSDKConfigLoginTests.swift | 6 ++---- 14 files changed, 37 insertions(+), 43 deletions(-) diff --git a/Sources/CrowdinSDK/Features/LoginFeature/CrowdinLoginConfig.swift b/Sources/CrowdinSDK/Features/LoginFeature/CrowdinLoginConfig.swift index 41313766..b67a01b1 100644 --- a/Sources/CrowdinSDK/Features/LoginFeature/CrowdinLoginConfig.swift +++ b/Sources/CrowdinSDK/Features/LoginFeature/CrowdinLoginConfig.swift @@ -24,15 +24,6 @@ private let URLSchemeDocumentationLink = "https://developer.apple.com/documentat try self.init(with: clientId, clientSecret: clientSecret, scope: scope, redirectURI: redirectURI) } - public convenience init(clientId: String, clientSecret: String, scope: String, organizationName: String) throws { - guard let redirectURI = Bundle.main.urlSchemes?.first else { throw NSError(domain: "Application do not support any URL Scheme. To setup it, please check - \(URLSchemeDocumentationLink)", code: defaultCrowdinErrorCode, userInfo: nil) } - try self.init(with: clientId, clientSecret: clientSecret, scope: scope, redirectURI: redirectURI) - } - - public convenience init(clientId: String, clientSecret: String, scope: String, redirectURI: String, organizationName: String) throws { - try self.init(with: clientId, clientSecret: clientSecret, scope: scope, redirectURI: redirectURI) - } - private init(with clientId: String, clientSecret: String, scope: String, redirectURI: String) throws { guard !clientId.isEmpty else { throw NSError(domain: "clientId could not be empty.", code: defaultCrowdinErrorCode, userInfo: nil) } self.clientId = clientId diff --git a/Sources/CrowdinSDK/Providers/Crowdin/Extensions/CrowdinSDKConfig+CrowdinProvider.swift b/Sources/CrowdinSDK/Providers/Crowdin/Extensions/CrowdinSDKConfig+CrowdinProvider.swift index 7c34215a..72efda69 100644 --- a/Sources/CrowdinSDK/Providers/Crowdin/Extensions/CrowdinSDKConfig+CrowdinProvider.swift +++ b/Sources/CrowdinSDK/Providers/Crowdin/Extensions/CrowdinSDKConfig+CrowdinProvider.swift @@ -13,10 +13,10 @@ extension CrowdinSDKConfig { // Realtime updates var crowdinProviderConfig: CrowdinProviderConfig? { get { - return CrowdinSDKConfig.crowdinProviderConfig + return Self.crowdinProviderConfig } set { - CrowdinSDKConfig.crowdinProviderConfig = newValue + Self.crowdinProviderConfig = newValue } } @@ -28,4 +28,8 @@ extension CrowdinSDKConfig { self.crowdinProviderConfig = crowdinProviderConfig return self } + + static func resetStoredConfig() { + Self.crowdinProviderConfig = nil + } } diff --git a/Sources/Tests/Core/CrowdinSDKConfigTests.swift b/Sources/Tests/Core/CrowdinSDKConfigTests.swift index 5dfb084e..6f4fc41a 100644 --- a/Sources/Tests/Core/CrowdinSDKConfigTests.swift +++ b/Sources/Tests/Core/CrowdinSDKConfigTests.swift @@ -2,6 +2,10 @@ import XCTest @testable import CrowdinSDK class CrowdinSDKConfigTests: XCTestCase { + static override func setUp() { + CrowdinSDKConfig.resetStoredConfig() + } + func testConfigInitialization() { let config = CrowdinSDKConfig.config() XCTAssertNil(config.crowdinProviderConfig) @@ -13,12 +17,12 @@ class CrowdinSDKConfigTests: XCTestCase { } func testConfigFalseEnterprise() { - let config = CrowdinSDKConfig.config().with(enterprise: false) + let config = CrowdinSDKConfig.config().with(crowdinProviderConfig: CrowdinProviderConfig(hashString: "hashString", sourceLanguage: "sourceLanguage")) XCTAssert(config.enterprise == false, "Showuldn't be true as default value is false") } func testConfigTrueEnterprise() { - let config = CrowdinSDKConfig.config().with(enterprise: true) + let config = CrowdinSDKConfig.config().with(crowdinProviderConfig: CrowdinProviderConfig(hashString: "hashString", sourceLanguage: "sourceLanguage", organizationName: "organizationName")) XCTAssert(config.enterprise, "Showuld be true as per set-up") } } diff --git a/Sources/Tests/CrowdinAPI/CrowdinAPITests.swift b/Sources/Tests/CrowdinAPI/CrowdinAPITests.swift index 6b2e63ad..76bb382d 100644 --- a/Sources/Tests/CrowdinAPI/CrowdinAPITests.swift +++ b/Sources/Tests/CrowdinAPI/CrowdinAPITests.swift @@ -6,7 +6,7 @@ class CrowdinAPITests: XCTestCase { var api: CrowdinAPI! func testAPIInitialization() { - api = CrowdinAPI() + api = CrowdinAPI(organizationName: nil) XCTAssert(api.baseURL == "https://api.crowdin.com/api/v2/") XCTAssert(api.apiPath == "") diff --git a/Sources/Tests/CrowdinAPI/CrowdinLoginAPITests.swift b/Sources/Tests/CrowdinAPI/CrowdinLoginAPITests.swift index 226b90cc..0f839688 100644 --- a/Sources/Tests/CrowdinAPI/CrowdinLoginAPITests.swift +++ b/Sources/Tests/CrowdinAPI/CrowdinLoginAPITests.swift @@ -23,13 +23,14 @@ class CrowdinLoginAPITests: XCTestCase { } func testLoginAPIInitialization() { - loginAPI = LoginAPI(clientId: "clientId", clientSecret: "clientSecret", scope: "scope", redirectURI: "redirectURI") + loginAPI = LoginAPI(clientId: "clientId", clientSecret: "clientSecret", scope: "scope", redirectURI: "redirectURI", organizationName: nil) XCTAssertNotNil(loginAPI) XCTAssert(loginAPI.clientId == "clientId") XCTAssert(loginAPI.clientSecret == "clientSecret") XCTAssert(loginAPI.scope == "scope") XCTAssert(loginAPI.redirectURI == "redirectURI") + XCTAssert(loginAPI.organizationName == nil) XCTAssertNil(loginAPI.organizationName) } diff --git a/Sources/Tests/CrowdinAPI/DistributionsAPITests.swift b/Sources/Tests/CrowdinAPI/DistributionsAPITests.swift index ffb6822e..86b28c35 100644 --- a/Sources/Tests/CrowdinAPI/DistributionsAPITests.swift +++ b/Sources/Tests/CrowdinAPI/DistributionsAPITests.swift @@ -17,7 +17,7 @@ class DistributionsAPITests: XCTestCase { let defaultTimeoutForExpectation = 2.0 func testAPIInitialization() { - api = DistributionsAPI(hashString: testHashString) + api = DistributionsAPI(hashString: testHashString, organizationName: nil) XCTAssert(api.baseURL == "https://api.crowdin.com/api/v2/") XCTAssert(api.apiPath == "distributions/metadata?hash=\(testHashString)") diff --git a/Sources/Tests/CrowdinAPI/LanguagesAPITests.swift b/Sources/Tests/CrowdinAPI/LanguagesAPITests.swift index bc482ea2..af1b0600 100644 --- a/Sources/Tests/CrowdinAPI/LanguagesAPITests.swift +++ b/Sources/Tests/CrowdinAPI/LanguagesAPITests.swift @@ -17,7 +17,7 @@ class LanguagesAPITests: XCTestCase { var testOrganization = "test_organization" func testAPIInitialization() { - api = LanguagesAPI() + api = LanguagesAPI(organizationName: nil) XCTAssert(api.baseURL == "https://api.crowdin.com/api/v2/") XCTAssert(api.apiPath == "languages") diff --git a/Sources/Tests/CrowdinAPI/ProjectsAPITests.swift b/Sources/Tests/CrowdinAPI/ProjectsAPITests.swift index 2d10f5d7..711a8c1d 100644 --- a/Sources/Tests/CrowdinAPI/ProjectsAPITests.swift +++ b/Sources/Tests/CrowdinAPI/ProjectsAPITests.swift @@ -19,7 +19,7 @@ class ProjectsAPITests: XCTestCase { let defaultTimeoutForExpectation = 2.0 func testAPIInitialization() { - api = ProjectsAPI() + api = ProjectsAPI(organizationName: nil) XCTAssert(api.baseURL == "https://api.crowdin.com/api/v2/") XCTAssert(api.apiPath == "projects") diff --git a/Sources/Tests/CrowdinProvider/ManifestManagerTests.swift b/Sources/Tests/CrowdinProvider/ManifestManagerTests.swift index 1fe03362..df2b0de7 100644 --- a/Sources/Tests/CrowdinProvider/ManifestManagerTests.swift +++ b/Sources/Tests/CrowdinProvider/ManifestManagerTests.swift @@ -18,7 +18,7 @@ class ManifestManagerTests: XCTestCase { func testDownloadManifest() { let expectation = XCTestExpectation(description: "Manifest download expectation") - let manifest = ManifestManager.manifest(for: crowdinTestHash) + let manifest = ManifestManager.manifest(for: crowdinTestHash, organizationName: nil) XCTAssertFalse(manifest.loaded) XCTAssertFalse(manifest.downloaded) diff --git a/Tests/Tests.xcodeproj/project.pbxproj b/Tests/Tests.xcodeproj/project.pbxproj index 5083dc81..6e18d059 100644 --- a/Tests/Tests.xcodeproj/project.pbxproj +++ b/Tests/Tests.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -590,7 +590,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 13.1; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -645,7 +645,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 13.1; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; @@ -664,7 +664,7 @@ DEVELOPMENT_TEAM = 22AFPHX3AU; ENABLE_TESTABILITY = YES; INFOPLIST_FILE = Tests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -685,7 +685,7 @@ DEVELOPMENT_TEAM = 22AFPHX3AU; ENABLE_TESTABILITY = YES; INFOPLIST_FILE = Tests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -707,7 +707,7 @@ DEVELOPMENT_TEAM = 22AFPHX3AU; ENABLE_TESTABILITY = YES; INFOPLIST_FILE = Tests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -731,7 +731,7 @@ DEVELOPMENT_TEAM = 22AFPHX3AU; ENABLE_TESTABILITY = YES; INFOPLIST_FILE = Tests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -754,7 +754,7 @@ DEVELOPMENT_TEAM = 22AFPHX3AU; ENABLE_TESTABILITY = YES; INFOPLIST_FILE = UITests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -777,7 +777,7 @@ DEVELOPMENT_TEAM = 22AFPHX3AU; ENABLE_TESTABILITY = YES; INFOPLIST_FILE = UITests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/Tests/UnitTests/AddErrorHandlersTests.swift b/Tests/UnitTests/AddErrorHandlersTests.swift index d7f77718..86a9b94e 100644 --- a/Tests/UnitTests/AddErrorHandlersTests.swift +++ b/Tests/UnitTests/AddErrorHandlersTests.swift @@ -21,7 +21,6 @@ class AddErrorHandlersTests: XCTestCase { let crowdinProviderConfig = CrowdinProviderConfig(hashString: "wrong_hash", sourceLanguage: "en") let crowdinSDKConfig = CrowdinSDKConfig.config().with(crowdinProviderConfig: crowdinProviderConfig) - .with(enterprise: true) CrowdinSDK.currentLocalization = nil let expectation = XCTestExpectation(description: "Error handler is called") diff --git a/Tests/UnitTests/InitializationCompletionHandlerTests.swift b/Tests/UnitTests/InitializationCompletionHandlerTests.swift index 5efc8949..6882cd00 100644 --- a/Tests/UnitTests/InitializationCompletionHandlerTests.swift +++ b/Tests/UnitTests/InitializationCompletionHandlerTests.swift @@ -22,7 +22,6 @@ class InitializationCompletionHandlerTests: XCTestCase { let crowdinProviderConfig = CrowdinProviderConfig(hashString: "wrong_hash", sourceLanguage: "en") let crowdinSDKConfig = CrowdinSDKConfig.config().with(crowdinProviderConfig: crowdinProviderConfig) - .with(enterprise: true) CrowdinSDK.startWithConfig(crowdinSDKConfig, completion: { XCTAssert(true, "Initialization completion handler called") expectation.fulfill() diff --git a/Tests/UnitTests/Login/CrowdinLoginConfigTests.swift b/Tests/UnitTests/Login/CrowdinLoginConfigTests.swift index 328fc534..c200429c 100644 --- a/Tests/UnitTests/Login/CrowdinLoginConfigTests.swift +++ b/Tests/UnitTests/Login/CrowdinLoginConfigTests.swift @@ -30,58 +30,56 @@ class CrowdinLoginConfigTests: XCTestCase { } func testLoginConfigOrganization() { - loginConfig = try? CrowdinLoginConfig(clientId: "clientId", clientSecret: "clientSecret", scope: "scope", redirectURI: "crowdintest://", organizationName: "organizationName") + loginConfig = try? CrowdinLoginConfig(clientId: "clientId", clientSecret: "clientSecret", scope: "scope", redirectURI: "crowdintest://") XCTAssertNotNil(loginConfig) XCTAssert(loginConfig.clientId == "clientId") XCTAssert(loginConfig.clientSecret == "clientSecret") XCTAssert(loginConfig.scope == "scope") XCTAssert(loginConfig.redirectURI == "crowdintest://") - XCTAssert(loginConfig.organizationName == "organizationName") } func testLoginConfigOrganizationInitWithoutRedirectURI() { - loginConfig = try? CrowdinLoginConfig(clientId: "clientId", clientSecret: "clientSecret", scope: "scope", organizationName: "organizationName") + loginConfig = try? CrowdinLoginConfig(clientId: "clientId", clientSecret: "clientSecret", scope: "scope") XCTAssertNotNil(loginConfig) XCTAssert(loginConfig.clientId == "clientId") XCTAssert(loginConfig.clientSecret == "clientSecret") XCTAssert(loginConfig.scope == "scope") XCTAssert(loginConfig.redirectURI == "crowdintest://") - XCTAssert(loginConfig.organizationName == "organizationName") } func testLoginConfigInitWithEmptyClientId() { do { - loginConfig = try CrowdinLoginConfig(clientId: "", clientSecret: "clientSecret", scope: "scope", redirectURI: "crowdintest://", organizationName: "organizationName") + loginConfig = try CrowdinLoginConfig(clientId: "", clientSecret: "clientSecret", scope: "scope", redirectURI: "crowdintest://") } catch { XCTAssertNotNil(error) } } func testLoginConfigInitWithEmptyClientSecret() { do { - loginConfig = try CrowdinLoginConfig(clientId: "clientId", clientSecret: "", scope: "scope", redirectURI: "crowdintest://", organizationName: "organizationName") + loginConfig = try CrowdinLoginConfig(clientId: "clientId", clientSecret: "", scope: "scope", redirectURI: "crowdintest://") } catch { XCTAssertNotNil(error) } } func testLoginConfigInitWithEmptyScope() { do { - loginConfig = try CrowdinLoginConfig(clientId: "clientId", clientSecret: "clientSecret", scope: "", redirectURI: "crowdintest://", organizationName: "organizationName") + loginConfig = try CrowdinLoginConfig(clientId: "clientId", clientSecret: "clientSecret", scope: "", redirectURI: "crowdintest://") } catch { XCTAssertNotNil(error) } } func testLoginConfigInitWithEmptyRedirectURI() { do { - loginConfig = try CrowdinLoginConfig(clientId: "clientId", clientSecret: "clientSecret", scope: "scope", redirectURI: "", organizationName: "organizationName") + loginConfig = try CrowdinLoginConfig(clientId: "clientId", clientSecret: "clientSecret", scope: "scope", redirectURI: "") } catch { XCTAssertNotNil(error) } } func testLoginConfigInitWithIcorrectRedirectURI() { do { - loginConfig = try CrowdinLoginConfig(clientId: "clientId", clientSecret: "clientSecret", scope: "scope", redirectURI: "crowdintest", organizationName: "organizationName") + loginConfig = try CrowdinLoginConfig(clientId: "clientId", clientSecret: "clientSecret", scope: "scope", redirectURI: "crowdintest") } catch { XCTAssertNotNil(error) } diff --git a/Tests/UnitTests/Login/CrowdinSDKConfigLoginTests.swift b/Tests/UnitTests/Login/CrowdinSDKConfigLoginTests.swift index 41552de1..482322b9 100644 --- a/Tests/UnitTests/Login/CrowdinSDKConfigLoginTests.swift +++ b/Tests/UnitTests/Login/CrowdinSDKConfigLoginTests.swift @@ -14,7 +14,7 @@ class CrowdinSDKConfigLoginTests: XCTestCase { override func setUp() { super.setUp() - guard let loginConfig = try? CrowdinLoginConfig(clientId: "clientId", clientSecret: "clientSecret", scope: "scope", redirectURI: "crowdintest://", organizationName: "organizationName") else { return } + guard let loginConfig = try? CrowdinLoginConfig(clientId: "clientId", clientSecret: "clientSecret", scope: "scope", redirectURI: "crowdintest://") else { return } config = CrowdinSDKConfig.config().with(loginConfig: loginConfig) } @@ -34,7 +34,7 @@ class CrowdinSDKConfigLoginTests: XCTestCase { } func testChangeConfigAfterSetup() { - guard let loginConfig = try? CrowdinLoginConfig(clientId: "clientId1", clientSecret: "clientSecret1", scope: "scope1", redirectURI: "crowdintest://", organizationName: "organizationName1") else { return } + guard let loginConfig = try? CrowdinLoginConfig(clientId: "clientId1", clientSecret: "clientSecret1", scope: "scope1", redirectURI: "crowdintest://") else { return } config.loginConfig = loginConfig XCTAssertNotNil(config.loginConfig) @@ -47,7 +47,5 @@ class CrowdinSDKConfigLoginTests: XCTestCase { XCTAssert(config.loginConfig?.scope == "scope1") XCTAssertNotNil(config.loginConfig?.redirectURI) XCTAssert(config.loginConfig?.redirectURI == "crowdintest://") - XCTAssertNotNil(config.loginConfig?.organizationName) - XCTAssert(config.loginConfig?.organizationName == "organizationName1") } }