2019-01-12 02:46:23 +00:00
|
|
|
//
|
|
|
|
// StoreSearchSpec.swift
|
|
|
|
// MasKitTests
|
|
|
|
//
|
|
|
|
// Created by Ben Chatelain on 1/11/19.
|
|
|
|
// Copyright © 2019 mas-cli. All rights reserved.
|
|
|
|
//
|
|
|
|
@testable import MasKit
|
|
|
|
import Result
|
|
|
|
import Quick
|
|
|
|
import Nimble
|
|
|
|
|
|
|
|
/// Protocol minimal implementation
|
|
|
|
struct StoreSearchForTesting: StoreSearch {
|
2019-01-18 05:06:25 +00:00
|
|
|
func lookup(app appId: Int) throws -> SearchResult? { return nil }
|
2019-01-12 02:46:23 +00:00
|
|
|
func search(for appName: String) throws -> SearchResultList { return SearchResultList(resultCount: 0, results: []) }
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
expect(urlString) ==
|
|
|
|
"https://itunes.apple.com/search?entity=macSoftware&term=\(appName)&attribute=allTrackTerm"
|
|
|
|
}
|
|
|
|
it("contains the encoded app name") {
|
|
|
|
let appName = "My App"
|
|
|
|
let appNameEncoded = "My%20App"
|
|
|
|
let urlString = storeSearch.searchURLString(forApp: appName)
|
|
|
|
expect(urlString) ==
|
|
|
|
"https://itunes.apple.com/search?entity=macSoftware&term=\(appNameEncoded)&attribute=allTrackTerm"
|
|
|
|
}
|
2019-01-12 03:02:21 +00:00
|
|
|
// Find a character that causes addingPercentEncoding(withAllowedCharacters to return nil
|
2019-01-12 02:46:23 +00:00
|
|
|
xit("is nil when app name cannot be url encoded") {
|
|
|
|
let appName = "`~!@#$%^&*()_+ 💩"
|
|
|
|
let urlString = storeSearch.searchURLString(forApp: appName)
|
|
|
|
expect(urlString).to(beNil())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|