mas/MasKitTests/Controllers/StoreSearchMock.swift
Ben Chatelain 35d2846f19 🎨 Format source
2020-09-07 11:35:44 -06: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 = [:]
}
}