@@ -32,6 +32,23 @@ class HttpClientCachingTests: XCTestCase {
3232 XCTAssertTrue ( cachedData. elementsEqual ( data) , " Should cache data " )
3333 XCTAssertEqual ( 1 , try ! FileManager . default. contentsOfDirectory ( atPath: cacheDirectory. path) . count, " Should save data on disk " )
3434 }
35+
36+ func testCacheCustomMethodResponse( ) {
37+ let data = " Some responded data " . data ( using: . utf8) !
38+ let requestUrl = URL ( string: " https://test.com/json " ) !
39+ let _ = stub ( condition: { $0. url == requestUrl && $0. httpMethod == HttpMethod . put. rawValue } ) { _ in
40+ return OHHTTPStubsResponse ( data: data, statusCode: 200 , headers: nil )
41+ }
42+
43+ let cacheMode = CacheMode ( cacheResponse: true , returnCachedResponse: true , invokeRequest: true , cacheHttpMethods: [ . put] )
44+ let exp = expectation ( description: " Should complete request " )
45+ _ = client. requestData ( url: requestUrl, method: . put, requestCacheMode: cacheMode) . subscribe ( onCompleted: { exp. fulfill ( ) } )
46+ waitForExpectations ( timeout: waitTimeout, handler: nil )
47+
48+ let cachedData = try ! Data ( contentsOf: cacheDirectory. appendingPathComponent ( requestUrl. sha1 ( ) ) )
49+ XCTAssertTrue ( cachedData. elementsEqual ( data) , " Should cache data " )
50+ XCTAssertEqual ( 1 , try ! FileManager . default. contentsOfDirectory ( atPath: cacheDirectory. path) . count, " Should save data on disk " )
51+ }
3552
3653 func testReturnCachedResponse( ) {
3754 let data = " Some responded data " . data ( using: . utf8) !
0 commit comments