<commit_before>//
//  FetchCombineTests.swift
//  Fetch-iOS
//
//  Created by <NAME> on 21/06/2019.
//  Copyright © 2019 <NAME>. All rights reserved.
//

#if canImport(Combine)
    import Combine
    @testable import Fetch
    import Nimble
    import OHHTTPStubs
    import XCTest

    @available(iOS 13.0, *)
    extension FetchTests {
        func testItIsPossibleToMakeAGetRequestUsingAPublisher() {
            stubRequest(passingTest: { $0.url! == testURL && $0.httpMethod == "GET" })
            let publisher = session!.publisher(for: basicRequest, errorParser: nil) as AnyPublisher<TestResponse, Error>
            let exp = expectation(description: "get request")
            _ = publisher.sink {
                expect($0.name).to(equal("test name"))
                expect($0.desc).to(equal("test desc"))
                exp.fulfill()
            }
            waitForExpectations(timeout: 1.0, handler: nil)
        }

        func testSessionErrorsAreReturnedUsingAPublisher() {
            let testError = NSError(domain: NSURLErrorDomain, code: NSURLErrorCancelled, userInfo: nil)
            OHHTTPStubs.stubRequests(passingTest: { (request) -> Bool in
                return request.url! == testURL && request.httpMethod == "GET"
            }, withStubResponse: { (_) -> OHHTTPStubsResponse in
                return OHHTTPStubsResponse(error: testError)
            })
            let publisher = session!.publisher(for: basicRequest, errorParser: nil) as AnyPublisher<TestResponse, Error>
            let exp = expectation(description: "get request")
            _ = publisher.sink(receiveCompletion: {
                switch $0 {
                case .finished:
                    fail("Expected an error")
                case .failure(let error):
                    expect(error as NSError).to(equal(testError))
                }
                exp.fulfill()
            }, receiveValue: { _ in })
            waitForExpectations(timeout: 1.0, handler: nil)
        }

        func testItReturnsParsedErrorsCorrectlyUsingAPublisher() {
            stubRequest(statusCode: 400) { (request) -> Bool in
                return request.url! == testURL && request.httpMethod == "GET"
            }
            let exp = expectation(description: "get request")
            let publisher = session!.publisher(for: basicRequest, errorParser: CustomError.self) as AnyPublisher<NoDataResponse, Error>
            var receivedError: Error?
            _ = publisher.sink(receiveCompletion: {
                switch $0 {
                case .finished:
                    fail("Expected an error")
                case .failure(let error):
                    receivedError = error
                }
                exp.fulfill()
            }, receiveValue: { _ in })
            waitForExpectations(timeout: 1.0, handler: nil)
            let customError = receivedError as! CustomError // swiftlint:disable:this force_cast
            expect(customError).to(equal(CustomError.error))
        }

        func testItIncrementsTheActivityMonitorCorrectly() {
            let stubMonitor = SessionActivityMonitor(initialValue: 0, isAsynchronous: false)
            stubRequest(passingTest: { $0.url! == testURL && $0.httpMethod == "GET" })
            var isCurrentlyActive: Bool = false
            SessionActivityMonitor.sessionActivityChanged = {
                isCurrentlyActive = $0
            }
            session.activityMonitor = stubMonitor
            let publisher = session!.publisher(for: basicRequest, errorParser: nil) as AnyPublisher<TestResponse, Error>
            expect(isCurrentlyActive).to(beTrue())
            let exp = expectation(description: "get request")
            _ = publisher.sink { _ in
                exp.fulfill()
            }
            waitForExpectations(timeout: 1.0, handler: nil)
            expect(isCurrentlyActive).to(beFalse())
        }

        func testItDecrementsTheActivityMonitorCorrectlyOnSessionErrors() {
            let stubMonitor = SessionActivityMonitor(initialValue: 0, isAsynchronous: false)
            session.activityMonitor = stubMonitor
            let testError = NSError(domain: NSURLErrorDomain, code: NSURLErrorCancelled, userInfo: nil)
            OHHTTPStubs.stubRequests(passingTest: { (request) -> Bool in
                return request.url! == testURL && request.httpMethod == "GET"
            }, withStubResponse: { (_) -> OHHTTPStubsResponse in
                return OHHTTPStubsResponse(error: testError)
            })
            var isCurrentlyActive: Bool = false
            SessionActivityMonitor.sessionActivityChanged = {
                isCurrentlyActive = $0
            }
            let publisher = session!.publisher(for: basicRequest, errorParser: nil) as AnyPublisher<TestResponse, Error>
            let exp = expectation(description: "get request")
            _ = publisher.sink(receiveCompletion: { _ in
                exp.fulfill()<commit_msg>Update to use latest beta<commit_after>//
//  FetchCombineTests.swift
//  Fetch-iOS
//
//  Created by <NAME> on 21/06/2019.
//  Copyright © 2019 <NAME>. All rights reserved.
//

#if canImport(Combine)
    import Combine
    @testable import Fetch
    import Nimble
    import OHHTTPStubs
    import XCTest

    @available(iOS 13.0, *)
    extension FetchTests {
        func testItIsPossibleToMakeAGetRequestUsingAPublisher() {
            stubRequest(passingTest: { $0.url! == testURL && $0.httpMethod == "GET" })
            let publisher = session!.publisher(for: basicRequest, errorParser: nil) as AnyPublisher<TestResponse, Error>
            let exp = expectation(description: "get request")
            _ = publisher.sink(receiveCompletion: { _ in
            }, receiveValue: {
                expect($0.name).to(equal("test name"))
                expect($0.desc).to(equal("test desc"))
                exp.fulfill()
            })
            waitForExpectations(timeout: 1.0, handler: nil)
        }

        func testSessionErrorsAreReturnedUsingAPublisher() {
            let testError = NSError(domain: NSURLErrorDomain, code: NSURLErrorCancelled, userInfo: nil)
            OHHTTPStubs.stubRequests(passingTest: { (request) -> Bool in
                return request.url! == testURL && request.httpMethod == "GET"
            }, withStubResponse: { (_) -> OHHTTPStubsResponse in
                return OHHTTPStubsResponse(error: testError)
            })
            let publisher = session!.publisher(for: basicRequest, errorParser: nil) as AnyPublisher<TestResponse, Error>
            let exp = expectation(description: "get request")
            _ = publisher.sink(receiveCompletion: {
                switch $0 {
                case .finished:
                    fail("Expected an error")
                case .failure(let error):
                    expect(error as NSError).to(equal(testError))
                }
                exp.fulfill()
            }, receiveValue: { _ in })
            waitForExpectations(timeout: 1.0, handler: nil)
        }

        func testItReturnsParsedErrorsCorrectlyUsingAPublisher() {
            stubRequest(statusCode: 400) { (request) -> Bool in
                return request.url! == testURL && request.httpMethod == "GET"
            }
            let exp = expectation(description: "get request")
            let publisher = session!.publisher(for: basicRequest, errorParser: CustomError.self) as AnyPublisher<NoDataResponse, Error>
            var receivedError: Error?
            _ = publisher.sink(receiveCompletion: {
                switch $0 {
                case .finished:
                    fail("Expected an error")
                case .failure(let error):
                    receivedError = error
                }
                exp.fulfill()
            }, receiveValue: { _ in })
            waitForExpectations(timeout: 1.0, handler: nil)
            let customError = receivedError as! CustomError // swiftlint:disable:this force_cast
            expect(customError).to(equal(CustomError.error))
        }

        func testItIncrementsTheActivityMonitorCorrectly() {
            let stubMonitor = SessionActivityMonitor(initialValue: 0, isAsynchronous: false)
            stubRequest(passingTest: { $0.url! == testURL && $0.httpMethod == "GET" })
            var isCurrentlyActive: Bool = false
            SessionActivityMonitor.sessionActivityChanged = {
                isCurrentlyActive = $0
            }
            session.activityMonitor = stubMonitor
            let publisher = session!.publisher(for: basicRequest, errorParser: nil) as AnyPublisher<TestResponse, Error>
            expect(isCurrentlyActive).to(beTrue())
            let exp = expectation(description: "get request")
            _ = publisher.sink(receiveCompletion: { _ in }, receiveValue: { _ in
                exp.fulfill()
            })
            waitForExpectations(timeout: 1.0, handler: nil)
            expect(isCurrentlyActive).to(beFalse())
        }

        func testItDecrementsTheActivityMonitorCorrectlyOnSessionErrors() {
            let stubMonitor = SessionActivityMonitor(initialValue: 0, isAsynchronous: false)
            session.activityMonitor = stubMonitor
            let testError = NSError(domain: NSURLErrorDomain, code: NSURLErrorCancelled, userInfo: nil)
            OHHTTPStubs.stubRequests(passingTest: { (request) -> Bool in
                return request.url! == testURL && request.httpMethod == "GET"
            }, withStubResponse: { (_) -> OHHTTPStubsResponse in
                return OHHTTPStubsResponse(error: testError)
            })
            var isCurrentlyActive: Bool = false
            SessionActivityMonitor.sessionActivityChanged = {
                isCurrentlyActive = $0
            }
            let publisher = session!.publisher(for: basicRequest, errorParser: nil) as AnyPublisher<TestResponse, Error>
            let exp = expectation(description: "get request")
            _ = publisher.sink(receiveCompletion: { _ in
                exp.fulfill()
{'fraction_non_alphanumeric': 0.09559848635729934, 'fraction_numerical': 0.007568213503286198, 'mean_word_length': 2.0854070660522273, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4028413', 'n_tokens_mistral': 2723, 'n_tokens_neox': 2534, 'n_words': 571}