krz/hutch

an ios client for sourcehut

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

v3.6.0: 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        fields: .init(
18            id: 1,
19            rid: "repo-1",
20            service: .git,
21            name: "hutch",
22            description: nil,
23            visibility: .publicVisibility,
24            updated: .distantPast,
25            owner: Entity(canonicalName: "~ccleberg"),
26            head: nil
27        )
28    )
29    private let tracker = TrackerSummary(
30        id: 2,
31        rid: "tracker-1",
32        name: "todo",
33        description: nil,
34        visibility: .publicVisibility,
35        updated: .distantPast,
36        owner: Entity(canonicalName: "~ccleberg")
37    )
38
39    @Test
40    func browserOnlyServiceURLsUseCanonicalHosts() {
41        #expect(SRHTWebURL.chat.absoluteString == Expected.chatOrigin)
42        #expect(SRHTWebURL.status.absoluteString == Expected.statusOrigin)
43    }
44
45    @Test
46    func repositoryAndCloneURLsUseStableUserScopedPaths() {
47        #expect(SRHTWebURL.repository(repository)?.absoluteString == Expected.gitRepoHTTPS)
48        #expect(SRHTWebURL.httpsCloneURL(repository) == Expected.gitRepoHTTPS)
49        #expect(SRHTWebURL.sshCloneURL(repository) == Expected.gitSSH)
50    }
51
52    @Test
53    func trackerTicketAndBuildURLsUseStableUserScopedPaths() {
54        #expect(SRHTWebURL.tracker(tracker)?.absoluteString == Expected.tracker)
55        #expect(SRHTWebURL.ticket(ownerUsername: "ccleberg", trackerName: "todo", ticketId: 42)?.absoluteString == Expected.ticket)
56        #expect(SRHTWebURL.build(jobId: 12, ownerCanonicalName: "~ccleberg")?.absoluteString == Expected.buildJob)
57    }
58}