2019-01-05 15:39:07 +00:00
|
|
|
//
|
|
|
|
// MasStoreSearchSpec.swift
|
2024-10-01 18:05:41 +00:00
|
|
|
// masTests
|
2019-01-05 15:39:07 +00:00
|
|
|
//
|
|
|
|
// Created by Ben Chatelain on 1/4/19.
|
|
|
|
// Copyright © 2019 mas-cli. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Nimble
|
2019-01-30 06:15:24 +00:00
|
|
|
import Quick
|
2019-01-05 15:39:07 +00:00
|
|
|
|
2024-10-01 18:05:41 +00:00
|
|
|
@testable import mas
|
2021-03-22 05:25:18 +00:00
|
|
|
|
2021-05-08 22:49:32 +00:00
|
|
|
public class MasStoreSearchSpec: QuickSpec {
|
2021-05-09 20:25:20 +00:00
|
|
|
override public func spec() {
|
2021-04-23 07:01:18 +00:00
|
|
|
beforeSuite {
|
2024-10-01 18:05:41 +00:00
|
|
|
Mas.initialize()
|
2021-04-23 07:01:18 +00:00
|
|
|
}
|
2022-10-08 23:32:26 +00:00
|
|
|
describe("url string") {
|
|
|
|
it("contains the app name") {
|
|
|
|
let appName = "myapp"
|
2024-02-18 06:46:44 +00:00
|
|
|
let urlString = MasStoreSearch().searchURL(for: appName, inCountry: "US")?.absoluteString
|
|
|
|
expect(urlString) == """
|
|
|
|
https://itunes.apple.com/search?media=software&entity=macSoftware&term=\(appName)&country=US
|
|
|
|
"""
|
2022-10-08 23:32:26 +00:00
|
|
|
}
|
|
|
|
it("contains the encoded app name") {
|
|
|
|
let appName = "My App"
|
|
|
|
let appNameEncoded = "My%20App"
|
2024-02-18 06:46:44 +00:00
|
|
|
let urlString = MasStoreSearch().searchURL(for: appName, inCountry: "US")?.absoluteString
|
|
|
|
expect(urlString) == """
|
|
|
|
https://itunes.apple.com/search?media=software&entity=macSoftware&term=\(appNameEncoded)&country=US
|
|
|
|
"""
|
2022-10-08 23:32:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-06 20:15:02 +00:00
|
|
|
describe("store") {
|
|
|
|
context("when searched") {
|
|
|
|
it("can find slack") {
|
|
|
|
let networkSession = NetworkSessionMockFromFile(responseFile: "search/slack.json")
|
|
|
|
let storeSearch = MasStoreSearch(networkManager: NetworkManager(session: networkSession))
|
2019-01-12 00:10:36 +00:00
|
|
|
|
2021-04-22 00:25:35 +00:00
|
|
|
var results: [SearchResult]
|
2020-09-06 20:15:02 +00:00
|
|
|
do {
|
2021-05-06 22:08:56 +00:00
|
|
|
results = try storeSearch.search(for: "slack").wait()
|
2021-04-22 00:25:35 +00:00
|
|
|
expect(results.count) == 39
|
2020-09-06 20:15:02 +00:00
|
|
|
} catch {
|
|
|
|
let maserror = error as! MASError
|
2021-05-08 20:26:25 +00:00
|
|
|
if case .jsonParsing(let nserror) = maserror {
|
2020-09-06 20:15:02 +00:00
|
|
|
fail("\(maserror) \(nserror!)")
|
|
|
|
}
|
2019-01-12 00:11:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-12 00:10:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 20:15:02 +00:00
|
|
|
context("when lookup used") {
|
|
|
|
it("can find slack") {
|
2024-10-14 05:50:10 +00:00
|
|
|
let appID: AppID = 803_453_959
|
2020-09-06 20:15:02 +00:00
|
|
|
let networkSession = NetworkSessionMockFromFile(responseFile: "lookup/slack.json")
|
|
|
|
let storeSearch = MasStoreSearch(networkManager: NetworkManager(session: networkSession))
|
|
|
|
|
|
|
|
var lookup: SearchResult?
|
|
|
|
do {
|
2024-10-14 05:50:10 +00:00
|
|
|
lookup = try storeSearch.lookup(appID: appID).wait()
|
2020-09-06 20:15:02 +00:00
|
|
|
} catch {
|
|
|
|
let maserror = error as! MASError
|
2021-05-08 20:26:25 +00:00
|
|
|
if case .jsonParsing(let nserror) = maserror {
|
2020-09-06 20:15:02 +00:00
|
|
|
fail("\(maserror) \(nserror!)")
|
|
|
|
}
|
2019-01-12 00:33:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 20:15:02 +00:00
|
|
|
guard let result = lookup else { fatalError("lookup result was nil") }
|
2019-01-05 15:39:07 +00:00
|
|
|
|
2024-10-14 05:50:10 +00:00
|
|
|
expect(result.trackId) == appID
|
2020-09-06 20:15:02 +00: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 15:39:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|