krz/hutch

an ios client for sourcehut

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

v3.1.3: HutchTests/SRHTWebURLTests.swift · raw

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