This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #462 from christianvogt/httpclient
fix(httpclient): move to HttpClient in preparation for ng6
- Loading branch information
Showing
21 changed files
with
477 additions
and
552 deletions.
There are no files selected for viewing
54 changes: 25 additions & 29 deletions
54
src/app/stack/card-details/card-details.component.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 |
---|---|---|
@@ -1,42 +1,38 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { Http, ConnectionBackend, RequestOptions, BaseRequestOptions } from '@angular/http'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { TabsModule } from 'ngx-bootstrap'; | ||
|
||
import { CardDetailsComponent } from './card-details.component'; | ||
import { ReportInformationModule } from './report-information/report-information.module'; | ||
|
||
const imports = [ | ||
TabsModule, | ||
ReportInformationModule | ||
TabsModule, | ||
ReportInformationModule, | ||
HttpClientModule | ||
]; | ||
|
||
describe ('CardDetailsComponent', () => { | ||
let component: CardDetailsComponent; | ||
let fixture: ComponentFixture<CardDetailsComponent>; | ||
describe('CardDetailsComponent', () => { | ||
let component: CardDetailsComponent; | ||
let fixture: ComponentFixture<CardDetailsComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
...imports | ||
], | ||
declarations: [ | ||
CardDetailsComponent | ||
], | ||
providers: [ | ||
Http, | ||
ConnectionBackend, | ||
{ provide: RequestOptions, useClass: BaseRequestOptions } | ||
] | ||
}).compileComponents(); | ||
})); | ||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
...imports | ||
], | ||
declarations: [ | ||
CardDetailsComponent | ||
] | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CardDetailsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CardDetailsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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
50 changes: 24 additions & 26 deletions
50
src/app/stack/card-details/report-information/no-data/no-data.component.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 |
---|---|---|
@@ -1,40 +1,38 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { Http, ConnectionBackend, RequestOptions, BaseRequestOptions } from '@angular/http'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
|
||
import { | ||
MCardDetails | ||
MCardDetails | ||
} from '../../../models/ui.model'; | ||
|
||
import { NoDataComponent } from './no-data.component'; | ||
|
||
const components = [ | ||
NoDataComponent | ||
NoDataComponent | ||
]; | ||
|
||
describe ('NoDataComponent', () => { | ||
let component: NoDataComponent; | ||
let fixture: ComponentFixture<NoDataComponent>; | ||
describe('NoDataComponent', () => { | ||
let component: NoDataComponent; | ||
let fixture: ComponentFixture<NoDataComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
...components | ||
], | ||
providers: [ | ||
Http, | ||
ConnectionBackend, | ||
{ provide: RequestOptions, useClass: BaseRequestOptions } | ||
] | ||
}).compileComponents(); | ||
})); | ||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
...components | ||
], | ||
imports: [ | ||
HttpClientModule | ||
] | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(NoDataComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
beforeEach(() => { | ||
fixture = TestBed.createComponent(NoDataComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,46 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Http, Response, Headers, RequestOptions } from '@angular/http'; | ||
import { HttpErrorResponse, HttpHeaders, HttpClient, HttpResponse } from '@angular/common/http'; | ||
import { AuthenticationService } from 'ngx-login-client'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import 'rxjs/add/operator/catch'; | ||
import 'rxjs/operators/map'; | ||
|
||
@Injectable() | ||
export class FeedbackService { | ||
private headers: Headers = new Headers({'Content-Type': 'application/json'}); | ||
constructor( | ||
private http: Http, | ||
private auth: AuthenticationService) { | ||
if (this.auth.getToken() !== null) { | ||
this.headers.set('Authorization', 'Bearer ' + this.auth.getToken()); | ||
} | ||
} | ||
private headers: HttpHeaders = new HttpHeaders({'Content-Type': 'application/json'}); | ||
constructor( | ||
private http: HttpClient, | ||
private auth: AuthenticationService) { | ||
if (this.auth.getToken() !== null) { | ||
this.headers.set('Authorization', 'Bearer ' + this.auth.getToken()); | ||
} | ||
} | ||
|
||
public submit(feedback: any): Observable<any> { | ||
let url: string = 'https://recommender.api.openshift.io/api/v1/user-feedback'; | ||
let options: RequestOptions = new RequestOptions({ | ||
headers: this.headers | ||
}); | ||
public submit(feedback: any): Observable<any> { | ||
let url: string = 'https://recommender.api.openshift.io/api/v1/user-feedback'; | ||
let options = { | ||
headers: this.headers | ||
}; | ||
|
||
return this.http | ||
.post(url, JSON.stringify(feedback), options) | ||
.map(this.extractData) | ||
.catch(this.handleError); | ||
} | ||
return this.http | ||
.post<any>(url, JSON.stringify(feedback), options) | ||
.map(this.extractData) | ||
.catch(this.handleError); | ||
} | ||
|
||
private extractData(res: Response) { | ||
let body = res.json(); | ||
return body || {}; | ||
} | ||
private extractData(body: any): any { | ||
return body || {}; | ||
} | ||
|
||
private handleError(error: Response | any) { | ||
// In a real world app, we might use a remote logging infrastructure | ||
let errMsg: string; | ||
if (error instanceof Response) { | ||
const body = error.json() || ''; | ||
const err = body.error || JSON.stringify(body); | ||
errMsg = `${error.status} - ${error.statusText || ''} ${err}`; | ||
} else { | ||
errMsg = error.message ? error.message : error.toString(); | ||
} | ||
console.error(errMsg); | ||
return Observable.throw(errMsg); | ||
private handleError(error: HttpErrorResponse) { | ||
let errMsg: string; | ||
if (error.error instanceof ErrorEvent) { | ||
errMsg = error.error.message || error.error.toString(); | ||
} else { | ||
const body = error.error || ''; | ||
const err = body.error || JSON.stringify(body); | ||
errMsg = `${error.status} - ${error.statusText || ''} ${err}`; | ||
} | ||
return Observable.throw(errMsg); | ||
} | ||
} |
Oops, something went wrong.