Skip to content

Commit

Permalink
Merge pull request #1775 from damienbod/fg/fix-prettier
Browse files Browse the repository at this point in the history
fix prettier and get config closer to default
  • Loading branch information
FabianGosebrink committed Jun 12, 2023
2 parents 920b508 + 5a16822 commit 4726eb5
Show file tree
Hide file tree
Showing 344 changed files with 12,677 additions and 5,371 deletions.
3 changes: 1 addition & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 140
"trailingComma": "es5"
}
5 changes: 4 additions & 1 deletion projects/angular-auth-oidc-client/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
{
"files": ["*.ts"],
"parserOptions": {
"project": ["projects/angular-auth-oidc-client/tsconfig.lib.json", "projects/angular-auth-oidc-client/tsconfig.spec.json"],
"project": [
"projects/angular-auth-oidc-client/tsconfig.lib.json",
"projects/angular-auth-oidc-client/tsconfig.spec.json"
],
"createDefaultProgram": true
},
"rules": {
Expand Down
5 changes: 4 additions & 1 deletion projects/angular-auth-oidc-client/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ module.exports = function (config) {
suppressAll: true, // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, '../../coverage/angular-auth-oidc-client'),
dir: require('path').join(
__dirname,
'../../coverage/angular-auth-oidc-client'
),
subdir: '.',
reporters: [{ type: 'html' }, { type: 'text-summary' }, { type: 'lcov' }],
},
Expand Down
7 changes: 6 additions & 1 deletion projects/angular-auth-oidc-client/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
"lib": {
"entryFile": "src/public-api.ts"
},
"allowedNonPeerDependencies": ["rfc4648", "@angular-devkit/core", "@schematics/angular", "@angular-devkit/schematics"]
"allowedNonPeerDependencies": [
"rfc4648",
"@angular-devkit/core",
"@schematics/angular",
"@angular-devkit/schematics"
]
}
211 changes: 105 additions & 106 deletions projects/angular-auth-oidc-client/src/lib/api/data.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { HttpHeaders } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import {
HttpClientTestingModule,
HttpTestingController,
} from '@angular/common/http/testing';
import { TestBed, waitForAsync } from '@angular/core/testing';
import { DataService } from './data.service';
import { HttpBaseService } from './http-base.service';
Expand All @@ -25,160 +28,156 @@ describe('Data Service', () => {
});

describe('get', () => {
it(
'get call sets the accept header',
waitForAsync(() => {
const url = 'anyurl';
it('get call sets the accept header', waitForAsync(() => {
const url = 'anyurl';

dataService.get(url, { configId: 'configId1' }).subscribe((data: unknown) => {
dataService
.get(url, { configId: 'configId1' })
.subscribe((data: unknown) => {
expect(data).toBe('bodyData');
});
const req = httpMock.expectOne(url);
const req = httpMock.expectOne(url);

expect(req.request.method).toBe('GET');
expect(req.request.headers.get('Accept')).toBe('application/json');
expect(req.request.method).toBe('GET');
expect(req.request.headers.get('Accept')).toBe('application/json');

req.flush('bodyData');
req.flush('bodyData');

httpMock.verify();
})
);
httpMock.verify();
}));

it(
'get call with token the accept header and the token',
waitForAsync(() => {
const url = 'anyurl';
const token = 'token';
it('get call with token the accept header and the token', waitForAsync(() => {
const url = 'anyurl';
const token = 'token';

dataService.get(url, { configId: 'configId1' }, token).subscribe((data: unknown) => {
dataService
.get(url, { configId: 'configId1' }, token)
.subscribe((data: unknown) => {
expect(data).toBe('bodyData');
});
const req = httpMock.expectOne(url);
const req = httpMock.expectOne(url);

expect(req.request.method).toBe('GET');
expect(req.request.headers.get('Accept')).toBe('application/json');
expect(req.request.headers.get('Authorization')).toBe('Bearer ' + token);
expect(req.request.method).toBe('GET');
expect(req.request.headers.get('Accept')).toBe('application/json');
expect(req.request.headers.get('Authorization')).toBe('Bearer ' + token);

req.flush('bodyData');
req.flush('bodyData');

httpMock.verify();
})
);
httpMock.verify();
}));

it(
'call without ngsw-bypass param by default',
waitForAsync(() => {
const url = 'anyurl';
it('call without ngsw-bypass param by default', waitForAsync(() => {
const url = 'anyurl';

dataService.get(url, { configId: 'configId1' }).subscribe((data: unknown) => {
dataService
.get(url, { configId: 'configId1' })
.subscribe((data: unknown) => {
expect(data).toBe('bodyData');
});
const req = httpMock.expectOne(url);
const req = httpMock.expectOne(url);

expect(req.request.method).toBe('GET');
expect(req.request.headers.get('Accept')).toBe('application/json');
expect(req.request.params.get('ngsw-bypass')).toBeNull();
expect(req.request.method).toBe('GET');
expect(req.request.headers.get('Accept')).toBe('application/json');
expect(req.request.params.get('ngsw-bypass')).toBeNull();

req.flush('bodyData');
req.flush('bodyData');

httpMock.verify();
})
);
httpMock.verify();
}));

it(
'call with ngsw-bypass param',
waitForAsync(() => {
const url = 'anyurl';
it('call with ngsw-bypass param', waitForAsync(() => {
const url = 'anyurl';

dataService.get(url, { configId: 'configId1', ngswBypass: true }).subscribe((data: unknown) => {
dataService
.get(url, { configId: 'configId1', ngswBypass: true })
.subscribe((data: unknown) => {
expect(data).toBe('bodyData');
});
const req = httpMock.expectOne(url + '?ngsw-bypass=');
const req = httpMock.expectOne(url + '?ngsw-bypass=');

expect(req.request.method).toBe('GET');
expect(req.request.headers.get('Accept')).toBe('application/json');
expect(req.request.params.get('ngsw-bypass')).toBe('');
expect(req.request.method).toBe('GET');
expect(req.request.headers.get('Accept')).toBe('application/json');
expect(req.request.params.get('ngsw-bypass')).toBe('');

req.flush('bodyData');
req.flush('bodyData');

httpMock.verify();
})
);
httpMock.verify();
}));
});

describe('post', () => {
it(
'call sets the accept header when no other params given',
waitForAsync(() => {
const url = 'anyurl';
it('call sets the accept header when no other params given', waitForAsync(() => {
const url = 'anyurl';

dataService.post(url, { some: 'thing' }, { configId: 'configId1' }).subscribe();
const req = httpMock.expectOne(url);
dataService
.post(url, { some: 'thing' }, { configId: 'configId1' })
.subscribe();
const req = httpMock.expectOne(url);

expect(req.request.method).toBe('POST');
expect(req.request.headers.get('Accept')).toBe('application/json');
expect(req.request.method).toBe('POST');
expect(req.request.headers.get('Accept')).toBe('application/json');

req.flush('bodyData');
req.flush('bodyData');

httpMock.verify();
})
);
httpMock.verify();
}));

it(
'call sets custom headers ONLY (No ACCEPT header) when custom headers are given',
waitForAsync(() => {
const url = 'anyurl';
let headers = new HttpHeaders();
it('call sets custom headers ONLY (No ACCEPT header) when custom headers are given', waitForAsync(() => {
const url = 'anyurl';
let headers = new HttpHeaders();

headers = headers.set('X-MyHeader', 'Genesis');
headers = headers.set('X-MyHeader', 'Genesis');

dataService.post(url, { some: 'thing' }, { configId: 'configId1' }, headers).subscribe();
const req = httpMock.expectOne(url);
dataService
.post(url, { some: 'thing' }, { configId: 'configId1' }, headers)
.subscribe();
const req = httpMock.expectOne(url);

expect(req.request.method).toBe('POST');
expect(req.request.headers.get('X-MyHeader')).toEqual('Genesis');
expect(req.request.headers.get('X-MyHeader')).not.toEqual('Genesis333');
expect(req.request.method).toBe('POST');
expect(req.request.headers.get('X-MyHeader')).toEqual('Genesis');
expect(req.request.headers.get('X-MyHeader')).not.toEqual('Genesis333');

req.flush('bodyData');
req.flush('bodyData');

httpMock.verify();
})
);
httpMock.verify();
}));

it(
'call without ngsw-bypass param by default',
waitForAsync(() => {
const url = 'anyurl';
it('call without ngsw-bypass param by default', waitForAsync(() => {
const url = 'anyurl';

dataService.post(url, { some: 'thing' }, { configId: 'configId1' }).subscribe();
const req = httpMock.expectOne(url);
dataService
.post(url, { some: 'thing' }, { configId: 'configId1' })
.subscribe();
const req = httpMock.expectOne(url);

expect(req.request.method).toBe('POST');
expect(req.request.headers.get('Accept')).toBe('application/json');
expect(req.request.params.get('ngsw-bypass')).toBeNull();
expect(req.request.method).toBe('POST');
expect(req.request.headers.get('Accept')).toBe('application/json');
expect(req.request.params.get('ngsw-bypass')).toBeNull();

req.flush('bodyData');
req.flush('bodyData');

httpMock.verify();
})
);
httpMock.verify();
}));

it(
'call with ngsw-bypass param',
waitForAsync(() => {
const url = 'anyurl';
it('call with ngsw-bypass param', waitForAsync(() => {
const url = 'anyurl';

dataService.post(url, { some: 'thing' }, { configId: 'configId1', ngswBypass: true }).subscribe();
const req = httpMock.expectOne(url + '?ngsw-bypass=');
dataService
.post(
url,
{ some: 'thing' },
{ configId: 'configId1', ngswBypass: true }
)
.subscribe();
const req = httpMock.expectOne(url + '?ngsw-bypass=');

expect(req.request.method).toBe('POST');
expect(req.request.headers.get('Accept')).toBe('application/json');
expect(req.request.params.get('ngsw-bypass')).toBe('');
expect(req.request.method).toBe('POST');
expect(req.request.headers.get('Accept')).toBe('application/json');
expect(req.request.params.get('ngsw-bypass')).toBe('');

req.flush('bodyData');
req.flush('bodyData');

httpMock.verify();
})
);
httpMock.verify();
}));
});
});
18 changes: 15 additions & 3 deletions projects/angular-auth-oidc-client/src/lib/api/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ const NGSW_CUSTOM_PARAM = 'ngsw-bypass';
export class DataService {
constructor(private readonly httpClient: HttpBaseService) {}

get<T>(url: string, config: OpenIdConfiguration, token?: string): Observable<T> {
get<T>(
url: string,
config: OpenIdConfiguration,
token?: string
): Observable<T> {
const headers = this.prepareHeaders(token);
const params = this.prepareParams(config);

Expand All @@ -20,7 +24,12 @@ export class DataService {
});
}

post<T>(url: string, body: any, config: OpenIdConfiguration, headersParams?: HttpHeaders): Observable<T> {
post<T>(
url: string,
body: any,

Check warning on line 29 in projects/angular-auth-oidc-client/src/lib/api/data.service.ts

View workflow job for this annotation

GitHub Actions / Built, Lint and Test Library

Unexpected any. Specify a different type
config: OpenIdConfiguration,
headersParams?: HttpHeaders
): Observable<T> {
const headers = headersParams || this.prepareHeaders();
const params = this.prepareParams(config);

Expand All @@ -33,7 +42,10 @@ export class DataService {
headers = headers.set('Accept', 'application/json');

if (!!token) {
headers = headers.set('Authorization', 'Bearer ' + decodeURIComponent(token));
headers = headers.set(
'Authorization',
'Bearer ' + decodeURIComponent(token)
);
}

return headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export class HttpBaseService {
return this.http.get<T>(url, params);
}

post<T>(url: string, body: any, params?: { [key: string]: any }): Observable<T> {
post<T>(
url: string,
body: any,

Check warning on line 15 in projects/angular-auth-oidc-client/src/lib/api/http-base.service.ts

View workflow job for this annotation

GitHub Actions / Built, Lint and Test Library

Unexpected any. Specify a different type
params?: { [key: string]: any }

Check warning on line 16 in projects/angular-auth-oidc-client/src/lib/api/http-base.service.ts

View workflow job for this annotation

GitHub Actions / Built, Lint and Test Library

Unexpected any. Specify a different type
): Observable<T> {
return this.http.post<T>(url, body, params);
}
}
13 changes: 10 additions & 3 deletions projects/angular-auth-oidc-client/src/lib/auth-config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { InjectionToken, Provider } from '@angular/core';
import { StsConfigLoader, StsConfigStaticLoader } from './config/loader/config-loader';
import {
StsConfigLoader,
StsConfigStaticLoader,
} from './config/loader/config-loader';
import { OpenIdConfiguration } from './config/openid-configuration';

export interface PassedInitialConfig {
config?: OpenIdConfiguration | OpenIdConfiguration[];
loader?: Provider;
}

export function createStaticLoader(passedConfig: PassedInitialConfig): StsConfigLoader {
export function createStaticLoader(
passedConfig: PassedInitialConfig
): StsConfigLoader {
return new StsConfigStaticLoader(passedConfig.config);
}

export const PASSED_CONFIG = new InjectionToken<PassedInitialConfig>('PASSED_CONFIG');
export const PASSED_CONFIG = new InjectionToken<PassedInitialConfig>(
'PASSED_CONFIG'
);
Loading

0 comments on commit 4726eb5

Please sign in to comment.