-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a78819
commit 561a600
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
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,37 @@ | ||
// | ||
// decode.swift | ||
// NativebrikTests | ||
// | ||
// Created by Ryosuke Suzuki on 2023/11/01. | ||
// | ||
|
||
import Foundation | ||
|
||
import XCTest | ||
@testable import Nativebrik | ||
|
||
final class DecodeJsonTests: XCTestCase { | ||
func testShouldEncodeApiHttpRequest() throws { | ||
let decoder = JSONDecoder() | ||
let json = """ | ||
{ | ||
"__typename": "ApiHttpRequest", | ||
"method": "GET", | ||
"url": "http://localhost:8070/health" | ||
} | ||
""" | ||
let result = try decoder.decode(ApiHttpRequest.self, from: Data(json.utf8)) | ||
XCTAssertEqual(ApiHttpRequestMethod.GET, result.method) | ||
XCTAssertEqual("http://localhost:8070/health", result.url) | ||
} | ||
|
||
func testShouldEncodeUIBlockEventDispatcher() throws { | ||
let decoder = JSONDecoder() | ||
let json = """ | ||
{"__typename":"UIBlockEventDispatcher","destinationPageId":"0.2c4944c774deb","httpRequest":{"__typename":"ApiHttpRequest","method":"GET","url":"http://localhost:8070/health"}} | ||
""" | ||
let result = try decoder.decode(UIBlockEventDispatcher.self, from: Data(json.utf8)) | ||
XCTAssertEqual("0.2c4944c774deb", result.destinationPageId) | ||
XCTAssertEqual("http://localhost:8070/health", result.httpRequest?.url) | ||
} | ||
} |
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,37 @@ | ||
// | ||
// repository.swift | ||
// NativebrikTests | ||
// | ||
// Created by Ryosuke Suzuki on 2023/11/02. | ||
// | ||
|
||
import Foundation | ||
|
||
import XCTest | ||
@testable import Nativebrik | ||
|
||
let HEALTH_CHECK_URL = "https://track.nativebrik.com/health" | ||
|
||
final class HttpRequestReposotiryTests: XCTestCase { | ||
func testShouldCallApiHttpRequest() throws { | ||
let expectation = expectation(description: "Request should be expected.") | ||
let repository = ApiHttpRequestRepository(interceptor: nil) | ||
repository.fetch(request: ApiHttpRequest(url: HEALTH_CHECK_URL), assertion: nil, propeties: nil) { entry in | ||
XCTAssertEqual(entry.state, .EXPECTED) | ||
expectation.fulfill() | ||
} | ||
|
||
wait(for: [expectation], timeout: 5) | ||
} | ||
|
||
func testShouldAssertHttpRequest() throws { | ||
let expectation = expectation(description: "Request should be unexpected.") | ||
let repository = ApiHttpRequestRepository(interceptor: nil) | ||
repository.fetch(request: ApiHttpRequest(url: HEALTH_CHECK_URL), assertion: ApiHttpResponseAssertion(statusCodes: [300]), propeties: nil) { entry in | ||
XCTAssertEqual(entry.state, .UNEXPECTED) | ||
expectation.fulfill() | ||
} | ||
|
||
wait(for: [expectation], timeout: 5) | ||
} | ||
} |