summaryrefslogtreecommitdiff
path: root/HutchTests/SRHTWebURLTests.swift
blob: d1053e6673a6ef810ab424c7ea91ec5bc2c4d232 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import Foundation
import Testing
@testable import Hutch

struct SRHTWebURLTests {
    private enum Expected {
        static let chatOrigin = "https://chat.sr.ht"
        static let statusOrigin = "https://status.sr.ht"
        static let gitRepoHTTPS = "https://git.sr.ht/~ccleberg/hutch"
        static let gitSSH = "[email protected]:~ccleberg/hutch"
        static let tracker = "https://todo.sr.ht/~ccleberg/todo"
        static let ticket = "https://todo.sr.ht/~ccleberg/todo/42"
        static let buildJob = "https://builds.sr.ht/~ccleberg/job/12"
    }

    private let repository = RepositorySummary(
        fields: .init(
            id: 1,
            rid: "repo-1",
            service: .git,
            name: "hutch",
            description: nil,
            visibility: .publicVisibility,
            updated: .distantPast,
            owner: Entity(canonicalName: "~ccleberg"),
            head: nil
        )
    )
    private let tracker = TrackerSummary(
        id: 2,
        rid: "tracker-1",
        name: "todo",
        description: nil,
        visibility: .publicVisibility,
        updated: .distantPast,
        owner: Entity(canonicalName: "~ccleberg")
    )

    @Test
    func browserOnlyServiceURLsUseCanonicalHosts() {
        #expect(SRHTWebURL.chat.absoluteString == Expected.chatOrigin)
        #expect(SRHTWebURL.status.absoluteString == Expected.statusOrigin)
    }

    @Test
    func repositoryAndCloneURLsUseStableUserScopedPaths() {
        #expect(SRHTWebURL.repository(repository)?.absoluteString == Expected.gitRepoHTTPS)
        #expect(SRHTWebURL.httpsCloneURL(repository) == Expected.gitRepoHTTPS)
        #expect(SRHTWebURL.sshCloneURL(repository) == Expected.gitSSH)
    }

    @Test
    func trackerTicketAndBuildURLsUseStableUserScopedPaths() {
        #expect(SRHTWebURL.tracker(tracker)?.absoluteString == Expected.tracker)
        #expect(SRHTWebURL.ticket(ownerUsername: "ccleberg", trackerName: "todo", ticketId: 42)?.absoluteString == Expected.ticket)
        #expect(SRHTWebURL.build(jobId: 12, ownerCanonicalName: "~ccleberg")?.absoluteString == Expected.buildJob)
    }
}