fix: fix all biome

This commit is contained in:
2025-01-31 05:57:51 +08:00
parent 316361bd3c
commit c9d0066d64
114 changed files with 2255 additions and 2068 deletions

View File

@@ -10,6 +10,7 @@ import {
HttpTestingController,
provideHttpClientTesting,
} from '@ngify/http/testing';
import { lastValueFrom } from 'rxjs';
import { vi } from 'vitest';
import { AuthStateService } from '../auth-state/auth-state.service';
import { ConfigurationService } from '../config/config.service';
@@ -18,14 +19,14 @@ import { mockProvider } from '../testing/mock';
import { AuthInterceptor, authInterceptor } from './auth.interceptor';
import { ClosestMatchingRouteService } from './closest-matching-route.service';
describe(`AuthHttpInterceptor`, () => {
describe('AuthHttpInterceptor', () => {
let httpTestingController: HttpTestingController;
let configurationService: ConfigurationService;
let httpClient: HttpClient;
let authStateService: AuthStateService;
let closestMatchingRouteService: ClosestMatchingRouteService;
describe(`with Class Interceptor`, () => {
describe('with Class Interceptor', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
@@ -51,6 +52,7 @@ describe(`AuthHttpInterceptor`, () => {
closestMatchingRouteService = TestBed.inject(ClosestMatchingRouteService);
});
// biome-ignore lint/correctness/noUndeclaredVariables: <explanation>
afterEach(() => {
httpTestingController.verify();
});
@@ -58,7 +60,7 @@ describe(`AuthHttpInterceptor`, () => {
runTests();
});
describe(`with Functional Interceptor`, () => {
describe('with Functional Interceptor', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
@@ -78,6 +80,7 @@ describe(`AuthHttpInterceptor`, () => {
closestMatchingRouteService = TestBed.inject(ClosestMatchingRouteService);
});
// biome-ignore lint/correctness/noUndeclaredVariables: <explanation>
afterEach(() => {
httpTestingController.verify();
});
@@ -87,7 +90,7 @@ describe(`AuthHttpInterceptor`, () => {
function runTests(): void {
it('should add an Authorization header when route matches and token is present', async () => {
const actionUrl = `https://jsonplaceholder.typicode.com/`;
const actionUrl = 'https://jsonplaceholder.typicode.com/';
vi.spyOn(configurationService, 'getAllConfigurations').mockReturnValue([
{
@@ -104,7 +107,7 @@ describe(`AuthHttpInterceptor`, () => {
);
const response = await lastValueFrom(httpClient.get(actionUrl));
expect(response).toBeTruthy();
expect(response).toBeTruthy();
const httpRequest = httpTestingController.expectOne(actionUrl);
@@ -115,7 +118,7 @@ expect(response).toBeTruthy();
});
it('should not add an Authorization header when `secureRoutes` is not given', async () => {
const actionUrl = `https://jsonplaceholder.typicode.com/`;
const actionUrl = 'https://jsonplaceholder.typicode.com/';
vi.spyOn(configurationService, 'getAllConfigurations').mockReturnValue([
{
@@ -130,7 +133,7 @@ expect(response).toBeTruthy();
);
const response = await lastValueFrom(httpClient.get(actionUrl));
expect(response).toBeTruthy();
expect(response).toBeTruthy();
const httpRequest = httpTestingController.expectOne(actionUrl);
@@ -141,7 +144,7 @@ expect(response).toBeTruthy();
});
it('should not add an Authorization header when no routes configured', async () => {
const actionUrl = `https://jsonplaceholder.typicode.com/`;
const actionUrl = 'https://jsonplaceholder.typicode.com/';
vi.spyOn(configurationService, 'getAllConfigurations').mockReturnValue([
{
@@ -158,7 +161,7 @@ expect(response).toBeTruthy();
);
const response = await lastValueFrom(httpClient.get(actionUrl));
expect(response).toBeTruthy();
expect(response).toBeTruthy();
const httpRequest = httpTestingController.expectOne(actionUrl);
@@ -169,7 +172,7 @@ expect(response).toBeTruthy();
});
it('should not add an Authorization header when no routes configured', async () => {
const actionUrl = `https://jsonplaceholder.typicode.com/`;
const actionUrl = 'https://jsonplaceholder.typicode.com/';
vi.spyOn(configurationService, 'getAllConfigurations').mockReturnValue([
{
@@ -183,7 +186,7 @@ expect(response).toBeTruthy();
);
const response = await lastValueFrom(httpClient.get(actionUrl));
expect(response).toBeTruthy();
expect(response).toBeTruthy();
const httpRequest = httpTestingController.expectOne(actionUrl);
@@ -194,7 +197,7 @@ expect(response).toBeTruthy();
});
it('should not add an Authorization header when route is configured but no token is present', async () => {
const actionUrl = `https://jsonplaceholder.typicode.com/`;
const actionUrl = 'https://jsonplaceholder.typicode.com/';
vi.spyOn(configurationService, 'getAllConfigurations').mockReturnValue([
{
@@ -209,7 +212,7 @@ expect(response).toBeTruthy();
vi.spyOn(authStateService, 'getAccessToken').mockReturnValue('');
const response = await lastValueFrom(httpClient.get(actionUrl));
expect(response).toBeTruthy();
expect(response).toBeTruthy();
const httpRequest = httpTestingController.expectOne(actionUrl);
@@ -220,14 +223,14 @@ expect(response).toBeTruthy();
});
it('should not add an Authorization header when no config is present', async () => {
const actionUrl = `https://jsonplaceholder.typicode.com/`;
const actionUrl = 'https://jsonplaceholder.typicode.com/';
vi.spyOn(configurationService, 'hasAtLeastOneConfig').mockReturnValue(
false
);
const response = await lastValueFrom(httpClient.get(actionUrl));
expect(response).toBeTruthy();
expect(response).toBeTruthy();
const httpRequest = httpTestingController.expectOne(actionUrl);
@@ -241,7 +244,7 @@ expect(response).toBeTruthy();
vi.spyOn(configurationService, 'hasAtLeastOneConfig').mockReturnValue(
true
);
const actionUrl = `https://jsonplaceholder.typicode.com/`;
const actionUrl = 'https://jsonplaceholder.typicode.com/';
vi.spyOn(configurationService, 'getAllConfigurations').mockReturnValue([
{
@@ -258,7 +261,7 @@ expect(response).toBeTruthy();
});
const response = await lastValueFrom(httpClient.get(actionUrl));
expect(response).toBeTruthy();
expect(response).toBeTruthy();
const httpRequest = httpTestingController.expectOne(actionUrl);
@@ -269,8 +272,8 @@ expect(response).toBeTruthy();
});
it('should add an Authorization header when multiple routes are configured and token is present', async () => {
const actionUrl = `https://jsonplaceholder.typicode.com/`;
const actionUrl2 = `https://some-other-url.com/`;
const actionUrl = 'https://jsonplaceholder.typicode.com/';
const actionUrl2 = 'https://some-other-url.com/';
vi.spyOn(configurationService, 'getAllConfigurations').mockReturnValue([
{ secureRoutes: [actionUrl, actionUrl2], configId: 'configId1' },
@@ -283,11 +286,11 @@ expect(response).toBeTruthy();
true
);
const response = await lastValueFrom(httpClient.get(actionUrl));
expect(response).toBeTruthy();
let response = await lastValueFrom(httpClient.get(actionUrl));
expect(response).toBeTruthy();
const response = await lastValueFrom(httpClient.get(actionUrl2));
expect(response).toBeTruthy();
response = await lastValueFrom(httpClient.get(actionUrl2));
expect(response).toBeTruthy();
const httpRequest = httpTestingController.expectOne(actionUrl);

View File

@@ -73,7 +73,7 @@ function interceptRequest(
if (allRoutesConfiguredFlat.length === 0) {
deps.loggerService.logDebug(
allConfigurations[0],
`No routes to check configured`
'No routes to check configured'
);
return next(req);
@@ -114,7 +114,7 @@ function interceptRequest(
`'${req.url}' matches configured route '${matchingRoute}', adding token`
);
req = req.clone({
headers: req.headers.set('Authorization', 'Bearer ' + token),
headers: req.headers.set('Authorization', `Bearer ${token}`),
});
return next(req);

View File

@@ -1,5 +1,4 @@
import { TestBed } from '@/testing';
import { vi } from 'vitest';
import { LoggerService } from '../logging/logger.service';
import { mockProvider } from '../testing/mock';
import { ClosestMatchingRouteService } from './closest-matching-route.service';
@@ -11,9 +10,6 @@ describe('ClosestMatchingRouteService', () => {
TestBed.configureTestingModule({
providers: [ClosestMatchingRouteService, mockProvider(LoggerService)],
});
});
beforeEach(() => {
service = TestBed.inject(ClosestMatchingRouteService);
});

View File

@@ -1,5 +1,5 @@
import { Injectable } from 'injection-js';
import { OpenIdConfiguration } from '../config/openid-configuration';
import type { OpenIdConfiguration } from '../config/openid-configuration';
@Injectable()
export class ClosestMatchingRouteService {