Skip to content

Commit

Permalink
fix: load quote-requests on login and page refresh (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian-Haehnlein authored and dhhyi committed Dec 15, 2019
1 parent f8a05eb commit b43d5b4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { ApplyConfiguration } from 'ish-core/store/configuration';
import { configurationReducer } from 'ish-core/store/configuration/configuration.reducer';
import { LoadProductIfNotLoaded } from 'ish-core/store/shopping/products';
import { shoppingReducers } from 'ish-core/store/shopping/shopping-store.module';
import { LoadCompanyUserSuccess, LoginUserSuccess } from 'ish-core/store/user';
import { LoadCompanyUser, LoadCompanyUserSuccess, LoginUserSuccess } from 'ish-core/store/user';
import { userReducer } from 'ish-core/store/user/user.reducer';
import { ngrxTesting } from 'ish-core/utils/dev/ngrx-testing';

Expand Down Expand Up @@ -1038,4 +1038,21 @@ describe('Quote Request Effects', () => {
expect(effects.loadQuoteRequestItemsAfterSelectQuoteRequest$).toBeObservable(cold('---a--a', { a: expected }));
});
});

describe('loadQuoteRequestsOnLogin', () => {
beforeEach(() => {
store$.dispatch(
new LoginUserSuccess({
customer: {} as Customer,
user: {} as User,
})
);
});
it('should fire LoadQuoteRequests if getLoggedInCustomer selector streams true.', () => {
actions$ = hot('a', { a: new LoadCompanyUser() });
expect(effects.loadQuoteRequestsOnLogin$).toBeObservable(
cold('(a|)', { a: new quoteRequestActions.LoadQuoteRequests() })
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { LineItemUpdate } from 'ish-core/models/line-item-update/line-item-updat
import { ProductCompletenessLevel } from 'ish-core/models/product/product.model';
import { getCurrentBasket } from 'ish-core/store/checkout/basket';
import { LoadProductIfNotLoaded } from 'ish-core/store/shopping/products';
import { UserActionTypes, getUserAuthorized } from 'ish-core/store/user';
import { UserActionTypes, getLoggedInCustomer, getUserAuthorized } from 'ish-core/store/user';
import { mapErrorToAction, mapToPayload, mapToPayloadProperty, whenFalsy, whenTruthy } from 'ish-core/utils/operators';

import { QuoteRequest } from '../../models/quote-request/quote-request.model';
Expand Down Expand Up @@ -370,6 +370,14 @@ export class QuoteRequestEffects {
map(([quoteId]) => new actions.LoadQuoteRequestItems({ id: quoteId }))
);

@Effect()
loadQuoteRequestsOnLogin$ = this.store.pipe(
select(getLoggedInCustomer),
whenTruthy(),
first(),
mapTo(new actions.LoadQuoteRequests())
);

/**
* Filter for itemId and update pairs with actual quantity or sku changes.
* @param payloadItems The items of the action payload, containing items to update.
Expand Down

0 comments on commit b43d5b4

Please sign in to comment.