mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2025-12-13 01:36:22 +00:00
refactor: use GET for id-cards requests
This commit is contained in:
@@ -38,13 +38,12 @@ export class IdCardsProvider {
|
||||
}
|
||||
|
||||
private fetchIdCards(url: string, token: string): Observable<SCIdCard[]> {
|
||||
// eslint-disable-next-line unicorn/no-null
|
||||
return this.httpClient.post(url, null, {
|
||||
return this.httpClient.get<SCIdCard[]>(url, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
responseType: 'json',
|
||||
}) as Observable<SCIdCard[]>;
|
||||
});
|
||||
}
|
||||
|
||||
private fetchFallbackIdCards(user: SCUserConfiguration): Observable<SCIdCard[]> {
|
||||
|
||||
@@ -23,7 +23,7 @@ describe('IdCards', () => {
|
||||
configProvider.config = {
|
||||
app: {features: {extern: {idCards: {url: 'http://id-cards.local', authProvider: 'fakeAuth'}}}},
|
||||
} as never;
|
||||
httpClient = jasmine.createSpyObj('HttpClient', ['post']);
|
||||
httpClient = jasmine.createSpyObj('HttpClient', ['get']);
|
||||
fakeAuth = new FakeAuth();
|
||||
authHelper = jasmine.createSpyObj('AuthHelperService', ['getProvider']);
|
||||
authHelper.getProvider = jasmine.createSpy().and.returnValue(fakeAuth);
|
||||
@@ -37,15 +37,15 @@ describe('IdCards', () => {
|
||||
|
||||
it('should emit network result when logged in', async () => {
|
||||
fakeAuth.isAuthenticated$.next(true);
|
||||
httpClient.post = jasmine.createSpy().and.returnValue(of(['abc']));
|
||||
httpClient.get = jasmine.createSpy().and.returnValue(of(['abc']));
|
||||
fakeAuth.getValidToken = jasmine.createSpy().and.resolveTo({accessToken: 'fake-token'});
|
||||
const provider = new IdCardsProvider(authHelper, configProvider, httpClient);
|
||||
expect(await firstValueFrom(provider.getIdCards())).toEqual(['abc' as never]);
|
||||
expect(authHelper.getProvider).toHaveBeenCalledOnceWith('fakeAuth' as SCAuthorizationProviderType);
|
||||
// eslint-disable-next-line unicorn/no-null
|
||||
expect(httpClient.post).toHaveBeenCalledOnceWith('http://id-cards.local', null, {
|
||||
expect(httpClient.get).toHaveBeenCalledOnceWith('http://id-cards.local', {
|
||||
headers: {
|
||||
Authorization: 'Bearer: fake-token',
|
||||
Authorization: 'Bearer fake-token',
|
||||
},
|
||||
responseType: 'json',
|
||||
});
|
||||
@@ -55,7 +55,7 @@ describe('IdCards', () => {
|
||||
const provider = new IdCardsProvider(authHelper, configProvider, httpClient);
|
||||
const observable = provider.getIdCards();
|
||||
expect(await firstValueFrom(observable)).toEqual([]);
|
||||
httpClient.post = jasmine.createSpy().and.returnValue(of(['abc']));
|
||||
httpClient.get = jasmine.createSpy().and.returnValue(of(['abc']));
|
||||
fakeAuth.getValidToken = jasmine.createSpy().and.resolveTo({accessToken: 'fake-token'});
|
||||
fakeAuth.isAuthenticated$.next(true);
|
||||
// this is counter-intuitive, but because we unsubscribed above the first value
|
||||
|
||||
Reference in New Issue
Block a user