mas/Tests/masTests/Commands/OpenSpec.swift
Ross Goldberg 388d963cd1
Do not return Result (or anything else) from command run(…) functions.
Throw when failure. Normal Void return when success.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
2024-10-14 03:44:12 -04:00

68 lines
2.3 KiB
Swift

//
// OpenSpec.swift
// masTests
//
// Created by Ben Chatelain on 2019-01-03.
// Copyright © 2019 mas-cli. All rights reserved.
//
import Foundation
import Nimble
import Quick
@testable import mas
public class OpenSpec: QuickSpec {
override public func spec() {
let result = SearchResult(
trackId: 1111,
trackViewUrl: "fakescheme://some/url",
version: "0.0"
)
let storeSearch = StoreSearchMock()
let openCommand = OpenSystemCommandMock()
beforeSuite {
Mas.initialize()
}
describe("open command") {
beforeEach {
storeSearch.reset()
}
it("fails to open app with invalid ID") {
expect {
try Mas.Open.parse(["--", "-999"]).run(storeSearch: storeSearch, openCommand: openCommand)
}
.to(throwError(MASError.searchFailed))
}
it("can't find app with unknown ID") {
expect {
try Mas.Open.parse(["999"]).run(storeSearch: storeSearch, openCommand: openCommand)
}
.to(throwError(MASError.noSearchResultsFound))
}
it("opens app in MAS") {
storeSearch.apps[result.trackId] = result
expect {
try Mas.Open.parse([result.trackId.description])
.run(storeSearch: storeSearch, openCommand: openCommand)
}
.toNot(throwError())
expect(openCommand.arguments).toNot(beNil())
let url = URL(string: openCommand.arguments!.first!)
expect(url).toNot(beNil())
expect(url?.scheme) == "macappstore"
}
it("just opens MAS if no app specified") {
expect {
try Mas.Open.parse(["appstore"]).run(storeSearch: storeSearch, openCommand: openCommand)
}
.toNot(throwError())
expect(openCommand.arguments).toNot(beNil())
let url = URL(string: openCommand.arguments!.first!)
expect(url).toNot(beNil())
expect(url) == URL(string: "macappstore://")
}
}
}
}