Skip to content

Commit 7a04ca6

Browse files
authored
Add unit tests for ActionCodeURL (#14683)
1 parent 27a7fea commit 7a04ca6

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
@testable import FirebaseAuth
16+
import Foundation
17+
import XCTest
18+
19+
/// Unit tests for ActionCodeURL
20+
class ActionCodeURLTests: XCTestCase {
21+
22+
/// Tests parsing a valid URL with resetPassword mode.
23+
func testParseURL() {
24+
let urlString = "https://www.example.com?apiKey=API_KEY&mode=resetPassword&oobCode=OOB_CODE"
25+
let actionCodeURL = ActionCodeURL(link: urlString)
26+
XCTAssertNotNil(actionCodeURL)
27+
XCTAssertEqual(actionCodeURL?.apiKey, "API_KEY")
28+
XCTAssertEqual(actionCodeURL?.operation, .passwordReset)
29+
XCTAssertEqual(actionCodeURL?.code, "OOB_CODE")
30+
}
31+
32+
/// Tests parsing an invalid URL.
33+
func testParseInvalidURL() {
34+
let urlString = "invalid_url"
35+
let actionCodeURL = ActionCodeURL(link: urlString)
36+
XCTAssertNil(actionCodeURL)
37+
}
38+
39+
/// Tests parsing a URL with missing parameters.
40+
func testParseURLMissingParameters() {
41+
let urlString = "https://www.example.com"
42+
let actionCodeURL = ActionCodeURL(link: urlString)
43+
XCTAssertNil(actionCodeURL)
44+
}
45+
46+
// Tests parsing a URL with an operation and a code.
47+
func testParseURLDifferentMode() {
48+
let urlString = "https://www.example.com?apiKey=API_KEY&mode=verifyEmail&oobCode=OOB_CODE"
49+
let actionCodeURL = ActionCodeURL(link: urlString)
50+
XCTAssertNotNil(actionCodeURL)
51+
XCTAssertEqual(actionCodeURL?.apiKey, "API_KEY")
52+
XCTAssertEqual(actionCodeURL?.operation, .verifyEmail)
53+
XCTAssertEqual(actionCodeURL?.code, "OOB_CODE")
54+
}
55+
56+
/// Tests parsing a URL with all properties.
57+
func testParseURLWithAllProperties() {
58+
let urlString =
59+
"https://www.example.com?apiKey=API_KEY&mode=recoverEmail&oobCode=OOB_CODE&continueUrl=https://www.continue.com&lang=en"
60+
let actionCodeURL = ActionCodeURL(link: urlString)
61+
XCTAssertNotNil(actionCodeURL)
62+
XCTAssertEqual(actionCodeURL?.apiKey, "API_KEY")
63+
XCTAssertEqual(actionCodeURL?.operation, .recoverEmail)
64+
XCTAssertEqual(actionCodeURL?.code, "OOB_CODE")
65+
XCTAssertEqual(actionCodeURL?.continueURL?.absoluteString, "https://www.continue.com")
66+
XCTAssertEqual(actionCodeURL?.languageCode, "en")
67+
}
68+
69+
/// Tests parsing a URL with missing oobCode.
70+
func testParseURLMissingOobCode() {
71+
let urlString = "https://www.example.com?apiKey=API_KEY&mode=resetPassword"
72+
let actionCodeURL = ActionCodeURL(link: urlString)
73+
XCTAssertNil(actionCodeURL?.code)
74+
}
75+
76+
/// Tests parsing a URL with invalid mode.
77+
func testParseURLInvalidMode() {
78+
let urlString = "https://www.example.com?apiKey=API_KEY&mode=invalidMode&oobCode=OOB_CODE"
79+
let actionCodeURL = ActionCodeURL(link: urlString)
80+
XCTAssertEqual(actionCodeURL?.operation, .unknown)
81+
}
82+
83+
/// Tests parsing a URL with language code.
84+
func testActionCodeURL_languageCode() {
85+
let urlString = "https://example.com?lang=fr"
86+
let actionCodeURL = ActionCodeURL(link: urlString)
87+
XCTAssertEqual(actionCodeURL?.languageCode, "fr")
88+
}
89+
}

0 commit comments

Comments
 (0)