Skip to content
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

Updated to Swift 5.0 #28

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
updates unit tests
  • Loading branch information
svenbacia committed Sep 2, 2018
commit 4ae6ae9fd5d62bcbcae2f259b249b8dacd00303a
66 changes: 21 additions & 45 deletions Tests/iTunesSearchAPITests/iTunesSearchAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ class iTunesSearchAPITests: XCTestCase {
let task = client.search(for: "Suits") { _ in }
task?.resume()

XCTAssertEqual(session.completedURLs.first!.absoluteString, "https://itunes.apple.com/search?term=Suits&media=all")
XCTAssertTrue(session.completedURLs.first!.absoluteString.starts(with: "https://itunes.apple.com/search?"))

let components = URLComponents(url: session.completedURLs[0], resolvingAgainstBaseURL: false)!
let queryItems = components.queryItems!
XCTAssertEqual(2, queryItems.count)
XCTAssertEqual(queryItems.first(where: { $0.name == "term" })!.value!, "Suits")
XCTAssertEqual(queryItems.first(where: { $0.name == "media" })!.value!, "all")
}

func testSearchWithOptions() {
Expand All @@ -39,7 +45,14 @@ class iTunesSearchAPITests: XCTestCase {
let task = client.search(for: "Suits", options: Options(country: .germany), completion: { _ in })
task?.resume()

XCTAssertEqual(session.completedURLs.first!.absoluteString, "https://itunes.apple.com/search?country=de&term=Suits&media=all")
XCTAssertTrue(session.completedURLs.first!.absoluteString.starts(with: "https://itunes.apple.com/search?"))

let components = URLComponents(url: session.completedURLs[0], resolvingAgainstBaseURL: false)!
let queryItems = components.queryItems!
XCTAssertEqual(3, queryItems.count)
XCTAssertEqual(queryItems.first(where: { $0.name == "term" })!.value!, "Suits")
XCTAssertEqual(queryItems.first(where: { $0.name == "media" })!.value!, "all")
XCTAssertEqual(queryItems.first(where: { $0.name == "country" })!.value!, "de")
}

func testBasicLookupByID() {
Expand All @@ -59,49 +72,12 @@ class iTunesSearchAPITests: XCTestCase {
let task = client.lookup(by: .id("909253"), options: Options(country: .germany)) { _ in }
task?.resume()

XCTAssertEqual(session.completedURLs.first!.absoluteString, "https://itunes.apple.com/lookup?id=909253&country=de")
}

func testSearch_withServerIssue() {
let session = FakeURLSession.serverIssue

let client = iTunes(session: session, debug: true)
let task = client.search(for: "Suits") { _ in }
task?.resume()

XCTAssertEqual(session.completedURLs.first!.absoluteString, "https://itunes.apple.com/search?term=Suits&media=all")
}

func testSearch_withUnknownResponse() {
let session = FakeURLSession.invalidResponse

let client = iTunes(session: session, debug: true)
let task = client.search(for: "Suits") { _ in }
task?.resume()

XCTAssertEqual(session.completedURLs.first!.absoluteString, "https://itunes.apple.com/search?term=Suits&media=all")
}

func testSearch_withInvalidJSON() {
let session = FakeURLSession.invalidJSON

let client = iTunes(session: session, debug: true)
let task = client.search(for: "Suits") { _ in }
task?.resume()

XCTAssertEqual(session.completedURLs.first!.absoluteString, "https://itunes.apple.com/search?term=Suits&media=all")
}

func testSearch_withMissingData() {
let session = FakeURLSession { (url) -> (iTunes.Result<(Data?, URLResponse?), iTunes.Error>) in
let response = HTTPURLResponse(url: url, statusCode: 200, httpVersion: nil, headerFields: nil)
return (iTunes.Result.success((nil, response)))
}

let client = iTunes(session: session, debug: true)
let task = client.search(for: "Suits") { _ in }
task?.resume()
XCTAssertTrue(session.completedURLs.first!.absoluteString.starts(with: "https://itunes.apple.com/lookup?"))

XCTAssertEqual(session.completedURLs.first!.absoluteString, "https://itunes.apple.com/search?term=Suits&media=all")
let components = URLComponents(url: session.completedURLs[0], resolvingAgainstBaseURL: false)!
let queryItems = components.queryItems!
XCTAssertEqual(2, queryItems.count)
XCTAssertEqual(queryItems.first(where: { $0.name == "id" })!.value!, "909253")
XCTAssertEqual(queryItems.first(where: { $0.name == "country" })!.value!, "de")
}
}
18 changes: 8 additions & 10 deletions iTunesSearchAPI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0900;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = "Sven Bacia";
TargetAttributes = {
260CBEDA1F93EF7500E4D15F = {
Expand Down Expand Up @@ -502,7 +502,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -615,7 +615,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 10.0;
};
Expand All @@ -639,7 +638,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 10.0;
};
Expand All @@ -657,7 +655,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.svenbacia.iTunesSearchAPITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -674,7 +671,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -697,7 +693,6 @@
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -720,7 +715,6 @@
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -741,7 +735,6 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -765,7 +758,6 @@
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -784,12 +776,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -823,6 +817,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -842,12 +837,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand All @@ -873,6 +870,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,9 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -57,7 +56,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,9 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -57,7 +56,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down