mas/Tests/MasKitTests/Controllers/StoreSearchMock.swift

40 lines
968 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, _ completion: @escaping ([SearchResult]?, Error?) -> Void) {
let filtered = apps.filter { $1.trackName.contains(appName) }
let results = filtered.map { $1 }
completion(results, nil)
}
func lookup(app appId: Int, _ completion: @escaping (SearchResult?, Error?) -> Void) {
2019-01-05 00:54:00 +00:00
// Negative numbers are invalid
guard appId > 0 else {
completion(nil, MASError.searchFailed)
return
2019-01-05 00:54:00 +00:00
}
guard let result = apps[appId]
else {
completion(nil, MASError.noSearchResultsFound)
return
}
2019-01-05 00:54:00 +00:00
completion(result, nil)
2019-01-05 00:54:00 +00:00
}
func reset() {
apps = [:]
}
}