Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} else {
var id = parseInt(request.url.split('/')[1]);
mediaItems = this._mediaItems.filter(mediaItem => mediaItem.id === id);
responseOptions = new ResponseOptions({
body: JSON.parse(JSON.stringify(mediaItems[0])),
status: 200
});
}
break;
case RequestMethod.Post:
var mediaItem = JSON.parse(request.text().toString());
mediaItem.id = this._getNewId();
this._mediaItems.push(mediaItem);
responseOptions = new ResponseOptions({ status: 201 });
break;
case RequestMethod.Delete:
var id = parseInt(request.url.split('/')[1]);
this._deleteMediaItem(id);
responseOptions = new ResponseOptions({ status: 200 });
}
var responseObject = new Response(responseOptions);
responseObserver.next(responseObject);
responseObserver.complete();
return () => { };
});
return { response };
delete(url: string, options?: JwtRequestOptionsArgs): Observable {
options = options || {};
options.method = RequestMethod.Delete;
return this.request(url, options);
}
return 'create';
}
if (method === 'put') {
return 'update';
}
if (method === 'delete') {
return 'delete';
}
} else if (typeof method === 'number') {
if (method === RequestMethod.Post) {
return 'create';
}
if (method === RequestMethod.Put) {
return 'update';
}
if (method === RequestMethod.Delete) {
return 'delete';
}
}
return 'fetch';
}
return 'create';
}
if (method === 'put') {
return 'update';
}
if (method === 'delete') {
return 'delete';
}
} else if (typeof method === 'number') {
if (method === RequestMethod.Post) {
return 'create';
}
if (method === RequestMethod.Put) {
return 'update';
}
if (method === RequestMethod.Delete) {
return 'delete';
}
}
return 'fetch';
}
deleteRule(ruleId: string): Observable<{ success: boolean } | CwError> {
const siteId = this.loadRulesSiteId();
return this.coreWebService
.request({
method: RequestMethod.Delete,
url: `${this._apiRoot.baseUrl}api/v1/sites/${siteId}${this._rulesEndpointUrl}/${ruleId}`
}).pipe(
map(result => {
return { success: true };
}));
}
backend.connections.subscribe((connection: MockConnection) => {
expect(connection.request.method).toBe(RequestMethod.Delete)
//expect(connection.request.url).toBe(`/experiments/${expId}`)
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: {
status: true
}
})))
backendSpy()
})
public delete(url: string, paramMap: any = null, success: Function=function(successful, data, res){}, error: Function=function(successful, msg, err){}): any {
return this.request(url, new RequestOptions({
method: RequestMethod.Delete,
search: HttpService.buildURLSearchParams(paramMap).toString()
}), success, error);
}
mockBackend.connections.subscribe((connection: MockConnection) => {
expect(connection.request.url).toBe(
'www.url.com/path/to/endpoint/id-of-something',
'url with :id didnt match the expected url',
);
expect(connection.request.method).toBe(RequestMethod.Delete, 'request didnt have DELETE method');
connection.mockRespond(
new Response(
new ResponseOptions({
status: 200,
body: JSON.stringify('success'),
}),
),
);
});
let success: boolean = false;
public delete(url: string, apiName?: string, params?: any): Observable {
return this.request({
method: RequestMethod.Delete,
url: url,
params: params,
apiName: apiName
});
}
mockBackend.connections.subscribe((connection: MockConnection) => {
expect(connection.request.url)
.toBe('www.url.com/path/to/endpoint/id-of-something',
'url with :id didnt match the expected url');
expect(connection.request.method).toBe(RequestMethod.Delete, 'request didnt have DELETE method');
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: JSON.stringify('success')},
)));
});
let success: boolean = false;