mirror of
https://github.com/mas-cli/mas
synced 2024-11-24 20:43:10 +00:00
🐛 Don't consider an app outdated if the update can't be installed on the current OS
Fixes #420
This commit is contained in:
parent
d4c06f9858
commit
84461fa5c6
2 changed files with 50 additions and 0 deletions
|
@ -24,7 +24,19 @@ extension SoftwareProduct {
|
|||
appName.isEmpty ? bundleIdentifier : appName
|
||||
}
|
||||
|
||||
/// Determines whether the app is considered outdated. Updates that require a higher OS version are excluded.
|
||||
/// - Parameter storeApp: App from search result.
|
||||
/// - Returns: true if the app is outdated; false otherwise.
|
||||
func isOutdatedWhenComparedTo(_ storeApp: SearchResult) -> Bool {
|
||||
// Only look at min OS version if we have one
|
||||
if let osVersion = Version(storeApp.minimumOsVersion) {
|
||||
let requiredVersion = OperatingSystemVersion(majorVersion: osVersion.major, minorVersion: osVersion.minor, patchVersion: osVersion.patch)
|
||||
// Don't consider an app outdated if the version in the app store requires a higher OS version.
|
||||
guard ProcessInfo.processInfo.isOperatingSystemAtLeast(requiredVersion) else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// The App Store does not enforce semantic versioning, but we assume most apps follow versioning
|
||||
// schemes that increase numerically over time.
|
||||
guard let semanticBundleVersion = Version(tolerant: bundleVersion),
|
||||
|
|
38
Tests/MasKitTests/Models/SoftwareProductSpec.swift
Normal file
38
Tests/MasKitTests/Models/SoftwareProductSpec.swift
Normal file
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// SoftwareProductSpec.swift
|
||||
// MasKitTests
|
||||
//
|
||||
// Created by Ben Chatelain on 9/30/21.
|
||||
// Copyright © 2018 mas-cli. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Nimble
|
||||
import Quick
|
||||
|
||||
@testable import MasKit
|
||||
|
||||
public class SoftwareProductSpec: QuickSpec {
|
||||
override public func spec() {
|
||||
beforeSuite {
|
||||
MasKit.initialize()
|
||||
}
|
||||
describe("software product") {
|
||||
let app = SoftwareProductMock(appName: "App", bundleIdentifier: "", bundlePath: "", bundleVersion: "1.0.0", itemIdentifier: 111)
|
||||
|
||||
let currentApp = SearchResult(version: "1.0.0")
|
||||
let appUpdate = SearchResult(version: "2.0.0")
|
||||
let higherOs = SearchResult(minimumOsVersion: "99.0.0", version: "3.0.0")
|
||||
|
||||
it("is not outdated there is no new version available") {
|
||||
expect(app.isOutdatedWhenComparedTo(currentApp)) == false
|
||||
}
|
||||
it("is outdated when there is a new version available") {
|
||||
expect(app.isOutdatedWhenComparedTo(appUpdate)) == true
|
||||
}
|
||||
it("is not outdated when the new version requires a higher OS version") {
|
||||
expect(app.isOutdatedWhenComparedTo(higherOs)) == false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue