forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and implement unit and e2e tests
- Loading branch information
1 parent
26edcdf
commit 6b808d7
Showing
5 changed files
with
88 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...mo-template/angular2-product-app/src/main/frontend/src/app/keycloak/keycloak.http.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {Injectable, ReflectiveInjector} from '@angular/core'; | ||
import {async, fakeAsync, tick} from '@angular/core/testing'; | ||
import {BaseRequestOptions, ConnectionBackend, Http, RequestOptions} from '@angular/http'; | ||
import {Response, ResponseOptions} from '@angular/http'; | ||
import {MockBackend, MockConnection} from '@angular/http/testing'; | ||
|
||
import { KeycloakHttp, KEYCLOAK_HTTP_PROVIDER, keycloakHttpFactory } from './keycloak.http'; | ||
import { KeycloakService } from './keycloak.service'; | ||
|
||
@Injectable() | ||
class MockKeycloakService extends KeycloakService { | ||
getToken(): Promise<string> { | ||
return Promise.resolve('hello'); | ||
} | ||
} | ||
|
||
describe('KeycloakHttp', () => { | ||
|
||
let injector: ReflectiveInjector; | ||
let backend: MockBackend; | ||
let lastConnection: MockConnection; | ||
let http: Http; | ||
|
||
beforeEach(() => { | ||
injector = ReflectiveInjector.resolveAndCreate([ | ||
{provide: ConnectionBackend, useClass: MockBackend}, | ||
{provide: RequestOptions, useClass: BaseRequestOptions}, | ||
{provide: KeycloakService, useClass: MockKeycloakService}, | ||
{ | ||
provide: Http, | ||
useFactory: keycloakHttpFactory, | ||
deps: [ConnectionBackend, RequestOptions, KeycloakService] | ||
} | ||
]); | ||
http = injector.get(Http); | ||
backend = injector.get(ConnectionBackend) as MockBackend; | ||
backend.connections.subscribe((c: MockConnection) => lastConnection = c); | ||
}); | ||
|
||
it('should set Authorization header', fakeAsync(() => { | ||
http.get('foo').subscribe(r => console.log(r)); | ||
tick(); | ||
expect(lastConnection).toBeDefined('no http service connection at all?'); | ||
expect(lastConnection.request.headers.get('Authorization')).toBe('Bearer hello'); | ||
})); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters