Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianGosebrink committed Feb 23, 2021
1 parent 9de5f10 commit 3ff334f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { SilentRenewServiceMock } from './iframe/silent-renew.service-mock';
import { LoggerService } from './logging/logger.service';
import { LoggerServiceMock } from './logging/logger.service-mock';
import { PopUpService } from './login/popup/popup.service';
import { PopUpServiceMock } from './login/popup/popup.service-mock';
import { UserService } from './userData/user-service';

describe('CheckAuthService', () => {
Expand All @@ -31,6 +32,7 @@ describe('CheckAuthService', () => {
let silentRenewService: SilentRenewService;
let periodicallyTokenCheckService: PeriodicallyTokenCheckService;
let refreshSessionService: RefreshSessionService;
let popUpService: PopUpService;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -45,7 +47,7 @@ describe('CheckAuthService', () => {
{ provide: CallbackService, useClass: CallbackServiceMock },
{ provide: RefreshSessionService, useClass: RefreshSessionServiceMock },
{ provide: PeriodicallyTokenCheckService, useClass: PeriodicallyTokenCheckServiceMock },
PopUpService,
{ provide: PopUpService, useClass: PopUpServiceMock },
],
});
});
Expand All @@ -60,6 +62,7 @@ describe('CheckAuthService', () => {
callBackService = TestBed.inject(CallbackService);
silentRenewService = TestBed.inject(SilentRenewService);
periodicallyTokenCheckService = TestBed.inject(PeriodicallyTokenCheckService);
popUpService = TestBed.inject(PopUpService);
});

it('should create', () => {
Expand All @@ -75,6 +78,20 @@ describe('CheckAuthService', () => {
})
);

it(
'returns null and sendMessageToMainWindow if currently in a popup',
waitForAsync(() => {
spyOn(configurationProvider, 'hasValidConfig').and.returnValue(true);
spyOnProperty(configurationProvider, 'openIDConfiguration', 'get').and.returnValue('stsServer');
spyOn(popUpService, 'isCurrentlyInPopup').and.returnValue(true);
const popupSpy = spyOn(popUpService, 'sendMessageToMainWindow');
checkAuthService.checkAuth().subscribe((result) => {
expect(result).toBeNull();
expect(popupSpy).toHaveBeenCalled();
});
})
);

it(
'returns false in case handleCallbackAndFireEvents throws an error',
waitForAsync(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export class PopUpServiceMock {
return true;
}

isCurrentlyInPopup(): boolean {
return false;
}

openPopUp(url: string, popupOptions?: PopupOptions) {}

sendMessageToMainWindow(url: string) {}
Expand Down

0 comments on commit 3ff334f

Please sign in to comment.