2019-01-05 08:39:07 -07:00
|
|
|
//
|
2024-10-25 20:29:17 -04:00
|
|
|
// ITunesSearchAppStoreSearcherSpec.swift
|
2024-10-01 14:05:41 -04:00
|
|
|
// masTests
|
2019-01-05 08:39:07 -07:00
|
|
|
//
|
|
|
|
// Created by Ben Chatelain on 1/4/19.
|
|
|
|
// Copyright © 2019 mas-cli. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Nimble
|
2019-01-29 23:15:24 -07:00
|
|
|
import Quick
|
2019-01-05 08:39:07 -07:00
|
|
|
|
2024-10-01 14:05:41 -04:00
|
|
|
@testable import mas
|
2021-03-21 22:25:18 -07:00
|
|
|
|
2024-10-25 20:29:17 -04:00
|
|
|
public class ITunesSearchAppStoreSearcherSpec: QuickSpec {
|
2024-10-18 10:28:44 -04:00
|
|
|
override public func spec() {
|
2021-04-23 00:01:18 -07:00
|
|
|
beforeSuite {
|
2024-10-25 13:21:19 -04:00
|
|
|
MAS.initialize()
|
2021-04-23 00:01:18 -07:00
|
|
|
}
|
2022-10-08 17:32:26 -06:00
|
|
|
describe("url string") {
|
|
|
|
it("contains the app name") {
|
2024-10-01 22:16:06 -04:00
|
|
|
expect {
|
2024-10-25 20:29:17 -04:00
|
|
|
ITunesSearchAppStoreSearcher().searchURL(for: "myapp", inCountry: "US")?.absoluteString
|
2024-10-01 22:16:06 -04:00
|
|
|
}
|
2024-10-14 16:29:47 -04:00
|
|
|
== "https://itunes.apple.com/search?media=software&entity=desktopSoftware&country=US&term=myapp"
|
2022-10-08 17:32:26 -06:00
|
|
|
}
|
|
|
|
it("contains the encoded app name") {
|
2024-10-01 22:16:06 -04:00
|
|
|
expect {
|
2024-10-25 20:29:17 -04:00
|
|
|
ITunesSearchAppStoreSearcher().searchURL(for: "My App", inCountry: "US")?.absoluteString
|
2024-10-01 22:16:06 -04:00
|
|
|
}
|
2024-10-14 16:29:47 -04:00
|
|
|
== "https://itunes.apple.com/search?media=software&entity=desktopSoftware&country=US&term=My%20App"
|
2022-10-08 17:32:26 -06:00
|
|
|
}
|
|
|
|
}
|
2020-09-06 14:15:02 -06:00
|
|
|
describe("store") {
|
|
|
|
context("when searched") {
|
|
|
|
it("can find slack") {
|
2024-10-25 23:09:31 -04:00
|
|
|
let networkSession = MockFromFileNetworkSession(responseFile: "search/slack.json")
|
2024-10-25 20:29:17 -04:00
|
|
|
let searcher = ITunesSearchAppStoreSearcher(networkManager: NetworkManager(session: networkSession))
|
2019-01-11 17:10:36 -07:00
|
|
|
|
2024-10-01 22:16:06 -04:00
|
|
|
expect {
|
2024-10-25 20:29:17 -04:00
|
|
|
try searcher.search(for: "slack").wait()
|
2019-01-11 17:11:53 -07:00
|
|
|
}
|
2024-10-01 22:16:06 -04:00
|
|
|
.to(haveCount(39))
|
2019-01-11 17:11:53 -07:00
|
|
|
}
|
2019-01-11 17:10:36 -07:00
|
|
|
}
|
|
|
|
|
2020-09-06 14:15:02 -06:00
|
|
|
context("when lookup used") {
|
|
|
|
it("can find slack") {
|
2024-10-14 01:50:10 -04:00
|
|
|
let appID: AppID = 803_453_959
|
2024-10-25 23:09:31 -04:00
|
|
|
let networkSession = MockFromFileNetworkSession(responseFile: "lookup/slack.json")
|
2024-10-25 20:29:17 -04:00
|
|
|
let searcher = ITunesSearchAppStoreSearcher(networkManager: NetworkManager(session: networkSession))
|
2020-09-06 14:15:02 -06:00
|
|
|
|
2024-10-01 22:16:06 -04:00
|
|
|
var result: SearchResult?
|
2020-09-06 14:15:02 -06:00
|
|
|
do {
|
2024-10-25 20:29:17 -04:00
|
|
|
result = try searcher.lookup(appID: appID).wait()
|
2020-09-06 14:15:02 -06:00
|
|
|
} catch {
|
|
|
|
let maserror = error as! MASError
|
2021-05-08 13:26:25 -07:00
|
|
|
if case .jsonParsing(let nserror) = maserror {
|
2020-09-06 14:15:02 -06:00
|
|
|
fail("\(maserror) \(nserror!)")
|
|
|
|
}
|
2019-01-11 17:33:41 -07:00
|
|
|
}
|
|
|
|
|
2024-10-01 22:16:06 -04:00
|
|
|
guard let result else {
|
|
|
|
fatalError("lookup result was nil")
|
|
|
|
}
|
2019-01-05 08:39:07 -07:00
|
|
|
|
2024-10-14 01:50:10 -04:00
|
|
|
expect(result.trackId) == appID
|
2020-09-06 14:15:02 -06:00
|
|
|
expect(result.bundleId) == "com.tinyspeck.slackmacgap"
|
|
|
|
expect(result.price) == 0
|
|
|
|
expect(result.sellerName) == "Slack Technologies, Inc."
|
|
|
|
expect(result.sellerUrl) == "https://slack.com"
|
|
|
|
expect(result.trackName) == "Slack"
|
|
|
|
expect(result.trackViewUrl) == "https://itunes.apple.com/us/app/slack/id803453959?mt=12&uo=4"
|
|
|
|
expect(result.version) == "3.3.3"
|
|
|
|
}
|
2019-01-05 08:39:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|