feat: init
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { mockProvider } from '../../../test/auto-mock';
|
||||
import { TestBed, mockImplementationWhenArgsEqual } from '@/testing';
|
||||
import { vi } from 'vitest';
|
||||
import { LogLevel } from '../../logging/log-level';
|
||||
import { LoggerService } from '../../logging/logger.service';
|
||||
import { OpenIdConfiguration } from '../openid-configuration';
|
||||
import { mockProvider } from '../../testing/mock';
|
||||
import type { OpenIdConfiguration } from '../openid-configuration';
|
||||
import { ConfigValidationService } from './config-validation.service';
|
||||
import { allMultipleConfigRules } from './rules';
|
||||
|
||||
@@ -14,6 +15,8 @@ describe('Config Validation Service', () => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ConfigValidationService, mockProvider(LoggerService)],
|
||||
});
|
||||
configValidationService = TestBed.inject(ConfigValidationService);
|
||||
loggerService = TestBed.inject(LoggerService);
|
||||
});
|
||||
|
||||
const VALID_CONFIG = {
|
||||
@@ -29,11 +32,6 @@ describe('Config Validation Service', () => {
|
||||
logLevel: LogLevel.Debug,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
configValidationService = TestBed.inject(ConfigValidationService);
|
||||
loggerService = TestBed.inject(LoggerService);
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(configValidationService).toBeTruthy();
|
||||
});
|
||||
@@ -42,26 +40,27 @@ describe('Config Validation Service', () => {
|
||||
const config = {};
|
||||
const result = configValidationService.validateConfig(config);
|
||||
|
||||
expect(result).toBeFalse();
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return true for valid config', () => {
|
||||
const result = configValidationService.validateConfig(VALID_CONFIG);
|
||||
|
||||
expect(result).toBeTrue();
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it('calls `logWarning` if one rule has warning level', () => {
|
||||
const loggerWarningSpy = spyOn(loggerService, 'logWarning');
|
||||
const messageTypeSpy = spyOn(
|
||||
const loggerWarningSpy = vi.spyOn(loggerService, 'logWarning');
|
||||
const messageTypeSpy = vi.spyOn(
|
||||
configValidationService as any,
|
||||
'getAllMessagesOfType'
|
||||
);
|
||||
|
||||
messageTypeSpy
|
||||
.withArgs('warning', jasmine.any(Array))
|
||||
.and.returnValue(['A warning message']);
|
||||
messageTypeSpy.withArgs('error', jasmine.any(Array)).and.callThrough();
|
||||
mockImplementationWhenArgsEqual(
|
||||
messageTypeSpy,
|
||||
(arg1: any, arg2: any) => arg1 === 'warning' && Array.isArray(arg2),
|
||||
() => ['A warning message']
|
||||
);
|
||||
|
||||
configValidationService.validateConfig(VALID_CONFIG);
|
||||
expect(loggerWarningSpy).toHaveBeenCalled();
|
||||
@@ -72,7 +71,7 @@ describe('Config Validation Service', () => {
|
||||
const config = { ...VALID_CONFIG, clientId: '' } as OpenIdConfiguration;
|
||||
const result = configValidationService.validateConfig(config);
|
||||
|
||||
expect(result).toBeFalse();
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -84,7 +83,7 @@ describe('Config Validation Service', () => {
|
||||
} as OpenIdConfiguration;
|
||||
const result = configValidationService.validateConfig(config);
|
||||
|
||||
expect(result).toBeFalse();
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -93,7 +92,7 @@ describe('Config Validation Service', () => {
|
||||
const config = { ...VALID_CONFIG, redirectUrl: '' };
|
||||
const result = configValidationService.validateConfig(config);
|
||||
|
||||
expect(result).toBeFalse();
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -107,7 +106,7 @@ describe('Config Validation Service', () => {
|
||||
} as OpenIdConfiguration;
|
||||
const result = configValidationService.validateConfig(config);
|
||||
|
||||
expect(result).toBeFalse();
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -120,12 +119,12 @@ describe('Config Validation Service', () => {
|
||||
scopes: 'scope1 scope2 but_no_offline_access',
|
||||
};
|
||||
|
||||
const loggerSpy = spyOn(loggerService, 'logError');
|
||||
const loggerWarningSpy = spyOn(loggerService, 'logWarning');
|
||||
const loggerSpy = vi.spyOn(loggerService, 'logError');
|
||||
const loggerWarningSpy = vi.spyOn(loggerService, 'logWarning');
|
||||
|
||||
const result = configValidationService.validateConfig(config);
|
||||
|
||||
expect(result).toBeTrue();
|
||||
expect(result).toBeTruthy();
|
||||
expect(loggerSpy).not.toHaveBeenCalled();
|
||||
expect(loggerWarningSpy).toHaveBeenCalled();
|
||||
});
|
||||
@@ -146,47 +145,47 @@ describe('Config Validation Service', () => {
|
||||
scopes: 'scope1 scope2 but_no_offline_access',
|
||||
};
|
||||
|
||||
const loggerErrorSpy = spyOn(loggerService, 'logError');
|
||||
const loggerWarningSpy = spyOn(loggerService, 'logWarning');
|
||||
const loggerErrorSpy = vi.spyOn(loggerService, 'logError');
|
||||
const loggerWarningSpy = vi.spyOn(loggerService, 'logWarning');
|
||||
|
||||
const result = configValidationService.validateConfigs([
|
||||
config1,
|
||||
config2,
|
||||
]);
|
||||
|
||||
expect(result).toBeTrue();
|
||||
expect(result).toBeTruthy();
|
||||
expect(loggerErrorSpy).not.toHaveBeenCalled();
|
||||
expect(loggerWarningSpy.calls.argsFor(0)).toEqual([
|
||||
expect(vi.mocked(loggerWarningSpy).mock.calls[0]).toEqual([
|
||||
config1,
|
||||
'You added multiple configs with the same authority, clientId and scope',
|
||||
]);
|
||||
expect(loggerWarningSpy.calls.argsFor(1)).toEqual([
|
||||
expect(vi.mocked(loggerWarningSpy).mock.calls[1]).toEqual([
|
||||
config2,
|
||||
'You added multiple configs with the same authority, clientId and scope',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return false and a better error message when config is not passed as object with config property', () => {
|
||||
const loggerWarningSpy = spyOn(loggerService, 'logWarning');
|
||||
const loggerWarningSpy = vi.spyOn(loggerService, 'logWarning');
|
||||
|
||||
const result = configValidationService.validateConfigs([]);
|
||||
|
||||
expect(result).toBeFalse();
|
||||
expect(result).toBeFalsy();
|
||||
expect(loggerWarningSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateConfigs', () => {
|
||||
it('calls internal method with empty array if something falsy is passed', () => {
|
||||
const spy = spyOn(
|
||||
const spy = vi.spyOn(
|
||||
configValidationService as any,
|
||||
'validateConfigsInternal'
|
||||
).and.callThrough();
|
||||
);
|
||||
|
||||
const result = configValidationService.validateConfigs([]);
|
||||
|
||||
expect(result).toBeFalse();
|
||||
expect(spy).toHaveBeenCalledOnceWith([], allMultipleConfigRules);
|
||||
expect(result).toBeFalsy();
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith([], allMultipleConfigRules);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user