Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should handle returning no Bot', async(inject([], () => {
let resp = new Response(new ResponseOptions({status: 200, body: {data: []}}));
backend.connections.subscribe((c: MockConnection) => c.mockRespond(resp));
service.getBot(100) // unknown id
.then(bot => expect(bot.id).not.toBeDefined('should have no Bot'));
})));
});
public appointmentExistsHeadAppointmentsid(id: string, extraHttpRequestParams?: any): Observable {
const path = this.basePath + `/appointments/${id}`;
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.values()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling appointmentExistsHeadAppointmentsid.');
}
// to determine the Content-Type header
let consumes: string[] = [
'application/json',
'application/x-www-form-urlencoded',
'application/xml',
'text/xml'
];
// to determine the Accept header
let produces: string[] = [
'application/json',
getRequestOptionArgs(options?: RequestOptionsArgs): RequestOptionsArgs {
if (options == null) {
options = new RequestOptions();
}
if (options.headers == null) {
options.headers = new Headers();
}
// ADD user AUTH
let sessionToken = this._authStore.getSessionToken();
if (sessionToken) {
options.headers.append(this._authStore.localStorageSessionKey, sessionToken);
} else {
let user = this._authStore.getUser();
if (user != null) {
options.headers.append('Authorization', 'Basic ' + user.token);
}
}
return options;
}
}
getCurrentUser(username?: string, password?: string): Observable {
if (this.conf.config.useBasicAuth && username && password) {
this.apiConf.username = username;
this.apiConf.password = password;
}
// the added timestamp of the query string forces legacy browsers to not cache the http response
// for current user. this fixes current user differentiated tests.
const search = new URLSearchParams(`v=${Date.now()}`.toString());
return this.currentUserApi.currentUserGetCurrentUserWithHttpInfo({search}).map((res) => {
this.userAuthorizations = res.json();
this._user.next(res.json());
this.encryptedUserIdentifier = this.encryptionService.encryptAndGet((res.json() as UserAuthorizations).userId);
return res.json();
});
}
const field: DotCMSContentTypeField = {
...dotcmsContentTypeFieldBasicMock,
contentTypeId: '1b',
id: '1'
};
this.fieldVariableService.load(field).subscribe((variables: DotFieldVariable[]) => {
expect(variables).toEqual(mockResponse.entity);
expect(0).toBe(this.lastConnection.request.method); // 2 is GET method
expect(this.lastConnection.request.url)
.toContain(`v1/contenttype/${field.contentTypeId}/fields/id/${field.id}/variables`);
});
this.lastConnection.mockRespond(
new Response(
new ResponseOptions({
body: JSON.stringify(mockResponse)
})
)
);
});
postWithPromise(apiUrl: string, body: any): Promise {
let headers = new Headers(
{
'Content-Type': 'application/json',
'Authorization': this.accessToken.token_type + ' ' + this.accessToken.access_token
});
// headers['Access-Control-Allow-Origin'] = '*'
let options = new RequestOptions(
{
method: RequestMethod.Post,
url: apiUrl,
headers: headers,
body: body
}
);
// this.spinnerService.show();
let request = this.http.request(apiUrl, options);
return request.toPromise()
.then(result => this.extractData(options, result
, this.spinnerService
))
.catch(errors => this.handleErrorPromise(options, errors
, this.spinnerService
));
}
extractData(request: RequestOptions, res: Response
setTimeout(() => {
// get all employees
if (connection.request.url.endsWith('/fake-backend/employees') &&
connection.request.method === RequestMethod.Get) {
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: data
})));
return;
}
// create employee
if (connection.request.url.endsWith('/fake-backend/employees') &&
connection.request.method === RequestMethod.Post) {
let receivedEmployee = JSON.parse(connection.request.getBody());
let newEmployee = Object.assign(receivedEmployee, {id: uuid.generate()});
data[data.length] = newEmployee;
localStorage.setItem('employees', JSON.stringify(data));
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: newEmployee
})));
return;
}
// update employee
if (connection.request.url.endsWith('/fake-backend/employees') &&
let newEmployee = Object.assign(receivedEmployee, {id: uuid.generate()});
data[data.length] = newEmployee;
localStorage.setItem('employees', JSON.stringify(data));
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: newEmployee
})));
return;
}
// update employee
if (connection.request.url.endsWith('/fake-backend/employees') &&
connection.request.method === RequestMethod.Put) {
let receivedEmployee = JSON.parse(connection.request.getBody());
let clonedEmployee = Object.assign({}, receivedEmployee);
let employeeWasFound = false;
data.some((element: Employee, index: number) => {
if (element.id === clonedEmployee.id) {
data[index] = clonedEmployee;
employeeWasFound = true;
return true;
}
});
if (!employeeWasFound) {
connection.mockRespond(new Response(new ResponseOptions({
status: 400,
body: 'Employee could not be updated because was not found'
})));
beforeEach(() => {
backend = TestBed.get(XHRBackend);
http = TestBed.get(Http);
service = new HttpHeroService(http);
fakeHeroes = makeHeroData();
let options = new ResponseOptions({status: 200, body: {data: fakeHeroes}});
response = new Response(options);
});
cloudmersiveDetect(form: FormGroup) {
const headers = new Headers({
'ApiKey': '59710ec3-24ee-4d4c-a90e-efb6170e2f50',
});
const options = new RequestOptions({
headers: headers
});
console.log("cloudmersiveDetect");
console.log(this.http.post("https://api.cloudmersive.com/image/recognize/describe", form ,options).map(res => res.json()));
return this.http.post("https://api.cloudmersive.com/image/recognize/describe", form ,options).map(res => res.json());
}