Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
Add organizationName to all initialisers where needed.
  • Loading branch information
serhii-londar committed Oct 15, 2023
1 parent de04eb2 commit a10559d
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -28,4 +28,8 @@ extension CrowdinSDKConfig {
self.crowdinProviderConfig = crowdinProviderConfig
return self
}

static func resetStoredConfig() {
Self.crowdinProviderConfig = nil
}
}
8 changes: 6 additions & 2 deletions Sources/Tests/Core/CrowdinSDKConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
}
}
2 changes: 1 addition & 1 deletion Sources/Tests/CrowdinAPI/CrowdinAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "")
Expand Down
3 changes: 2 additions & 1 deletion Sources/Tests/CrowdinAPI/CrowdinLoginAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tests/CrowdinAPI/DistributionsAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tests/CrowdinAPI/LanguagesAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tests/CrowdinAPI/ProjectsAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tests/CrowdinProvider/ManifestManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 9 additions & 9 deletions Tests/Tests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
1 change: 0 additions & 1 deletion Tests/UnitTests/AddErrorHandlersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion Tests/UnitTests/InitializationCompletionHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 7 additions & 9 deletions Tests/UnitTests/Login/CrowdinLoginConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 2 additions & 4 deletions Tests/UnitTests/Login/CrowdinSDKConfigLoginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
Expand All @@ -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")
}
}

0 comments on commit a10559d

Please sign in to comment.