1
0
mirror of git://jb55.com/damus synced 2024-09-30 00:40:45 +00:00
damus/damusTests/RelayURLTests.swift
Daniel D’Aquino e951370a76 Fix relay URL trailing slash issues
This commit tries to replace all usage of `String` to represent relay
URLs and use `RelayURL` which automatically converts strings to a
canonical relay URL format that is more reliable and avoids issues related to
trailing slashes.

Test 1: Main issue fix
-----------------------

PASS

Device: iPhone 15 Simulator
iOS: 17.4
Damus: This commit
Steps:
1. Delete all connected relays
2. Add `wss://relay.damus.io/` (with the trailing slash) to the relay list
3. Try to post. Post should succeed. PASS
4. Try removing this newly added relay. Relay should be removed successfully. PASS

Test 2: Persistent relay list after upgrade
--------------------------------------------

PASS

Device: iPhone 15 Simulator
iOS: 17.4
Damus: 1.8 (1) `247f313b` + This commit
Steps:
1. Downgrade to old version
2. Add some relays to the list, some without a trailing slash, some with
3. Upgrade to this commit
4. All relays added in step 2 should still be there, and ones with a trailing slash should have been corrected to remove the trailing slash

Test 3: Miscellaneous regression tests
--------------------------------------

Device: iPhone 15 Simulator
iOS: 17.4
Damus: This commit
Coverage:
1. Posting works
2. Search works
3. Relay connection status works
4. Adding relays work
5. Removing relays work
6. Adding relay with trailing slashes works (it fixes itself to remove the trailing slash)
7. Adding relays with different paths works (e.g. wss://yabu.me/v1 and wss://yabu.me/v2)
8. Adding duplicate relay (but with trailing slash) gets rejected as expected
9. Relay details page works. All items on that view loads correctly
10. Relay logs work
11. Getting follower counts and seeing follow lists on profiles still work
12. Relay list changes persist after app restart
13. Notifications view still work
14. Copying the user's pubkey and profile link works
15. Share note + copy link button still works
16. Connecting NWC wallet works
17. One-tap zaps work
18. Onboarding works
19. Unit tests all passing

Closes: https://github.com/damus-io/damus/issues/2072
Changelog-Fixed: Fix bug that would cause connection issues with relays defined with a trailing slash URL, and an inability to delete them.
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>
2024-03-25 09:24:17 +01:00

85 lines
4.5 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// RelayURLTests.swift
// damusTests
//
// Created by Daniel DAquino on 2024-03-20.
//
import Foundation
import XCTest
@testable import damus
final class RelayURLTests : XCTestCase {
func testRelayURLTrailingSlash() {
let relay_url_1: RelayURL = RelayURL("wss://relay.damus.io")!
let relay_url_2: RelayURL = RelayURL("wss://relay.damus.io/")!
XCTAssertEqual(relay_url_1.id, relay_url_2.id, "Relays with the same address should have the same ID even if one of them was initialized with a trailing slash")
XCTAssertEqual(relay_url_1, relay_url_2, "Relays with the same address should be equal even if one of them was initialized with a trailing slash")
var relays: [RelayURL: Int] = [:]
relays[relay_url_1] = 1
relays[relay_url_2] = 2
XCTAssertEqual(relays[relay_url_1], 2, "RelayURL with a trailing slash should evaluate to the same hash in a dictionary as an equivalent one without trailing slashes")
}
func testRelayURLDifferentProtocols() {
let relay_url_1: RelayURL = RelayURL("wss://relay.damus.io")!
let relay_url_2: RelayURL = RelayURL("ws://relay.damus.io")!
XCTAssertNotEqual(relay_url_1.id, relay_url_2.id, "Relays with different protocols should not have the same ID")
XCTAssertNotEqual(relay_url_1, relay_url_2, "Relays with different protocols should not be equal")
var relays: [RelayURL: Int] = [:]
relays[relay_url_1] = 1
relays[relay_url_2] = 2
XCTAssertNotEqual(relays[relay_url_1], relays[relay_url_2], "RelayURL with different protocols should not evaluate to the same hash in a dictionary")
}
func testRelayURLDifferentDomains() {
let relay_url_1: RelayURL = RelayURL("wss://relay.damus.io")!
let relay_url_3: RelayURL = RelayURL("wss://example.com")!
XCTAssertNotEqual(relay_url_1, relay_url_3, "Relays with different domains should not be equal")
var relays: [RelayURL: Int] = [:]
relays[relay_url_1] = 1
relays[relay_url_3] = 3
XCTAssertNotEqual(relays[relay_url_1], relays[relay_url_3], "RelayURL with different domains should not evaluate to the same hash in a dictionary")
}
func testRelayURLDifferentPaths() {
let relay_url_1: RelayURL = RelayURL("wss://relay.damus.io")!
let relay_url_2: RelayURL = RelayURL("wss://relay.damus.io/")!
let relay_url_3: RelayURL = RelayURL("wss://relay.damus.io/v1")!
let relay_url_4: RelayURL = RelayURL("wss://relay.damus.io/v2")!
let relay_url_5: RelayURL = RelayURL("wss://relay.damus.io/v2/beta")!
let relay_url_6: RelayURL = RelayURL("wss://relay.damus.io/v2/beta/")!
XCTAssertEqual(relay_url_1.id, relay_url_2.id, "Relays with the same address should have the same ID even if one of them was initialized with a trailing slash")
XCTAssertEqual(relay_url_1, relay_url_2, "Relays with the same address should be equal even if one of them was initialized with a trailing slash")
XCTAssertNotEqual(relay_url_1, relay_url_3, "Relays with different paths should not be equal")
XCTAssertNotEqual(relay_url_3, relay_url_4, "Relays with different paths should not be equal")
XCTAssertNotEqual(relay_url_4, relay_url_5, "Relays with different subpaths should not be equal")
XCTAssertEqual(relay_url_5, relay_url_6, "Relays with the same address should be equal if one of them is initialized with a trailing slash")
var relays: [RelayURL: Int] = [:]
relays[relay_url_1] = 1
relays[relay_url_2] = 2
relays[relay_url_3] = 3
relays[relay_url_4] = 4
relays[relay_url_5] = 5
relays[relay_url_6] = 6
XCTAssertEqual(relays[relay_url_1], relays[relay_url_2], "RelayURL with the same path should evaluate to the same hash in a dictionary")
XCTAssertNotEqual(relays[relay_url_1], relays[relay_url_3], "RelayURLs with different pathsshould not evaluate to the same hash in a dictionary")
XCTAssertNotEqual(relays[relay_url_3], relays[relay_url_4], "RelayURLs with different paths should not evaluate to the same hash in a dictionary")
XCTAssertNotEqual(relays[relay_url_4], relays[relay_url_5], "RelayURLs with different subpaths should not evaluate to the same hash in a dictionary")
XCTAssertEqual(relays[relay_url_5], relays[relay_url_6], "RelayURL with the same subpath should evaluate to the same hash in a dictionary even if one of them is initialized with a trailing slash")
}
}