diff --git a/ios/Nativebrik/Nativebrik.xcodeproj/project.pbxproj b/ios/Nativebrik/Nativebrik.xcodeproj/project.pbxproj index de26121..2d9d171 100644 --- a/ios/Nativebrik/Nativebrik.xcodeproj/project.pbxproj +++ b/ios/Nativebrik/Nativebrik.xcodeproj/project.pbxproj @@ -47,6 +47,8 @@ C13634602AEBB49900B9F437 /* user.swift in Sources */ = {isa = PBXBuildFile; fileRef = C136345F2AEBB49900B9F437 /* user.swift */; }; C13634622AEBBC6500B9F437 /* remote-config.swift in Sources */ = {isa = PBXBuildFile; fileRef = C13634612AEBBC6500B9F437 /* remote-config.swift */; }; C13634642AEF92F700B9F437 /* embedding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C13634632AEF92F700B9F437 /* embedding.swift */; }; + C13634662AF242B100B9F437 /* decode.swift in Sources */ = {isa = PBXBuildFile; fileRef = C13634652AF242B100B9F437 /* decode.swift */; }; + C13634682AF36D7600B9F437 /* repository.swift in Sources */ = {isa = PBXBuildFile; fileRef = C13634672AF36D7600B9F437 /* repository.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -113,6 +115,8 @@ C136345F2AEBB49900B9F437 /* user.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = user.swift; sourceTree = ""; }; C13634612AEBBC6500B9F437 /* remote-config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "remote-config.swift"; sourceTree = ""; }; C13634632AEF92F700B9F437 /* embedding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = embedding.swift; sourceTree = ""; }; + C13634652AF242B100B9F437 /* decode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = decode.swift; sourceTree = ""; }; + C13634672AF36D7600B9F437 /* repository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = repository.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -200,6 +204,8 @@ C136345F2AEBB49900B9F437 /* user.swift */, C13634612AEBBC6500B9F437 /* remote-config.swift */, C13634632AEF92F700B9F437 /* embedding.swift */, + C13634652AF242B100B9F437 /* decode.swift */, + C13634672AF36D7600B9F437 /* repository.swift */, ); path = NativebrikTests; sourceTree = ""; @@ -371,7 +377,9 @@ C13634622AEBBC6500B9F437 /* remote-config.swift in Sources */, C13633AB2AEB769800B9F437 /* sdk.swift in Sources */, C13634642AEF92F700B9F437 /* embedding.swift in Sources */, + C13634682AF36D7600B9F437 /* repository.swift in Sources */, C13634602AEBB49900B9F437 /* user.swift in Sources */, + C13634662AF242B100B9F437 /* decode.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ios/Nativebrik/NativebrikTests/decode.swift b/ios/Nativebrik/NativebrikTests/decode.swift new file mode 100644 index 0000000..30ba989 --- /dev/null +++ b/ios/Nativebrik/NativebrikTests/decode.swift @@ -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) + } +} diff --git a/ios/Nativebrik/NativebrikTests/repository.swift b/ios/Nativebrik/NativebrikTests/repository.swift new file mode 100644 index 0000000..bba02a1 --- /dev/null +++ b/ios/Nativebrik/NativebrikTests/repository.swift @@ -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) + } +}