From fb439a82a8e6775c533b7476171e45b9d3f15eb9 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Sun, 30 Apr 2023 12:33:41 +0000 Subject: [PATCH] [Enhancement] Communications library for non Apple platforms (#15) This PR contains the work done to allow the `MakeURLRequestUseCase` use case to be used in non-Apple platforms, as it use has been restricted before. To provide further details about the work done: - [x] improved the `MakeURLRequestUseCase` use case to be available in non-Apple platforms; - [x] moved the `TestEndpoint` helper endpoint to its own file; - [x] moved some test cases files around; - [x] updated some text in the `README` file. Co-authored-by: Javier Cicchelli Reviewed-on: https://repo.rock-n-code.com/rock-n-code/swift-libs/pulls/15 --- README.md | 4 +- .../Use Cases/MakeURLRequestUseCase.swift | 6 ++- .../MakeURLRequestUseCaseTests.swift | 37 ++-------------- .../Helpers/Endpoints/TestEndpoint.swift | 43 +++++++++++++++++++ .../Extensions/Bool+InitTests.swift | 0 .../Extensions/String+EmptyTests.swift | 0 6 files changed, 53 insertions(+), 37 deletions(-) create mode 100644 Tests/Communications/Helpers/Endpoints/TestEndpoint.swift rename Tests/Core/{ => Cases}/Extensions/Bool+InitTests.swift (100%) rename Tests/Core/{ => Cases}/Extensions/String+EmptyTests.swift (100%) diff --git a/README.md b/README.md index 27f83fc..c348c0d 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ To provide further details about the libraries included in this package: * `Coordination`: protocols to implement the [Coordinator pattern](https://khanlou.com/2015/01/the-coordinator/) and some ready-to-use platform-specific concrete routers; * `Core`: extensions we usually add to the base layer functionality and primitive types provided by the [Swift standard library](https://https://www.swift.org/documentation/#standard-library); * `Dependencies`: a ready-to-use, simple [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) mechanism that levers heavily on the [dynamic property wrappers](https://www.hackingwithswift.com/plus/intermediate-swiftui/creating-a-custom-property-wrapper-using-dynamicproperty) provided by the [Swift programming language](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/properties/#Projecting-a-Value-From-a-Property-Wrapper); -* `Persistence`: protocols, extensions and a ready-to-use fetcher class to simplify the building of the [CoreData](https://developer.apple.com/documentation/coredata) persistence layer; +* `Persistence` (*available for Apple platforms only*): protocols, extensions and a ready-to-use fetcher class to simplify the building of the [CoreData](https://developer.apple.com/documentation/coredata) persistence layer; ## Installation @@ -73,6 +73,6 @@ In an opened Xcode project, it is required to follow these steps to install the ### Other considerations -This library is fully supported on Apple platforms: *iOS*, *macOS*, *tvOS*, and *watchOS*. In addition, basic support for *Linux* platform has been added as well, but it is rather limited for the time being, but it is just a matter of time as the Foundation framework is [moving towards cross-platform support](https://www.swift.org/blog/foundation-preview-now-available). +This library is fully supported on Apple platforms: *iOS*, *macOS*, *tvOS*, and *watchOS*. In addition, basic support for *Linux* platform has been added as well, but it is rather limited for the time being. It is just a matter of time, though, as the Foundation framework is [moving towards cross-platform support](https://www.swift.org/blog/foundation-preview-now-available) by moving away from its dependency on legacy Objective-C components. ⚠️ Please notice that this library only supports the [Swift Package Manager](https://www.swift.org/package-manager/), and that support for other dependency managers such as *Cocoapods* and *Carthage* has not been prioritised. diff --git a/Sources/Communications/Use Cases/MakeURLRequestUseCase.swift b/Sources/Communications/Use Cases/MakeURLRequestUseCase.swift index f483f8a..aed0a84 100644 --- a/Sources/Communications/Use Cases/MakeURLRequestUseCase.swift +++ b/Sources/Communications/Use Cases/MakeURLRequestUseCase.swift @@ -10,9 +10,12 @@ // //===----------------------------------------------------------------------===// -#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) import Foundation +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif + /// This use case generate a url request out of a given endpoint. public struct MakeURLRequestUseCase { @@ -56,4 +59,3 @@ public struct MakeURLRequestUseCase { } } -#endif diff --git a/Tests/Communications/Cases/Use Cases/MakeURLRequestUseCaseTests.swift b/Tests/Communications/Cases/Use Cases/MakeURLRequestUseCaseTests.swift index ab95f5d..3fdd850 100644 --- a/Tests/Communications/Cases/Use Cases/MakeURLRequestUseCaseTests.swift +++ b/Tests/Communications/Cases/Use Cases/MakeURLRequestUseCaseTests.swift @@ -10,11 +10,14 @@ // //===----------------------------------------------------------------------===// -#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) import Communications import Foundation import XCTest +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif + final class MakeURLRequestUseCaseTests: XCTestCase { // MARK: Properties @@ -111,35 +114,3 @@ final class MakeURLRequestUseCaseTests: XCTestCase { } } - -// MARK: - TestEndpoint - -private struct TestEndpoint: Endpoint { - - // MARK: Properties - - let scheme: String = "http" - let host: String = "www.something.com" - let port: Int? - let path: String = "/path/to/endpoint" - let parameters: Parameters - let method: HTTPRequestMethod = .get - let headers: Headers - let body: Data? - - // MARK: Initialisers - - init( - port: Int? = nil, - parameters: Parameters = [:], - headers: Headers = [:], - body: Data? = nil - ) { - self.port = port - self.parameters = parameters - self.headers = headers - self.body = body - } - -} -#endif diff --git a/Tests/Communications/Helpers/Endpoints/TestEndpoint.swift b/Tests/Communications/Helpers/Endpoints/TestEndpoint.swift new file mode 100644 index 0000000..f7f5ce5 --- /dev/null +++ b/Tests/Communications/Helpers/Endpoints/TestEndpoint.swift @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftLibs open source project +// +// Copyright (c) 2023 Röck+Cöde VoF. and the SwiftLibs project authors +// Licensed under the EUPL 1.2 or later. +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of SwiftLibs project authors +// +//===----------------------------------------------------------------------===// + +import Communications +import Foundation + +struct TestEndpoint: Endpoint { + + // MARK: Properties + + let scheme: String = "http" + let host: String = "www.something.com" + let port: Int? + let path: String = "/path/to/endpoint" + let parameters: Parameters + let method: HTTPRequestMethod = .get + let headers: Headers + let body: Data? + + // MARK: Initialisers + + init( + port: Int? = nil, + parameters: Parameters = [:], + headers: Headers = [:], + body: Data? = nil + ) { + self.port = port + self.parameters = parameters + self.headers = headers + self.body = body + } + +} diff --git a/Tests/Core/Extensions/Bool+InitTests.swift b/Tests/Core/Cases/Extensions/Bool+InitTests.swift similarity index 100% rename from Tests/Core/Extensions/Bool+InitTests.swift rename to Tests/Core/Cases/Extensions/Bool+InitTests.swift diff --git a/Tests/Core/Extensions/String+EmptyTests.swift b/Tests/Core/Cases/Extensions/String+EmptyTests.swift similarity index 100% rename from Tests/Core/Extensions/String+EmptyTests.swift rename to Tests/Core/Cases/Extensions/String+EmptyTests.swift