Skip to content

Commit da37e9f

Browse files
authored
Merge pull request #975 from rgoldberg/974-cleanup
Swift cleanup
2 parents a20056f + 54bcec8 commit da37e9f

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

Sources/MAS/Commands/Open.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ extension MAS {
4343
return
4444
}
4545

46-
try await openInMacAppStore(
47-
pageForAppID: AppID(from: appIDString, forceBundleID: forceBundleIDOptionGroup.forceBundleID),
48-
searcher: searcher
46+
try await openMacAppStorePage(
47+
forURLString: try await searcher.lookup(
48+
appID: AppID(from: appIDString, forceBundleID: forceBundleIDOptionGroup.forceBundleID)
49+
)
50+
.trackViewUrl
4951
)
5052
}
5153
}
@@ -62,8 +64,7 @@ private func openMacAppStore() async throws {
6264
try await NSWorkspace.shared.openApplication(at: appURL, configuration: NSWorkspace.OpenConfiguration())
6365
}
6466

65-
private func openInMacAppStore(pageForAppID appID: AppID, searcher: AppStoreSearcher) async throws {
66-
let urlString = try await searcher.lookup(appID: appID).trackViewUrl
67+
private func openMacAppStorePage(forURLString urlString: String) async throws {
6768
guard var urlComponents = URLComponents(string: urlString) else {
6869
throw MASError.urlParsing(urlString)
6970
}

Sources/MAS/Models/SearchResult.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ struct SearchResult: Decodable {
1919
var version = ""
2020
}
2121

22-
extension SearchResult {
23-
var adamID: ADAMID {
24-
trackId
25-
}
26-
27-
var outputPrice: String {
28-
formattedPrice ?? "?"
29-
}
22+
extension SearchResult: AppIdentifying {
23+
var adamID: ADAMID { trackId }
24+
var bundleID: String { bundleId }
25+
var outputPrice: String { formattedPrice ?? "?" }
3026
}
3127

3228
extension SearchResult: Hashable {

Tests/MASTests/Commands/InfoTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func cannotFindAppInfoForUnknownAppID() async {
1919

2020
@Test
2121
func outputsAppInfo() async {
22-
let mockResult = SearchResult(
22+
let result = SearchResult(
2323
currentVersionReleaseDate: "2019-01-07T18:53:13Z",
2424
fileSizeBytes: "1024",
2525
formattedPrice: "$2.00",
@@ -32,8 +32,8 @@ func outputsAppInfo() async {
3232
)
3333
#expect(
3434
await consequencesOf(
35-
try await MAS.Info.parse([String(mockResult.trackId)]).run(
36-
searcher: MockAppStoreSearcher([.adamID(mockResult.adamID): mockResult])
35+
try await MAS.Info.parse([String(result.trackId)]).run(
36+
searcher: MockAppStoreSearcher([.adamID(result.adamID): result])
3737
)
3838
)
3939
== UnvaluedConsequences( // swiftformat:disable indent

Tests/MASTests/Commands/OutdatedTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal import Testing
1111

1212
@Test
1313
func outputsOutdatedApps() async {
14-
let mockSearchResult =
14+
let result =
1515
SearchResult(
1616
bundleId: "au.haroldchu.mac.Bandwidth",
1717
currentVersionReleaseDate: "2024-09-02T00:27:00Z",
@@ -30,14 +30,14 @@ func outputsOutdatedApps() async {
3030
try await MAS.Outdated.parse([]).run(
3131
installedApps: [
3232
InstalledApp(
33-
adamID: mockSearchResult.trackId,
34-
bundleID: mockSearchResult.bundleId,
35-
name: mockSearchResult.trackName,
33+
adamID: result.trackId,
34+
bundleID: result.bundleId,
35+
name: result.trackName,
3636
path: "/Applications/Bandwidth+.app",
3737
version: "1.27"
3838
),
3939
],
40-
searcher: MockAppStoreSearcher([.bundleID(mockSearchResult.bundleId): mockSearchResult])
40+
searcher: MockAppStoreSearcher([.bundleID(result.bundleId): result])
4141
)
4242
)
4343
== UnvaluedConsequences(nil, "490461369 Bandwidth+ (1.27 -> 1.28)\n") // swiftformat:disable:this indent

Tests/MASTests/Commands/SearchTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ internal import Testing
1111

1212
@Test
1313
func searchesForSlack() async {
14-
let mockResult = SearchResult(trackId: 1111, trackName: "slack", trackViewUrl: "mas preview url", version: "0.0")
14+
let result = SearchResult(trackId: 1111, trackName: "slack", trackViewUrl: "mas preview url", version: "0.0")
1515
#expect(
1616
await consequencesOf(
1717
try await MAS.Search.parse(["slack"]).run(
18-
searcher: MockAppStoreSearcher([.adamID(mockResult.adamID): mockResult])
18+
searcher: MockAppStoreSearcher([.adamID(result.adamID): result])
1919
)
2020
)
2121
== UnvaluedConsequences(nil, "1111 slack (0.0)\n") // swiftformat:disable:this indent

0 commit comments

Comments
 (0)