-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the public scope of the
buildEither(component:)
components of…
… `URLBuilder` (#13) * Fixed #11 * Added BodyBuilderTests.swift for increase test coverage * wip * Added HeaderBuilderTest.swift for increase test coverage
- Loading branch information
Showing
6 changed files
with
233 additions
and
3 deletions.
There are no files selected for viewing
Binary file modified
BIN
+16.1 KB
(130%)
...m/xcode/package.xcworkspace/xcuserdata/ijaewon.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import Foundation | ||
import XCTest | ||
@testable import APIRouter | ||
|
||
final class BodyBuilderTests: XCTestCase { | ||
func testSwitchConditionalStatementWorkingForBuildEitherInBodyBuilder() { | ||
enum BodyOptions { | ||
case one | ||
case two | ||
|
||
var request: Request { | ||
Request { | ||
Body { | ||
switch self { | ||
case .one: | ||
Param("VALUE", forKey: "OPTIONONE") | ||
case .two: | ||
Param("VALUE", forKey: "OPTIONTWO") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if let optionOneBody = BodyOptions.one.request.urlRequest?.httpBody, | ||
let optionOneBodyString = String(data: optionOneBody, encoding: .utf8), | ||
let optionTwoBody = BodyOptions.two.request.urlRequest?.httpBody, | ||
let optionTwoBodyString = String(data: optionTwoBody, encoding: .utf8) { | ||
XCTAssertEqual(optionOneBodyString, "{\"OPTIONONE\":\"VALUE\"}") | ||
XCTAssertEqual(optionTwoBodyString, "{\"OPTIONTWO\":\"VALUE\"}") | ||
} | ||
} | ||
|
||
func testIfConditionalStatementWorkingForBuildEitherInUrlBuilder() { | ||
enum BodyOptions { | ||
case one | ||
case two | ||
|
||
var request: Request { | ||
Request { | ||
Body { | ||
if self == .one { | ||
Param("VALUE", forKey: "OPTIONONE") | ||
} else { | ||
Param("VALUE", forKey: "OPTIONTWO") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if let optionOneBody = BodyOptions.one.request.urlRequest?.httpBody, | ||
let optionOneBodyString = String(data: optionOneBody, encoding: .utf8), | ||
let optionTwoBody = BodyOptions.two.request.urlRequest?.httpBody, | ||
let optionTwoBodyString = String(data: optionTwoBody, encoding: .utf8) { | ||
XCTAssertEqual(optionOneBodyString, "{\"OPTIONONE\":\"VALUE\"}") | ||
XCTAssertEqual(optionTwoBodyString, "{\"OPTIONTWO\":\"VALUE\"}") | ||
} | ||
} | ||
|
||
func testForLoopStatementWorkingForBuildEitherInBodyBuilder() { | ||
let params = [ | ||
"key1": "value1", | ||
"key2": "value2", | ||
"key3": "value3", | ||
"key4": "value4", | ||
] | ||
|
||
let request = Request { | ||
Body { | ||
for param in params { | ||
Param(param.value, forKey: param.key) | ||
} | ||
} | ||
} | ||
|
||
if let httpBody = request.urlRequest?.httpBody, | ||
let bodyString = String(data: httpBody, encoding: .utf8) { | ||
XCTAssertEqual(bodyString.sorted(), ["\"", "\"", "\"", "\"", "\"", "\"", "\"", "\"", "\"", "\"", "\"", "\"", "\"", "\"", "\"", "\"", ",", ",", ",", "1", "1", "2", "2", "3", "3", "4", "4", ":", ":", ":", ":", "a", "a", "a", "a", "e", "e", "e", "e", "e", "e", "e", "e", "k", "k", "k", "k", "l", "l", "l", "l", "u", "u", "u", "u", "v", "v", "v", "v", "y", "y", "y", "y", "{", "}"]) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import Foundation | ||
import XCTest | ||
@testable import APIRouter | ||
|
||
final class HeaderBuilderTests: XCTestCase { | ||
func testSwitchConditionStatemntWorkingForBuildEitherInHeaderBuilder() { | ||
enum HeaderOptions { | ||
case one | ||
case two | ||
|
||
var request: Request { | ||
Request { | ||
Header { | ||
switch self { | ||
case .one: | ||
Field("VALUE", forKey: "OPTIONONE") | ||
case .two: | ||
Field("VALUE", forKey: "OPTIONTWO") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if let optionOneHeaderFields = HeaderOptions.one.request.urlRequest?.allHTTPHeaderFields, | ||
let optionTwoHeaderFields = HeaderOptions.two.request.urlRequest?.allHTTPHeaderFields { | ||
XCTAssertEqual(optionOneHeaderFields, ["OPTIONONE":"VALUE"]) | ||
XCTAssertEqual(optionTwoHeaderFields, ["OPTIONTWO":"VALUE"]) | ||
} | ||
} | ||
|
||
func testIfConditionalStatementWorkingForBuildEitherInUrlBuilder() { | ||
enum HeaderOptions { | ||
case one | ||
case two | ||
|
||
var request: Request { | ||
Request { | ||
Header { | ||
if self == .one { | ||
Field("VALUE", forKey: "OPTIONONE") | ||
} else { | ||
Field("VALUE", forKey: "OPTIONTWO") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if let optionOneHeaderFields = HeaderOptions.one.request.urlRequest?.allHTTPHeaderFields, | ||
let optionTwoHeaderFields = HeaderOptions.two.request.urlRequest?.allHTTPHeaderFields { | ||
XCTAssertEqual(optionOneHeaderFields, ["OPTIONONE":"VALUE"]) | ||
XCTAssertEqual(optionTwoHeaderFields, ["OPTIONTWO":"VALUE"]) | ||
} | ||
} | ||
|
||
func testForLoopStatementWorkingForBuildEitherInHeaderBuilder() { | ||
let fields = [ | ||
"key1": "value1", | ||
"key2": "value2", | ||
"key3": "value3", | ||
"key4": "value4", | ||
] | ||
|
||
let request = Request { | ||
Header { | ||
for field in fields { | ||
Field(field.value, forKey: field.key) | ||
} | ||
} | ||
} | ||
|
||
if let sortedAllHTTPHeaderFields = request.urlRequest?.allHTTPHeaderFields { | ||
XCTAssertEqual(sortedAllHTTPHeaderFields, ["key1": "value1", "key2": "value2", "key3": "value3", "key4": "value4"]) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters