Rename *StoreSearch as *AppStoreSearcher.

Rename `MasStoreSearch` as `ITunesSearchAppStoreSearcher`.

Rename `StoreSearchMock` as `MockAppStoreSearcher`.

Rename variables/parameters of the above types as `searcher`.

Fix 'App Store.app' mention in help.

Partial #585

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
This commit is contained in:
Ross Goldberg 2024-10-25 20:29:17 -04:00
parent ab22e22ace
commit d7072fc66d
No known key found for this signature in database
21 changed files with 79 additions and 79 deletions

View file

@ -21,12 +21,12 @@ extension MAS {
/// Runs the command. /// Runs the command.
func run() throws { func run() throws {
try run(storeSearch: MasStoreSearch(), openCommand: OpenSystemCommand()) try run(searcher: ITunesSearchAppStoreSearcher(), openCommand: OpenSystemCommand())
} }
func run(storeSearch: StoreSearch, openCommand: ExternalCommand) throws { func run(searcher: AppStoreSearcher, openCommand: ExternalCommand) throws {
do { do {
guard let result = try storeSearch.lookup(appID: appID).wait() else { guard let result = try searcher.lookup(appID: appID).wait() else {
throw MASError.noSearchResultsFound throw MASError.noSearchResultsFound
} }

View file

@ -22,12 +22,12 @@ extension MAS {
/// Runs the command. /// Runs the command.
func run() throws { func run() throws {
try run(storeSearch: MasStoreSearch()) try run(searcher: ITunesSearchAppStoreSearcher())
} }
func run(storeSearch: StoreSearch) throws { func run(searcher: AppStoreSearcher) throws {
do { do {
guard let result = try storeSearch.lookup(appID: appID).wait() else { guard let result = try searcher.lookup(appID: appID).wait() else {
throw MASError.noSearchResultsFound throw MASError.noSearchResultsFound
} }

View file

@ -25,14 +25,14 @@ extension MAS {
/// Runs the command. /// Runs the command.
func run() throws { func run() throws {
try run(appLibrary: MasAppLibrary(), storeSearch: MasStoreSearch()) try run(appLibrary: MasAppLibrary(), searcher: ITunesSearchAppStoreSearcher())
} }
func run(appLibrary: AppLibrary, storeSearch: StoreSearch) throws { func run(appLibrary: AppLibrary, searcher: AppStoreSearcher) throws {
var appID: AppID? var appID: AppID?
do { do {
let results = try storeSearch.search(for: searchTerm).wait() let results = try searcher.search(for: searchTerm).wait()
guard let result = results.first else { guard let result = results.first else {
printError("No results found") printError("No results found")
throw MASError.noSearchResultsFound throw MASError.noSearchResultsFound

View file

@ -16,7 +16,7 @@ extension MAS {
/// https://performance-partners.apple.com/search-api /// https://performance-partners.apple.com/search-api
struct Open: ParsableCommand { struct Open: ParsableCommand {
static let configuration = CommandConfiguration( static let configuration = CommandConfiguration(
abstract: "Opens app page in AppStore.app" abstract: "Opens app page in 'App Store.app'"
) )
@Argument(help: "the app ID") @Argument(help: "the app ID")
@ -24,10 +24,10 @@ extension MAS {
/// Runs the command. /// Runs the command.
func run() throws { func run() throws {
try run(storeSearch: MasStoreSearch(), openCommand: OpenSystemCommand()) try run(searcher: ITunesSearchAppStoreSearcher(), openCommand: OpenSystemCommand())
} }
func run(storeSearch: StoreSearch, openCommand: ExternalCommand) throws { func run(searcher: AppStoreSearcher, openCommand: ExternalCommand) throws {
do { do {
guard let appID else { guard let appID else {
// If no app ID is given, just open the MAS GUI app // If no app ID is given, just open the MAS GUI app
@ -35,7 +35,7 @@ extension MAS {
return return
} }
guard let result = try storeSearch.lookup(appID: appID).wait() else { guard let result = try searcher.lookup(appID: appID).wait() else {
throw MASError.noSearchResultsFound throw MASError.noSearchResultsFound
} }

View file

@ -23,15 +23,15 @@ extension MAS {
/// Runs the command. /// Runs the command.
func run() throws { func run() throws {
try run(appLibrary: MasAppLibrary(), storeSearch: MasStoreSearch()) try run(appLibrary: MasAppLibrary(), searcher: ITunesSearchAppStoreSearcher())
} }
func run(appLibrary: AppLibrary, storeSearch: StoreSearch) throws { func run(appLibrary: AppLibrary, searcher: AppStoreSearcher) throws {
_ = try when( _ = try when(
fulfilled: fulfilled:
appLibrary.installedApps.map { installedApp in appLibrary.installedApps.map { installedApp in
firstly { firstly {
storeSearch.lookup(appID: installedApp.itemIdentifier.appIDValue) searcher.lookup(appID: installedApp.itemIdentifier.appIDValue)
} }
.done { storeApp in .done { storeApp in
guard let storeApp else { guard let storeApp else {

View file

@ -23,12 +23,12 @@ extension MAS {
var searchTerm: String var searchTerm: String
func run() throws { func run() throws {
try run(storeSearch: MasStoreSearch()) try run(searcher: ITunesSearchAppStoreSearcher())
} }
func run(storeSearch: StoreSearch) throws { func run(searcher: AppStoreSearcher) throws {
do { do {
let results = try storeSearch.search(for: searchTerm).wait() let results = try searcher.search(for: searchTerm).wait()
if results.isEmpty { if results.isEmpty {
throw MASError.noSearchResultsFound throw MASError.noSearchResultsFound
} }

View file

@ -22,13 +22,13 @@ extension MAS {
/// Runs the command. /// Runs the command.
func run() throws { func run() throws {
try run(appLibrary: MasAppLibrary(), storeSearch: MasStoreSearch()) try run(appLibrary: MasAppLibrary(), searcher: ITunesSearchAppStoreSearcher())
} }
func run(appLibrary: AppLibrary, storeSearch: StoreSearch) throws { func run(appLibrary: AppLibrary, searcher: AppStoreSearcher) throws {
let apps: [(installedApp: SoftwareProduct, storeApp: SearchResult)] let apps: [(installedApp: SoftwareProduct, storeApp: SearchResult)]
do { do {
apps = try findOutdatedApps(appLibrary: appLibrary, storeSearch: storeSearch) apps = try findOutdatedApps(appLibrary: appLibrary, searcher: searcher)
} catch { } catch {
throw error as? MASError ?? .searchFailed throw error as? MASError ?? .searchFailed
} }
@ -53,7 +53,7 @@ extension MAS {
private func findOutdatedApps( private func findOutdatedApps(
appLibrary: AppLibrary, appLibrary: AppLibrary,
storeSearch: StoreSearch searcher: AppStoreSearcher
) throws -> [(SoftwareProduct, SearchResult)] { ) throws -> [(SoftwareProduct, SearchResult)] {
let apps = let apps =
appIDs.isEmpty appIDs.isEmpty
@ -71,7 +71,7 @@ extension MAS {
let promises = apps.map { installedApp in let promises = apps.map { installedApp in
// only upgrade apps whose local version differs from the store version // only upgrade apps whose local version differs from the store version
firstly { firstly {
storeSearch.lookup(appID: installedApp.itemIdentifier.appIDValue) searcher.lookup(appID: installedApp.itemIdentifier.appIDValue)
} }
.map { result -> (SoftwareProduct, SearchResult)? in .map { result -> (SoftwareProduct, SearchResult)? in
guard let storeApp = result, installedApp.isOutdatedWhenComparedTo(storeApp) else { guard let storeApp = result, installedApp.isOutdatedWhenComparedTo(storeApp) else {

View file

@ -21,12 +21,12 @@ extension MAS {
/// Runs the command. /// Runs the command.
func run() throws { func run() throws {
try run(storeSearch: MasStoreSearch(), openCommand: OpenSystemCommand()) try run(searcher: ITunesSearchAppStoreSearcher(), openCommand: OpenSystemCommand())
} }
func run(storeSearch: StoreSearch, openCommand: ExternalCommand) throws { func run(searcher: AppStoreSearcher, openCommand: ExternalCommand) throws {
do { do {
guard let result = try storeSearch.lookup(appID: appID).wait() else { guard let result = try searcher.lookup(appID: appID).wait() else {
throw MASError.noSearchResultsFound throw MASError.noSearchResultsFound
} }

View file

@ -1,5 +1,5 @@
// //
// StoreSearch.swift // AppStoreSearcher.swift
// mas // mas
// //
// Created by Ben Chatelain on 12/29/18. // Created by Ben Chatelain on 12/29/18.
@ -10,7 +10,7 @@ import Foundation
import PromiseKit import PromiseKit
/// Protocol for searching the MAS catalog. /// Protocol for searching the MAS catalog.
protocol StoreSearch { protocol AppStoreSearcher {
func lookup(appID: AppID) -> Promise<SearchResult?> func lookup(appID: AppID) -> Promise<SearchResult?>
func search(for searchTerm: String) -> Promise<[SearchResult]> func search(for searchTerm: String) -> Promise<[SearchResult]>
} }
@ -37,7 +37,7 @@ private enum URLAction {
} }
// MARK: - Common methods // MARK: - Common methods
extension StoreSearch { extension AppStoreSearcher {
/// Builds the search URL for an app. /// Builds the search URL for an app.
/// ///
/// - Parameters: /// - Parameters:

View file

@ -1,5 +1,5 @@
// //
// MasStoreSearch.swift // ITunesSearchAppStoreSearcher.swift
// mas // mas
// //
// Created by Ben Chatelain on 12/29/18. // Created by Ben Chatelain on 12/29/18.
@ -12,7 +12,7 @@ import Regex
import Version import Version
/// Manages searching the MAS catalog through the iTunes Search and Lookup APIs. /// Manages searching the MAS catalog through the iTunes Search and Lookup APIs.
class MasStoreSearch: StoreSearch { class ITunesSearchAppStoreSearcher: AppStoreSearcher {
private static let appVersionExpression = Regex(#"\"versionDisplay\"\:\"([^\"]+)\""#) private static let appVersionExpression = Regex(#"\"versionDisplay\"\:\"([^\"]+)\""#)
// CommerceKit and StoreFoundation don't seem to expose the region of the Apple ID signed // CommerceKit and StoreFoundation don't seem to expose the region of the Apple ID signed

View file

@ -13,7 +13,7 @@ import Quick
public class HomeSpec: QuickSpec { public class HomeSpec: QuickSpec {
override public func spec() { override public func spec() {
let storeSearch = StoreSearchMock() let searcher = MockAppStoreSearcher()
let openCommand = OpenSystemCommandMock() let openCommand = OpenSystemCommandMock()
beforeSuite { beforeSuite {
@ -21,17 +21,17 @@ public class HomeSpec: QuickSpec {
} }
describe("home command") { describe("home command") {
beforeEach { beforeEach {
storeSearch.reset() searcher.reset()
} }
it("fails to open app with invalid ID") { it("fails to open app with invalid ID") {
expect { expect {
try MAS.Home.parse(["--", "-999"]).run(storeSearch: storeSearch, openCommand: openCommand) try MAS.Home.parse(["--", "-999"]).run(searcher: searcher, openCommand: openCommand)
} }
.to(throwError()) .to(throwError())
} }
it("can't find app with unknown ID") { it("can't find app with unknown ID") {
expect { expect {
try MAS.Home.parse(["999"]).run(storeSearch: storeSearch, openCommand: openCommand) try MAS.Home.parse(["999"]).run(searcher: searcher, openCommand: openCommand)
} }
.to(throwError(MASError.noSearchResultsFound)) .to(throwError(MASError.noSearchResultsFound))
} }
@ -41,10 +41,10 @@ public class HomeSpec: QuickSpec {
trackViewUrl: "mas preview url", trackViewUrl: "mas preview url",
version: "0.0" version: "0.0"
) )
storeSearch.apps[mockResult.trackId] = mockResult searcher.apps[mockResult.trackId] = mockResult
expect { expect {
try MAS.Home.parse([String(mockResult.trackId)]) try MAS.Home.parse([String(mockResult.trackId)])
.run(storeSearch: storeSearch, openCommand: openCommand) .run(searcher: searcher, openCommand: openCommand)
return openCommand.arguments return openCommand.arguments
} }
== [mockResult.trackViewUrl] == [mockResult.trackViewUrl]

View file

@ -14,24 +14,24 @@ import Quick
public class InfoSpec: QuickSpec { public class InfoSpec: QuickSpec {
override public func spec() { override public func spec() {
let storeSearch = StoreSearchMock() let searcher = MockAppStoreSearcher()
beforeSuite { beforeSuite {
MAS.initialize() MAS.initialize()
} }
describe("Info command") { describe("Info command") {
beforeEach { beforeEach {
storeSearch.reset() searcher.reset()
} }
it("fails to open app with invalid ID") { it("fails to open app with invalid ID") {
expect { expect {
try MAS.Info.parse(["--", "-999"]).run(storeSearch: storeSearch) try MAS.Info.parse(["--", "-999"]).run(searcher: searcher)
} }
.to(throwError()) .to(throwError())
} }
it("can't find app with unknown ID") { it("can't find app with unknown ID") {
expect { expect {
try MAS.Info.parse(["999"]).run(storeSearch: storeSearch) try MAS.Info.parse(["999"]).run(searcher: searcher)
} }
.to(throwError(MASError.noSearchResultsFound)) .to(throwError(MASError.noSearchResultsFound))
} }
@ -47,10 +47,10 @@ public class InfoSpec: QuickSpec {
trackViewUrl: "https://awesome.app", trackViewUrl: "https://awesome.app",
version: "1.0" version: "1.0"
) )
storeSearch.apps[mockResult.trackId] = mockResult searcher.apps[mockResult.trackId] = mockResult
expect { expect {
try captureStream(stdout) { try captureStream(stdout) {
try MAS.Info.parse([String(mockResult.trackId)]).run(storeSearch: storeSearch) try MAS.Info.parse([String(mockResult.trackId)]).run(searcher: searcher)
} }
} }
== """ == """

View file

@ -14,7 +14,7 @@ import Quick
public class LuckySpec: QuickSpec { public class LuckySpec: QuickSpec {
override public func spec() { override public func spec() {
let networkSession = NetworkSessionMockFromFile(responseFile: "search/slack.json") let networkSession = NetworkSessionMockFromFile(responseFile: "search/slack.json")
let storeSearch = MasStoreSearch(networkManager: NetworkManager(session: networkSession)) let searcher = ITunesSearchAppStoreSearcher(networkManager: NetworkManager(session: networkSession))
beforeSuite { beforeSuite {
MAS.initialize() MAS.initialize()
@ -22,7 +22,7 @@ public class LuckySpec: QuickSpec {
xdescribe("lucky command") { xdescribe("lucky command") {
xit("installs the first app matching a search") { xit("installs the first app matching a search") {
expect { expect {
try MAS.Lucky.parse(["Slack"]).run(appLibrary: AppLibraryMock(), storeSearch: storeSearch) try MAS.Lucky.parse(["Slack"]).run(appLibrary: AppLibraryMock(), searcher: searcher)
} }
.toNot(throwError()) .toNot(throwError())
} }

View file

@ -14,7 +14,7 @@ import Quick
public class OpenSpec: QuickSpec { public class OpenSpec: QuickSpec {
override public func spec() { override public func spec() {
let storeSearch = StoreSearchMock() let searcher = MockAppStoreSearcher()
let openCommand = OpenSystemCommandMock() let openCommand = OpenSystemCommandMock()
beforeSuite { beforeSuite {
@ -22,17 +22,17 @@ public class OpenSpec: QuickSpec {
} }
describe("open command") { describe("open command") {
beforeEach { beforeEach {
storeSearch.reset() searcher.reset()
} }
it("fails to open app with invalid ID") { it("fails to open app with invalid ID") {
expect { expect {
try MAS.Open.parse(["--", "-999"]).run(storeSearch: storeSearch, openCommand: openCommand) try MAS.Open.parse(["--", "-999"]).run(searcher: searcher, openCommand: openCommand)
} }
.to(throwError()) .to(throwError())
} }
it("can't find app with unknown ID") { it("can't find app with unknown ID") {
expect { expect {
try MAS.Open.parse(["999"]).run(storeSearch: storeSearch, openCommand: openCommand) try MAS.Open.parse(["999"]).run(searcher: searcher, openCommand: openCommand)
} }
.to(throwError(MASError.noSearchResultsFound)) .to(throwError(MASError.noSearchResultsFound))
} }
@ -42,17 +42,17 @@ public class OpenSpec: QuickSpec {
trackViewUrl: "fakescheme://some/url", trackViewUrl: "fakescheme://some/url",
version: "0.0" version: "0.0"
) )
storeSearch.apps[mockResult.trackId] = mockResult searcher.apps[mockResult.trackId] = mockResult
expect { expect {
try MAS.Open.parse([mockResult.trackId.description]) try MAS.Open.parse([mockResult.trackId.description])
.run(storeSearch: storeSearch, openCommand: openCommand) .run(searcher: searcher, openCommand: openCommand)
return openCommand.arguments return openCommand.arguments
} }
== ["macappstore://some/url"] == ["macappstore://some/url"]
} }
it("just opens MAS if no app specified") { it("just opens MAS if no app specified") {
expect { expect {
try MAS.Open.parse([]).run(storeSearch: storeSearch, openCommand: openCommand) try MAS.Open.parse([]).run(searcher: searcher, openCommand: openCommand)
return openCommand.arguments return openCommand.arguments
} }
== ["macappstore://"] == ["macappstore://"]

View file

@ -33,8 +33,8 @@ public class OutdatedSpec: QuickSpec {
trackViewUrl: "https://apps.apple.com/us/app/bandwidth/id490461369?mt=12&uo=4", trackViewUrl: "https://apps.apple.com/us/app/bandwidth/id490461369?mt=12&uo=4",
version: "1.28" version: "1.28"
) )
let mockStoreSearch = StoreSearchMock() let searcher = MockAppStoreSearcher()
mockStoreSearch.apps[mockSearchResult.trackId] = mockSearchResult searcher.apps[mockSearchResult.trackId] = mockSearchResult
let mockAppLibrary = AppLibraryMock() let mockAppLibrary = AppLibraryMock()
mockAppLibrary.installedApps.append( mockAppLibrary.installedApps.append(
@ -48,7 +48,7 @@ public class OutdatedSpec: QuickSpec {
) )
expect { expect {
try captureStream(stdout) { try captureStream(stdout) {
try MAS.Outdated.parse([]).run(appLibrary: mockAppLibrary, storeSearch: mockStoreSearch) try MAS.Outdated.parse([]).run(appLibrary: mockAppLibrary, searcher: searcher)
} }
} }
== "490461369 Bandwidth+ (1.27 -> 1.28)\n" == "490461369 Bandwidth+ (1.27 -> 1.28)\n"

View file

@ -14,14 +14,14 @@ import Quick
public class SearchSpec: QuickSpec { public class SearchSpec: QuickSpec {
override public func spec() { override public func spec() {
let storeSearch = StoreSearchMock() let searcher = MockAppStoreSearcher()
beforeSuite { beforeSuite {
MAS.initialize() MAS.initialize()
} }
describe("search command") { describe("search command") {
beforeEach { beforeEach {
storeSearch.reset() searcher.reset()
} }
it("can find slack") { it("can find slack") {
let mockResult = SearchResult( let mockResult = SearchResult(
@ -30,17 +30,17 @@ public class SearchSpec: QuickSpec {
trackViewUrl: "mas preview url", trackViewUrl: "mas preview url",
version: "0.0" version: "0.0"
) )
storeSearch.apps[mockResult.trackId] = mockResult searcher.apps[mockResult.trackId] = mockResult
expect { expect {
try captureStream(stdout) { try captureStream(stdout) {
try MAS.Search.parse(["slack"]).run(storeSearch: storeSearch) try MAS.Search.parse(["slack"]).run(searcher: searcher)
} }
} }
== " 1111 slack (0.0)\n" == " 1111 slack (0.0)\n"
} }
it("fails when searching for nonexistent app") { it("fails when searching for nonexistent app") {
expect { expect {
try MAS.Search.parse(["nonexistent"]).run(storeSearch: storeSearch) try MAS.Search.parse(["nonexistent"]).run(searcher: searcher)
} }
.to(throwError(MASError.noSearchResultsFound)) .to(throwError(MASError.noSearchResultsFound))
} }

View file

@ -22,7 +22,7 @@ public class UpgradeSpec: QuickSpec {
expect { expect {
try captureStream(stderr) { try captureStream(stderr) {
try MAS.Upgrade.parse([]) try MAS.Upgrade.parse([])
.run(appLibrary: AppLibraryMock(), storeSearch: StoreSearchMock()) .run(appLibrary: AppLibraryMock(), searcher: MockAppStoreSearcher())
} }
} }
== "Warning: Nothing found to upgrade\n" == "Warning: Nothing found to upgrade\n"

View file

@ -13,7 +13,7 @@ import Quick
public class VendorSpec: QuickSpec { public class VendorSpec: QuickSpec {
override public func spec() { override public func spec() {
let storeSearch = StoreSearchMock() let searcher = MockAppStoreSearcher()
let openCommand = OpenSystemCommandMock() let openCommand = OpenSystemCommandMock()
beforeSuite { beforeSuite {
@ -21,17 +21,17 @@ public class VendorSpec: QuickSpec {
} }
describe("vendor command") { describe("vendor command") {
beforeEach { beforeEach {
storeSearch.reset() searcher.reset()
} }
it("fails to open app with invalid ID") { it("fails to open app with invalid ID") {
expect { expect {
try MAS.Vendor.parse(["--", "-999"]).run(storeSearch: storeSearch, openCommand: openCommand) try MAS.Vendor.parse(["--", "-999"]).run(searcher: searcher, openCommand: openCommand)
} }
.to(throwError()) .to(throwError())
} }
it("can't find app with unknown ID") { it("can't find app with unknown ID") {
expect { expect {
try MAS.Vendor.parse(["999"]).run(storeSearch: storeSearch, openCommand: openCommand) try MAS.Vendor.parse(["999"]).run(searcher: searcher, openCommand: openCommand)
} }
.to(throwError(MASError.noSearchResultsFound)) .to(throwError(MASError.noSearchResultsFound))
} }
@ -42,10 +42,10 @@ public class VendorSpec: QuickSpec {
trackViewUrl: "https://apps.apple.com/us/app/awesome/id1111?mt=12&uo=4", trackViewUrl: "https://apps.apple.com/us/app/awesome/id1111?mt=12&uo=4",
version: "0.0" version: "0.0"
) )
storeSearch.apps[mockResult.trackId] = mockResult searcher.apps[mockResult.trackId] = mockResult
expect { expect {
try MAS.Vendor.parse([String(mockResult.trackId)]) try MAS.Vendor.parse([String(mockResult.trackId)])
.run(storeSearch: storeSearch, openCommand: openCommand) .run(searcher: searcher, openCommand: openCommand)
return openCommand.arguments return openCommand.arguments
} }
== [mockResult.sellerUrl] == [mockResult.sellerUrl]

View file

@ -1,5 +1,5 @@
// //
// MasStoreSearchSpec.swift // ITunesSearchAppStoreSearcherSpec.swift
// masTests // masTests
// //
// Created by Ben Chatelain on 1/4/19. // Created by Ben Chatelain on 1/4/19.
@ -11,7 +11,7 @@ import Quick
@testable import mas @testable import mas
public class MasStoreSearchSpec: QuickSpec { public class ITunesSearchAppStoreSearcherSpec: QuickSpec {
override public func spec() { override public func spec() {
beforeSuite { beforeSuite {
MAS.initialize() MAS.initialize()
@ -19,13 +19,13 @@ public class MasStoreSearchSpec: QuickSpec {
describe("url string") { describe("url string") {
it("contains the app name") { it("contains the app name") {
expect { expect {
MasStoreSearch().searchURL(for: "myapp", inCountry: "US")?.absoluteString ITunesSearchAppStoreSearcher().searchURL(for: "myapp", inCountry: "US")?.absoluteString
} }
== "https://itunes.apple.com/search?media=software&entity=desktopSoftware&country=US&term=myapp" == "https://itunes.apple.com/search?media=software&entity=desktopSoftware&country=US&term=myapp"
} }
it("contains the encoded app name") { it("contains the encoded app name") {
expect { expect {
MasStoreSearch().searchURL(for: "My App", inCountry: "US")?.absoluteString ITunesSearchAppStoreSearcher().searchURL(for: "My App", inCountry: "US")?.absoluteString
} }
== "https://itunes.apple.com/search?media=software&entity=desktopSoftware&country=US&term=My%20App" == "https://itunes.apple.com/search?media=software&entity=desktopSoftware&country=US&term=My%20App"
} }
@ -34,10 +34,10 @@ public class MasStoreSearchSpec: QuickSpec {
context("when searched") { context("when searched") {
it("can find slack") { it("can find slack") {
let networkSession = NetworkSessionMockFromFile(responseFile: "search/slack.json") let networkSession = NetworkSessionMockFromFile(responseFile: "search/slack.json")
let storeSearch = MasStoreSearch(networkManager: NetworkManager(session: networkSession)) let searcher = ITunesSearchAppStoreSearcher(networkManager: NetworkManager(session: networkSession))
expect { expect {
try storeSearch.search(for: "slack").wait() try searcher.search(for: "slack").wait()
} }
.to(haveCount(39)) .to(haveCount(39))
} }
@ -47,11 +47,11 @@ public class MasStoreSearchSpec: QuickSpec {
it("can find slack") { it("can find slack") {
let appID: AppID = 803_453_959 let appID: AppID = 803_453_959
let networkSession = NetworkSessionMockFromFile(responseFile: "lookup/slack.json") let networkSession = NetworkSessionMockFromFile(responseFile: "lookup/slack.json")
let storeSearch = MasStoreSearch(networkManager: NetworkManager(session: networkSession)) let searcher = ITunesSearchAppStoreSearcher(networkManager: NetworkManager(session: networkSession))
var result: SearchResult? var result: SearchResult?
do { do {
result = try storeSearch.lookup(appID: appID).wait() result = try searcher.lookup(appID: appID).wait()
} catch { } catch {
let maserror = error as! MASError let maserror = error as! MASError
if case .jsonParsing(let nserror) = maserror { if case .jsonParsing(let nserror) = maserror {

View file

@ -1,5 +1,5 @@
// //
// StoreSearchMock.swift // MockAppStoreSearcher.swift
// masTests // masTests
// //
// Created by Ben Chatelain on 1/4/19. // Created by Ben Chatelain on 1/4/19.
@ -10,7 +10,7 @@ import PromiseKit
@testable import mas @testable import mas
class StoreSearchMock: StoreSearch { class MockAppStoreSearcher: AppStoreSearcher {
var apps: [AppID: SearchResult] = [:] var apps: [AppID: SearchResult] = [:]
func search(for searchTerm: String) -> Promise<[SearchResult]> { func search(for searchTerm: String) -> Promise<[SearchResult]> {

View file

@ -46,7 +46,7 @@ complete -c mas -n "__fish_seen_subcommand_from help" -xa "list"
complete -c mas -n "__fish_use_subcommand" -f -a lucky -d "Install the first result from the Mac App Store" complete -c mas -n "__fish_use_subcommand" -f -a lucky -d "Install the first result from the Mac App Store"
complete -c mas -n "__fish_seen_subcommand_from help" -xa "lucky" complete -c mas -n "__fish_seen_subcommand_from help" -xa "lucky"
### open ### open
complete -c mas -n "__fish_use_subcommand" -f -a open -d "Opens app page in AppStore.app" complete -c mas -n "__fish_use_subcommand" -f -a open -d "Opens app page in 'App Store.app'"
complete -c mas -n "__fish_seen_subcommand_from help" -xa "open" complete -c mas -n "__fish_seen_subcommand_from help" -xa "open"
### outdated ### outdated
complete -c mas -n "__fish_use_subcommand" -f -a outdated -d "Lists pending updates from the Mac App Store" complete -c mas -n "__fish_use_subcommand" -f -a outdated -d "Lists pending updates from the Mac App Store"