Skip to content

Commit

Permalink
Wires SimplenoteEndpoints SPM
Browse files Browse the repository at this point in the history
  • Loading branch information
jleandroperez committed Jul 25, 2024
1 parent 7049055 commit fd6845f
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 48 deletions.
57 changes: 17 additions & 40 deletions Simplenote.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion Simplenote.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "1f66ac352dc04da5870abacba5f42306bd560111ad295c7c60a13a7af5c25ec8",
"originHash" : "7f8dc02b0065be779873bdc5b585794a5005edfeb5a5e51a04644d5b3c18e322",
"pins" : [
{
"identity" : "automattic-tracks-ios",
Expand All @@ -19,6 +19,15 @@
"version" : "8.28.0"
}
},
{
"identity" : "simplenoteendpoints-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Automattic/SimplenoteEndpoints-Swift",
"state" : {
"branch" : "trunk",
"revision" : "3d1c0a5db39ca798a7de10e7faeef8ae66e941e6"
}
},
{
"identity" : "simplenotefoundation-swift",
"kind" : "remoteSourceControl",
Expand Down
2 changes: 2 additions & 0 deletions Simplenote/AccountDeletionController.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Foundation
import SimplenoteEndpoints


@objc
class AccountDeletionController: NSObject {
Expand Down
2 changes: 2 additions & 0 deletions Simplenote/AccountVerificationController.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Foundation
import SimplenoteEndpoints


// MARK: - AccountVerificationController
//
Expand Down
2 changes: 2 additions & 0 deletions Simplenote/AuthViewController+Swift.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Foundation
import SimplenoteEndpoints


// MARK: - AuthViewController: Interface Initialization
//
Expand Down
1 change: 1 addition & 0 deletions Simplenote/MagicLinkAuthenticator.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import SimplenoteEndpoints


// MARK: - Notifications
Expand Down
5 changes: 5 additions & 0 deletions Simplenote/SimperiumAuthenticatorProtocol.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Foundation
import SimplenoteEndpoints
import Simperium_OSX


// MARK: - SimperiumAuthenticatorProtocol
Expand All @@ -9,3 +11,6 @@ protocol SimperiumAuthenticatorProtocol {


extension SPAuthenticator: SimperiumAuthenticatorProtocol { }


extension SPUser: UserProtocol { }
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import Foundation
import SimplenoteEndpoints
@testable import Simplenote


extension AccountVerificationController {
func randomResult() -> Result<Data?, RemoteError> {
return Bool.random() ? .success(nil) : .failure(RemoteError.requestError(0, nil))
if Bool.random() {
return .success(nil)
}

let error = RemoteError(statusCode: .zero, response: nil, networkError: nil)
return .failure(error)
}
}
1 change: 1 addition & 0 deletions SimplenoteTests/AccountVerificationControllerTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import XCTest
import SimplenoteEndpoints
@testable import Simplenote

// MARK: - AccountVerificationControllerTests
Expand Down
8 changes: 6 additions & 2 deletions SimplenoteTests/AccountVerificationRemoteTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import XCTest
import SimplenoteEndpoints
@testable import Simplenote


// MARK: - AccountVerificationRemoteTests
//
class AccountVerificationRemoteTests: XCTestCase {
Expand All @@ -16,12 +18,14 @@ class AccountVerificationRemoteTests: XCTestCase {
func testFailureWhenStatusCodeIs4xxOr5xx() {
for _ in 0..<5 {
let statusCode = Int.random(in: 400..<600)
test(withStatusCode: statusCode, expectedResult: Result.failure(RemoteError.requestError(statusCode, nil)))
let error = RemoteError(statusCode: statusCode, response: nil, networkError: nil)
test(withStatusCode: statusCode, expectedResult: Result.failure(error))
}
}

func testFailureWhenNoResponse() {
test(withStatusCode: nil, expectedResult: Result.failure(RemoteError.network))
let expectedError = RemoteError(statusCode: .zero, response: nil, networkError: nil)
test(withStatusCode: nil, expectedResult: Result.failure(expectedError))
}

private func test(withStatusCode statusCode: Int?, expectedResult: Result<Data?, RemoteError>) {
Expand Down
3 changes: 2 additions & 1 deletion SimplenoteTests/LoginRemoteTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import XCTest
import SimplenoteEndpoints
@testable import Simplenote

class LoginRemoteTests: XCTestCase {
Expand All @@ -13,7 +14,7 @@ class LoginRemoteTests: XCTestCase {
do {
try await loginRemote.requestLoginEmail(email: "email@gmail.com")
} catch {
XCTAssertEqual(error as? RemoteError, RemoteError.init(statusCode: statusCode))
XCTAssertEqual(error as? RemoteError, RemoteError(statusCode: statusCode, response: nil, networkError: nil))
}
}

Expand Down
1 change: 1 addition & 0 deletions SimplenoteTests/MagicLinkAuthenticatorTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import XCTest
import SimplenoteEndpoints
@testable import Simplenote


Expand Down
2 changes: 2 additions & 0 deletions SimplenoteTests/MockAccountVerificationRemote.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import XCTest
@testable import SimplenoteEndpoints
@testable import Simplenote


// MARK: - MockAccountVerificationRemote
//
class MockAccountRemote: AccountRemote {
Expand Down
3 changes: 2 additions & 1 deletion SimplenoteTests/MockLoginRemote.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import SimplenoteEndpoints
@testable import Simplenote


Expand All @@ -15,7 +16,7 @@ class MockLoginRemote: LoginRemoteProtocol {

func requestLoginConfirmation(email: String, authCode: String) async throws -> LoginConfirmationResponse {
guard let response = onLoginConfirmationRequest?(email, authCode) else {
throw RemoteError.network
throw RemoteError(statusCode: .zero, response: nil, networkError: nil)
}

return response
Expand Down
4 changes: 3 additions & 1 deletion SimplenoteTests/MockURLSession.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Foundation
import SimplenoteEndpoints
@testable import Simplenote


// MARK: - MockURLSession
//
class MockURLSession: URLSessionProtocol {
Expand Down Expand Up @@ -31,6 +33,6 @@ class MockURLSession: URLSessionProtocol {
return (responseData, urlResponse)
}

throw RemoteError.network
throw RemoteError(statusCode: .zero, response: nil, networkError: nil)
}
}
5 changes: 4 additions & 1 deletion SimplenoteTests/SignupRemoteTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import XCTest
import SimplenoteEndpoints
@testable import Simplenote


class SignupRemoteTests: XCTestCase {
private lazy var urlSession = MockURLSession()
private lazy var signupRemote = SignupRemote(urlSession: urlSession)
Expand All @@ -11,7 +13,8 @@ class SignupRemoteTests: XCTestCase {

func testFailureWhenStatusCodeIs4xxOr5xx() {
let statusCode = Int.random(in: 400..<600)
verifySignupSucceeds(withStatusCode: statusCode, email: "email@gmail.com", expectedSuccess: Result.failure(RemoteError.requestError(statusCode, nil)))
let expectedError = RemoteError(statusCode: statusCode, response: nil, networkError: nil)
verifySignupSucceeds(withStatusCode: statusCode, email: "email@gmail.com", expectedSuccess: Result.failure(expectedError))
}

func testRequestSetsEmailToCorrectCase() throws {
Expand Down

0 comments on commit fd6845f

Please sign in to comment.