-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mobile Payments] Show IPP address errors when using site credentials (…
- Loading branch information
Showing
10 changed files
with
247 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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
16 changes: 16 additions & 0 deletions
16
Yosemite/YosemiteTests/Mocks/MockCardReaderCapableRemote.swift
This file contains 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,16 @@ | ||
import Foundation | ||
import Yosemite | ||
import Networking | ||
import Fakes | ||
|
||
struct MockCardReaderCapableRemote: CardReaderCapableRemote { | ||
func loadConnectionToken(for siteID: Int64, completion: @escaping (Result<Networking.ReaderConnectionToken, any Error>) -> Void) { | ||
// no-op | ||
} | ||
|
||
var resultForDefaultReaderLocation: (Result<RemoteReaderLocation, any Error>) = .success(RemoteReaderLocation.fake()) | ||
func loadDefaultReaderLocation(for siteID: Int64, onCompletion: @escaping (Result<RemoteReaderLocation, any Error>) -> Void) { | ||
onCompletion(resultForDefaultReaderLocation) | ||
} | ||
|
||
} |
132 changes: 132 additions & 0 deletions
132
Yosemite/YosemiteTests/Tools/CommonReaderConfigProviderTests.swift
This file contains 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,132 @@ | ||
import Testing | ||
|
||
@testable import Yosemite | ||
import Networking | ||
|
||
struct CommonReaderConfigProviderTests { | ||
|
||
@Test func fetchDefaultLocationID_returns_incompleteStoreAddress_error_when_jetpack_site_has_incomplete_store_address() async throws { | ||
let adminURL = "https://example.com/wp-admin/set-address" | ||
let mockRemote = MockCardReaderCapableRemote( | ||
resultForDefaultReaderLocation: .failure( | ||
DotcomError.unknown(code: "store_address_is_incomplete", | ||
message: adminURL))) | ||
|
||
let sut = CommonReaderConfigProvider(siteID: 123, | ||
readerConfigRemote: mockRemote) | ||
|
||
let expectedError = CardReaderConfigError.incompleteStoreAddress(adminUrl: URL(string: adminURL)!) | ||
await #expect(throws: expectedError) { | ||
try await withCheckedThrowingContinuation { continuation in | ||
sut.fetchDefaultLocationID { result in | ||
continuation.resume(with: result) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test func fetchDefaultLocationID_returns_invalidPostalCode_error_when_jetpack_site_has_no_postcode() async throws { | ||
let mockRemote = MockCardReaderCapableRemote( | ||
resultForDefaultReaderLocation: .failure( | ||
DotcomError.unknown(code: "postal_code_invalid", | ||
message: ""))) | ||
|
||
let sut = CommonReaderConfigProvider(siteID: 123, | ||
readerConfigRemote: mockRemote) | ||
|
||
await #expect(throws: CardReaderConfigError.invalidPostalCode) { | ||
try await withCheckedThrowingContinuation { continuation in | ||
sut.fetchDefaultLocationID { result in | ||
continuation.resume(with: result) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test( | ||
.bug("https://github.com/woocommerce/woocommerce-ios/issues/14333", id: "14333") | ||
) | ||
func fetchDefaultLocationID_returns_incompleteStoreAddress_error_when_site_has_incomplete_store_address_and_siteCredentials_used() async throws { | ||
let errorResponseJSON = """ | ||
{"code":"store_address_is_incomplete","message":"https://example.com/wp-admin/admin.php?page=wc-settings&tab=general","data":null} | ||
""" | ||
let mockRemote = MockCardReaderCapableRemote( | ||
resultForDefaultReaderLocation: .failure( | ||
NetworkError.unacceptableStatusCode( | ||
statusCode: 500, | ||
response: errorResponseJSON.data(using: .utf8) | ||
) | ||
) | ||
) | ||
|
||
let sut = CommonReaderConfigProvider(siteID: 123, | ||
readerConfigRemote: mockRemote) | ||
|
||
let expectedError = CardReaderConfigError.incompleteStoreAddress( | ||
adminUrl: URL(string: "https://example.com/wp-admin/admin.php?page=wc-settings&tab=general")!) | ||
await #expect(throws: expectedError) { | ||
try await withCheckedThrowingContinuation { continuation in | ||
sut.fetchDefaultLocationID { result in | ||
continuation.resume(with: result) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
func fetchDefaultLocationID_returns_incompleteStoreAddress_error_when_site_has_incomplete_store_address_without_url_and_siteCredentials_used() async throws { | ||
let errorResponseJSON = """ | ||
{"code":"store_address_is_incomplete","message":null,"data":null} | ||
""" | ||
let mockRemote = MockCardReaderCapableRemote( | ||
resultForDefaultReaderLocation: .failure( | ||
NetworkError.unacceptableStatusCode( | ||
statusCode: 500, | ||
response: errorResponseJSON.data(using: .utf8) | ||
) | ||
) | ||
) | ||
|
||
let sut = CommonReaderConfigProvider(siteID: 123, | ||
readerConfigRemote: mockRemote) | ||
|
||
let expectedError = CardReaderConfigError.incompleteStoreAddress(adminUrl: nil) | ||
await #expect(throws: expectedError) { | ||
try await withCheckedThrowingContinuation { continuation in | ||
sut.fetchDefaultLocationID { result in | ||
continuation.resume(with: result) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test( | ||
.bug("https://github.com/woocommerce/woocommerce-ios/issues/14333", id: "14333") | ||
) | ||
func fetchDefaultLocationID_returns_invalidPostalCode_error_when_site_has_no_postcode_and_siteCredentials_used() async throws { | ||
let errorResponseJSON = """ | ||
{"code":"postal_code_invalid"} | ||
""" | ||
let mockRemote = MockCardReaderCapableRemote( | ||
resultForDefaultReaderLocation: .failure( | ||
NetworkError.unacceptableStatusCode( | ||
statusCode: 500, | ||
response: errorResponseJSON.data(using: .utf8) | ||
) | ||
) | ||
) | ||
|
||
let sut = CommonReaderConfigProvider(siteID: 123, | ||
readerConfigRemote: mockRemote) | ||
|
||
let expectedError = CardReaderConfigError.invalidPostalCode | ||
await #expect(throws: expectedError) { | ||
try await withCheckedThrowingContinuation { continuation in | ||
sut.fetchDefaultLocationID { result in | ||
continuation.resume(with: result) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |