@@ -252,38 +252,40 @@ final class CardPresentPaymentStoreTests: XCTestCase {
252252 /// Verifies that the PaymentGatewayAccountStore hits the network when loading a WCPay Account and places nothing in storage in case of error.
253253 ///
254254 func test_loadAccounts_handles_failure( ) throws {
255- let expectation = self . expectation ( description: " Load Account error response " )
256255 network. simulateResponse ( requestUrlSuffix: " payments/accounts " ,
257256 filename: " generic_error " )
258257 network. simulateResponse ( requestUrlSuffix: " wc_stripe/account/summary " ,
259258 filename: " generic_error " )
260259
261- let action = CardPresentPaymentAction . loadAccounts ( siteID: sampleSiteID, onCompletion: { result in
262- XCTAssertTrue ( result. isFailure)
263- expectation. fulfill ( )
264- } )
260+ // When
261+ let result = waitFor { promise in
262+ self . cardPresentStore. onAction ( CardPresentPaymentAction . loadAccounts ( siteID: self . sampleSiteID, onCompletion: { result in
263+ promise ( result)
264+ } ) )
265+ }
265266
266- cardPresentStore . onAction ( action )
267- wait ( for : [ expectation ] , timeout : Constants . expectationTimeout )
267+ // Then
268+ XCTAssertTrue ( result . isFailure )
268269
269270 XCTAssertNil ( viewStorage. firstObject ( ofType: Storage . PaymentGatewayAccount. self, matching: nil ) )
270271 }
271272
272273 /// Verifies that the PaymentGatewayAccountStore hits the network when loading a WCPay Account, propagates success and upserts the account into storage.
273274 ///
274275 func test_loadAccounts_returns_expected_data( ) throws {
275- let expectation = self . expectation ( description: " Load Account fetch response " )
276276 network. simulateResponse ( requestUrlSuffix: " payments/accounts " ,
277277 filename: " wcpay-account-complete " )
278278 network. simulateResponse ( requestUrlSuffix: " wc_stripe/account/summary " ,
279279 filename: " stripe-account-complete " )
280- let action = CardPresentPaymentAction . loadAccounts ( siteID: sampleSiteID, onCompletion: { result in
281- XCTAssertTrue ( result. isSuccess)
282- expectation. fulfill ( )
283- } )
280+ // When
281+ let result = waitFor { promise in
282+ self . cardPresentStore. onAction ( CardPresentPaymentAction . loadAccounts ( siteID: self . sampleSiteID, onCompletion: { result in
283+ promise ( result)
284+ } ) )
285+ }
284286
285- cardPresentStore . onAction ( action )
286- wait ( for : [ expectation ] , timeout : Constants . expectationTimeout )
287+ // Then
288+ XCTAssertTrue ( result . isSuccess )
287289
288290 XCTAssert ( viewStorage. countObjects ( ofType: Storage . PaymentGatewayAccount. self, matching: nil ) == 2 )
289291
@@ -297,6 +299,89 @@ final class CardPresentPaymentStoreTests: XCTestCase {
297299 XCTAssert ( storageAccount? . status == " complete " )
298300 }
299301
302+ /// Verifies that loadAccounts succeeds when only WCPay succeeds and Stripe fails.
303+ ///
304+ func test_loadAccounts_succeeds_when_only_wcpay_succeeds( ) throws {
305+ // Given
306+ network. simulateResponse ( requestUrlSuffix: " payments/accounts " ,
307+ filename: " wcpay-account-complete " )
308+ network. simulateResponse ( requestUrlSuffix: " wc_stripe/account/summary " ,
309+ filename: " generic_error " )
310+
311+ // When
312+ let result = waitFor { promise in
313+ self . cardPresentStore. onAction ( CardPresentPaymentAction . loadAccounts ( siteID: self . sampleSiteID, onCompletion: { result in
314+ promise ( result)
315+ } ) )
316+ }
317+
318+ // Then
319+ XCTAssertTrue ( result. isSuccess)
320+
321+ XCTAssert ( viewStorage. countObjects ( ofType: Storage . PaymentGatewayAccount. self, matching: nil ) == 1 )
322+
323+ let storageAccount = viewStorage. loadPaymentGatewayAccount (
324+ siteID: sampleSiteID,
325+ gatewayID: WCPayAccount . gatewayID
326+ )
327+
328+ XCTAssert ( storageAccount? . siteID == sampleSiteID)
329+ XCTAssert ( storageAccount? . gatewayID == WCPayAccount . gatewayID)
330+ XCTAssert ( storageAccount? . status == " complete " )
331+ }
332+
333+ /// Verifies that loadAccounts succeeds when only Stripe succeeds and WCPay fails.
334+ ///
335+ func test_loadAccounts_succeeds_when_only_stripe_succeeds( ) throws {
336+ // Given
337+ network. simulateResponse ( requestUrlSuffix: " payments/accounts " ,
338+ filename: " generic_error " )
339+ network. simulateResponse ( requestUrlSuffix: " wc_stripe/account/summary " ,
340+ filename: " stripe-account-complete " )
341+
342+ // When
343+ let result = waitFor { promise in
344+ self . cardPresentStore. onAction ( CardPresentPaymentAction . loadAccounts ( siteID: self . sampleSiteID, onCompletion: { result in
345+ promise ( result)
346+ } ) )
347+ }
348+
349+ // Then
350+ XCTAssertTrue ( result. isSuccess)
351+
352+ XCTAssert ( viewStorage. countObjects ( ofType: Storage . PaymentGatewayAccount. self, matching: nil ) == 1 )
353+
354+ let storageAccount = viewStorage. loadPaymentGatewayAccount (
355+ siteID: sampleSiteID,
356+ gatewayID: StripeAccount . gatewayID
357+ )
358+
359+ XCTAssert ( storageAccount? . siteID == sampleSiteID)
360+ XCTAssert ( storageAccount? . gatewayID == StripeAccount . gatewayID)
361+ XCTAssert ( storageAccount? . status == " complete " )
362+ }
363+
364+ /// Verifies that loadAccounts returns an error when both WCPay and Stripe fail.
365+ ///
366+ func test_loadAccounts_fails_when_both_wcpay_and_stripe_fail( ) throws {
367+ // Given
368+ network. simulateResponse ( requestUrlSuffix: " payments/accounts " ,
369+ filename: " generic_error " )
370+ network. simulateResponse ( requestUrlSuffix: " wc_stripe/account/summary " ,
371+ filename: " generic_error " )
372+ // When
373+ let result = waitFor { promise in
374+ self . cardPresentStore. onAction ( CardPresentPaymentAction . loadAccounts ( siteID: self . sampleSiteID, onCompletion: { result in
375+ promise ( result)
376+ } ) )
377+ }
378+
379+ // Then
380+ XCTAssertTrue ( result. isFailure)
381+
382+ XCTAssertNil ( viewStorage. firstObject ( ofType: Storage . PaymentGatewayAccount. self, matching: nil ) )
383+ }
384+
300385 /// Verifies that the store hits the network when fetching a charge, and propagates success.
301386 ///
302387 func test_fetchWCPayCharge_returns_expected_data( ) throws {
0 commit comments