<commit_before>//
//  AlamofireExtensionTests.swift
//  Serializable
//
//  Created by <NAME> on 18/03/16.
//  Copyright © 2016 Nodes. All rights reserved.
//

import XCTest
import Serializable
import Alamofire

class AlamofireExtensionTests: XCTestCase {
	
    let timeoutDuration = 15.0
    
	let manager = SessionManager()
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
 
	
	func testAlamofireExtension() {
		let expectation = self.expectation(description: "Expected network request success")
		let handler:(Alamofire.DataResponse<NetworkTestModel>) -> Void = { result in
			switch result.result {
			case .success:
				expectation.fulfill()
			default:
				break // Fail
				
			}
		}
		manager.request("http://httpbin.org/get", method: .get).responseSerializable(handler)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
	
	func testAlamofireExtensionBadJSON() {
		let expectation = self.expectation(description: "Expected bad data from response")
		let handler:(Alamofire.DataResponse<NetworkTestModel>) -> Void = { result in
			switch result.result {
			case .failure:
				expectation.fulfill()
			default:
				break
			}
		}
		manager.request("http://httpbin.org/deny", method: .get).responseSerializable(handler)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}

	
	func testAlamofireExtensionBadJSONObject() {
		let expectation = self.expectation(description: "Expected bad object from response")
		let handler:(Alamofire.DataResponse<[NetworkTestModel]>) -> Void = { result in
			switch result.result {
			case .failure:
				expectation.fulfill()
			default:
				break
			}
		}
		manager.request("http://httpbin.org/get", method: .get).responseSerializable(handler)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
	func testAlamofireExtensionUnexpectedArrayJSON() {
		let expectation = self.expectation(description: "Expected array data to single object from response")
		let handler:(Alamofire.DataResponse<DecodableModel>) -> Void = { result in
			switch result.result {
			case .failure:
				expectation.fulfill()
			default:
				break
			}
		}
		manager.request("https://raw.githubusercontent.com/nodes-ios/Serializable/master/Serializable/SerializableTests/TestEndpoint/ArrayTest.json", method: .get).responseSerializable(handler)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
	func testAlamofireExtensionEmptyJSON() {
		let expectation = self.expectation(description: "Expected empty response")
		let handler:(Alamofire.DataResponse<NetworkTestModel>) -> Void = { result in
			switch result.result {
			case .failure:
				expectation.fulfill()
			default:
				break
			}
		}
		manager.request("https://raw.githubusercontent.com/nodes-ios/Serializable/master/Serializable/SerializableTests/TestEndpoint/Empty.json", method: .get).responseSerializable(handler)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
	func testAlamofireArrayUnwrapper() {
		let expectation = self.expectation(description: "Expected unwrapped array response")
		let handler:(Alamofire.DataResponse<[DecodableModel]>) -> Void = { result in
			switch result.result {
			case .success:
				expectation.fulfill()
			default:
				break
			}
		}
		let unwrapper: Parser.Unwrapper = { $0.0["data"] }
		
		manager.request("https://raw.githubusercontent.com/nodes-ios/Serializable/master/Serializable/SerializableTests/TestEndpoint/NestedArrayTest.json",
		                method: .get)
			.responseSerializable(handler, unwrapper: unwrapper)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
	
	func testAlamofireArrayNotUnwrapped() {
		let expectation = self.expectation(description: "Expected unwrapped array response")
		let handler:(Alamofire.DataResponse<[DecodableModel]>) -> Void = { result in
			switch result.result {
			case .failure:
				expectation.fulfill()
			default:
				break
			}
		}		
		
		manager.request("https://raw.githubusercontent.com/nodes-ios/Serializable/master/Serializable/SerializableTests/TestEndpoint/NestedArrayTest.json",
		                method: .get)
			.responseSerializable(handler)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
	func testAlamofireWrongTypeUnwrapper() {
		let expectation = self.expectation(description: "Expected unwrapped array response")
		let handler:(Alamofire.DataResponse<DecodableModel>) -> Void = { result in
			switch result.result {
			case .success:
				expectation.fulfill()
			default:
				break
			}
		}
		let unwrapper: Parser.Unwrapper = { $0.0["data"] }
		
		manager.request("https://raw.githubusercontent.com/nodes-ios/Serializable/master/Serializable/SerializableTests/TestEndpoint/NestedArrayTest.json",
			method: .get)
			.responseSerializable(handler, unwrapper: unwrapper)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
    
    func testAlamofireExtensionNonSerializable() {
        let expectation = self.expectation(description: "Expected empty response")
        let handler:(Alamofire.DataResponse<NilSerializable>) -> Void = { result in
            switch result.result {
            case .failure:
                expectation.fulfill()
            default:
                break
            }
        }
        manager.request("https://raw.githubusercontent.com/nodes-ios/Serializable/master/Serializable/SerializableTests/TestEndpoint/Empty.json", method: .get).responseSerializable(handler)
        waitForExpectations(timeout: timeoutDuration, handler: nil)
    }
}
<commit_msg>Upped timeout to 60 secs for tests to pass during peak hours<commit_after>//
//  AlamofireExtensionTests.swift
//  Serializable
//
//  Created by <NAME> on 18/03/16.
//  Copyright © 2016 Nodes. All rights reserved.
//

import XCTest
import Serializable
import Alamofire

class AlamofireExtensionTests: XCTestCase {
	
    let timeoutDuration = 60.0
    
	let manager = SessionManager()
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
 
	
	func testAlamofireExtension() {
		let expectation = self.expectation(description: "Expected network request success")
		let handler:(Alamofire.DataResponse<NetworkTestModel>) -> Void = { result in
			switch result.result {
			case .success:
				expectation.fulfill()
			default:
				break // Fail
				
			}
		}
		manager.request("http://httpbin.org/get", method: .get).responseSerializable(handler)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
	
	func testAlamofireExtensionBadJSON() {
		let expectation = self.expectation(description: "Expected bad data from response")
		let handler:(Alamofire.DataResponse<NetworkTestModel>) -> Void = { result in
			switch result.result {
			case .failure:
				expectation.fulfill()
			default:
				break
			}
		}
		manager.request("http://httpbin.org/deny", method: .get).responseSerializable(handler)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}

	
	func testAlamofireExtensionBadJSONObject() {
		let expectation = self.expectation(description: "Expected bad object from response")
		let handler:(Alamofire.DataResponse<[NetworkTestModel]>) -> Void = { result in
			switch result.result {
			case .failure:
				expectation.fulfill()
			default:
				break
			}
		}
		manager.request("http://httpbin.org/get", method: .get).responseSerializable(handler)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
	func testAlamofireExtensionUnexpectedArrayJSON() {
		let expectation = self.expectation(description: "Expected array data to single object from response")
		let handler:(Alamofire.DataResponse<DecodableModel>) -> Void = { result in
			switch result.result {
			case .failure:
				expectation.fulfill()
			default:
				break
			}
		}
		manager.request("https://raw.githubusercontent.com/nodes-ios/Serializable/master/Serializable/SerializableTests/TestEndpoint/ArrayTest.json", method: .get).responseSerializable(handler)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
	func testAlamofireExtensionEmptyJSON() {
		let expectation = self.expectation(description: "Expected empty response")
		let handler:(Alamofire.DataResponse<NetworkTestModel>) -> Void = { result in
			switch result.result {
			case .failure:
				expectation.fulfill()
			default:
				break
			}
		}
		manager.request("https://raw.githubusercontent.com/nodes-ios/Serializable/master/Serializable/SerializableTests/TestEndpoint/Empty.json", method: .get).responseSerializable(handler)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
	func testAlamofireArrayUnwrapper() {
		let expectation = self.expectation(description: "Expected unwrapped array response")
		let handler:(Alamofire.DataResponse<[DecodableModel]>) -> Void = { result in
			switch result.result {
			case .success:
				expectation.fulfill()
			default:
				break
			}
		}
		let unwrapper: Parser.Unwrapper = { $0.0["data"] }
		
		manager.request("https://raw.githubusercontent.com/nodes-ios/Serializable/master/Serializable/SerializableTests/TestEndpoint/NestedArrayTest.json",
		                method: .get)
			.responseSerializable(handler, unwrapper: unwrapper)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
	
	func testAlamofireArrayNotUnwrapped() {
		let expectation = self.expectation(description: "Expected unwrapped array response")
		let handler:(Alamofire.DataResponse<[DecodableModel]>) -> Void = { result in
			switch result.result {
			case .failure:
				expectation.fulfill()
			default:
				break
			}
		}		
		
		manager.request("https://raw.githubusercontent.com/nodes-ios/Serializable/master/Serializable/SerializableTests/TestEndpoint/NestedArrayTest.json",
		                method: .get)
			.responseSerializable(handler)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
	func testAlamofireWrongTypeUnwrapper() {
		let expectation = self.expectation(description: "Expected unwrapped array response")
		let handler:(Alamofire.DataResponse<DecodableModel>) -> Void = { result in
			switch result.result {
			case .success:
				expectation.fulfill()
			default:
				break
			}
		}
		let unwrapper: Parser.Unwrapper = { $0.0["data"] }
		
		manager.request("https://raw.githubusercontent.com/nodes-ios/Serializable/master/Serializable/SerializableTests/TestEndpoint/NestedArrayTest.json",
			method: .get)
			.responseSerializable(handler, unwrapper: unwrapper)
		waitForExpectations(timeout: timeoutDuration, handler: nil)
	}
    
    func testAlamofireExtensionNonSerializable() {
        let expectation = self.expectation(description: "Expected empty response")
        let handler:(Alamofire.DataResponse<NilSerializable>) -> Void = { result in
            switch result.result {
            case .failure:
                expectation.fulfill()
            default:
                break
            }
        }
        manager.request("https://raw.githubusercontent.com/nodes-ios/Serializable/master/Serializable/SerializableTests/TestEndpoint/Empty.json", method: .get).responseSerializable(handler)
        waitForExpectations(timeout: timeoutDuration, handler: nil)
    }
}

{'fraction_non_alphanumeric': 0.106550837691694, 'fraction_numerical': 0.003191206453328606, 'mean_word_length': 3.888214904679376, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 41, 'https://': 12, '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': '2404345', 'n_tokens_mistral': 3682, 'n_tokens_neox': 3227, 'n_words': 659}