mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
87968: Fix unit tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { fakeAsync, flush, TestBed } from '@angular/core/testing';
|
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||||
|
|
||||||
import { provideMockActions } from '@ngrx/effects/testing';
|
import { provideMockActions } from '@ngrx/effects/testing';
|
||||||
import { Store, StoreModule } from '@ngrx/store';
|
import { Store, StoreModule } from '@ngrx/store';
|
||||||
@@ -396,44 +396,43 @@ describe('AuthEffects', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('when auth loaded is false', () => {
|
describe('when auth loaded is false', () => {
|
||||||
it('should not call removeToken method', (done) => {
|
it('should not call removeToken method', fakeAsync(() => {
|
||||||
store.overrideSelector(isAuthenticatedLoaded, false);
|
store.overrideSelector(isAuthenticatedLoaded, false);
|
||||||
actions = hot('--a-|', { a: { type: StoreActionTypes.REHYDRATE } });
|
actions = observableOf({ type: StoreActionTypes.REHYDRATE });
|
||||||
spyOn(authServiceStub, 'removeToken');
|
spyOn(authServiceStub, 'removeToken');
|
||||||
|
|
||||||
authEffects.clearInvalidTokenOnRehydrate$.subscribe(() => {
|
authEffects.clearInvalidTokenOnRehydrate$.subscribe(() => {
|
||||||
expect(authServiceStub.removeToken).not.toHaveBeenCalled();
|
expect(false).toBeTrue(); // subscribe to trigger taps, fail if the effect emits (we don't expect it to)
|
||||||
|
|
||||||
});
|
});
|
||||||
|
tick(1000);
|
||||||
done();
|
expect(authServiceStub.removeToken).not.toHaveBeenCalled();
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when auth loaded is true', () => {
|
describe('when auth loaded is true', () => {
|
||||||
it('should call removeToken method', fakeAsync(() => {
|
it('should call removeToken method', (done) => {
|
||||||
|
spyOn(console, 'log').and.callThrough();
|
||||||
|
|
||||||
store.overrideSelector(isAuthenticatedLoaded, true);
|
store.overrideSelector(isAuthenticatedLoaded, true);
|
||||||
actions = hot('--a-|', { a: { type: StoreActionTypes.REHYDRATE } });
|
actions = observableOf({ type: StoreActionTypes.REHYDRATE });
|
||||||
spyOn(authServiceStub, 'removeToken');
|
spyOn(authServiceStub, 'removeToken');
|
||||||
|
|
||||||
authEffects.clearInvalidTokenOnRehydrate$.subscribe(() => {
|
authEffects.clearInvalidTokenOnRehydrate$.subscribe(() => {
|
||||||
expect(authServiceStub.removeToken).toHaveBeenCalled();
|
expect(authServiceStub.removeToken).toHaveBeenCalled();
|
||||||
flush();
|
done();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('invalidateAuthorizationsRequestCache$', () => {
|
describe('invalidateAuthorizationsRequestCache$', () => {
|
||||||
it('should call invalidateAuthorizationsRequestCache method in response to a REHYDRATE action', (done) => {
|
it('should call invalidateAuthorizationsRequestCache method in response to a REHYDRATE action', (done) => {
|
||||||
actions = hot('--a-|', { a: { type: StoreActionTypes.REHYDRATE } });
|
actions = observableOf({ type: StoreActionTypes.REHYDRATE });
|
||||||
|
|
||||||
authEffects.invalidateAuthorizationsRequestCache$.subscribe(() => {
|
authEffects.invalidateAuthorizationsRequestCache$.subscribe(() => {
|
||||||
expect((authEffects as any).authorizationsService.invalidateAuthorizationsRequestCache).toHaveBeenCalled();
|
expect((authEffects as any).authorizationsService.invalidateAuthorizationsRequestCache).toHaveBeenCalled();
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -25,9 +25,11 @@ describe('Notifications reducer', () => {
|
|||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [NotificationComponent, NotificationsBoardComponent],
|
declarations: [NotificationComponent, NotificationsBoardComponent],
|
||||||
providers: [NotificationsService],
|
providers: [
|
||||||
imports: [
|
NotificationsService,
|
||||||
ChangeDetectorRef,
|
ChangeDetectorRef,
|
||||||
|
],
|
||||||
|
imports: [
|
||||||
StoreModule.forRoot({ notificationsReducer }, storeModuleConfig),
|
StoreModule.forRoot({ notificationsReducer }, storeModuleConfig),
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user