Skip to content

Commit

Permalink
feat(core): set state to error for operation failure (#2796)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed May 14, 2024
1 parent b2c1e90 commit dc08afa
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 46 deletions.
12 changes: 6 additions & 6 deletions libs/auth/state/src/reducers/auth/auth.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ describe('@daffodil/auth/state | daffAuthReducer', () => {
result = reducer(state, authCheckFailure);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});

it('adds an error to state.daffErrors', () => {
Expand Down Expand Up @@ -199,8 +199,8 @@ describe('@daffodil/auth/state | daffAuthReducer', () => {
result = reducer(state, authServerSide);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});

it('adds an error to state.daffErrors', () => {
Expand Down Expand Up @@ -228,8 +228,8 @@ describe('@daffodil/auth/state | daffAuthReducer', () => {
result = reducer(state, authStorageFailure);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});

it('adds an error to state.daffErrors', () => {
Expand Down
8 changes: 7 additions & 1 deletion libs/auth/state/src/reducers/auth/auth.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ export function daffAuthReducer(
};

case DaffAuthActionTypes.AuthCheckFailureAction:
case DaffAuthActionTypes.AuthGuardLogoutAction:
return {
...daffOperationFailed([action.errorMessage], state),
loggedIn: false,
};

case DaffAuthActionTypes.AuthGuardLogoutAction:
return {
...daffCompleteOperation(state),
daffErrors: [action.errorMessage],
loggedIn: false,
};

case DaffAuthActionTypes.AuthServerSideAction:
case DaffAuthActionTypes.AuthStorageFailureAction:
return daffOperationFailed([action.errorMessage], state);
Expand Down
8 changes: 4 additions & 4 deletions libs/auth/state/src/reducers/reset-password/reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ describe('@daffodil/auth/state | daffAuthResetPasswordReducer', () => {
result = reducer(state, authResetPasswordFailure);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});

it('adds an error to state.daffErrors', () => {
Expand Down Expand Up @@ -146,8 +146,8 @@ describe('@daffodil/auth/state | daffAuthResetPasswordReducer', () => {
result = reducer(state, authSendResetEmailFailure);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});

it('adds an error to state.daffErrors', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ describe('@daffodil/cart-store-credit/state | daffCartStoreCreditReducer', () =>
expect(result.daffErrors.length).toEqual(1);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});

Expand Down Expand Up @@ -187,8 +187,8 @@ describe('@daffodil/cart-store-credit/state | daffCartStoreCreditReducer', () =>
expect(result.daffErrors.length).toEqual(1);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ describe('@daffodil/category/state | daffCategoryReducer', () => {
expect(result.daffErrors).toEqual([error]);
});

it('sets daffState to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets daffState to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});
});
4 changes: 2 additions & 2 deletions libs/core/state/src/operation/adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ describe('@daffodil/core/state | daffOperationFailed', () => {
result = daffOperationFailed([error], state);
});

it('should set loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('should set loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});

it('should add the error', () => {
Expand Down
2 changes: 1 addition & 1 deletion libs/core/state/src/operation/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function daffCompleteOperation <T extends DaffOperationState = DaffOperat
export function daffOperationFailed <T extends DaffOperationState = DaffOperationState>(errors: T['daffErrors'], state: T): T {
return {
...state,
daffState: DaffState.Stable,
daffState: DaffState.Error,
daffErrors: errors,
};
};
Expand Down
12 changes: 6 additions & 6 deletions libs/customer-payment/state/src/reducers/payment/reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ describe('@daffodil/customer-payment/state | daffCustomerPaymentReducer', () =>
expect(result.daffErrors.length).toEqual(1);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});

Expand Down Expand Up @@ -201,8 +201,8 @@ describe('@daffodil/customer-payment/state | daffCustomerPaymentReducer', () =>
expect(result.daffErrors.length).toEqual(1);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});

Expand Down Expand Up @@ -422,8 +422,8 @@ describe('@daffodil/customer-payment/state | daffCustomerPaymentReducer', () =>
expect(result.daffErrors.length).toEqual(1);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ describe('@daffodil/customer-store-credit/state | daffCustomerStoreCreditReducer
expect(result.daffErrors.length).toEqual(1);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});
});
8 changes: 4 additions & 4 deletions libs/customer/state/src/reducers/address/reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ describe('@daffodil/customer/state | daffCustomerAddressReducer', () => {
expect(result.daffErrors.length).toEqual(1);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});

Expand Down Expand Up @@ -199,8 +199,8 @@ describe('@daffodil/customer/state | daffCustomerAddressReducer', () => {
expect(result.daffErrors.length).toEqual(1);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});

Expand Down
16 changes: 8 additions & 8 deletions libs/customer/state/src/reducers/customer/reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ describe('@daffodil/customer/state | daffCustomerReducer', () => {
expect(result.daffErrors.length).toEqual(1);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});

Expand Down Expand Up @@ -204,8 +204,8 @@ describe('@daffodil/customer/state | daffCustomerReducer', () => {
expect(result.daffErrors.length).toEqual(1);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});

Expand Down Expand Up @@ -287,8 +287,8 @@ describe('@daffodil/customer/state | daffCustomerReducer', () => {
expect(result.daffErrors.length).toEqual(1);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});

Expand Down Expand Up @@ -364,8 +364,8 @@ describe('@daffodil/customer/state | daffCustomerReducer', () => {
expect(result.daffErrors.length).toEqual(1);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});

Expand Down
8 changes: 4 additions & 4 deletions libs/order/state/src/reducers/order/order.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ describe('@daffodil/order/state | daffOrderReducer', () => {
expect(result.daffErrors).toEqual([mockError]);
});

it('sets loading to false', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});

Expand Down Expand Up @@ -184,8 +184,8 @@ describe('@daffodil/order/state | daffOrderReducer', () => {
expect(result.daffErrors).toEqual([mockError]);
});

it('sets loading to false', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ describe('@daffodil/product/state | daffProductReducer', () => {
result = daffProductReducer(state, productLoadFailure);
});

it('sets loading to stable', () => {
expect(result.daffState).toEqual(DaffState.Stable);
it('sets loading to error', () => {
expect(result.daffState).toEqual(DaffState.Error);
});

it('stores the error', () => {
Expand Down

0 comments on commit dc08afa

Please sign in to comment.