2020-03-28 21:15:07 -06:00
|
|
|
//
|
|
|
|
// MasAppLibrarySpec.swift
|
|
|
|
// MasKitTests
|
|
|
|
//
|
|
|
|
// Created by Ben Chatelain on 3/1/20.
|
|
|
|
// Copyright © 2020 mas-cli. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Nimble
|
|
|
|
import Quick
|
|
|
|
|
2021-03-21 22:25:18 -07:00
|
|
|
@testable import MasKit
|
|
|
|
|
2020-03-28 21:15:07 -06:00
|
|
|
class MasAppLibrarySpec: QuickSpec {
|
|
|
|
override func spec() {
|
2020-05-13 22:15:47 -06:00
|
|
|
let library = MasAppLibrary(softwareMap: SoftwareMapMock(products: apps))
|
|
|
|
|
2020-03-28 21:15:07 -06:00
|
|
|
describe("mas app library") {
|
|
|
|
it("contains all installed apps") {
|
2020-05-13 22:15:47 -06:00
|
|
|
expect(library.installedApps.count) == apps.count
|
|
|
|
expect(library.installedApps.first!.appName) == myApp.appName
|
|
|
|
}
|
|
|
|
it("can locate an app by bundle id") {
|
|
|
|
let app = library.installedApp(forBundleId: "com.example")!
|
|
|
|
expect(app.bundleIdentifier) == myApp.bundleIdentifier
|
2020-03-28 21:15:07 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Test Data
|
2020-05-13 22:15:47 -06:00
|
|
|
let myApp = SoftwareProductMock(
|
|
|
|
appName: "MyApp",
|
|
|
|
bundleIdentifier: "com.example",
|
|
|
|
bundlePath: "",
|
|
|
|
bundleVersion: "",
|
|
|
|
itemIdentifier: 1234)
|
2020-03-28 21:15:07 -06:00
|
|
|
|
2021-03-21 22:25:18 -07:00
|
|
|
var apps: [SoftwareProduct] = [myApp]
|
2020-03-28 21:15:07 -06:00
|
|
|
|
|
|
|
// MARK: - SoftwareMapMock
|
|
|
|
struct SoftwareMapMock: SoftwareMap {
|
|
|
|
var products: [SoftwareProduct] = []
|
|
|
|
|
|
|
|
func allSoftwareProducts() -> [SoftwareProduct] {
|
|
|
|
return products
|
|
|
|
}
|
|
|
|
|
|
|
|
func product(for bundleIdentifier: String) -> SoftwareProduct? {
|
2020-05-14 21:08:38 -06:00
|
|
|
for product in products where product.bundleIdentifier == bundleIdentifier {
|
|
|
|
return product
|
2020-03-28 21:15:07 -06:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|