2018-02-11 22:41:21 +00:00
|
|
|
//
|
|
|
|
// MASErrorTestCase.swift
|
2024-10-01 18:05:41 +00:00
|
|
|
// masTests
|
2018-02-11 22:41:21 +00:00
|
|
|
//
|
|
|
|
// Created by Ben Chatelain on 2/11/18.
|
|
|
|
// Copyright © 2018 Andrew Naylor. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2019-01-30 06:15:24 +00:00
|
|
|
import XCTest
|
2018-02-11 22:41:21 +00:00
|
|
|
|
2024-10-01 18:05:41 +00:00
|
|
|
@testable import mas
|
2021-03-22 05:25:18 +00:00
|
|
|
|
2018-02-11 22:41:21 +00:00
|
|
|
class MASErrorTestCase: XCTestCase {
|
2018-02-11 23:11:09 +00:00
|
|
|
private let errorDomain = "MAS"
|
2024-10-21 11:40:14 +00:00
|
|
|
private var error: MASError!
|
|
|
|
private var nserror: NSError!
|
2018-02-11 23:11:09 +00:00
|
|
|
|
|
|
|
/// Convenience property for setting the value which will be use for the localized description
|
2024-10-21 11:10:31 +00:00
|
|
|
/// value of the next NSError created.
|
|
|
|
///
|
|
|
|
/// Only used when the NSError does not have a user info
|
2018-02-11 23:11:09 +00:00
|
|
|
/// entry for localized description.
|
2024-10-21 11:40:14 +00:00
|
|
|
private var localizedDescription: String {
|
2021-03-22 05:46:17 +00:00
|
|
|
get { "dummy value" }
|
2018-02-11 23:11:09 +00:00
|
|
|
set {
|
2024-10-20 12:09:01 +00:00
|
|
|
NSError.setUserInfoValueProvider(forDomain: errorDomain) { _, _ in
|
2019-01-30 06:15:24 +00:00
|
|
|
newValue
|
2018-02-11 23:11:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-11 22:41:21 +00:00
|
|
|
|
|
|
|
override func setUp() {
|
|
|
|
super.setUp()
|
2024-10-25 17:21:19 +00:00
|
|
|
MAS.initialize()
|
2018-02-11 23:18:57 +00:00
|
|
|
nserror = NSError(domain: errorDomain, code: 999)
|
|
|
|
localizedDescription = "foo"
|
2018-02-11 22:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tearDown() {
|
2018-02-11 23:11:09 +00:00
|
|
|
nserror = nil
|
|
|
|
error = nil
|
2018-02-11 22:41:21 +00:00
|
|
|
super.tearDown()
|
|
|
|
}
|
|
|
|
|
|
|
|
func testNotSignedIn() {
|
|
|
|
error = .notSignedIn
|
|
|
|
XCTAssertEqual(error.description, "Not signed in")
|
|
|
|
}
|
2018-02-11 23:11:09 +00:00
|
|
|
|
|
|
|
func testSignInFailed() {
|
|
|
|
error = .signInFailed(error: nil)
|
|
|
|
XCTAssertEqual(error.description, "Sign in failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testSignInFailedError() {
|
|
|
|
error = .signInFailed(error: nserror)
|
2018-02-11 23:18:57 +00:00
|
|
|
XCTAssertEqual(error.description, "Sign in failed: foo")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAlreadySignedIn() {
|
2024-10-25 16:14:14 +00:00
|
|
|
error = .alreadySignedIn(asAppleID: "person@example.com")
|
2024-10-10 21:47:59 +00:00
|
|
|
XCTAssertEqual(error.description, "Already signed in as person@example.com")
|
2018-02-11 23:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testPurchaseFailed() {
|
|
|
|
error = .purchaseFailed(error: nil)
|
|
|
|
XCTAssertEqual(error.description, "Download request failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testPurchaseFailedError() {
|
|
|
|
error = .purchaseFailed(error: nserror)
|
|
|
|
XCTAssertEqual(error.description, "Download request failed: foo")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testDownloadFailed() {
|
|
|
|
error = .downloadFailed(error: nil)
|
|
|
|
XCTAssertEqual(error.description, "Download failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testDownloadFailedError() {
|
|
|
|
error = .downloadFailed(error: nserror)
|
|
|
|
XCTAssertEqual(error.description, "Download failed: foo")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testNoDownloads() {
|
|
|
|
error = .noDownloads
|
|
|
|
XCTAssertEqual(error.description, "No downloads began")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCancelled() {
|
|
|
|
error = .cancelled
|
|
|
|
XCTAssertEqual(error.description, "Download cancelled")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testSearchFailed() {
|
|
|
|
error = .searchFailed
|
|
|
|
XCTAssertEqual(error.description, "Search failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testNoSearchResultsFound() {
|
|
|
|
error = .noSearchResultsFound
|
2024-10-29 08:08:56 +00:00
|
|
|
XCTAssertEqual(error.description, "No apps found")
|
2018-02-11 23:11:09 +00:00
|
|
|
}
|
2018-12-27 21:50:38 +00:00
|
|
|
|
2019-01-12 00:11:26 +00:00
|
|
|
func testNoVendorWebsite() {
|
|
|
|
error = .noVendorWebsite
|
|
|
|
XCTAssertEqual(error.description, "App does not have a vendor website")
|
|
|
|
}
|
|
|
|
|
2018-12-27 21:50:38 +00:00
|
|
|
func testNotInstalled() {
|
2024-10-23 16:57:34 +00:00
|
|
|
error = .notInstalled(appID: 123)
|
|
|
|
XCTAssertEqual(error.description, "No apps installed with app ID 123")
|
2018-12-27 21:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testUninstallFailed() {
|
2024-10-23 18:11:52 +00:00
|
|
|
error = .uninstallFailed(error: nil)
|
2018-12-27 21:50:38 +00:00
|
|
|
XCTAssertEqual(error.description, "Uninstall failed")
|
|
|
|
}
|
2019-01-12 00:11:53 +00:00
|
|
|
|
|
|
|
func testNoData() {
|
|
|
|
error = .noData
|
|
|
|
XCTAssertEqual(error.description, "Service did not return data")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testJsonParsing() {
|
2024-09-16 05:12:23 +00:00
|
|
|
error = .jsonParsing(data: nil)
|
|
|
|
XCTAssertEqual(error.description, "Received empty response")
|
2019-01-12 00:11:53 +00:00
|
|
|
}
|
2018-02-11 22:41:21 +00:00
|
|
|
}
|