Skip to content

Commit 7f8aa40

Browse files
committed
Add unit tests for ActionCodeURL
1 parent b91f255 commit 7f8aa40

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
class ActionCodeURLTests: XCTestCase {
20+
func testParseURL() {
21+
let urlString = "https://www.example.com?apiKey=API_KEY&mode=resetPassword&oobCode=OOB_CODE"
22+
let actionCodeURL = ActionCodeURL(link: urlString)
23+
XCTAssertNotNil(actionCodeURL)
24+
XCTAssertEqual(actionCodeURL?.apiKey, "API_KEY")
25+
XCTAssertEqual(actionCodeURL?.operation, .passwordReset)
26+
XCTAssertEqual(actionCodeURL?.code, "OOB_CODE")
27+
}
28+
29+
func testParseInvalidURL() {
30+
let urlString = "invalid_url"
31+
let actionCodeURL = ActionCodeURL(link: urlString)
32+
XCTAssertNil(actionCodeURL)
33+
}
34+
35+
func testParseURLMissingParameters() {
36+
let urlString = "https://www.example.com"
37+
let actionCodeURL = ActionCodeURL(link: urlString)
38+
XCTAssertNil(actionCodeURL)
39+
}
40+
41+
func testParseURLDifferentMode() {
42+
let urlString = "https://www.example.com?apiKey=API_KEY&mode=verifyEmail&oobCode=OOB_CODE"
43+
let actionCodeURL = ActionCodeURL(link: urlString)
44+
XCTAssertNotNil(actionCodeURL)
45+
XCTAssertEqual(actionCodeURL?.apiKey, "API_KEY")
46+
XCTAssertEqual(actionCodeURL?.operation, .verifyEmail)
47+
XCTAssertEqual(actionCodeURL?.code, "OOB_CODE")
48+
}
49+
50+
func testParseURLWithAllProperties() {
51+
let urlString =
52+
"https://www.example.com?apiKey=API_KEY&mode=recoverEmail&oobCode=OOB_CODE&continueUrl=https://www.continue.com&lang=en"
53+
let actionCodeURL = ActionCodeURL(link: urlString)
54+
XCTAssertNotNil(actionCodeURL)
55+
XCTAssertEqual(actionCodeURL?.apiKey, "API_KEY")
56+
XCTAssertEqual(actionCodeURL?.operation, .recoverEmail)
57+
XCTAssertEqual(actionCodeURL?.code, "OOB_CODE")
58+
XCTAssertEqual(actionCodeURL?.continueURL?.absoluteString, "https://www.continue.com")
59+
XCTAssertEqual(actionCodeURL?.languageCode, "en")
60+
}
61+
62+
func testParseURLMissingOobCode() {
63+
let urlString = "https://www.example.com?apiKey=API_KEY&mode=resetPassword"
64+
let actionCodeURL = ActionCodeURL(link: urlString)
65+
XCTAssertNil(actionCodeURL?.code)
66+
}
67+
68+
func testParseURLInvalidMode() {
69+
let urlString = "https://www.example.com?apiKey=API_KEY&mode=invalidMode&oobCode=OOB_CODE"
70+
let actionCodeURL = ActionCodeURL(link: urlString)
71+
XCTAssertEqual(actionCodeURL?.operation, .unknown)
72+
}
73+
74+
func testActionCodeURL_languageCode() {
75+
let urlString = "https://example.com?lang=fr"
76+
let actionCodeURL = ActionCodeURL(link: urlString)
77+
XCTAssertEqual(actionCodeURL?.languageCode, "fr")
78+
}
79+
}

0 commit comments

Comments
 (0)