Skip to content

Commit

Permalink
feat(authorizenet): only dispatch success when accept.js actually loa…
Browse files Browse the repository at this point in the history
…ds (#2436)
  • Loading branch information
griest024 committed May 11, 2023
1 parent 24272f9 commit 37e0548
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions libs/authorizenet/state/src/effects/authorize-net.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
DaffAuthorizeNetConfig,
DaffAuthorizeNetDriver,
DaffAuthorizeNetPaymentId,
DaffAuthorizeNetAcceptjsMissingError,
} from '@daffodil/authorizenet/driver';
import { MAGENTO_AUTHORIZE_NET_PAYMENT_ID } from '@daffodil/authorizenet/driver/magento';
import { DaffTestingAuthorizeNetDriverModule } from '@daffodil/authorizenet/driver/testing';
Expand Down Expand Up @@ -220,5 +221,14 @@ describe('DaffAuthorizeNetEffects', () => {

expect(effects.loadAcceptJs$(0, 0)).toBeObservable(expected);
});

it('should trigger a DaffLoadAcceptJsFailure action if acceptJs fails to load but does not throw an error', () => {
acceptJsLoadingServiceSpy.getAccept.and.returnValue(null);
const loadAcceptJsAction = new DaffLoadAcceptJs();
actions$ = hot('--a', { a: loadAcceptJsAction });
const expected = cold('--b', { b: new DaffLoadAcceptJsFailure(<any>jasmine.any(DaffAuthorizeNetAcceptjsMissingError)) });

expect(effects.loadAcceptJs$(0, 0)).toBeObservable(expected);
});
});
});
3 changes: 2 additions & 1 deletion libs/authorizenet/state/src/effects/authorize-net.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
DaffAuthorizeNetDriver,
DaffAuthorizeNetService,
DaffAuthorizeNetPaymentId,
DaffAuthorizeNetAcceptjsMissingError,
} from '@daffodil/authorizenet/driver';
import {
DaffCartPaymentActionTypes,
Expand Down Expand Up @@ -109,7 +110,7 @@ export class DaffAuthorizeNetEffects<T extends DaffAuthorizeNetTokenRequest = Da
tap((action: DaffLoadAcceptJs) => this.acceptJsLoadingService.load()),
switchMap(() => defer(() => of(this.acceptJsLoadingService.getAccept())).pipe(
backoff(maxTries, ms),
map(() => new DaffLoadAcceptJsSuccess()),
map((Accept) => Accept ? new DaffLoadAcceptJsSuccess() : new DaffLoadAcceptJsFailure(new DaffAuthorizeNetAcceptjsMissingError('Accept.js failed to load.'))),
catchError((error: DaffError) => of(new DaffLoadAcceptJsFailure(this.errorMatcher(error)))),
)),
));
Expand Down

0 comments on commit 37e0548

Please sign in to comment.