Skip to content

Commit 95ca57b

Browse files
committed
Added Tests
1 parent dedd08a commit 95ca57b

11 files changed

Lines changed: 227 additions & 39 deletions

HTTPFramework.xcodeproj/project.pbxproj

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
/* Begin PBXBuildFile section */
1010
61C6A80E0C9A5F5C2756D592 /* libPods-HTTPFramework.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BF286CA8C5E32ACBCFFAF266 /* libPods-HTTPFramework.a */; };
1111
AD7F1A582545A7FD00FD12B0 /* HTTPFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD7F1A4E2545A7FC00FD12B0 /* HTTPFramework.framework */; };
12-
AD7F1A5D2545A7FD00FD12B0 /* HTTPFrameworkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD7F1A5C2545A7FD00FD12B0 /* HTTPFrameworkTests.swift */; };
1312
AD7F1A5F2545A7FD00FD12B0 /* HTTPFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = AD7F1A512545A7FC00FD12B0 /* HTTPFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
1413
AD7F1A6B2545A84700FD12B0 /* HTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD7F1A6A2545A84700FD12B0 /* HTTPMethod.swift */; };
1514
AD7F1A6F2545A88400FD12B0 /* HTTPRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD7F1A6E2545A88400FD12B0 /* HTTPRequest.swift */; };
@@ -18,6 +17,13 @@
1817
AD7F1A7B2545ABD600FD12B0 /* HTTPResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD7F1A7A2545ABD600FD12B0 /* HTTPResult.swift */; };
1918
AD7F1A7F2545AC2400FD12B0 /* HTTPError.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD7F1A7E2545AC2400FD12B0 /* HTTPError.swift */; };
2019
ADFF720E2550027E00E78549 /* HTTPBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADFF720D2550027E00E78549 /* HTTPBody.swift */; };
20+
ADFF72122550180E00E78549 /* HTTPMethodTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADFF72112550180E00E78549 /* HTTPMethodTests.swift */; };
21+
ADFF72162550197A00E78549 /* HTTPStatusTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADFF72152550197A00E78549 /* HTTPStatusTests.swift */; };
22+
ADFF721A25501A0900E78549 /* HTTPRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADFF721925501A0900E78549 /* HTTPRequestTests.swift */; };
23+
ADFF721E25501F9100E78549 /* HTTPResponseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADFF721D25501F9100E78549 /* HTTPResponseTests.swift */; };
24+
ADFF72242550237D00E78549 /* HTTPResultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADFF72232550237D00E78549 /* HTTPResultTests.swift */; };
25+
ADFF7228255024A900E78549 /* HTTPErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADFF7227255024A900E78549 /* HTTPErrorTests.swift */; };
26+
ADFF722E255025B700E78549 /* HTTPBodyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADFF722D255025B700E78549 /* HTTPBodyTests.swift */; };
2127
/* End PBXBuildFile section */
2228

2329
/* Begin PBXContainerItemProxy section */
@@ -37,7 +43,6 @@
3743
AD7F1A512545A7FC00FD12B0 /* HTTPFramework.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTTPFramework.h; sourceTree = "<group>"; };
3844
AD7F1A522545A7FC00FD12B0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3945
AD7F1A572545A7FD00FD12B0 /* HTTPFrameworkTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HTTPFrameworkTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
40-
AD7F1A5C2545A7FD00FD12B0 /* HTTPFrameworkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPFrameworkTests.swift; sourceTree = "<group>"; };
4146
AD7F1A5E2545A7FD00FD12B0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4247
AD7F1A6A2545A84700FD12B0 /* HTTPMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPMethod.swift; sourceTree = "<group>"; };
4348
AD7F1A6E2545A88400FD12B0 /* HTTPRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPRequest.swift; sourceTree = "<group>"; };
@@ -46,6 +51,13 @@
4651
AD7F1A7A2545ABD600FD12B0 /* HTTPResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPResult.swift; sourceTree = "<group>"; };
4752
AD7F1A7E2545AC2400FD12B0 /* HTTPError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPError.swift; sourceTree = "<group>"; };
4853
ADFF720D2550027E00E78549 /* HTTPBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPBody.swift; sourceTree = "<group>"; };
54+
ADFF72112550180E00E78549 /* HTTPMethodTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPMethodTests.swift; sourceTree = "<group>"; };
55+
ADFF72152550197A00E78549 /* HTTPStatusTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPStatusTests.swift; sourceTree = "<group>"; };
56+
ADFF721925501A0900E78549 /* HTTPRequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPRequestTests.swift; sourceTree = "<group>"; };
57+
ADFF721D25501F9100E78549 /* HTTPResponseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPResponseTests.swift; sourceTree = "<group>"; };
58+
ADFF72232550237D00E78549 /* HTTPResultTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPResultTests.swift; sourceTree = "<group>"; };
59+
ADFF7227255024A900E78549 /* HTTPErrorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPErrorTests.swift; sourceTree = "<group>"; };
60+
ADFF722D255025B700E78549 /* HTTPBodyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPBodyTests.swift; sourceTree = "<group>"; };
4961
BF286CA8C5E32ACBCFFAF266 /* libPods-HTTPFramework.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-HTTPFramework.a"; sourceTree = BUILT_PRODUCTS_DIR; };
5062
/* End PBXFileReference section */
5163

@@ -116,8 +128,14 @@
116128
AD7F1A5B2545A7FD00FD12B0 /* HTTPFrameworkTests */ = {
117129
isa = PBXGroup;
118130
children = (
119-
AD7F1A5C2545A7FD00FD12B0 /* HTTPFrameworkTests.swift */,
120131
AD7F1A5E2545A7FD00FD12B0 /* Info.plist */,
132+
ADFF72112550180E00E78549 /* HTTPMethodTests.swift */,
133+
ADFF72152550197A00E78549 /* HTTPStatusTests.swift */,
134+
ADFF721925501A0900E78549 /* HTTPRequestTests.swift */,
135+
ADFF721D25501F9100E78549 /* HTTPResponseTests.swift */,
136+
ADFF72232550237D00E78549 /* HTTPResultTests.swift */,
137+
ADFF7227255024A900E78549 /* HTTPErrorTests.swift */,
138+
ADFF722D255025B700E78549 /* HTTPBodyTests.swift */,
121139
);
122140
path = HTTPFrameworkTests;
123141
sourceTree = "<group>";
@@ -298,7 +316,13 @@
298316
isa = PBXSourcesBuildPhase;
299317
buildActionMask = 2147483647;
300318
files = (
301-
AD7F1A5D2545A7FD00FD12B0 /* HTTPFrameworkTests.swift in Sources */,
319+
ADFF721E25501F9100E78549 /* HTTPResponseTests.swift in Sources */,
320+
ADFF722E255025B700E78549 /* HTTPBodyTests.swift in Sources */,
321+
ADFF72122550180E00E78549 /* HTTPMethodTests.swift in Sources */,
322+
ADFF721A25501A0900E78549 /* HTTPRequestTests.swift in Sources */,
323+
ADFF72162550197A00E78549 /* HTTPStatusTests.swift in Sources */,
324+
ADFF7228255024A900E78549 /* HTTPErrorTests.swift in Sources */,
325+
ADFF72242550237D00E78549 /* HTTPResultTests.swift in Sources */,
302326
);
303327
runOnlyForDeploymentPostprocessing = 0;
304328
};

HTTPFramework/HTTPRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public struct HTTPRequest {
1111
private var urlComponents = URLComponents()
1212
public var method: HTTPMethod = .get
1313
public var headers: [String: String] = [:]
14-
public var body: Data?
14+
public var body: HTTPBody = EmptyBody()
1515

1616
public init() {
1717
urlComponents.scheme = "https"

HTTPFramework/HTTPResponse.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import Foundation
1010
public struct HTTPResponse {
1111
private let response: HTTPURLResponse
1212
public let request: HTTPRequest
13-
public let body: HTTPBody = EmptyBody()
13+
public let body: Data?
14+
15+
init(response: HTTPURLResponse, request: HTTPRequest, body: Data?) {
16+
self.response = response
17+
self.request = request
18+
self.body = body
19+
}
1420
}
1521

1622
public extension HTTPResponse {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// HTTPBodyTests.swift
3+
// HTTPFrameworkTests
4+
//
5+
// Created by Антон Савинов on 02.11.2020.
6+
//
7+
8+
import XCTest
9+
@testable import HTTPFramework
10+
11+
class HTTPBodyTests: XCTestCase {
12+
func testHttpEmptyBody() throws {
13+
let emptyBody = EmptyBody()
14+
XCTAssertTrue(emptyBody.isEmpty)
15+
XCTAssertTrue(emptyBody.additionalHeaders.isEmpty)
16+
XCTAssertTrue(try emptyBody.encodeData().isEmpty)
17+
}
18+
19+
func testHttpDataBody() throws {
20+
let data = Data()
21+
let dataBody = DataBody(data: data)
22+
XCTAssertTrue(dataBody.isEmpty)
23+
XCTAssertTrue(dataBody.additionalHeaders.isEmpty)
24+
XCTAssertTrue(try dataBody.encodeData() == data)
25+
}
26+
27+
func testHttpJsonBody() throws {
28+
let string = "Some string"
29+
let jsonBody = JSONBody(value: string)
30+
XCTAssertFalse(jsonBody.isEmpty)
31+
XCTAssertFalse(jsonBody.additionalHeaders.isEmpty)
32+
XCTAssertNotNil(try jsonBody.encodeData())
33+
}
34+
35+
func testHttpFormBodyBody() throws {
36+
let formBody = FormBody(queryItems: [URLQueryItem(name: "parameter", value: "1")])
37+
XCTAssertFalse(formBody.isEmpty)
38+
XCTAssertFalse(formBody.additionalHeaders.isEmpty)
39+
XCTAssertNotNil(try formBody.encodeData())
40+
}
41+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// HTTPError.swift
3+
// HTTPFrameworkTests
4+
//
5+
// Created by Антон Савинов on 02.11.2020.
6+
//
7+
8+
import XCTest
9+
@testable import HTTPFramework
10+
11+
class HTTPErrorTests: XCTestCase {
12+
func testHttpErrorShouldBeInitializedWithEmpty() throws {
13+
let httpRequest = HTTPRequest()
14+
let httpResponse = HTTPResponse(response: HTTPURLResponse(), request: httpRequest, body: nil)
15+
let httpError = HTTPError(code: .unkown, request: httpRequest, response: httpResponse, underlyingError: nil)
16+
17+
XCTAssertNotNil(httpError.request)
18+
XCTAssertNotNil(httpError.response)
19+
XCTAssertNil(httpError.underlyingError)
20+
XCTAssertTrue(httpError.code == .unkown)
21+
}
22+
}

HTTPFrameworkTests/HTTPFrameworkTests.swift

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// HTTPMethodTests.swift
3+
// HTTPFrameworkTests
4+
//
5+
// Created by Антон Савинов on 02.11.2020.
6+
//
7+
8+
import XCTest
9+
@testable import HTTPFramework
10+
11+
class HTTPMethodTests: XCTestCase {
12+
func testSetHTTPMethodGet() throws {
13+
let getMethod = HTTPMethod(rawValue: "GET")
14+
XCTAssertTrue(getMethod.rawValue == "GET")
15+
}
16+
17+
func testSetHTTPMethodPost() throws {
18+
let postMethod = HTTPMethod(rawValue: "POST")
19+
XCTAssertTrue(postMethod.rawValue == "POST")
20+
}
21+
22+
func testSetHTTPMethodPut() throws {
23+
let putMethod = HTTPMethod(rawValue: "PUT")
24+
XCTAssertTrue(putMethod.rawValue == "PUT")
25+
}
26+
27+
func testSetHTTPMethodDelete() throws {
28+
let deleteMethod = HTTPMethod(rawValue: "DELETE")
29+
XCTAssertTrue(deleteMethod.rawValue == "DELETE")
30+
}
31+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// HTTPRequestTests.swift
3+
// HTTPFrameworkTests
4+
//
5+
// Created by Антон Савинов on 02.11.2020.
6+
//
7+
8+
import XCTest
9+
@testable import HTTPFramework
10+
11+
class HTTPRequestTests: XCTestCase {
12+
func testHTTPRequestShouldBeInitializedWithEmpty() throws {
13+
let request = HTTPRequest()
14+
XCTAssertTrue(request.method == .get)
15+
XCTAssertTrue(request.headers.isEmpty == true)
16+
XCTAssertTrue(request.body is EmptyBody)
17+
XCTAssertTrue(request.scheme == "https")
18+
XCTAssertNil(request.host)
19+
XCTAssertNotNil(request.path)
20+
}
21+
22+
func testHTTPRequestShouldBeInitializedWithNonEmptyBody() throws {
23+
var request = HTTPRequest()
24+
request.body = FormBody(queryItems: [URLQueryItem(name: "parameter", value: "1")])
25+
XCTAssertNotNil(request.body)
26+
}
27+
28+
func testHTTPRequestShouldBeInitializedWithNonEmptyHostAndPath() throws {
29+
var request = HTTPRequest()
30+
request.host = "google.com"
31+
request.path = "/images"
32+
XCTAssertEqual(request.host, "google.com")
33+
XCTAssertEqual(request.path, "/images")
34+
}
35+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// HTTPResponseTests.swift
3+
// HTTPFrameworkTests
4+
//
5+
// Created by Антон Савинов on 02.11.2020.
6+
//
7+
8+
import XCTest
9+
@testable import HTTPFramework
10+
11+
class HTTPResponseTests: XCTestCase {
12+
func testHttpResponseShouldBeEmpty() throws {
13+
let httpRequest = HTTPRequest()
14+
let httpResponse = HTTPResponse(response: HTTPURLResponse(), request: httpRequest, body: nil)
15+
XCTAssertTrue(httpResponse.request.body.isEmpty == httpRequest.body.isEmpty)
16+
XCTAssertTrue(httpResponse.request.headers == httpRequest.headers)
17+
XCTAssertTrue(httpResponse.request.host == httpRequest.host)
18+
XCTAssertTrue(httpResponse.request.method == httpRequest.method)
19+
XCTAssertTrue(httpResponse.request.path == httpRequest.path)
20+
XCTAssertTrue(httpResponse.status.rawValue == 200)
21+
XCTAssertNil(httpResponse.body)
22+
}
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// HTTPResultTests.swift
3+
// HTTPFrameworkTests
4+
//
5+
// Created by Антон Савинов on 02.11.2020.
6+
//
7+
8+
import XCTest
9+
@testable import HTTPFramework
10+
11+
class HTTPResultTests: XCTestCase {
12+
13+
}

0 commit comments

Comments
 (0)