diff --git a/LeadKit.xcodeproj/project.pbxproj b/LeadKit.xcodeproj/project.pbxproj index 896bdc19..8db125c4 100644 --- a/LeadKit.xcodeproj/project.pbxproj +++ b/LeadKit.xcodeproj/project.pbxproj @@ -533,6 +533,9 @@ A6F32C101F6EBE9600AC08EE /* StringExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F32C0E1F6EBE8E00AC08EE /* StringExtensionTests.swift */; }; A6F32C111F6EBE9700AC08EE /* StringExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F32C0E1F6EBE8E00AC08EE /* StringExtensionTests.swift */; }; A6F32C121F6EBE9800AC08EE /* StringExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F32C0E1F6EBE8E00AC08EE /* StringExtensionTests.swift */; }; + B84D64B120A70B7000DD76DA /* NetworkServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84D64B020A70B7000DD76DA /* NetworkServiceTests.swift */; }; + B84D64B220A70B7000DD76DA /* NetworkServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84D64B020A70B7000DD76DA /* NetworkServiceTests.swift */; }; + B84D64B320A70B7000DD76DA /* NetworkServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84D64B020A70B7000DD76DA /* NetworkServiceTests.swift */; }; BA6C6DB45950382041948FC5 /* Pods_LeadKit_LeadKit_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CFE9323150A9760008093F73 /* Pods_LeadKit_LeadKit_iOS.framework */; }; D6EE55093E404DEA62B03DDF /* Pods_LeadKit_LeadKit_watchOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8590CA7831555C295C5DC572 /* Pods_LeadKit_LeadKit_watchOS.framework */; }; DEE25FE98D40ED1C168F384A /* Pods_LeadKit_LeadKit_iOS_Extensions.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 887F99C5326BD220C2811BD6 /* Pods_LeadKit_LeadKit_iOS_Extensions.framework */; }; @@ -780,6 +783,7 @@ A6F32C071F6EBDAA00AC08EE /* String+LocalizedComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+LocalizedComponent.swift"; sourceTree = ""; }; A6F32C0E1F6EBE8E00AC08EE /* StringExtensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensionTests.swift; sourceTree = ""; }; A854A36EB179651E6D0CC9FB /* Pods_LeadKit_tvOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKit_tvOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + B84D64B020A70B7000DD76DA /* NetworkServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkServiceTests.swift; sourceTree = ""; }; BECC6E4BF63781403877B059 /* Pods-LeadKit-LeadKit watchOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKit-LeadKit watchOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKit-LeadKit watchOS/Pods-LeadKit-LeadKit watchOS.release.xcconfig"; sourceTree = ""; }; CB02EAC4E52AF48AD64EC045 /* Pods-LeadKit iOS ExtensionsTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKit iOS ExtensionsTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKit iOS ExtensionsTests/Pods-LeadKit iOS ExtensionsTests.debug.xcconfig"; sourceTree = ""; }; CD7003F75FD6DDC97DC99A7A /* Pods-LeadKit iOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKit iOSTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKit iOSTests/Pods-LeadKit iOSTests.debug.xcconfig"; sourceTree = ""; }; @@ -1279,6 +1283,7 @@ 67186C1A1EB24B7800CFAFFB /* Info-iOS.plist */, 6782BBB91EB31DD90086E0B8 /* Info-tvOS.plist */, 671463B01EB34B1E00EAB194 /* LoadFromNibTests.swift */, + B84D64B020A70B7000DD76DA /* NetworkServiceTests.swift */, ); path = Tests; sourceTree = ""; @@ -2724,6 +2729,7 @@ 671463BE1EB34B1E00EAB194 /* LoadFromNibTests.swift in Sources */, A6C9A50F1F8BC79D009311CC /* Comparable+Extensions.swift in Sources */, 671463C41EB34B1E00EAB194 /* Post.swift in Sources */, + B84D64B120A70B7000DD76DA /* NetworkServiceTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2980,6 +2986,7 @@ buildActionMask = 2147483647; files = ( 671463CC1EB34B1E00EAB194 /* TestView.swift in Sources */, + B84D64B320A70B7000DD76DA /* NetworkServiceTests.swift in Sources */, 671463BA1EB34B1E00EAB194 /* StubCursor.swift in Sources */, 671463BD1EB34B1E00EAB194 /* CursorTests.swift in Sources */, A6F32C121F6EBE9800AC08EE /* StringExtensionTests.swift in Sources */, @@ -3136,6 +3143,7 @@ files = ( A6C9A5111F8BC79D009311CC /* Comparable+Extensions.swift in Sources */, 671463BF1EB34B1E00EAB194 /* LoadFromNibTests.swift in Sources */, + B84D64B220A70B7000DD76DA /* NetworkServiceTests.swift in Sources */, 671463C51EB34B1E00EAB194 /* Post.swift in Sources */, 671463CB1EB34B1E00EAB194 /* TestView.swift in Sources */, A6F32C111F6EBE9700AC08EE /* StringExtensionTests.swift in Sources */, diff --git a/Tests/NetworkServiceTests.swift b/Tests/NetworkServiceTests.swift new file mode 100644 index 00000000..47c281ca --- /dev/null +++ b/Tests/NetworkServiceTests.swift @@ -0,0 +1,79 @@ +// +// Copyright (c) 2017 Touch Instinct +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +import XCTest +import LeadKit +import RxSwift + +class NetworkServiceTests: XCTestCase { + + var disposeBag: DisposeBag! + + var networkService: NetworkService! + + override func setUp() { + super.setUp() + + let configuration = NetworkServiceConfiguration(baseUrl: "") + networkService = NetworkService(configuration: configuration) + disposeBag = DisposeBag() + } + + override func tearDown() { + disposeBag = nil + networkService = nil + super.tearDown() + } + + func testModelRequest() { + // given + let expectedModel = Post(userId: 1, + postId: 1, + title: "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", + body: "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto") + + var receivedModel: Post? + var error: Error? + let requestCompletedExpectation = expectation(description: "Request completed") + let apiRequest = ApiRequestParameters(url: "https://jsonplaceholder.typicode.com/posts/1", + headers: ["Content-Type": "application/json"]) + + // when + networkService.rxRequest(with: apiRequest) + .subscribe(onNext: { (_, model: Post) in + receivedModel = model + requestCompletedExpectation.fulfill() + }, onError: { + error = $0 + requestCompletedExpectation.fulfill() + }) + .disposed(by: disposeBag) + + waitForExpectations(timeout: 20, handler: nil) + + // then + XCTAssertNil(error) + XCTAssertNotNil(receivedModel) + XCTAssertEqual(receivedModel, expectedModel) + } + +}