diff --git a/Tests/ApolloTests/Interceptors/MultipartResponseDeferParserTests.swift b/Tests/ApolloTests/Interceptors/MultipartResponseDeferParserTests.swift index ed6c87a32..f74805136 100644 --- a/Tests/ApolloTests/Interceptors/MultipartResponseDeferParserTests.swift +++ b/Tests/ApolloTests/Interceptors/MultipartResponseDeferParserTests.swift @@ -168,6 +168,56 @@ final class MultipartResponseDeferParserTests: XCTestCase { wait(for: [expectation], timeout: defaultTimeout) } + func test__parsing__givenSingleChunk_withMultipleContentTypeDirectives_shouldReturnSuccess() throws { + let subject = InterceptorTester(interceptor: MultipartResponseParsingInterceptor()) + + let expectation = expectation(description: "Received callback") + + let expected: JSONObject = [ + "data": [ + "key": "value" + ], + "hasNext": true + ] + + subject.intercept( + request: .mock(operation: MockQuery.mock()), + response: .mock( + headerFields: ["Content-Type": "multipart/mixed;boundary=graphql;deferSpec=20220824"], + data: """ + + --graphql + Content-Type: application/json; charset=utf-8 + + { + "data" : { + "key" : "value" + }, + "hasNext": true + } + --graphql-- + """.crlfFormattedData() + ) + ) { result in + defer { + expectation.fulfill() + } + + expect(result).to(beSuccess()) + + guard + let response = try! result.get(), + let deserialized = try! JSONSerialization.jsonObject(with: response.rawData) as? JSONObject + else { + return fail("data could not be deserialized!") + } + + expect(deserialized).to(equal(expected)) + } + + wait(for: [expectation], timeout: defaultTimeout) + } + func test__parsing__givenMultipleChunks_shouldReturnMultipleSuccess() throws { let subject = InterceptorTester(interceptor: MultipartResponseParsingInterceptor()) diff --git a/Tests/ApolloTests/Interceptors/MultipartResponseSubscriptionParserTests.swift b/Tests/ApolloTests/Interceptors/MultipartResponseSubscriptionParserTests.swift index d5ee9f209..9a561f750 100644 --- a/Tests/ApolloTests/Interceptors/MultipartResponseSubscriptionParserTests.swift +++ b/Tests/ApolloTests/Interceptors/MultipartResponseSubscriptionParserTests.swift @@ -475,6 +475,47 @@ final class MultipartResponseSubscriptionParserTests: XCTestCase { wait(for: [expectation], timeout: defaultTimeout) } + func test__parsing__givenSingleChunk_withMultipleContentTypeDirectives_shouldReturnSuccess() throws { + let network = buildNetworkTransport(responseData: """ + + --graphql + Content-Type: application/json; charset=utf-8 + + { + "payload": { + "data": { + "__typename": "Time", + "ticker": 1 + } + } + } + --graphql-- + """.crlfFormattedData() + ) + + let expectedData = try Time(data: [ + "__typename": "Time", + "ticker": 1 + ], variables: nil) + + let expectation = expectation(description: "Multipart data received") + + _ = network.send(operation: MockSubscription