diff --git a/Sources/mas/Commands/Outdated.swift b/Sources/mas/Commands/Outdated.swift index 58d574939..f3b7b567a 100644 --- a/Sources/mas/Commands/Outdated.swift +++ b/Sources/mas/Commands/Outdated.swift @@ -32,7 +32,7 @@ extension MAS { appLibrary.installedApps.map { installedApp in searcher.lookup(appID: installedApp.itemIdentifier.appIDValue) .done { storeApp in - if installedApp.isOutdatedWhenComparedTo(storeApp) { + if installedApp.isOutdated(comparedTo: storeApp) { print( """ \(installedApp.itemIdentifier) \(installedApp.displayName) \ diff --git a/Sources/mas/Commands/Upgrade.swift b/Sources/mas/Commands/Upgrade.swift index a062fd930..417cd2269 100644 --- a/Sources/mas/Commands/Upgrade.swift +++ b/Sources/mas/Commands/Upgrade.swift @@ -81,7 +81,7 @@ extension MAS { // only upgrade apps whose local version differs from the store version searcher.lookup(appID: installedApp.itemIdentifier.appIDValue) .map { storeApp -> (SoftwareProduct, SearchResult)? in - guard installedApp.isOutdatedWhenComparedTo(storeApp) else { + guard installedApp.isOutdated(comparedTo: storeApp) else { return nil } return (installedApp, storeApp) diff --git a/Sources/mas/Controllers/ITunesSearchAppStoreSearcher.swift b/Sources/mas/Controllers/ITunesSearchAppStoreSearcher.swift index f15c1d38a..4a76fc541 100644 --- a/Sources/mas/Controllers/ITunesSearchAppStoreSearcher.swift +++ b/Sources/mas/Controllers/ITunesSearchAppStoreSearcher.swift @@ -14,7 +14,7 @@ import Version /// Manages searching the MAS catalog. Uses the iTunes Search and Lookup APIs: /// https://performance-partners.apple.com/search-api struct ITunesSearchAppStoreSearcher: AppStoreSearcher { - private static let appVersionExpression = Regex(#"\"versionDisplay\"\:\"([^\"]+)\""#) + private static let appVersionRegex = Regex(#""versionDisplay":"([^"]+)""#) private let networkManager: NetworkManager @@ -119,7 +119,7 @@ struct ITunesSearchAppStoreSearcher: AppStoreSearcher { .map { data in guard let html = String(data: data, encoding: .utf8), - let capture = Self.appVersionExpression.firstMatch(in: html)?.captures[0], + let capture = Self.appVersionRegex.firstMatch(in: html)?.captures[0], let version = Version(tolerant: capture) else { return nil diff --git a/Sources/mas/Errors/MASError.swift b/Sources/mas/Errors/MASError.swift index 3c6ebfc84..c095934e5 100644 --- a/Sources/mas/Errors/MASError.swift +++ b/Sources/mas/Errors/MASError.swift @@ -37,7 +37,7 @@ enum MASError: Error, Equatable { case macOSUserMustBeRoot case noData - case jsonParsing(data: Data?) + case jsonParsing(data: Data) } // MARK: - CustomStringConvertible @@ -102,13 +102,10 @@ extension MASError: CustomStringConvertible { case .noData: return "Service did not return data" case .jsonParsing(let data): - if let data { - if let unparsable = String(data: data, encoding: .utf8) { - return "Unable to parse response as JSON: \n\(unparsable)" - } - return "Received defective response" + if let unparsable = String(data: data, encoding: .utf8) { + return "Unable to parse response as JSON:\n\(unparsable)" } - return "Received empty response" + return "Received defective response" } } } diff --git a/Sources/mas/Models/SearchResult.swift b/Sources/mas/Models/SearchResult.swift index ffc5f5045..c11382070 100644 --- a/Sources/mas/Models/SearchResult.swift +++ b/Sources/mas/Models/SearchResult.swift @@ -21,6 +21,6 @@ struct SearchResult: Decodable { extension SearchResult { var displayPrice: String { - formattedPrice ?? "Unknown" + formattedPrice ?? "?" } } diff --git a/Sources/mas/Models/SoftwareProduct.swift b/Sources/mas/Models/SoftwareProduct.swift index b244dae96..5bca4754f 100644 --- a/Sources/mas/Models/SoftwareProduct.swift +++ b/Sources/mas/Models/SoftwareProduct.swift @@ -34,7 +34,7 @@ extension SoftwareProduct { /// /// - Parameter storeApp: App from search result. /// - Returns: true if the app is outdated; false otherwise. - func isOutdatedWhenComparedTo(_ storeApp: SearchResult) -> Bool { + func isOutdated(comparedTo storeApp: SearchResult) -> Bool { // If storeApp requires a version of macOS newer than the running version, do not consider self outdated. if let osVersion = Version(tolerant: storeApp.minimumOsVersion) { let requiredVersion = OperatingSystemVersion( diff --git a/Tests/masTests/Controllers/ITunesSearchAppStoreSearcherSpec.swift b/Tests/masTests/Controllers/ITunesSearchAppStoreSearcherSpec.swift index 4734753c4..3107aa2ea 100644 --- a/Tests/masTests/Controllers/ITunesSearchAppStoreSearcherSpec.swift +++ b/Tests/masTests/Controllers/ITunesSearchAppStoreSearcherSpec.swift @@ -60,14 +60,10 @@ public class ITunesSearchAppStoreSearcherSpec: QuickSpec { let searcher = ITunesSearchAppStoreSearcher(networkManager: NetworkManager(session: networkSession)) var result: SearchResult? - do { + expect { result = try searcher.lookup(appID: appID).wait() - } catch { - let maserror = error as! MASError - if case .jsonParsing(let nserror) = maserror { - fail("\(maserror) \(nserror!)") - } } + .toNot(throwError()) guard let result else { fatalError("lookup result was nil") diff --git a/Tests/masTests/Errors/MASErrorTestCase.swift b/Tests/masTests/Errors/MASErrorTestCase.swift index a1a918010..4959b8746 100644 --- a/Tests/masTests/Errors/MASErrorTestCase.swift +++ b/Tests/masTests/Errors/MASErrorTestCase.swift @@ -87,6 +87,6 @@ class MASErrorTestCase: XCTestCase { } func testJsonParsing() { - XCTAssertEqual(MASError.jsonParsing(data: nil).description, "Received empty response") + XCTAssertEqual(MASError.jsonParsing(data: Data()).description, "Unable to parse response as JSON:\n") } } diff --git a/Tests/masTests/Models/SoftwareProductSpec.swift b/Tests/masTests/Models/SoftwareProductSpec.swift index cd5e15a65..c8e81cde7 100644 --- a/Tests/masTests/Models/SoftwareProductSpec.swift +++ b/Tests/masTests/Models/SoftwareProductSpec.swift @@ -32,16 +32,16 @@ public class SoftwareProductSpec: QuickSpec { let updateIos = SearchResult(minimumOsVersion: "99.0.0", version: "3.0.0") it("is not outdated when there is no new version available") { - expect(app.isOutdatedWhenComparedTo(currentApp)) == false + expect(app.isOutdated(comparedTo: currentApp)) == false } it("is outdated when there is a new version available") { - expect(app.isOutdatedWhenComparedTo(appUpdate)) == true + expect(app.isOutdated(comparedTo: appUpdate)) == true } it("is not outdated when the new version of mac-software requires a higher OS version") { - expect(app.isOutdatedWhenComparedTo(higherOs)) == false + expect(app.isOutdated(comparedTo: higherOs)) == false } it("is not outdated when the new version of software requires a higher OS version") { - expect(app.isOutdatedWhenComparedTo(updateIos)) == false + expect(app.isOutdated(comparedTo: updateIos)) == false } } }