feat: init
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { TestBed } from '@/testing';
|
||||
import { of } from 'rxjs';
|
||||
import { mockProvider } from '../../../test/auto-mock';
|
||||
import { vi } from 'vitest';
|
||||
import { CheckAuthService } from '../../auth-state/check-auth.service';
|
||||
import { AuthWellKnownService } from '../../config/auth-well-known/auth-well-known.service';
|
||||
import { LoggerService } from '../../logging/logger.service';
|
||||
import { mockProvider } from '../../testing/mock';
|
||||
import { RedirectService } from '../../utils/redirect/redirect.service';
|
||||
import { UrlService } from '../../utils/url/url.service';
|
||||
import { LoginResponse } from '../login-response';
|
||||
import { PopupResult } from '../popup/popup-result';
|
||||
import type { LoginResponse } from '../login-response';
|
||||
import type { PopupResult } from '../popup/popup-result';
|
||||
import { PopUpService } from '../popup/popup.service';
|
||||
import { ResponseTypeValidationService } from '../response-type-validation/response-type-validation.service';
|
||||
import { ParLoginService } from './par-login.service';
|
||||
import { ParResponse } from './par-response';
|
||||
import type { ParResponse } from './par-response';
|
||||
import { ParService } from './par.service';
|
||||
|
||||
describe('ParLoginService', () => {
|
||||
@@ -60,33 +61,33 @@ describe('ParLoginService', () => {
|
||||
});
|
||||
|
||||
describe('loginPar', () => {
|
||||
it('does nothing if it has an invalid response type', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('does nothing if it has an invalid response type', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(false);
|
||||
const loggerSpy = spyOn(loggerService, 'logError');
|
||||
).mockReturnValue(false);
|
||||
const loggerSpy = vi.spyOn(loggerService, 'logError');
|
||||
|
||||
const result = service.loginPar({});
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
expect(loggerSpy).toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
|
||||
it('calls parService.postParRequest without custom params when no custom params are passed', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('calls parService.postParRequest without custom params when no custom params are passed', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(true);
|
||||
).mockReturnValue(true);
|
||||
|
||||
spyOn(
|
||||
vi.spyOn(
|
||||
authWellKnownService,
|
||||
'queryAndStoreAuthWellKnownEndPoints'
|
||||
).and.returnValue(of({}));
|
||||
).mockReturnValue(of({}));
|
||||
|
||||
const spy = spyOn(parService, 'postParRequest').and.returnValue(
|
||||
of({ requestUri: 'requestUri' } as ParResponse)
|
||||
);
|
||||
const spy = vi
|
||||
.spyOn(parService, 'postParRequest')
|
||||
.mockReturnValue(of({ requestUri: 'requestUri' } as ParResponse));
|
||||
|
||||
const result = service.loginPar({
|
||||
authWellknownEndpointUrl: 'authWellknownEndpoint',
|
||||
@@ -95,69 +96,69 @@ describe('ParLoginService', () => {
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
expect(spy).toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
|
||||
it('calls parService.postParRequest with custom params when custom params are passed', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('calls parService.postParRequest with custom params when custom params are passed', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(true);
|
||||
).mockReturnValue(true);
|
||||
const config = {
|
||||
authWellknownEndpointUrl: 'authWellknownEndpoint',
|
||||
responseType: 'stubValue',
|
||||
};
|
||||
|
||||
spyOn(
|
||||
vi.spyOn(
|
||||
authWellKnownService,
|
||||
'queryAndStoreAuthWellKnownEndPoints'
|
||||
).and.returnValue(of({}));
|
||||
).mockReturnValue(of({}));
|
||||
|
||||
const spy = spyOn(parService, 'postParRequest').and.returnValue(
|
||||
of({ requestUri: 'requestUri' } as ParResponse)
|
||||
);
|
||||
const spy = vi
|
||||
.spyOn(parService, 'postParRequest')
|
||||
.mockReturnValue(of({ requestUri: 'requestUri' } as ParResponse));
|
||||
|
||||
const result = service.loginPar(config, {
|
||||
customParams: { some: 'thing' },
|
||||
});
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, {
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(config, {
|
||||
customParams: { some: 'thing' },
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('returns undefined and logs error when no url could be created', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('returns undefined and logs error when no url could be created', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(true);
|
||||
).mockReturnValue(true);
|
||||
const config = {
|
||||
authWellknownEndpointUrl: 'authWellknownEndpoint',
|
||||
responseType: 'stubValue',
|
||||
};
|
||||
|
||||
spyOn(
|
||||
vi.spyOn(
|
||||
authWellKnownService,
|
||||
'queryAndStoreAuthWellKnownEndPoints'
|
||||
).and.returnValue(of({}));
|
||||
).mockReturnValue(of({}));
|
||||
|
||||
spyOn(parService, 'postParRequest').and.returnValue(
|
||||
vi.spyOn(parService, 'postParRequest').mockReturnValue(
|
||||
of({ requestUri: 'requestUri' } as ParResponse)
|
||||
);
|
||||
spyOn(urlService, 'getAuthorizeParUrl').and.returnValue('');
|
||||
const spy = spyOn(loggerService, 'logError');
|
||||
vi.spyOn(urlService, 'getAuthorizeParUrl').mockReturnValue('');
|
||||
const spy = vi.spyOn(loggerService, 'logError');
|
||||
|
||||
const result = service.loginPar(config);
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
}));
|
||||
});
|
||||
|
||||
it('calls redirect service redirectTo when url could be created', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('calls redirect service redirectTo when url could be created', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(true);
|
||||
).mockReturnValue(true);
|
||||
const config = {
|
||||
authWellknownEndpointUrl: 'authWellknownEndpoint',
|
||||
responseType: 'stubValue',
|
||||
@@ -165,42 +166,46 @@ describe('ParLoginService', () => {
|
||||
|
||||
const authOptions = {};
|
||||
|
||||
spyOn(
|
||||
vi.spyOn(
|
||||
authWellKnownService,
|
||||
'queryAndStoreAuthWellKnownEndPoints'
|
||||
).and.returnValue(of({}));
|
||||
).mockReturnValue(of({}));
|
||||
|
||||
spyOn(parService, 'postParRequest').and.returnValue(
|
||||
vi.spyOn(parService, 'postParRequest').mockReturnValue(
|
||||
of({ requestUri: 'requestUri' } as ParResponse)
|
||||
);
|
||||
spyOn(urlService, 'getAuthorizeParUrl').and.returnValue('some-par-url');
|
||||
const spy = spyOn(redirectService, 'redirectTo');
|
||||
vi.spyOn(urlService, 'getAuthorizeParUrl').mockReturnValue(
|
||||
'some-par-url'
|
||||
);
|
||||
const spy = vi.spyOn(redirectService, 'redirectTo');
|
||||
|
||||
service.loginPar(config, authOptions);
|
||||
|
||||
expect(spy).toHaveBeenCalledOnceWith('some-par-url');
|
||||
}));
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith('some-par-url');
|
||||
});
|
||||
|
||||
it('calls urlHandler when URL is passed', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('calls urlHandler when URL is passed', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(true);
|
||||
).mockReturnValue(true);
|
||||
const config = {
|
||||
authWellknownEndpointUrl: 'authWellknownEndpoint',
|
||||
responseType: 'stubValue',
|
||||
};
|
||||
|
||||
spyOn(
|
||||
vi.spyOn(
|
||||
authWellKnownService,
|
||||
'queryAndStoreAuthWellKnownEndPoints'
|
||||
).and.returnValue(of({}));
|
||||
).mockReturnValue(of({}));
|
||||
|
||||
spyOn(parService, 'postParRequest').and.returnValue(
|
||||
vi.spyOn(parService, 'postParRequest').mockReturnValue(
|
||||
of({ requestUri: 'requestUri' } as ParResponse)
|
||||
);
|
||||
spyOn(urlService, 'getAuthorizeParUrl').and.returnValue('some-par-url');
|
||||
const redirectToSpy = spyOn(redirectService, 'redirectTo');
|
||||
vi.spyOn(urlService, 'getAuthorizeParUrl').mockReturnValue(
|
||||
'some-par-url'
|
||||
);
|
||||
const redirectToSpy = vi.spyOn(redirectService, 'redirectTo');
|
||||
const spy = jasmine.createSpy();
|
||||
const urlHandler = (url: any): void => {
|
||||
spy(url);
|
||||
@@ -208,18 +213,18 @@ describe('ParLoginService', () => {
|
||||
|
||||
service.loginPar(config, { urlHandler });
|
||||
|
||||
expect(spy).toHaveBeenCalledOnceWith('some-par-url');
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith('some-par-url');
|
||||
expect(redirectToSpy).not.toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('loginWithPopUpPar', () => {
|
||||
it('does nothing if it has an invalid response type', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('does nothing if it has an invalid response type', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(false);
|
||||
const loggerSpy = spyOn(loggerService, 'logError');
|
||||
).mockReturnValue(false);
|
||||
const loggerSpy = vi.spyOn(loggerService, 'logError');
|
||||
const config = {};
|
||||
const allConfigs = [config];
|
||||
|
||||
@@ -229,27 +234,27 @@ describe('ParLoginService', () => {
|
||||
expect(err.message).toBe('Invalid response type!');
|
||||
},
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('calls parService.postParRequest without custom params when no custom params are passed', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('calls parService.postParRequest without custom params when no custom params are passed', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(true);
|
||||
).mockReturnValue(true);
|
||||
const config = {
|
||||
authWellknownEndpointUrl: 'authWellknownEndpoint',
|
||||
responseType: 'stubValue',
|
||||
};
|
||||
const allConfigs = [config];
|
||||
|
||||
spyOn(
|
||||
vi.spyOn(
|
||||
authWellKnownService,
|
||||
'queryAndStoreAuthWellKnownEndPoints'
|
||||
).and.returnValue(of({}));
|
||||
).mockReturnValue(of({}));
|
||||
|
||||
const spy = spyOn(parService, 'postParRequest').and.returnValue(
|
||||
of({ requestUri: 'requestUri' } as ParResponse)
|
||||
);
|
||||
const spy = vi
|
||||
.spyOn(parService, 'postParRequest')
|
||||
.mockReturnValue(of({ requestUri: 'requestUri' } as ParResponse));
|
||||
|
||||
service.loginWithPopUpPar(config, allConfigs).subscribe({
|
||||
error: (err) => {
|
||||
@@ -259,27 +264,27 @@ describe('ParLoginService', () => {
|
||||
);
|
||||
},
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('calls parService.postParRequest with custom params when custom params are passed', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('calls parService.postParRequest with custom params when custom params are passed', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(true);
|
||||
).mockReturnValue(true);
|
||||
const config = {
|
||||
authWellknownEndpointUrl: 'authWellknownEndpoint',
|
||||
responseType: 'stubValue',
|
||||
};
|
||||
const allConfigs = [config];
|
||||
|
||||
spyOn(
|
||||
vi.spyOn(
|
||||
authWellKnownService,
|
||||
'queryAndStoreAuthWellKnownEndPoints'
|
||||
).and.returnValue(of({}));
|
||||
).mockReturnValue(of({}));
|
||||
|
||||
const spy = spyOn(parService, 'postParRequest').and.returnValue(
|
||||
of({ requestUri: 'requestUri' } as ParResponse)
|
||||
);
|
||||
const spy = vi
|
||||
.spyOn(parService, 'postParRequest')
|
||||
.mockReturnValue(of({ requestUri: 'requestUri' } as ParResponse));
|
||||
|
||||
service
|
||||
.loginWithPopUpPar(config, allConfigs, {
|
||||
@@ -287,7 +292,7 @@ describe('ParLoginService', () => {
|
||||
})
|
||||
.subscribe({
|
||||
error: (err) => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, {
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(config, {
|
||||
customParams: { some: 'thing' },
|
||||
});
|
||||
expect(err.message).toBe(
|
||||
@@ -295,29 +300,29 @@ describe('ParLoginService', () => {
|
||||
);
|
||||
},
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('returns undefined and logs error when no URL could be created', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('returns undefined and logs error when no URL could be created', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(true);
|
||||
).mockReturnValue(true);
|
||||
const config = {
|
||||
authWellknownEndpointUrl: 'authWellknownEndpoint',
|
||||
responseType: 'stubValue',
|
||||
};
|
||||
const allConfigs = [config];
|
||||
|
||||
spyOn(
|
||||
vi.spyOn(
|
||||
authWellKnownService,
|
||||
'queryAndStoreAuthWellKnownEndPoints'
|
||||
).and.returnValue(of({}));
|
||||
).mockReturnValue(of({}));
|
||||
|
||||
spyOn(parService, 'postParRequest').and.returnValue(
|
||||
vi.spyOn(parService, 'postParRequest').mockReturnValue(
|
||||
of({ requestUri: 'requestUri' } as ParResponse)
|
||||
);
|
||||
spyOn(urlService, 'getAuthorizeParUrl').and.returnValue('');
|
||||
const spy = spyOn(loggerService, 'logError');
|
||||
vi.spyOn(urlService, 'getAuthorizeParUrl').mockReturnValue('');
|
||||
const spy = vi.spyOn(loggerService, 'logError');
|
||||
|
||||
service
|
||||
.loginWithPopUpPar(config, allConfigs, {
|
||||
@@ -331,46 +336,52 @@ describe('ParLoginService', () => {
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
},
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('calls popupService openPopUp when URL could be created', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('calls popupService openPopUp when URL could be created', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(true);
|
||||
).mockReturnValue(true);
|
||||
const config = {
|
||||
authWellknownEndpointUrl: 'authWellknownEndpoint',
|
||||
responseType: 'stubValue',
|
||||
};
|
||||
const allConfigs = [config];
|
||||
|
||||
spyOn(
|
||||
vi.spyOn(
|
||||
authWellKnownService,
|
||||
'queryAndStoreAuthWellKnownEndPoints'
|
||||
).and.returnValue(of({}));
|
||||
).mockReturnValue(of({}));
|
||||
|
||||
spyOn(parService, 'postParRequest').and.returnValue(
|
||||
vi.spyOn(parService, 'postParRequest').mockReturnValue(
|
||||
of({ requestUri: 'requestUri' } as ParResponse)
|
||||
);
|
||||
spyOn(urlService, 'getAuthorizeParUrl').and.returnValue('some-par-url');
|
||||
spyOn(checkAuthService, 'checkAuth').and.returnValue(
|
||||
vi.spyOn(urlService, 'getAuthorizeParUrl').mockReturnValue(
|
||||
'some-par-url'
|
||||
);
|
||||
vi.spyOn(checkAuthService, 'checkAuth').mockReturnValue(
|
||||
of({} as LoginResponse)
|
||||
);
|
||||
spyOnProperty(popupService, 'result$').and.returnValue(
|
||||
vi.spyOnProperty(popupService, 'result$').mockReturnValue(
|
||||
of({} as PopupResult)
|
||||
);
|
||||
const spy = spyOn(popupService, 'openPopUp');
|
||||
const spy = vi.spyOn(popupService, 'openPopUp');
|
||||
|
||||
service.loginWithPopUpPar(config, allConfigs).subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith('some-par-url', undefined, config);
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
'some-par-url',
|
||||
undefined,
|
||||
config
|
||||
);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('returns correct properties if URL is received', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('returns correct properties if URL is received', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(true);
|
||||
).mockReturnValue(true);
|
||||
const config = {
|
||||
authWellknownEndpointUrl: 'authWellknownEndpoint',
|
||||
responseType: 'stubValue',
|
||||
@@ -378,34 +389,40 @@ describe('ParLoginService', () => {
|
||||
};
|
||||
const allConfigs = [config];
|
||||
|
||||
spyOn(
|
||||
vi.spyOn(
|
||||
authWellKnownService,
|
||||
'queryAndStoreAuthWellKnownEndPoints'
|
||||
).and.returnValue(of({}));
|
||||
).mockReturnValue(of({}));
|
||||
|
||||
spyOn(parService, 'postParRequest').and.returnValue(
|
||||
vi.spyOn(parService, 'postParRequest').mockReturnValue(
|
||||
of({ requestUri: 'requestUri' } as ParResponse)
|
||||
);
|
||||
spyOn(urlService, 'getAuthorizeParUrl').and.returnValue('some-par-url');
|
||||
|
||||
const checkAuthSpy = spyOn(checkAuthService, 'checkAuth').and.returnValue(
|
||||
of({
|
||||
isAuthenticated: true,
|
||||
configId: 'configId1',
|
||||
idToken: '',
|
||||
userData: { any: 'userData' },
|
||||
accessToken: 'anyAccessToken',
|
||||
})
|
||||
vi.spyOn(urlService, 'getAuthorizeParUrl').mockReturnValue(
|
||||
'some-par-url'
|
||||
);
|
||||
|
||||
const checkAuthSpy = vi
|
||||
.spyOn(checkAuthService, 'checkAuth')
|
||||
.mockReturnValue(
|
||||
of({
|
||||
isAuthenticated: true,
|
||||
configId: 'configId1',
|
||||
idToken: '',
|
||||
userData: { any: 'userData' },
|
||||
accessToken: 'anyAccessToken',
|
||||
})
|
||||
);
|
||||
const popupResult: PopupResult = {
|
||||
userClosed: false,
|
||||
receivedUrl: 'someUrl',
|
||||
};
|
||||
|
||||
spyOnProperty(popupService, 'result$').and.returnValue(of(popupResult));
|
||||
vi.spyOnProperty(popupService, 'result$').mockReturnValue(
|
||||
of(popupResult)
|
||||
);
|
||||
|
||||
service.loginWithPopUpPar(config, allConfigs).subscribe((result) => {
|
||||
expect(checkAuthSpy).toHaveBeenCalledOnceWith(
|
||||
expect(checkAuthSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
allConfigs,
|
||||
'someUrl'
|
||||
@@ -419,13 +436,13 @@ describe('ParLoginService', () => {
|
||||
accessToken: 'anyAccessToken',
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('returns correct properties if popup was closed by user', waitForAsync(() => {
|
||||
spyOn(
|
||||
it('returns correct properties if popup was closed by user', async () => {
|
||||
vi.spyOn(
|
||||
responseTypeValidationService,
|
||||
'hasConfigValidResponseType'
|
||||
).and.returnValue(true);
|
||||
).mockReturnValue(true);
|
||||
const config = {
|
||||
authWellknownEndpointUrl: 'authWellknownEndpoint',
|
||||
responseType: 'stubValue',
|
||||
@@ -433,20 +450,24 @@ describe('ParLoginService', () => {
|
||||
};
|
||||
const allConfigs = [config];
|
||||
|
||||
spyOn(
|
||||
vi.spyOn(
|
||||
authWellKnownService,
|
||||
'queryAndStoreAuthWellKnownEndPoints'
|
||||
).and.returnValue(of({}));
|
||||
).mockReturnValue(of({}));
|
||||
|
||||
spyOn(parService, 'postParRequest').and.returnValue(
|
||||
vi.spyOn(parService, 'postParRequest').mockReturnValue(
|
||||
of({ requestUri: 'requestUri' } as ParResponse)
|
||||
);
|
||||
spyOn(urlService, 'getAuthorizeParUrl').and.returnValue('some-par-url');
|
||||
vi.spyOn(urlService, 'getAuthorizeParUrl').mockReturnValue(
|
||||
'some-par-url'
|
||||
);
|
||||
|
||||
const checkAuthSpy = spyOn(checkAuthService, 'checkAuth');
|
||||
const checkAuthSpy = vi.spyOn(checkAuthService, 'checkAuth');
|
||||
const popupResult = { userClosed: true } as PopupResult;
|
||||
|
||||
spyOnProperty(popupService, 'result$').and.returnValue(of(popupResult));
|
||||
vi.spyOnProperty(popupService, 'result$').mockReturnValue(
|
||||
of(popupResult)
|
||||
);
|
||||
|
||||
service.loginWithPopUpPar(config, allConfigs).subscribe((result) => {
|
||||
expect(checkAuthSpy).not.toHaveBeenCalled();
|
||||
@@ -459,6 +480,6 @@ describe('ParLoginService', () => {
|
||||
accessToken: '',
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user