mas/MasKitTests/Controllers/StoreSearchMock.swift
Ben Chatelain e46a59f322 ♻️ Change lookup API to only accept Int
Better input validation for home, info, open and vendor commands
2019-01-17 22:06:25 -07:00

34 lines
826 B
Swift

//
// StoreSearchMock.swift
// MasKitTests
//
// Created by Ben Chatelain on 1/4/19.
// Copyright © 2019 mas-cli. All rights reserved.
//
@testable import MasKit
class StoreSearchMock: StoreSearch {
var apps: [Int: SearchResult] = [:]
func search(for appName: String) throws -> SearchResultList {
let filtered = apps.filter { $1.trackName.contains(appName) }
return SearchResultList(resultCount: filtered.count, results: filtered.map { $1 })
}
func lookup(app appId: Int) throws -> SearchResult? {
// Negative numbers are invalid
if appId <= 0 {
throw MASError.searchFailed
}
guard let result = apps[appId]
else { throw MASError.noSearchResultsFound }
return result
}
func reset() {
apps = [:]
}
}