-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Ast3r10n/release/0.2
Release 0.2
- Loading branch information
Showing
12 changed files
with
228 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,18 @@ | ||
name: Swift | ||
name: Test | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: macos-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Build | ||
run: swift build -v | ||
test: | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Run tests | ||
run: swift test -v --enable-code-coverage | ||
|
||
codecov: | ||
runs-on: macos-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Generate coverage report | ||
run: xcodebuild -scheme SwiftQuests -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 11 Pro' -enableCodeCoverage YES build test | ||
run: | | ||
swift test --enable-code-coverage | ||
xcrun llvm-cov export -format="lcov" .build/debug/SwiftQuestsPackageTests.xctest/Contents/MacOS/SwiftQuestsPackageTests -instr-profile .build/debug/codecov/default.profdata > info.lcov | ||
- name: Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: 44439f4d-d012-4000-a0c1-28647d07b545 | ||
# file: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
// swift-tools-version:5.1 | ||
// swift-tools-version:5.3 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "SwiftQuests", | ||
products: [ | ||
.library( | ||
name: "SwiftQuests", | ||
targets: ["SwiftQuests"]), | ||
], | ||
targets: [ | ||
.target( | ||
name: "SwiftQuests", | ||
dependencies: []), | ||
.testTarget( | ||
name: "SwiftQuestsTests", | ||
dependencies: ["SwiftQuests"]), | ||
] | ||
name: "SwiftQuests", | ||
products: [ | ||
.library( | ||
name: "SwiftQuests", | ||
targets: ["SwiftQuests"]), | ||
], | ||
targets: [ | ||
.target( | ||
name: "SwiftQuests", | ||
dependencies: []), | ||
.testTarget( | ||
name: "SwiftQuestsTests", | ||
dependencies: ["SwiftQuests"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// NetworkError.swift | ||
// | ||
// | ||
// Created by Andrea Sacerdoti on 17/12/20. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A specialized error for network purposes. | ||
public enum NetworkError: LocalizedError { | ||
|
||
/// A generic network error. | ||
case generic | ||
|
||
/// An error identifying the 400 HTTP status code. | ||
case badRequest | ||
|
||
/// An error identifying the 401 HTTP status code. | ||
case unauthorized | ||
|
||
/// An error identifying the 403 HTTP status code. | ||
case forbidden | ||
|
||
/// An error identifying the 404 HTTP status code. | ||
case notFound | ||
|
||
/// An error identifying the 500 HTTP status code. | ||
case internalServerError | ||
|
||
/// An error including a description provided by the backend. | ||
case withDescription(String) | ||
|
||
public var errorDescription: String? { | ||
switch self { | ||
case .generic: | ||
return NSLocalizedString("Generic error.", comment: "") | ||
case .badRequest: | ||
return NSLocalizedString("Bad request.", comment: "") | ||
case .unauthorized: | ||
return NSLocalizedString("Unauthorized.", comment: "") | ||
case .forbidden: | ||
return NSLocalizedString("Access denied.", comment: "") | ||
case .notFound: | ||
return NSLocalizedString("Resource not found.", comment: "") | ||
case .internalServerError: | ||
return NSLocalizedString("Internal server error.", comment: "") | ||
case .withDescription(let description): | ||
return NSLocalizedString(description, comment: "") | ||
} | ||
} | ||
|
||
/// Returns a NetworkError identifying a given HTTP error. | ||
/// - Parameter statusCode: The given HTTP status code. | ||
/// - Returns: A NetworkError identified by the given status code. | ||
public static func identifying(statusCode: Int) -> NetworkError { | ||
switch statusCode { | ||
case 400: | ||
return NetworkError.badRequest | ||
case 401: | ||
return NetworkError.unauthorized | ||
case 403: | ||
return NetworkError.forbidden | ||
case 404: | ||
return NetworkError.notFound | ||
case 500: | ||
return NetworkError.internalServerError | ||
default: | ||
return NetworkError.generic | ||
} | ||
} | ||
} | ||
|
||
// MARK: - | ||
extension NetworkError: Equatable { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// URLProtocolMock.swift | ||
// | ||
// | ||
// Created by Andrea Sacerdoti on 05/02/2020. | ||
// | ||
|
||
import Foundation | ||
|
||
class URLProtocolMock: URLProtocol { | ||
static var response: (data: Data?, response: URLResponse?, error: Error?)? | ||
|
||
override class func canInit(with request: URLRequest) -> Bool { | ||
true | ||
} | ||
|
||
override class func canonicalRequest(for request: URLRequest) -> URLRequest { | ||
request | ||
} | ||
|
||
override func startLoading() { | ||
if let (data, response, error) = URLProtocolMock.response { | ||
|
||
if let response = response { | ||
client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed) | ||
} | ||
|
||
if let data = data { | ||
client?.urlProtocol(self, didLoad: data) | ||
} | ||
|
||
if let error = error { | ||
client?.urlProtocol(self, didFailWithError: error) | ||
} | ||
} | ||
|
||
client?.urlProtocolDidFinishLoading(self) | ||
} | ||
|
||
override func stopLoading() { | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// NetworkErrorTests.swift | ||
// | ||
// | ||
// Created by Andrea Sacerdoti on 02/07/21. | ||
// | ||
|
||
import XCTest | ||
@testable import SwiftQuests | ||
|
||
final class NetworkErrorTests: XCTestCase { | ||
|
||
func testErrorDescription() { | ||
XCTAssertNotNil(NetworkError.generic.errorDescription) | ||
XCTAssertNotNil(NetworkError.badRequest.errorDescription) | ||
XCTAssertNotNil(NetworkError.unauthorized.errorDescription) | ||
XCTAssertNotNil(NetworkError.forbidden.errorDescription) | ||
XCTAssertNotNil(NetworkError.notFound.errorDescription) | ||
XCTAssertNotNil(NetworkError.internalServerError.errorDescription) | ||
XCTAssertEqual(NetworkError.withDescription("Test Description").localizedDescription, "Test Description") | ||
} | ||
|
||
func testIdentifying() { | ||
XCTAssertEqual(NetworkError.identifying(statusCode: 400), .badRequest) | ||
XCTAssertEqual(NetworkError.identifying(statusCode: 401), .unauthorized) | ||
XCTAssertEqual(NetworkError.identifying(statusCode: 403), .forbidden) | ||
XCTAssertEqual(NetworkError.identifying(statusCode: 404), .notFound) | ||
XCTAssertEqual(NetworkError.identifying(statusCode: 405), .generic) | ||
XCTAssertEqual(NetworkError.identifying(statusCode: 500), .internalServerError) | ||
} | ||
} |
Oops, something went wrong.