Skip to content

Commit fc7dc93

Browse files
committed
Update WooConstants with an un-scaped testing URL
`asURL()` is a private extension located on WooConstants, if we use it directle over a testing URL in the Unit Test, then the AlamoFire one will be called instead, which doesn’t deal with un-scaped strings and would keep crashing.
1 parent 0e4a799 commit fc7dc93

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

WooCommerce/Classes/System/WooConstants.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ extension WooConstants {
256256
/// URL for creating a store.
257257
case storeCreation = "https://woocommerce.com/start"
258258

259+
/// URL with un-escaped characters for testing purposes. It should read as `https://test.com/test-%E2%80%93-survey`
260+
///
261+
case testURLStringWithSpecialCharacters = "https://test.com/test-–-survey"
262+
259263
/// Returns the URL version of the receiver
260264
///
261265
func asURL() -> URL {

WooCommerce/WooCommerceTests/System/WooConstantsTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ final class WooConstantsTests: XCTestCase {
1818

1919
func test_URL_that_contains_special_characters_when_is_escaped_properly_then_does_not_return_nil() throws {
2020
// Given
21-
let urlStringWithSpecialCharacters = "https://test.com/test-–-survey"
21+
let urlStringWithSpecialCharacters = WooConstants.URLs.testURLStringWithSpecialCharacters
2222
let escapedURLStringWithSpecialCharacter = "https://test.com/test-%E2%80%93-survey"
2323

2424
// When
25-
let trustedURL = try urlStringWithSpecialCharacters.asURL()
25+
let trustedURL = urlStringWithSpecialCharacters.asURL()
2626

2727
// Then
2828
XCTAssertNotNil(trustedURL)
29-
XCTAssertEqual(trustedURL.absoluteString, escapedURLStringWithSpecialCharacter)
29+
XCTAssertEqual(try trustedURL.asURL().absoluteString, escapedURLStringWithSpecialCharacter)
3030
}
3131
}

0 commit comments

Comments
 (0)