mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-02-20 11:36:17 +00:00
Add tests for Router
This commit is contained in:
parent
7222d530dd
commit
b6317d7324
3 changed files with 61 additions and 0 deletions
|
@ -33,5 +33,9 @@ let package = Package(
|
||||||
.enableExperimentalFeature("StrictConcurrency"),
|
.enableExperimentalFeature("StrictConcurrency"),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
.testTarget(
|
||||||
|
name: "EnvTests",
|
||||||
|
dependencies: ["Env"]
|
||||||
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
50
Packages/Env/Tests/RouterTests.swift
Normal file
50
Packages/Env/Tests/RouterTests.swift
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
@testable import Env
|
||||||
|
import XCTest
|
||||||
|
import SwiftUI
|
||||||
|
import Network
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
final class RouterTests: XCTestCase {
|
||||||
|
func testRouterThreadsURL() {
|
||||||
|
let router = RouterPath()
|
||||||
|
let url = URL(string: "https://www.threads.net/@dimillian")!
|
||||||
|
_ = router.handle(url: url)
|
||||||
|
XCTAssertTrue(router.path.isEmpty)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testRouterTagsURL() {
|
||||||
|
let router = RouterPath()
|
||||||
|
let url = URL(string: "https://mastodon.social/tags/test")!
|
||||||
|
_ = router.handle(url: url)
|
||||||
|
XCTAssertTrue(router.path.first == .hashTag(tag: "test", account: nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testRouterLocalStatusURL() {
|
||||||
|
let router = RouterPath()
|
||||||
|
let client = Client(server: "mastodon.social",
|
||||||
|
oauthToken: .init(accessToken: "", tokenType: "", scope: "", createdAt: 0))
|
||||||
|
client.addConnections(["mastodon.social"])
|
||||||
|
router.client = client
|
||||||
|
let url = URL(string: "https://mastodon.social/status/1010384")!
|
||||||
|
_ = router.handle(url: url)
|
||||||
|
XCTAssertTrue(router.path.first == .statusDetail(id: "1010384"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testRouterRemoteStatusURL() {
|
||||||
|
let router = RouterPath()
|
||||||
|
let client = Client(server: "mastodon.social",
|
||||||
|
oauthToken: .init(accessToken: "", tokenType: "", scope: "", createdAt: 0))
|
||||||
|
client.addConnections(["mastodon.social", "mastodon.online"])
|
||||||
|
router.client = client
|
||||||
|
let url = URL(string: "https://mastodon.online/status/1010384")!
|
||||||
|
_ = router.handle(url: url)
|
||||||
|
XCTAssertTrue(router.path.first == .remoteStatusDetail(url: url))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testRouteRandomURL() {
|
||||||
|
let router = RouterPath()
|
||||||
|
let url = URL(string: "https://theweb.com/test/test/one")!
|
||||||
|
_ = router.handle(url: url)
|
||||||
|
XCTAssertTrue(router.path.isEmpty)
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,4 +5,11 @@ public struct OauthToken: Codable, Hashable, Sendable {
|
||||||
public let tokenType: String
|
public let tokenType: String
|
||||||
public let scope: String
|
public let scope: String
|
||||||
public let createdAt: Double
|
public let createdAt: Double
|
||||||
|
|
||||||
|
public init(accessToken: String, tokenType: String, scope: String, createdAt: Double) {
|
||||||
|
self.accessToken = accessToken
|
||||||
|
self.tokenType = tokenType
|
||||||
|
self.scope = scope
|
||||||
|
self.createdAt = createdAt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue