krz/hutch

an ios client for sourcehut

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

main: HutchTests/SRHTWebURLTests.swift · raw

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