Signal-iOS/SignalServiceKit/tests/Util/URLPathComponentsTest.swift
Evan Hahn 62215b97c3
Clean up "report spam" request code
This change should have no user impact.

This makes the following changes to `OWSRequestFactory.reportSpam`:

- Converts it to Swift
- Adds tests
- Handles a server GUID that couldn't be URL-encoded. For example, if it
  contained spaces, we'd crash constructing the URL. No longer!
- Handles an empty server GUID
2023-01-20 14:15:33 -06:00

21 lines
573 B
Swift

//
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import XCTest
import SignalServiceKit
final class URLPathComponentsTest: XCTestCase {
func testNoComponents() {
XCTAssertNil(URL(pathComponents: []))
XCTAssertNil(URL(pathComponents: [""]))
XCTAssertNil(URL(pathComponents: ["", "", ""]))
}
func testFilteringAndEncodingComponents() {
let url = URL(pathComponents: ["foo", "", "~", "bar / baz?qúx"])!
XCTAssertEqual(url.relativeString, "foo/~/bar%20%2F%20baz%3Fq%C3%BAx")
}
}