2019-01-11 19:46:23 -07:00
|
|
|
//
|
|
|
|
// StoreSearchSpec.swift
|
|
|
|
// MasKitTests
|
|
|
|
//
|
|
|
|
// Created by Ben Chatelain on 1/11/19.
|
|
|
|
// Copyright © 2019 mas-cli. All rights reserved.
|
|
|
|
//
|
|
|
|
import Nimble
|
2019-01-29 23:15:24 -07:00
|
|
|
import Quick
|
2019-01-11 19:46:23 -07:00
|
|
|
|
2021-03-21 22:25:18 -07:00
|
|
|
@testable import MasKit
|
|
|
|
|
2019-01-11 19:46:23 -07:00
|
|
|
/// Protocol minimal implementation
|
|
|
|
struct StoreSearchForTesting: StoreSearch {
|
2021-04-21 15:52:53 -07:00
|
|
|
func lookup(app _: Int, _ completion: @escaping (SearchResult?, Error?) -> Void) {
|
|
|
|
completion(nil, nil)
|
|
|
|
}
|
|
|
|
|
2021-04-21 17:25:35 -07:00
|
|
|
func search(for _: String, _ completion: @escaping ([SearchResult]?, Error?) -> Void) {
|
|
|
|
completion([], nil)
|
2021-04-21 15:52:53 -07:00
|
|
|
}
|
2019-01-11 19:46:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
class StoreSearchSpec: QuickSpec {
|
|
|
|
override func spec() {
|
|
|
|
let storeSearch = StoreSearchForTesting()
|
|
|
|
|
|
|
|
describe("url string") {
|
|
|
|
it("contains the app name") {
|
|
|
|
let appName = "myapp"
|
|
|
|
let urlString = storeSearch.searchURLString(forApp: appName)
|
2021-03-21 22:25:18 -07:00
|
|
|
expect(urlString) == "https://itunes.apple.com/search?media=software&entity=macSoftware&term=\(appName)"
|
2019-01-11 19:46:23 -07:00
|
|
|
}
|
|
|
|
it("contains the encoded app name") {
|
|
|
|
let appName = "My App"
|
|
|
|
let appNameEncoded = "My%20App"
|
|
|
|
let urlString = storeSearch.searchURLString(forApp: appName)
|
2021-03-21 22:25:18 -07:00
|
|
|
expect(urlString)
|
|
|
|
== "https://itunes.apple.com/search?media=software&entity=macSoftware&term=\(appNameEncoded)"
|
2019-01-11 19:46:23 -07:00
|
|
|
}
|
2019-01-11 20:02:21 -07:00
|
|
|
// Find a character that causes addingPercentEncoding(withAllowedCharacters to return nil
|
2019-01-11 19:46:23 -07:00
|
|
|
xit("is nil when app name cannot be url encoded") {
|
|
|
|
let appName = "`~!@#$%^&*()_+ 💩"
|
|
|
|
let urlString = storeSearch.searchURLString(forApp: appName)
|
|
|
|
expect(urlString).to(beNil())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|