mas/MasKitTests/Controllers/StoreSearchMock.swift

35 lines
822 B
Swift
Raw Normal View History

2019-01-05 00:54:00 +00:00
//
// StoreSearchMock.swift
2019-01-05 00:54:00 +00:00
// MasKitTests
//
// Created by Ben Chatelain on 1/4/19.
// Copyright © 2019 mas-cli. All rights reserved.
//
@testable import MasKit
class StoreSearchMock: StoreSearch {
2019-01-05 00:54:00 +00:00
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? {
2019-01-05 00:54:00 +00:00
// Negative numbers are invalid
if appId <= 0 {
2019-01-05 00:54:00 +00:00
throw MASError.searchFailed
}
guard let result = apps[appId]
2021-03-22 05:25:18 +00:00
else { throw MASError.noSearchResultsFound }
2019-01-05 00:54:00 +00:00
return result
}
func reset() {
apps = [:]
}
}