krz/hutch

an ios client for sourcehut

clone: git clone https://gitbay.org/krz/hutch.git

v3.0.4: HutchTests/SRHTWebURLTests.swift · raw

 1import Foundation
 2import Testing
 3@testable import Hutch
 4
 5struct SRHTWebURLTests {
 6    private let repository = RepositorySummary(
 7        id: 1,
 8        rid: "repo-1",
 9        service: .git,
10        name: "hutch",
11        description: nil,
12        visibility: .public,
13        updated: .distantPast,
14        owner: Entity(canonicalName: "~ccleberg"),
15        head: nil
16    )
17    private let tracker = TrackerSummary(
18        id: 2,
19        rid: "tracker-1",
20        name: "todo",
21        description: nil,
22        visibility: .public,
23        updated: .distantPast,
24        owner: Entity(canonicalName: "~ccleberg")
25    )
26
27    @Test
28    func browserOnlyServiceURLsUseCanonicalHosts() {
29        #expect(SRHTWebURL.chat.absoluteString == "https://chat.sr.ht")
30        #expect(SRHTWebURL.status.absoluteString == "https://status.sr.ht")
31    }
32
33    @Test
34    func repositoryAndCloneURLsUseStableUserScopedPaths() {
35        #expect(SRHTWebURL.repository(repository)?.absoluteString == "https://git.sr.ht/~ccleberg/hutch")
36        #expect(SRHTWebURL.httpsCloneURL(repository) == "https://git.sr.ht/~ccleberg/hutch")
37        #expect(SRHTWebURL.sshCloneURL(repository) == "git@git.sr.ht:~ccleberg/hutch")
38    }
39
40    @Test
41    func trackerTicketAndBuildURLsUseStableUserScopedPaths() {
42        #expect(SRHTWebURL.tracker(tracker)?.absoluteString == "https://todo.sr.ht/~ccleberg/todo")
43        #expect(SRHTWebURL.ticket(ownerUsername: "ccleberg", trackerName: "todo", ticketId: 42)?.absoluteString == "https://todo.sr.ht/~ccleberg/todo/42")
44        #expect(SRHTWebURL.build(jobId: 12, ownerCanonicalName: "~ccleberg")?.absoluteString == "https://builds.sr.ht/~ccleberg/job/12")
45    }
46}