-
Notifications
You must be signed in to change notification settings - Fork 12
feat:[HL-76] create FirebaseLoginRequest 🍕 #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
a7maad-ayman
wants to merge
4
commits into
develop
Choose a base branch
from
feat/firebase-login
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0b561b2
feat:create FirebaseLoginRequest
a7maad-ayman 91e5942
add unitTest , and update to match the reviewer changes
a7maad-ayman 57db81a
Merge branch 'develop' into feat/firebase-login
a7maad-ayman f0d347f
reslove firebaseKey conflict
a7maad-ayman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
Networking/Sources/Networking/Requests/FirebaseLoginRequest.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||||||||||||||||||||||||||||||||||
| import Foundation | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // MARK: - FirebaseLoginResponse | ||||||||||||||||||||||||||||||||||||||
| public struct FirebaseLoginResponse: Codable { | ||||||||||||||||||||||||||||||||||||||
| let kind, localID, email, displayName: String | ||||||||||||||||||||||||||||||||||||||
| let idToken: String | ||||||||||||||||||||||||||||||||||||||
| let registered: Bool | ||||||||||||||||||||||||||||||||||||||
| let refreshToken, expiresIn: String | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // MARK: - FirebaseLoginRequest | ||||||||||||||||||||||||||||||||||||||
| public struct FirebaseLoginRequest: RequestType { | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| public typealias ResponseType = FirebaseLoginResponse | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private let email: String | ||||||||||||||||||||||||||||||||||||||
| private let password: String | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public init(email: String, password: String) { | ||||||||||||||||||||||||||||||||||||||
| self.email = email | ||||||||||||||||||||||||||||||||||||||
| self.password = password | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public var baseUrl: URL { Constants.firebaseAuth } | ||||||||||||||||||||||||||||||||||||||
| public var path: String { "/v1/accounts:signInWithPassword" } | ||||||||||||||||||||||||||||||||||||||
| public var method: String { "POST" } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public var queryParameters: [String: String] { | ||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||
| "key": Constants.firebaseKey | ||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public var headers: [String: String] { | ||||||||||||||||||||||||||||||||||||||
| [ "Content-Type": "application/json" ] | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public var requestBody: [String: Any] { | ||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||
| "email": email, | ||||||||||||||||||||||||||||||||||||||
| "password": password, | ||||||||||||||||||||||||||||||||||||||
| "returnSecureToken": true | ||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public let responseDecoder: (Data) throws -> FirebaseLoginResponse = { data in | ||||||||||||||||||||||||||||||||||||||
| try JSONDecoder().decode(ResponseType.self, from: data) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
Networking/Tests/NetworkingTests/Requests/FirebaseLoginRequestTest.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import XCTest | ||
| @testable import Networking | ||
|
|
||
| final class FirebaseLoginRequestTests: XCTestCase { | ||
|
|
||
| func testFirebaseLoginRequestProperties() { | ||
| // Given | ||
| let email = "[email protected]" | ||
| let password = "secretpassword" | ||
| let loginRequest = FirebaseLoginRequest(email: email, password: password) | ||
|
|
||
| // Then | ||
| XCTAssertEqual(loginRequest.baseUrl, Constants.firebaseAuth) | ||
| XCTAssertEqual(loginRequest.path, "/v1/accounts:signInWithPassword") | ||
| XCTAssertEqual(loginRequest.method, "POST") | ||
| XCTAssertEqual(loginRequest.queryParameters, [ | ||
| "key": Constants.fireBaseAuthKey | ||
| ]) | ||
| XCTAssertEqual(loginRequest.headers, [ | ||
| "Content-Type": "application/json" | ||
| ]) | ||
| } | ||
|
|
||
| func testFirebaseLoginRequestBody() { | ||
| // Given | ||
| let email = "[email protected]" | ||
| let password = "secretpassword" | ||
| let loginRequest = FirebaseLoginRequest(email: email, password: password) | ||
|
|
||
| // When | ||
| let requestBody = loginRequest.requestBody | ||
|
|
||
| // Then | ||
| XCTAssertEqual(requestBody["email"] as? String, email) | ||
| XCTAssertEqual(requestBody["password"] as? String, password) | ||
| XCTAssertEqual(requestBody["returnSecureToken"] as? Bool, true) | ||
| } | ||
|
|
||
| func testFirebaseLoginRequestResponseDecoder() throws { | ||
| // Given | ||
| let loginResponseAsString = """ | ||
| { | ||
| "kind": "identitytoolkit#VerifyPasswordResponse", | ||
| "localId": "1234567890", | ||
| "email": "[email protected]", | ||
| "displayName": "John Doe", | ||
| "idToken": "abcdefghijk", | ||
| "registered": true, | ||
| "refreshToken": "qrstuvwxyz", | ||
| "expiresIn": "3600" | ||
| } | ||
| """ | ||
| let loginRequest = FirebaseLoginRequest(email: "[email protected]", password: "secretpassword") | ||
|
|
||
| // When | ||
| let loginResponseData = try XCTUnwrap(loginResponseAsString.data(using: .utf8)) | ||
| guard let loginResponse = try? loginRequest.responseDecoder(loginResponseData) else { return } | ||
| // Then | ||
| XCTAssertNotNil(loginResponse) | ||
| XCTAssertEqual(loginResponse.kind, "identitytoolkit#VerifyPasswordResponse") | ||
| XCTAssertEqual(loginResponse.localID, "1234567890") | ||
| XCTAssertEqual(loginResponse.email, "[email protected]") | ||
| XCTAssertEqual(loginResponse.displayName, "John Doe") | ||
| XCTAssertEqual(loginResponse.idToken, "abcdefghijk") | ||
| XCTAssertEqual(loginResponse.registered, true) | ||
| XCTAssertEqual(loginResponse.refreshToken, "qrstuvwxyz") | ||
| XCTAssertEqual(loginResponse.expiresIn, "3600") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import XCTest | |
| final class RegisterRequestTests: XCTestCase { | ||
|
|
||
| // MARK: - Tests | ||
|
|
||
| func testRegisterRequestProperties() { | ||
| // Given | ||
| let email = "[email protected]" | ||
|
|
@@ -16,7 +16,7 @@ final class RegisterRequestTests: XCTestCase { | |
| XCTAssertEqual(registerRequest.path, "/accounts:signInWithPassword?key=\(Constants.firebaseKey)") | ||
| XCTAssertEqual(registerRequest.method, "POST") | ||
| } | ||
|
|
||
| func testRegisterRequestResponseDecoder() throws { | ||
| // Given | ||
| let registerResponseAsString = """ | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expiresIn should be converted to
Date