|
|
@ -1,8 +1,8 @@ |
|
|
import { HttpRequest } from '@angular/common/http'; |
|
|
import { HttpRequest } from '@angular/common/http'; |
|
|
import { SpyObject } from '@ngneat/spectator'; |
|
|
import { SpyObject } from '@ngneat/spectator'; |
|
|
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; |
|
|
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest'; |
|
|
import { OAuthService } from 'angular-oauth2-oidc'; |
|
|
import { OAuthService } from 'angular-oauth2-oidc'; |
|
|
import { Subject, timer } from 'rxjs'; |
|
|
import { Subject } from 'rxjs'; |
|
|
import { HttpWaitService, SessionStateService, TENANT_KEY } from '@abp/ng.core'; |
|
|
import { HttpWaitService, SessionStateService, TENANT_KEY } from '@abp/ng.core'; |
|
|
import { OAuthApiInterceptor } from '../interceptors'; |
|
|
import { OAuthApiInterceptor } from '../interceptors'; |
|
|
|
|
|
|
|
|
@ -29,7 +29,7 @@ describe('ApiInterceptor', () => { |
|
|
httpWaitService = spectator.inject(HttpWaitService); |
|
|
httpWaitService = spectator.inject(HttpWaitService); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should add headers to http request', done => { |
|
|
it('should add headers to http request', () => { |
|
|
oauthService.getAccessToken.andReturn('ey892mkwa8^2jk'); |
|
|
oauthService.getAccessToken.andReturn('ey892mkwa8^2jk'); |
|
|
sessionState.getLanguage.andReturn('tr'); |
|
|
sessionState.getLanguage.andReturn('tr'); |
|
|
sessionState.getTenant.andReturn({ id: 'Volosoft', name: 'Volosoft' }); |
|
|
sessionState.getTenant.andReturn({ id: 'Volosoft', name: 'Volosoft' }); |
|
|
@ -42,7 +42,6 @@ describe('ApiInterceptor', () => { |
|
|
expect(req.headers.get('Authorization')).toEqual('Bearer ey892mkwa8^2jk'); |
|
|
expect(req.headers.get('Authorization')).toEqual('Bearer ey892mkwa8^2jk'); |
|
|
expect(req.headers.get('Accept-Language')).toEqual('tr'); |
|
|
expect(req.headers.get('Accept-Language')).toEqual('tr'); |
|
|
expect(req.headers.get(testTenantKey)).toEqual('Volosoft'); |
|
|
expect(req.headers.get(testTenantKey)).toEqual('Volosoft'); |
|
|
done(); |
|
|
|
|
|
return handleRes$; |
|
|
return handleRes$; |
|
|
}, |
|
|
}, |
|
|
}; |
|
|
}; |
|
|
@ -53,9 +52,9 @@ describe('ApiInterceptor', () => { |
|
|
handleRes$.complete(); |
|
|
handleRes$.complete(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should call http wait services add request and delete request', done => { |
|
|
it('should call http wait services add request and delete request', () => { |
|
|
const spyAddRequest = jest.spyOn(httpWaitService, 'addRequest'); |
|
|
const spyAddRequest = vi.spyOn(httpWaitService, 'addRequest'); |
|
|
const spyDeleteRequest = jest.spyOn(httpWaitService, 'deleteRequest'); |
|
|
const spyDeleteRequest = vi.spyOn(httpWaitService, 'deleteRequest'); |
|
|
|
|
|
|
|
|
const request = new HttpRequest('GET', 'https://abp.io'); |
|
|
const request = new HttpRequest('GET', 'https://abp.io'); |
|
|
const handleRes$ = new Subject<void>(); |
|
|
const handleRes$ = new Subject<void>(); |
|
|
@ -71,10 +70,7 @@ describe('ApiInterceptor', () => { |
|
|
handleRes$.next(); |
|
|
handleRes$.next(); |
|
|
handleRes$.complete(); |
|
|
handleRes$.complete(); |
|
|
|
|
|
|
|
|
timer(0).subscribe(() => { |
|
|
expect(spyAddRequest).toHaveBeenCalled(); |
|
|
expect(spyAddRequest).toHaveBeenCalled(); |
|
|
expect(spyDeleteRequest).toHaveBeenCalled(); |
|
|
expect(spyDeleteRequest).toHaveBeenCalled(); |
|
|
|
|
|
done(); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|