|
| 1 | +// |
| 2 | +// PhotoKitServiceErrorTests.swift |
| 3 | +// RemoteImageTests |
| 4 | +// |
| 5 | +// Created by Christian Elies on 14.12.19. |
| 6 | +// |
| 7 | + |
| 8 | +@testable import RemoteImage |
| 9 | +import XCTest |
| 10 | + |
| 11 | +final class PhotoKitServiceErrorTests: XCTestCase { |
| 12 | + let localIdentifier = "TestIdentifier" |
| 13 | + |
| 14 | + func testMissingDataErrorDescription() { |
| 15 | + let error: PhotoKitServiceError = .missingData |
| 16 | + let expectedErrorDescription = "The asset could not be loaded." |
| 17 | + XCTAssertEqual(error.errorDescription, expectedErrorDescription) |
| 18 | + } |
| 19 | + |
| 20 | + func testMissingDataFailureReason() { |
| 21 | + let error: PhotoKitServiceError = .missingData |
| 22 | + let expectedFailureReason = "The asset data could not be fetched. Maybe you are not connected to the internet." |
| 23 | + XCTAssertEqual(error.failureReason, expectedFailureReason) |
| 24 | + } |
| 25 | + |
| 26 | + func testMissingDataRecoverySuggestion() { |
| 27 | + let error: PhotoKitServiceError = .missingData |
| 28 | + let expectedRecoverySuggestion = "Check your internet connection or try again later." |
| 29 | + XCTAssertEqual(error.recoverySuggestion, expectedRecoverySuggestion) |
| 30 | + } |
| 31 | + |
| 32 | + func testMissingDataErrorCode() { |
| 33 | + let error: PhotoKitServiceError = .missingData |
| 34 | + let expectedErrorCode: Int = 0 |
| 35 | + XCTAssertEqual(error.errorCode, expectedErrorCode) |
| 36 | + } |
| 37 | + |
| 38 | + func testPhAssetNotFoundErrorDescription() { |
| 39 | + let error: PhotoKitServiceError = .phAssetNotFound(localIdentifier: localIdentifier) |
| 40 | + let expectedErrorDescription = "A PHAsset with the identifier \(localIdentifier) was not found." |
| 41 | + XCTAssertEqual(error.errorDescription, expectedErrorDescription) |
| 42 | + } |
| 43 | + |
| 44 | + func testPhAssetNotFoundFailureReason() { |
| 45 | + let error: PhotoKitServiceError = .phAssetNotFound(localIdentifier: localIdentifier) |
| 46 | + let expectedFailureReason = "An asset with the identifier \(localIdentifier) doesn't exist anymore." |
| 47 | + XCTAssertEqual(error.failureReason, expectedFailureReason) |
| 48 | + } |
| 49 | + |
| 50 | + func testPhAssetNotFoundRecoverySuggestion() { |
| 51 | + let error: PhotoKitServiceError = .phAssetNotFound(localIdentifier: localIdentifier) |
| 52 | + XCTAssertNil(error.recoverySuggestion) |
| 53 | + } |
| 54 | + |
| 55 | + func testPhAssetNotFoundErrorCode() { |
| 56 | + let error: PhotoKitServiceError = .phAssetNotFound(localIdentifier: localIdentifier) |
| 57 | + let expectedErrorCode: Int = 1 |
| 58 | + XCTAssertEqual(error.errorCode, expectedErrorCode) |
| 59 | + } |
| 60 | + |
| 61 | + func testErrorDomain() { |
| 62 | + XCTAssertEqual(PhotoKitServiceError.errorDomain, String(describing: PhotoKitService.self)) |
| 63 | + } |
| 64 | +} |
0 commit comments