2019-01-05 00:54:00 +00:00
|
|
|
//
|
2019-01-06 21:01:08 +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
|
|
|
|
|
2019-01-06 21:01:08 +00:00
|
|
|
class StoreSearchMock: StoreSearch {
|
2019-01-05 00:54:00 +00:00
|
|
|
var apps: [Int: SearchResult] = [:]
|
|
|
|
|
2019-01-12 00:10:36 +00:00
|
|
|
func search(for appName: String) throws -> SearchResultList {
|
|
|
|
let filtered = apps.filter { $1.trackName.contains(appName) }
|
|
|
|
return SearchResultList(resultCount: filtered.count, results: filtered.map { $1 })
|
|
|
|
}
|
|
|
|
|
2019-01-18 05:06:25 +00:00
|
|
|
func lookup(app appId: Int) throws -> SearchResult? {
|
2019-01-05 00:54:00 +00:00
|
|
|
// Negative numbers are invalid
|
2019-01-18 05:06:25 +00:00
|
|
|
if appId <= 0 {
|
2019-01-05 00:54:00 +00:00
|
|
|
throw MASError.searchFailed
|
|
|
|
}
|
|
|
|
|
2019-01-18 05:06:25 +00:00
|
|
|
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 = [:]
|
|
|
|
}
|
|
|
|
}
|