Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RyosukeCla committed Nov 2, 2023
1 parent 0a78819 commit 561a600
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ios/Nativebrik/Nativebrik.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -113,6 +115,8 @@
C136345F2AEBB49900B9F437 /* user.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = user.swift; sourceTree = "<group>"; };
C13634612AEBBC6500B9F437 /* remote-config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "remote-config.swift"; sourceTree = "<group>"; };
C13634632AEF92F700B9F437 /* embedding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = embedding.swift; sourceTree = "<group>"; };
C13634652AF242B100B9F437 /* decode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = decode.swift; sourceTree = "<group>"; };
C13634672AF36D7600B9F437 /* repository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = repository.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -200,6 +204,8 @@
C136345F2AEBB49900B9F437 /* user.swift */,
C13634612AEBBC6500B9F437 /* remote-config.swift */,
C13634632AEF92F700B9F437 /* embedding.swift */,
C13634652AF242B100B9F437 /* decode.swift */,
C13634672AF36D7600B9F437 /* repository.swift */,
);
path = NativebrikTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
};
Expand Down
37 changes: 37 additions & 0 deletions ios/Nativebrik/NativebrikTests/decode.swift
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)
}
}
37 changes: 37 additions & 0 deletions ios/Nativebrik/NativebrikTests/repository.swift
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)
}
}

0 comments on commit 561a600

Please sign in to comment.