@@ -5,6 +5,12 @@ import {
55} from 'src/utilities/pollers'
66import { ErrorStatuses , ProcessingStatuses , ReadableStatuses } from 'src/const/Statuses'
77
8+ // CHALLENGED is intentionally excluded from error assertions because
9+ // handlePollingResponse routes it through the MFA-specific branch and message.
10+ const nonChallengedErrorStatuses = ErrorStatuses . filter (
11+ ( status ) => status !== ReadableStatuses . CHALLENGED ,
12+ )
13+
814describe ( 'handlePollingResponse' , ( ) => {
915 test ( 'it should stop polling and update the message' , ( ) => {
1016 testStatus ( ReadableStatuses . CHALLENGED , true , CONNECTING_MESSAGES . MFA )
@@ -62,16 +68,13 @@ describe('handlePollingResponse', () => {
6268
6369 describe ( 'Error states' , ( ) => {
6470 it ( 'should stop polling and show a message' , ( ) => {
65- ErrorStatuses . forEach ( ( status ) => {
66- // CHALLENGED state is an error state, but has specific logic
67- if ( status !== ReadableStatuses . CHALLENGED ) {
68- testStatus ( status , true , CONNECTING_MESSAGES . ERROR )
69- }
71+ nonChallengedErrorStatuses . forEach ( ( status ) => {
72+ testStatus ( status , true , CONNECTING_MESSAGES . ERROR )
7073 } )
7174 } )
7275
7376 it ( 'should wait for aggregation to be done for error states' , ( ) => {
74- ErrorStatuses . forEach ( ( status ) => {
77+ nonChallengedErrorStatuses . forEach ( ( status ) => {
7578 const pollingState = {
7679 ...DEFAULT_POLLING_STATE ,
7780 currentResponse : {
@@ -82,13 +85,10 @@ describe('handlePollingResponse', () => {
8285 } ,
8386 }
8487
85- // CHALLENGED state is an error state, but has specific logic
86- if ( status !== ReadableStatuses . CHALLENGED ) {
87- const [ stopPolling , message ] = handlePollingResponse ( pollingState )
88+ const [ stopPolling , message ] = handlePollingResponse ( pollingState )
8889
89- expect ( stopPolling ) . toEqual ( false )
90- expect ( message ) . toEqual ( CONNECTING_MESSAGES . VERIFYING )
91- }
90+ expect ( stopPolling ) . toEqual ( false )
91+ expect ( message ) . toEqual ( CONNECTING_MESSAGES . VERIFYING )
9292 } )
9393 } )
9494
@@ -118,9 +118,9 @@ describe('handlePollingResponse', () => {
118118 } )
119119 } )
120120
121- describe ( 'OAuth status ' , ( ) => {
121+ describe ( 'Terminal error code handling ' , ( ) => {
122122 it ( 'should keep polling and show the OAuth message if in error, but not finished agging' , ( ) => {
123- ErrorStatuses . forEach ( ( status ) => {
123+ nonChallengedErrorStatuses . forEach ( ( status ) => {
124124 const pollingState = {
125125 ...DEFAULT_POLLING_STATE ,
126126 currentResponse : {
@@ -132,17 +132,15 @@ describe('handlePollingResponse', () => {
132132 } ,
133133 }
134134
135- if ( status !== ReadableStatuses . CHALLENGED ) {
136- const [ stopPolling , message ] = handlePollingResponse ( pollingState )
135+ const [ stopPolling , message ] = handlePollingResponse ( pollingState )
137136
138- expect ( message ) . toEqual ( CONNECTING_MESSAGES . OAUTH )
139- expect ( stopPolling ) . toEqual ( false )
140- }
137+ expect ( message ) . toEqual ( CONNECTING_MESSAGES . OAUTH )
138+ expect ( stopPolling ) . toEqual ( false )
141139 } )
142140 } )
143141
144142 it ( 'should go to error view if we are done aggregating' , ( ) => {
145- ErrorStatuses . forEach ( ( status ) => {
143+ nonChallengedErrorStatuses . forEach ( ( status ) => {
146144 const pollingState = {
147145 ...DEFAULT_POLLING_STATE ,
148146 currentResponse : {
@@ -161,12 +159,31 @@ describe('handlePollingResponse', () => {
161159 } ,
162160 }
163161
164- if ( status !== ReadableStatuses . CHALLENGED ) {
165- const [ stopPolling , message ] = handlePollingResponse ( pollingState )
162+ const [ stopPolling , message ] = handlePollingResponse ( pollingState )
166163
167- expect ( message ) . toEqual ( CONNECTING_MESSAGES . ERROR )
168- expect ( stopPolling ) . toEqual ( true )
164+ expect ( message ) . toEqual ( CONNECTING_MESSAGES . ERROR )
165+ expect ( stopPolling ) . toEqual ( true )
166+ } )
167+ } )
168+
169+ it ( 'should stop polling when a terminal error code is present, oauth is true, and there is no previous response' , ( ) => {
170+ nonChallengedErrorStatuses . forEach ( ( status ) => {
171+ const pollingState = {
172+ ...DEFAULT_POLLING_STATE ,
173+ currentResponse : {
174+ member : {
175+ connection_status : status ,
176+ is_being_aggregated : false ,
177+ is_oauth : true ,
178+ error : { error_code : 'ANY_ERROR_CODE' } ,
179+ } ,
180+ } ,
169181 }
182+
183+ const [ stopPolling , message ] = handlePollingResponse ( pollingState )
184+
185+ expect ( message ) . toEqual ( CONNECTING_MESSAGES . ERROR )
186+ expect ( stopPolling ) . toEqual ( true )
170187 } )
171188 } )
172189 } )
0 commit comments