@@ -80,6 +80,35 @@ class MicroyaIntegrationTests: XCTestCase {
8080 XCTAssertEqual ( typedResponseBody. url, " https://postman-echo.com/post " )
8181 }
8282
83+ func testRawDataPost( ) throws {
84+ let dataResponseBody =
85+ try sampleApiProvider. performRawDataRequestAndWait (
86+ on: . post( fooBar: FooBar ( foo: " Lorem " , bar: " Ipsum " ) )
87+ )
88+ . get ( )
89+
90+ XCTAssertEqual ( TestDataStore . request? . allHTTPHeaderFields ? [ " Content-Type " ] , " application/json " )
91+ XCTAssertEqual ( TestDataStore . request? . allHTTPHeaderFields ? [ " Accept " ] , " application/json " )
92+ XCTAssertEqual ( TestDataStore . request? . allHTTPHeaderFields ? [ " Accept-Language " ] , " en " )
93+ XCTAssertEqual ( TestDataStore . request? . allHTTPHeaderFields ? [ " Authorization " ] , " Basic abc123 " )
94+
95+ XCTAssertEqual ( TestDataStore . request? . httpMethod, " POST " )
96+ XCTAssertEqual ( TestDataStore . request? . url? . path, " /post " )
97+ XCTAssertNil ( TestDataStore . request? . url? . query)
98+
99+ XCTAssertNotNil ( TestDataStore . urlSessionResult? . data)
100+ XCTAssertNil ( TestDataStore . urlSessionResult? . error)
101+ XCTAssertNotNil ( TestDataStore . urlSessionResult? . response)
102+
103+ let typedResponseBody = try JSONDecoder ( ) . decode ( PostmanEchoResponse . self, from: dataResponseBody)
104+
105+ XCTAssertEqual ( typedResponseBody. args, [ : ] )
106+ XCTAssertEqual ( typedResponseBody. headers [ " content-type " ] , " application/json " )
107+ XCTAssertEqual ( typedResponseBody. headers [ " accept " ] , " application/json " )
108+ XCTAssertEqual ( typedResponseBody. headers [ " accept-language " ] , " en " )
109+ XCTAssertEqual ( typedResponseBody. url, " https://postman-echo.com/post " )
110+ }
111+
83112 func testGet( ) throws {
84113 let expectation = XCTestExpectation ( )
85114
@@ -237,6 +266,46 @@ class MicroyaIntegrationTests: XCTestCase {
237266 #endif
238267 }
239268
269+ func testPostRawDataCombine( ) throws {
270+ #if canImport(Combine)
271+ let expectation = XCTestExpectation ( )
272+
273+ sampleApiProvider. rawDataPublisher (
274+ on: . post( fooBar: FooBar ( foo: " Lorem " , bar: " Ipsum " ) )
275+ )
276+ . sink (
277+ receiveCompletion: { _ in } ,
278+ receiveValue: { dataResponseBody in
279+ XCTAssertEqual ( TestDataStore . request? . allHTTPHeaderFields ? [ " Content-Type " ] , " application/json " )
280+ XCTAssertEqual ( TestDataStore . request? . allHTTPHeaderFields ? [ " Accept " ] , " application/json " )
281+ XCTAssertEqual ( TestDataStore . request? . allHTTPHeaderFields ? [ " Accept-Language " ] , " en " )
282+ XCTAssertEqual ( TestDataStore . request? . allHTTPHeaderFields ? [ " Authorization " ] , " Basic abc123 " )
283+
284+ XCTAssertEqual ( TestDataStore . request? . httpMethod, " POST " )
285+ XCTAssertEqual ( TestDataStore . request? . url? . path, " /post " )
286+ XCTAssertNil ( TestDataStore . request? . url? . query)
287+
288+ XCTAssertNotNil ( TestDataStore . urlSessionResult? . data)
289+ XCTAssertNil ( TestDataStore . urlSessionResult? . error)
290+ XCTAssertNotNil ( TestDataStore . urlSessionResult? . response)
291+
292+ let typedResponseBody = try ! JSONDecoder ( ) . decode ( PostmanEchoResponse . self, from: dataResponseBody)
293+
294+ XCTAssertEqual ( typedResponseBody. args, [ : ] )
295+ XCTAssertEqual ( typedResponseBody. headers [ " content-type " ] , " application/json " )
296+ XCTAssertEqual ( typedResponseBody. headers [ " accept " ] , " application/json " )
297+ XCTAssertEqual ( typedResponseBody. headers [ " accept-language " ] , " en " )
298+ XCTAssertEqual ( typedResponseBody. url, " https://postman-echo.com/post " )
299+
300+ expectation. fulfill ( )
301+ }
302+ )
303+ . store ( in: & cancellables)
304+
305+ wait ( for: [ expectation] , timeout: 10 )
306+ #endif
307+ }
308+
240309 func testGetCombine( ) throws {
241310 #if canImport(Combine)
242311 let expectation = XCTestExpectation ( )
@@ -525,6 +594,36 @@ class MicroyaIntegrationTests: XCTestCase {
525594 XCTAssertEqual ( typedResponseBody. url, " https://postman-echo.com/post " )
526595 }
527596
597+ @available ( iOS 15 , tvOS 15 , macOS 12 , watchOS 8 , * )
598+ func testPostRawDataAsync( ) async throws {
599+ let dataResponseBody =
600+ try await sampleApiProvider. rawDataResponse (
601+ on: . post( fooBar: FooBar ( foo: " Lorem " , bar: " Ipsum " ) )
602+ )
603+ . get ( )
604+
605+ XCTAssertEqual ( TestDataStore . request? . allHTTPHeaderFields ? [ " Content-Type " ] , " application/json " )
606+ XCTAssertEqual ( TestDataStore . request? . allHTTPHeaderFields ? [ " Accept " ] , " application/json " )
607+ XCTAssertEqual ( TestDataStore . request? . allHTTPHeaderFields ? [ " Accept-Language " ] , " en " )
608+ XCTAssertEqual ( TestDataStore . request? . allHTTPHeaderFields ? [ " Authorization " ] , " Basic abc123 " )
609+
610+ XCTAssertEqual ( TestDataStore . request? . httpMethod, " POST " )
611+ XCTAssertEqual ( TestDataStore . request? . url? . path, " /post " )
612+ XCTAssertNil ( TestDataStore . request? . url? . query)
613+
614+ XCTAssertNotNil ( TestDataStore . urlSessionResult? . data)
615+ XCTAssertNil ( TestDataStore . urlSessionResult? . error)
616+ XCTAssertNotNil ( TestDataStore . urlSessionResult? . response)
617+
618+ let typedResponseBody = try JSONDecoder ( ) . decode ( PostmanEchoResponse . self, from: dataResponseBody)
619+
620+ XCTAssertEqual ( typedResponseBody. args, [ : ] )
621+ XCTAssertEqual ( typedResponseBody. headers [ " content-type " ] , " application/json " )
622+ XCTAssertEqual ( typedResponseBody. headers [ " accept " ] , " application/json " )
623+ XCTAssertEqual ( typedResponseBody. headers [ " accept-language " ] , " en " )
624+ XCTAssertEqual ( typedResponseBody. url, " https://postman-echo.com/post " )
625+ }
626+
528627 @available ( iOS 15 , tvOS 15 , macOS 12 , watchOS 8 , * )
529628 func testGetAsync( ) async {
530629 let response = await sampleApiProvider. response (
0 commit comments