Skip to content

Commit

Permalink
Merge pull request #60 from tdeleon/develop
Browse files Browse the repository at this point in the history
Release 2.2.1
  • Loading branch information
tdeleon authored Jan 30, 2024
2 parents ca29367 + f1a0ba6 commit 30de4b5
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 11 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@ name: Build & Test
on: [push]

jobs:

build-xcode:
strategy:
fail-fast: false
matrix:
os: [macos-14]
destination: ["iOS Simulator", "macOS", "tvOS Simulator", "watchOS Simulator", "visionOS Simulator"]

runs-on: ${{ matrix.os }}

steps:
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_15.2.app

- name: Checkout
uses: actions/checkout@v4

- name: Test
run: xcodebuild -scheme Relax-Package -destination 'platform= ${{ matrix.destination }}' test

build:
strategy:
fail-fast: false
Expand Down
11 changes: 11 additions & 0 deletions Sources/Relax/Request/Properties/Body.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public struct Body: RequestProperty {
self.init(value: try? encoder.encode(value))
}

/// Creates a body from a dictionary
/// - Parameter dictionary: Dictionary to serialize as JSON
/// - Parameter options: Options for JSONSerialization
public init(_ dictionary: [String: Any], options: JSONSerialization.WritingOptions = []) {
self.init(value: try? JSONSerialization.data(withJSONObject: dictionary, options: options))
}

/// Creates a body from any number of `Data` or `Encodable` instances using a ``Builder``.
///
/// This initializer combines all `Data` or `Encodable` instances specified in `content`. Each instance will be appended to each other (from top to
Expand Down Expand Up @@ -99,5 +106,9 @@ extension Body {
public static func buildExpression<T: Encodable>(_ expression: T) -> Body {
.init(expression)
}

public static func buildExpression(_ expression: [String: Any]) -> Body {
.init(expression)
}
}
}
12 changes: 8 additions & 4 deletions Tests/RelaxTests/AsyncTests/AsyncErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ final class AsyncErrorTests: ErrorTest {
await requestError(expected: httpError)
}

func testURLError() async {
#if !os(watchOS)
func testURLError() async throws {
#if os(watchOS)
throw XCTSkip("Not supported on watchOS")
#else
await requestError(expected: urlError)
#endif
}
Expand All @@ -48,8 +50,10 @@ final class AsyncErrorTests: ErrorTest {
}
}

func testOtherError() async {
#if !os(watchOS)
func testOtherError() async throws {
#if os(watchOS)
throw XCTSkip("Not supported on watchOS")
#else
await requestError(expected: otherError)
#endif
}
Expand Down
11 changes: 8 additions & 3 deletions Tests/RelaxTests/AsyncTests/AsyncRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ final class AsyncRequestTests: XCTestCase {
try await makeSuccess(request: service.ComplexRequests.complex)
}

#if swift(>=5.9)
// fulfillment(of:) only available on swift 5.9+
func testOverrideSession() async throws {
#if swift(<5.9)
throw XCTSkip("await fulfillment() not available before Swift 5.9")
#else
let expectation = self.expectation(description: "Mock received")
let expectedSession = URLMock.session(.mock { _ in
expectation.fulfill()
Expand All @@ -70,18 +71,22 @@ final class AsyncRequestTests: XCTestCase {
try await override.send()

await fulfillment(of: [expectation], timeout: 1)
#endif
}

func testOverrideSessionOnSendAsync() async throws {
#if swift(<5.9)
throw XCTSkip("await fulfillment() not available before Swift 5.9")
#else
let expectation = self.expectation(description: "Mock received")
let expectedSession = URLMock.session(.mock { _ in
expectation.fulfill()
})
try await InheritService.User.get.send(session: expectedSession)

await fulfillment(of: [expectation], timeout: 1)
#endif
}
#endif

func testOverrideDecoderOnSend() async throws {
let model = InheritService.User.Response(date: Date())
Expand Down
8 changes: 6 additions & 2 deletions Tests/RelaxTests/CombineTests/CombineErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ final class CombineErrorTests: ErrorTest {
}

func testURLError() throws {
#if !os(watchOS)
#if os(watchOS)
throw XCTSkip("Not supported on watchOS")
#else
try requestError(expected: urlError)
#endif
}
Expand All @@ -71,7 +73,9 @@ final class CombineErrorTests: ErrorTest {
}

func testOtherError() throws {
#if !os(watchOS)
#if os(watchOS)
throw XCTSkip("Not supported on watchOS")
#else
try requestError(expected: otherError)
#endif
}
Expand Down
8 changes: 6 additions & 2 deletions Tests/RelaxTests/CompletionTests/CompletionErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ final class CompletionErrorTests: ErrorTest {
}

func testURLError() throws {
#if !os(watchOS)
#if os(watchOS)
throw XCTSkip("Not supported on watchOS")
#else
try requestError(expected: urlError)
#endif
}
Expand All @@ -58,7 +60,9 @@ final class CompletionErrorTests: ErrorTest {
}

func testOtherError() throws {
#if !os(watchOS)
#if os(watchOS)
throw XCTSkip("Not supported on watchOS")
#else
try requestError(expected: otherError)
#endif
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/RelaxTests/Request/Properties/BodyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ final class BodyTests: XCTestCase {
XCTAssertEqual(body, Body(content))
}

func testBuildHeterogenousDictionary() throws {

let content: [String: Any] = ["name": "value", "status": false]
@Body.Builder
var body: Body {
content
}
#if os(Windows) && swift(>=5.7) && swift(<5.9)
throw XCTSkip("Comparison does not work correctly on Windows with Swift 5.8")
#else
XCTAssertEqual(body, Body(content))
#endif
}

func testBuildLimitedAvailability() {
@Body.Builder
var body: Body {
Expand Down

0 comments on commit 30de4b5

Please sign in to comment.